From f27ee7c1f6972dbaa6b3e22b0259ac3dda8140a2 Mon Sep 17 00:00:00 2001 From: Aurelien Lourot Date: Fri, 9 Oct 2020 11:44:03 +0200 Subject: [PATCH] Make determination of app under test more robust --- zaza/openstack/charm_tests/test_utils.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index 9157bd344..74b76b27b 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -127,10 +127,28 @@ def setUpClass(cls, application_name=None, model_alias=None): else: cls.model_name = model.get_juju_model() cls.test_config = lifecycle_utils.get_charm_config(fatal=False) + charm_under_test_name = cls.test_config['charm_name'] + if application_name: cls.application_name = application_name else: - cls.application_name = cls.test_config['charm_name'] + deployed_app_names = model.sync_deployed(model_name=cls.model_name) + if charm_under_test_name in deployed_app_names: + # There is an application named like the charm under test. + # Let's consider it the application under test: + cls.application_name = charm_under_test_name + else: + # Let's search for any application whose name starts with the + # name of the charm under test and assume it's the application + # under test: + for app_name in deployed_app_names: + if app_name.startswith(charm_under_test_name): + cls.application_name = app_name + break + else: + logging.warning('Could not find application under test') + return + cls.lead_unit = model.get_lead_unit_name( cls.application_name, model_name=cls.model_name)