From 54d51480ee5c59faf99f1c3c7fa1dc09930593e4 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Wed, 14 Jun 2017 21:44:29 +0100 Subject: [PATCH] Use tempest.test.BaseTestCase for murano tempest tests While Tempest's own plugin documentation recommends that plugins only consume tempest.lib [0], the BaseTestCase in tempest.test is more feature-rich, comprehensive, and fault-tolerant than the BaseTestCase in tempest.lib. Many plugins like keystone_tempest_plugin already use the BaseTestCase in tempest.test. Also, QA PTL said it would be fine to make the transition when asked in IRC [1][2]. This commit specifically: - uses the base tempest class pattern specified in `tempest.test.BaseTestCase`: skip_checks for skipping tests based on environment config settings; setup_clients for instantiating clients and client managers; resource_setup for setting up class-level resources; and resource_cleanup for cleaning up class-level resources - removes unusued helpers like verify_nonempty, except in classes that explicitly already use it - removes clearing credentials in tearDown because the code isn't even executed due to a bug introduced by I51434685555c1da92401891a60285bf52571b8b5 - separate admin clients from non-admin clients by using os_admin vs os_primary [0] https://docs.openstack.org/developer/tempest/plugin.html#plugin-structure [1] http://eavesdrop.openstack.org/irclogs/%23openstack-qa/%23openstack-qa.2017-06-12.log.html#t2017-06-12T20:38:19 [2] http://eavesdrop.openstack.org/irclogs/%23openstack-qa/%23openstack-qa.2017-06-12.log.html#t2017-06-12T21:45:56 Change-Id: Ia09dbc52ba13ca822a539e509e0e517592435aec --- .../api/application_catalog/artifacts/base.py | 51 +++------ .../tests/api/application_catalog/base.py | 80 +++++-------- .../tests/api/service_broker/base.py | 102 +++++++++-------- .../scenario/application_catalog/base.py | 107 ++++++++---------- 4 files changed, 144 insertions(+), 196 deletions(-) diff --git a/murano_tempest_tests/tests/api/application_catalog/artifacts/base.py b/murano_tempest_tests/tests/api/application_catalog/artifacts/base.py index c443bb4..e7d993c 100644 --- a/murano_tempest_tests/tests/api/application_catalog/artifacts/base.py +++ b/murano_tempest_tests/tests/api/application_catalog/artifacts/base.py @@ -15,7 +15,7 @@ from tempest.common import credentials_factory as common_creds from tempest import config -from tempest.lib import base +from tempest import test from murano_tempest_tests import clients from murano_tempest_tests import utils @@ -23,22 +23,28 @@ from murano_tempest_tests import utils CONF = config.CONF -class BaseArtifactsTest(base.BaseTestCase): +class BaseArtifactsTest(test.BaseTestCase): """Base test class for Murano Glare tests.""" @classmethod - def setUpClass(cls): - super(BaseArtifactsTest, cls).setUpClass() - cls.resource_setup() + def skip_checks(cls): + super(BaseArtifactsTest, cls).skip_checks() + if not CONF.service_available.murano: + skip_msg = "Murano is disabled" + raise cls.skipException(skip_msg) @classmethod - def tearDownClass(cls): - cls.resource_cleanup() - super(BaseArtifactsTest, cls).tearDownClass() + def setup_clients(cls): + super(BaseArtifactsTest, cls).setup_clients() + if not hasattr(cls, "os_primary"): + creds = cls.get_configured_isolated_creds(type_of_creds='primary') + cls.os_primary = clients.Manager(credentials=creds) + cls.artifacts_client = cls.os_primary.artifacts_client + cls.application_catalog_client = \ + cls.os_primary.application_catalog_client @classmethod def get_client_with_isolated_creds(cls, type_of_creds="admin"): - creds = cls.get_configured_isolated_creds(type_of_creds=type_of_creds) os = clients.Manager(credentials=creds) @@ -69,33 +75,6 @@ class BaseArtifactsTest(base.BaseTestCase): return creds.credentials - @classmethod - def verify_nonempty(cls, *args): - if not all(args): - msg = "Missing API credentials in configuration." - raise cls.skipException(msg) - - @classmethod - def resource_setup(cls): - if not CONF.service_available.murano: - skip_msg = "Murano is disabled" - raise cls.skipException(skip_msg) - if not hasattr(cls, "os_primary"): - creds = cls.get_configured_isolated_creds(type_of_creds='primary') - cls.os_primary = clients.Manager(credentials=creds) - cls.artifacts_client = cls.os_primary.artifacts_client - cls.application_catalog_client = \ - cls.os_primary.application_catalog_client - - @classmethod - def resource_cleanup(cls): - cls.clear_isolated_creds() - - @classmethod - def clear_isolated_creds(cls): - if hasattr(cls, "dynamic_cred"): - cls.credentials.clear_creds() - @classmethod def upload_package(cls, application_name, version=None, require=None): abs_archive_path, dir_with_archive, archive_name = \ diff --git a/murano_tempest_tests/tests/api/application_catalog/base.py b/murano_tempest_tests/tests/api/application_catalog/base.py index 0f13088..6dce950 100644 --- a/murano_tempest_tests/tests/api/application_catalog/base.py +++ b/murano_tempest_tests/tests/api/application_catalog/base.py @@ -15,7 +15,7 @@ from tempest.common import credentials_factory as common_creds from tempest import config -from tempest.lib import base +from tempest import test from murano_tempest_tests import clients from murano_tempest_tests import utils @@ -23,22 +23,28 @@ from murano_tempest_tests import utils CONF = config.CONF -class BaseApplicationCatalogTest(base.BaseTestCase): +class BaseApplicationCatalogTest(test.BaseTestCase): """Base test class for Murano Service Broker API tests.""" @classmethod - def setUpClass(cls): - super(BaseApplicationCatalogTest, cls).setUpClass() - cls.resource_setup() + def skip_checks(cls): + super(BaseApplicationCatalogTest, cls).skip_checks() + if not CONF.service_available.murano: + skip_msg = "Murano is disabled" + raise cls.skipException(skip_msg) @classmethod - def tearDownClass(cls): - cls.resource_cleanup() - super(BaseApplicationCatalogTest, cls).tearDownClass() + def setup_clients(cls): + super(BaseApplicationCatalogTest, cls).setup_clients() + if not hasattr(cls, "os_primary"): + creds = cls.get_configured_isolated_creds(type_of_creds='primary') + cls.os_primary = clients.Manager(credentials=creds) + cls.application_catalog_client = \ + cls.os_primary.application_catalog_client + cls.artifacts_client = cls.os_primary.artifacts_client @classmethod def get_client_with_isolated_creds(cls, type_of_creds="admin"): - creds = cls.get_configured_isolated_creds(type_of_creds=type_of_creds) os = clients.Manager(credentials=creds) @@ -53,11 +59,10 @@ class BaseApplicationCatalogTest(base.BaseTestCase): cls.admin_role = CONF.identity.admin_role else: cls.admin_role = 'admin' - if not hasattr(cls, 'dynamic_cred'): - cls.credentials = common_creds.get_credentials_provider( - name=cls.__name__, - force_tenant_isolation=CONF.auth.use_dynamic_credentials, - identity_version=CONF.identity.auth_version) + cls.credentials = common_creds.get_credentials_provider( + name=cls.__name__, + force_tenant_isolation=CONF.auth.use_dynamic_credentials, + identity_version=CONF.identity.auth_version) if type_of_creds == 'primary': creds = cls.credentials.get_primary_creds() elif type_of_creds == 'admin': @@ -70,33 +75,6 @@ class BaseApplicationCatalogTest(base.BaseTestCase): return creds.credentials - @classmethod - def verify_nonempty(cls, *args): - if not all(args): - msg = "Missing API credentials in configuration." - raise cls.skipException(msg) - - @classmethod - def resource_setup(cls): - if not CONF.service_available.murano: - skip_msg = "Murano is disabled" - raise cls.skipException(skip_msg) - if not hasattr(cls, "os_primary"): - creds = cls.get_configured_isolated_creds(type_of_creds='primary') - cls.os_primary = clients.Manager(credentials=creds) - cls.application_catalog_client = \ - cls.os_primary.application_catalog_client - cls.artifacts_client = cls.os_primary.artifacts_client - - @classmethod - def resource_cleanup(cls): - cls.clear_isolated_creds() - - @classmethod - def clear_isolated_creds(cls): - if hasattr(cls, "dynamic_cred"): - cls.credentials.clear_creds() - @staticmethod def _get_demo_app(): return { @@ -119,18 +97,14 @@ class BaseApplicationCatalogTest(base.BaseTestCase): } -class BaseApplicationCatalogAdminTest(BaseApplicationCatalogTest): - - @classmethod - def resource_setup(cls): - cls.os_primary = clients.Manager() - super(BaseApplicationCatalogAdminTest, cls).resource_setup() - - class BaseApplicationCatalogIsolatedAdminTest(BaseApplicationCatalogTest): @classmethod - def resource_setup(cls): - creds = cls.get_configured_isolated_creds(type_of_creds='admin') - cls.os_primary = clients.Manager(credentials=creds) - super(BaseApplicationCatalogIsolatedAdminTest, cls).resource_setup() + def setup_clients(cls): + super(BaseApplicationCatalogIsolatedAdminTest, cls).setup_clients() + if not hasattr(cls, "os_admin"): + creds = cls.get_configured_isolated_creds(type_of_creds='admin') + cls.os_admin = clients.Manager(credentials=creds) + cls.application_catalog_client = \ + cls.os_admin.application_catalog_client + cls.artifacts_client = cls.os_admin.artifacts_client diff --git a/murano_tempest_tests/tests/api/service_broker/base.py b/murano_tempest_tests/tests/api/service_broker/base.py index b754ece..14222ec 100644 --- a/murano_tempest_tests/tests/api/service_broker/base.py +++ b/murano_tempest_tests/tests/api/service_broker/base.py @@ -18,55 +18,20 @@ import time from tempest.common import credentials_factory as common_creds from tempest import config -from tempest.lib import base from tempest.lib import exceptions +from tempest import test from murano_tempest_tests import clients CONF = config.CONF -class BaseServiceBrokerTest(base.BaseTestCase): +class BaseServiceBrokerTest(test.BaseTestCase): """Base test class for Murano Service Broker API tests.""" @classmethod - def setUpClass(cls): - super(BaseServiceBrokerTest, cls).setUpClass() - cls.resource_setup() - - @classmethod - def tearDownClass(cls): - cls.resource_cleanup() - super(BaseServiceBrokerTest, cls).tearDownClass() - - @classmethod - def get_client_with_isolated_creds(cls, name=None, - type_of_creds="admin"): - cls.credentials = common_creds.get_credentials_provider( - name=cls.__name__, - force_tenant_isolation=CONF.auth.use_dynamic_credentials, - identity_version=CONF.identity.auth_version) - if "admin" in type_of_creds: - creds = cls.credentials.get_admin_creds() - elif "alt" in type_of_creds: - creds = cls.credentials.get_alt_creds() - else: - creds = cls.credentials.get_credentials(type_of_creds) - cls.credentials.type_of_creds = type_of_creds - - os = clients.Manager(credentials=creds) - client = os.service_broker_client - - return client - - @classmethod - def verify_nonempty(cls, *args): - if not all(args): - msg = "Missing API credentials in configuration." - raise cls.skipException(msg) - - @classmethod - def resource_setup(cls): + def skip_checks(cls): + super(BaseServiceBrokerTest, cls).skip_checks() if not CONF.service_broker.run_service_broker_tests: skip_msg = "Service Broker API tests are disabled" raise cls.skipException(skip_msg) @@ -76,6 +41,10 @@ class BaseServiceBrokerTest(base.BaseTestCase): if not CONF.service_available.murano: skip_msg = "Murano is disabled" raise cls.skipException(skip_msg) + + @classmethod + def setup_clients(cls): + super(BaseServiceBrokerTest, cls).setup_clients() if not hasattr(cls, "os_primary"): cls.username = CONF.identity.username cls.password = CONF.identity.password @@ -86,18 +55,43 @@ class BaseServiceBrokerTest(base.BaseTestCase): cls.application_catalog_client = \ cls.os_primary.application_catalog_client - def setUp(self): - super(BaseServiceBrokerTest, self).setUp() - self.addCleanup(self.clear_isolated_creds) + @classmethod + def get_client_with_isolated_creds(cls, type_of_creds="admin"): + creds = cls.get_configured_isolated_creds(type_of_creds=type_of_creds) + + os = clients.Manager(credentials=creds) + client = os.application_catalog_client + + return client @classmethod - def resource_cleanup(cls): - cls.clear_isolated_creds() + def get_configured_isolated_creds(cls, type_of_creds='admin'): + identity_version = CONF.identity.auth_version + if identity_version == 'v3': + cls.admin_role = CONF.identity.admin_role + else: + cls.admin_role = 'admin' + cls.credentials = common_creds.get_credentials_provider( + name=cls.__name__, + force_tenant_isolation=CONF.auth.use_dynamic_credentials, + identity_version=CONF.identity.auth_version) + if type_of_creds == 'primary': + creds = cls.credentials.get_primary_creds() + elif type_of_creds == 'admin': + creds = cls.credentials.get_admin_creds() + elif type_of_creds == 'alt': + creds = cls.credentials.get_alt_creds() + else: + creds = cls.credentials.get_credentials(type_of_creds) + cls.credentials.type_of_creds = type_of_creds + + return creds.credentials @classmethod - def clear_isolated_creds(cls): - if hasattr(cls, "dynamic_cred"): - cls.credentials.clear_creds() + def verify_nonempty(cls, *args): + if not all(args): + msg = "Missing API credentials in configuration." + raise cls.skipException(msg) def wait_for_result(self, instance_id, timeout): start_time = time.time() @@ -129,6 +123,14 @@ class BaseServiceBrokerTest(base.BaseTestCase): class BaseServiceBrokerAdminTest(BaseServiceBrokerTest): @classmethod - def resource_setup(cls): - cls.os_primary = clients.Manager() - super(BaseServiceBrokerAdminTest, cls).resource_setup() + def setup_clients(cls): + super(BaseServiceBrokerTest, cls).setup_clients() + if not hasattr(cls, "os_admin"): + cls.username = CONF.identity.username + cls.password = CONF.identity.password + cls.tenant_name = CONF.identity.tenant_name + cls.verify_nonempty(cls.username, cls.password, cls.tenant_name) + cls.os_admin = clients.Manager() + cls.service_broker_client = cls.os_admin.service_broker_client + cls.application_catalog_client = \ + cls.os_admin.application_catalog_client diff --git a/murano_tempest_tests/tests/scenario/application_catalog/base.py b/murano_tempest_tests/tests/scenario/application_catalog/base.py index 355b899..d81c2ba 100644 --- a/murano_tempest_tests/tests/scenario/application_catalog/base.py +++ b/murano_tempest_tests/tests/scenario/application_catalog/base.py @@ -21,8 +21,8 @@ from tempest.clients import Manager as services_manager from tempest.common import credentials_factory as common_creds from tempest.common import waiters from tempest import config -from tempest.lib import base from tempest.lib import exceptions +from tempest import test from murano_tempest_tests import clients from murano_tempest_tests import utils @@ -30,22 +30,42 @@ from murano_tempest_tests import utils CONF = config.CONF -class BaseApplicationCatalogScenarioTest(base.BaseTestCase): +class BaseApplicationCatalogScenarioTest(test.BaseTestCase): """Base test class for Murano Application Catalog Scenario tests.""" @classmethod - def setUpClass(cls): - super(BaseApplicationCatalogScenarioTest, cls).setUpClass() - cls.resource_setup() + def skip_checks(cls): + super(BaseApplicationCatalogScenarioTest, cls).skip_checks() + if not CONF.service_available.murano: + skip_msg = "Murano is disabled" + raise cls.skipException(skip_msg) @classmethod - def tearDownClass(cls): - cls.resource_cleanup() - super(BaseApplicationCatalogScenarioTest, cls).tearDownClass() + def setup_clients(cls): + super(BaseApplicationCatalogScenarioTest, cls).setup_clients() + if not hasattr(cls, "os_primary"): + creds = cls.get_configured_isolated_creds(type_of_creds='primary') + cls.os_primary = clients.Manager(credentials=creds) + cls.services_manager = services_manager(creds) + + cls.application_catalog_client = \ + cls.os_primary.application_catalog_client + cls.artifacts_client = cls.os_primary.artifacts_client + cls.servers_client = cls.services_manager.servers_client + cls.orchestration_client = cls.services_manager.orchestration_client + cls.snapshots_client = cls.services_manager.snapshots_v2_client + cls.volumes_client = cls.services_manager.volumes_v2_client + cls.backups_client = cls.services_manager.backups_v2_client + cls.images_client = cls.services_manager.image_client_v2 + + @classmethod + def resource_setup(cls): + super(BaseApplicationCatalogScenarioTest, cls).resource_setup() + cls.linux_image = CONF.application_catalog.linux_image + cls.cirros_image = cls.get_required_image_name() @classmethod def get_client_with_isolated_creds(cls, type_of_creds="admin"): - creds = cls.get_configured_isolated_creds(type_of_creds=type_of_creds) os = clients.Manager(credentials=creds) @@ -60,11 +80,10 @@ class BaseApplicationCatalogScenarioTest(base.BaseTestCase): cls.admin_role = CONF.identity.admin_role else: cls.admin_role = 'admin' - if not hasattr(cls, 'dynamic_cred'): - cls.credentials = common_creds.get_credentials_provider( - name=cls.__name__, - force_tenant_isolation=CONF.auth.use_dynamic_credentials, - identity_version=CONF.identity.auth_version) + cls.credentials = common_creds.get_credentials_provider( + name=cls.__name__, + force_tenant_isolation=CONF.auth.use_dynamic_credentials, + identity_version=CONF.identity.auth_version) if type_of_creds == 'primary': creds = cls.credentials.get_primary_creds() elif type_of_creds == 'admin': @@ -77,48 +96,11 @@ class BaseApplicationCatalogScenarioTest(base.BaseTestCase): return creds.credentials - @classmethod - def verify_nonempty(cls, *args): - if not all(args): - msg = "Missing API credentials in configuration." - raise cls.skipException(msg) - - @classmethod - def resource_setup(cls): - if not CONF.service_available.murano: - skip_msg = "Murano is disabled" - raise cls.skipException(skip_msg) - if not hasattr(cls, "os_primary"): - creds = cls.get_configured_isolated_creds(type_of_creds='primary') - cls.os_primary = clients.Manager(credentials=creds) - cls.services_manager = services_manager(creds) - - cls.linux_image = CONF.application_catalog.linux_image - cls.application_catalog_client = \ - cls.os_primary.application_catalog_client - cls.artifacts_client = cls.os_primary.artifacts_client - cls.servers_client = cls.services_manager.servers_client - cls.orchestration_client = cls.services_manager.orchestration_client - cls.snapshots_client = cls.services_manager.snapshots_v2_client - cls.volumes_client = cls.services_manager.volumes_v2_client - cls.backups_client = cls.services_manager.backups_v2_client - cls.images_client = cls.services_manager.image_client_v2 - cls.cirros_image = cls.get_required_image_name() - @classmethod def get_required_image_name(cls): image = cls.images_client.show_image(CONF.compute.image_ref) return image['name'] - @classmethod - def resource_cleanup(cls): - cls.clear_isolated_creds() - - @classmethod - def clear_isolated_creds(cls): - if hasattr(cls, "dynamic_cred"): - cls.credentials.clear_creds() - def environment_delete(self, environment_id, timeout=180): self.application_catalog_client.delete_environment(environment_id) @@ -399,9 +381,20 @@ class BaseApplicationCatalogScenarioIsolatedAdminTest( BaseApplicationCatalogScenarioTest): @classmethod - def resource_setup(cls): - creds = cls.get_configured_isolated_creds(type_of_creds='admin') - cls.os_primary = clients.Manager(credentials=creds) - cls.services_manager = services_manager(creds) - super(BaseApplicationCatalogScenarioIsolatedAdminTest, cls).\ - resource_setup() + def setup_clients(cls): + super(BaseApplicationCatalogScenarioIsolatedAdminTest, + cls).setup_clients() + if not hasattr(cls, "os_admin"): + creds = cls.get_configured_isolated_creds(type_of_creds='admin') + cls.os_admin = clients.Manager(credentials=creds) + cls.services_manager = services_manager(creds) + + cls.application_catalog_client = \ + cls.os_admin.application_catalog_client + cls.artifacts_client = cls.os_admin.artifacts_client + cls.servers_client = cls.services_manager.servers_client + cls.orchestration_client = cls.services_manager.orchestration_client + cls.snapshots_client = cls.services_manager.snapshots_v2_client + cls.volumes_client = cls.services_manager.volumes_v2_client + cls.backups_client = cls.services_manager.backups_v2_client + cls.images_client = cls.services_manager.image_client_v2