diff options
| author | Alex Schultz <aschultz@redhat.com> | 2018-04-19 16:49:06 -0600 |
|---|---|---|
| committer | Martin André <m.andre@redhat.com> | 2018-04-20 06:28:05 +0000 |
| commit | 00bdb6d01f9492f40f9091df7905f751b54c98bf (patch) | |
| tree | 042bb9b51fd44683b9cf7da90ba7545c64b82295 /kolla | |
| parent | da329dd7be0a4693b947272929581741906f33ad (diff) | |
| download | kolla-00bdb6d01f9492f40f9091df7905f751b54c98bf.tar.gz kolla-00bdb6d01f9492f40f9091df7905f751b54c98bf.zip | |
Add network_mode for image building
Add the ability to specify a different network_mode when running the
image builds. Under the covers the default is to use bridge networking
but if that is unavailable or a user would like to specify a different
networking method they can now do so using the [DEFAULT]\network_mode
configuration.
Change-Id: I1d2398273b57ca4d52bbfacbc896ffecc58bc54b
Diffstat (limited to 'kolla')
| -rwxr-xr-x | kolla/common/config.py | 2 | ||||
| -rwxr-xr-x | kolla/image/build.py | 1 | ||||
| -rw-r--r-- | kolla/tests/test_build.py | 25 |
3 files changed, 24 insertions, 4 deletions
diff --git a/kolla/common/config.py b/kolla/common/config.py index e2520bcf1..933db4fe8 100755 --- a/kolla/common/config.py +++ b/kolla/common/config.py @@ -204,6 +204,8 @@ _CLI_OPTS = [ help='Show all available images (filtering supported)'), cfg.StrOpt('namespace', short='n', default='kolla', help='The Docker namespace name'), + cfg.StrOpt('network_mode', default=None, + help='The network mode for Docker build. Example: host'), cfg.BoolOpt('cache', default=True, help='Use the Docker cache when building'), cfg.MultiOpt('profile', types.String(), short='p', diff --git a/kolla/image/build.py b/kolla/image/build.py index 2f19baadc..cd59aa260 100755 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -570,6 +570,7 @@ class BuildTask(DockerTask): tag=image.canonical_name, nocache=not self.conf.cache, rm=True, + network_mode=self.conf.network_mode, pull=pull, forcerm=self.forcerm, buildargs=buildargs): diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index be2dce7e9..9c3dc8abd 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -87,13 +87,30 @@ class TasksTest(base.TestCase): mock_client().build.assert_called_once_with( path=self.image.path, tag=self.image.canonical_name, - nocache=False, rm=True, pull=True, forcerm=True, + network_mode=None, nocache=False, rm=True, pull=True, forcerm=True, buildargs=None) self.assertTrue(builder.success) @mock.patch.dict(os.environ, clear=True) @mock.patch('docker.APIClient') + def test_build_image_with_network_mode(self, mock_client): + self.dc = mock_client + push_queue = mock.Mock() + self.conf.set_override('network_mode', 'host') + + builder = build.BuildTask(self.conf, self.image, push_queue) + builder.run() + + mock_client().build.assert_called_once_with( + path=self.image.path, tag=self.image.canonical_name, + network_mode='host', nocache=False, rm=True, pull=True, + forcerm=True, buildargs=None) + + self.assertTrue(builder.success) + + @mock.patch.dict(os.environ, clear=True) + @mock.patch('docker.APIClient') def test_build_image_with_build_arg(self, mock_client): self.dc = mock_client build_args = { @@ -107,7 +124,7 @@ class TasksTest(base.TestCase): mock_client().build.assert_called_once_with( path=self.image.path, tag=self.image.canonical_name, - nocache=False, rm=True, pull=True, forcerm=True, + network_mode=None, nocache=False, rm=True, pull=True, forcerm=True, buildargs=build_args) self.assertTrue(builder.success) @@ -126,7 +143,7 @@ class TasksTest(base.TestCase): mock_client().build.assert_called_once_with( path=self.image.path, tag=self.image.canonical_name, - nocache=False, rm=True, pull=True, forcerm=True, + network_mode=None, nocache=False, rm=True, pull=True, forcerm=True, buildargs=build_args) self.assertTrue(builder.success) @@ -147,7 +164,7 @@ class TasksTest(base.TestCase): mock_client().build.assert_called_once_with( path=self.image.path, tag=self.image.canonical_name, - nocache=False, rm=True, pull=True, forcerm=True, + network_mode=None, nocache=False, rm=True, pull=True, forcerm=True, buildargs=build_args) self.assertTrue(builder.success) |
