From c0747c0a0be91c8265ad2eb3e2c6b2f2630a1ca9 Mon Sep 17 00:00:00 2001 From: Quique Llorente Date: Tue, 2 Apr 2019 11:12:17 +0200 Subject: [PATCH] Use "push" flag for buildah The push=False flag with use with kolla-build.conf is not working if we use buildah, clear example is the tripleo-build-containers-centos-7-buildah job, it's suppose to work like docker one but it's pushing too. Closes-Bug: #1822752 Change-Id: I01788b3c11ac701b2cf8c151f95ccad7046532de --- lower-constraints.txt | 2 +- requirements.txt | 2 +- tripleoclient/tests/test_utils.py | 25 ++++++++++++++++++- .../tests/v1/test_container_image.py | 7 ++++++ tripleoclient/utils.py | 12 ++++++++- tripleoclient/v1/container_image.py | 3 ++- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 8b9832a95..d8513b93a 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -146,7 +146,7 @@ testscenarios===0.4 testtools==2.2.0 tooz==1.58.0 traceback2==1.4.0 -tripleo-common==10.6.0 +tripleo-common==10.6.1 ujson==1.35 unittest2==1.1.0 vine==1.1.4 diff --git a/requirements.txt b/requirements.txt index d2bb9b321..51e2d4136 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,5 @@ simplejson>=3.5.1 # MIT six>=1.10.0 # MIT osc-lib>=1.8.0 # Apache-2.0 websocket-client>=0.44.0 # LGPLv2+ -tripleo-common>=10.6.0 # Apache-2.0 +tripleo-common>=10.6.1 # Apache-2.0 cryptography>=2.1 # BSD/Apache-2.0 diff --git a/tripleoclient/tests/test_utils.py b/tripleoclient/tests/test_utils.py index 99de8c180..0192a7e8b 100644 --- a/tripleoclient/tests/test_utils.py +++ b/tripleoclient/tests/test_utils.py @@ -1394,6 +1394,29 @@ class TestConfigParser(TestCase): config = utils.get_from_cfg(cfg, 'bar', 'foo') self.assertEqual(config, 'baz') + def test_getboolean_config_value(self): + cfg = ConfigParser() + cfg.add_section('foo') + test_data_set = [ + (True, 'True'), + (True, 'true'), + (False, 'False'), + (False, 'false') + ] + for test_data in test_data_set: + expected_value, config_value = test_data + cfg.set('foo', 'bar', config_value) + obtained_value = utils.getboolean_from_cfg(cfg, 'bar', 'foo') + self.assertEqual(obtained_value, expected_value) + + def test_getboolean_bad_config_value(self): + cfg = ConfigParser() + cfg.add_section('foo') + cfg.set('foo', 'bar', 'I am not a boolean') + self.assertRaises(exceptions.NotFound, + utils.getboolean_from_cfg, + cfg, 'bar', 'foo') + def test_get_config_value_multiple_files(self): _, cfile1_name = tempfile.mkstemp(dir=self.tmp_dir, text=True) _, cfile2_name = tempfile.mkstemp(dir=self.tmp_dir, text=True) @@ -1411,7 +1434,7 @@ class TestConfigParser(TestCase): self.assertEqual(config, 'boop') def test_get_config_value_bad_file(self): - self.assertRaises(exceptions.NotFound, + self.assertRaises(AttributeError, utils.get_from_cfg, 'does-not-exist', 'bar', 'foo') diff --git a/tripleoclient/tests/v1/test_container_image.py b/tripleoclient/tests/v1/test_container_image.py index 0c146c230..64e052c9d 100644 --- a/tripleoclient/tests/v1/test_container_image.py +++ b/tripleoclient/tests/v1/test_container_image.py @@ -510,6 +510,8 @@ class TestContainerImageBuild(TestPluginV1): @mock.patch('tempfile.mkstemp') @mock.patch( 'tripleoclient.utils.get_from_cfg') + @mock.patch( + 'tripleoclient.utils.getboolean_from_cfg') @mock.patch('tripleo_common.image.builder.buildah.BuildahBuilder', autospec=True) @mock.patch('tripleo_common.image.kolla_builder.KollaImageBuilder', @@ -519,6 +521,7 @@ class TestContainerImageBuild(TestPluginV1): def test_container_image_build_with_buildah(self, mock_remove, mock_read_conf, mock_builder, mock_buildah, + mock_kolla_boolean_cfg, mock_kolla_cfg, mock_mkstemp, mock_mkdtemp, mock_fdopen): arglist = [ @@ -551,7 +554,11 @@ class TestContainerImageBuild(TestPluginV1): mock.call(mock_read_conf.return_value, 'namespace'), mock.call(mock_read_conf.return_value, 'registry'), ] + cfg_boolean_calls = [ + mock.call(mock_read_conf.return_value, 'push'), + ] mock_kolla_cfg.assert_has_calls(cfg_calls) + mock_kolla_boolean_cfg.assert_has_calls(cfg_boolean_calls) mock_bb.build_all.assert_called_once() @mock.patch('tripleo_common.image.kolla_builder.KollaImageBuilder', diff --git a/tripleoclient/utils.py b/tripleoclient/utils.py index 679526a98..b3759fcb9 100644 --- a/tripleoclient/utils.py +++ b/tripleoclient/utils.py @@ -1549,10 +1549,20 @@ def get_read_config(cfg): return config +def getboolean_from_cfg(cfg, param, section="DEFAULT"): + """Return a parameter from Kolla config""" + return _get_from_cfg(cfg, cfg.getboolean, param, section) + + def get_from_cfg(cfg, param, section="DEFAULT"): + """Return a parameter from Kolla config""" + return _get_from_cfg(cfg, cfg.get, param, section) + + +def _get_from_cfg(cfg, accessor, param, section): """Return a parameter from Kolla config""" try: - val = cfg.get(section, param) + val = accessor(section, param) except Exception: raise exceptions.NotFound(_("Unable to find {section}/{option} in " "{config}").format(section=param, diff --git a/tripleoclient/v1/container_image.py b/tripleoclient/v1/container_image.py index fbc5d08b7..8aa710582 100644 --- a/tripleoclient/v1/container_image.py +++ b/tripleoclient/v1/container_image.py @@ -213,7 +213,8 @@ class BuildImage(command.Command): utils.get_from_cfg(kolla_cfg, "type"), utils.get_from_cfg(kolla_cfg, "tag"), utils.get_from_cfg(kolla_cfg, "namespace"), - utils.get_from_cfg(kolla_cfg, "registry")) + utils.get_from_cfg(kolla_cfg, "registry"), + utils.getboolean_from_cfg(kolla_cfg, "push")) bb.build_all() elif parsed_args.list_dependencies: deps = json.loads(result)