From 25cfab8651b105aaa68fd6e3685a4589877a5989 Mon Sep 17 00:00:00 2001 From: David Ames Date: Mon, 3 Dec 2018 19:33:06 +0000 Subject: [PATCH] Allow application_name parameter to config_change When the charm under test is not the self.application_name of the object of the setup/test class zaza.test_charms.test_utils.config_change would try to make a configuration change to the wrong charm. This lead to https://github.com/openstack-charmers/zaza/issues/168. This change allows passing application_name to config_change for when the charm under test is not the same as the object's self.application_name. Closes-Issue: https://github.com/openstack-charmers/zaza/issues/168 --- zaza/charm_tests/keystone/setup.py | 4 +++- zaza/charm_tests/test_utils.py | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/zaza/charm_tests/keystone/setup.py b/zaza/charm_tests/keystone/setup.py index 9a4d298..2e6b954 100644 --- a/zaza/charm_tests/keystone/setup.py +++ b/zaza/charm_tests/keystone/setup.py @@ -106,9 +106,11 @@ def add_demo_user(): _singleton = BaseKeystoneTest() _singleton.setUpClass() + # Explicitly set application name in case setup is called by a charm + # under test other than keystone. with _singleton.config_change( {'preferred-api-version': _singleton.default_api_version}, - {'preferred-api-version': '3'}): + {'preferred-api-version': '3'}, application_name="keystone"): _v3() else: # create only V3 user diff --git a/zaza/charm_tests/test_utils.py b/zaza/charm_tests/test_utils.py index 9c83e77..22de8ed 100644 --- a/zaza/charm_tests/test_utils.py +++ b/zaza/charm_tests/test_utils.py @@ -54,7 +54,8 @@ class OpenStackBaseTest(unittest.TestCase): logging.debug('Leader unit is {}'.format(cls.lead_unit)) @contextlib.contextmanager - def config_change(self, default_config, alternate_config): + def config_change(self, default_config, alternate_config, + application_name=None): """Run change config tests. Change config to `alternate_config`, wait for idle workload status, @@ -70,11 +71,17 @@ class OpenStackBaseTest(unittest.TestCase): :type default_config: dict :param alternate_config: Dict of charm settings to change to :type alternate_config: dict + :param application_name: String application name for use when called + by a charm under test other than the object's + application. + :type application_name: str """ + if not application_name: + application_name = self.application_name # we need to compare config values to what is already applied before # attempting to set them. otherwise the model will behave differently # than we would expect while waiting for completion of the change - _app_config = model.get_application_config(self.application_name) + _app_config = model.get_application_config(application_name) app_config = {} # convert the more elaborate config structure from libjuju to something # we can compare to what the caller supplies to this function @@ -97,7 +104,7 @@ class OpenStackBaseTest(unittest.TestCase): logging.debug('Changing charm setting to {}' .format(alternate_config)) model.set_application_config( - self.application_name, + application_name, alternate_config, model_name=self.model_name) @@ -117,7 +124,7 @@ class OpenStackBaseTest(unittest.TestCase): logging.debug('Restoring charm setting to {}'.format(default_config)) model.set_application_config( - self.application_name, + application_name, default_config, model_name=self.model_name)