From 6c4bb3d0bc4f3e4d9ae0c24d85df7e45a1ccf582 Mon Sep 17 00:00:00 2001 From: Ryan Hsu Date: Mon, 21 Oct 2013 21:22:50 -0700 Subject: [PATCH] Refactor duplicate isolated creds code The code to set the isolated credentials and the client manager for the compute and volume base test classes was duplicated. The duplicated code has been moved to tempest.test.BaseTestCase. Closes-Bug: #1177411 Change-Id: I70aeda46ab9f44a6726b7e1f256ef511a2f84218 --- tempest/api/compute/base.py | 16 ++-------------- tempest/api/volume/base.py | 14 ++------------ tempest/test.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py index 37573c4d95..5679a45d87 100644 --- a/tempest/api/compute/base.py +++ b/tempest/api/compute/base.py @@ -19,7 +19,6 @@ import time from tempest.api import compute from tempest import clients -from tempest.common import isolated_creds from tempest.common.utils.data_utils import parse_image_id from tempest.common.utils.data_utils import rand_name from tempest import exceptions @@ -42,21 +41,10 @@ class BaseComputeTest(tempest.test.BaseTestCase): if not cls.config.service_available.nova: skip_msg = ("%s skipped as nova is not available" % cls.__name__) raise cls.skipException(skip_msg) - cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__) - if (cls.config.compute.allow_tenant_isolation or - cls.force_tenant_isolation is True): - creds = cls.isolated_creds.get_primary_creds() - username, tenant_name, password = creds - os = clients.Manager(username=username, - password=password, - tenant_name=tenant_name, - interface=cls._interface) - else: - os = clients.Manager(interface=cls._interface) + os = cls.get_client_manager() cls.os = os - cls.build_interval = cls.config.compute.build_interval cls.build_timeout = cls.config.compute.build_timeout cls.ssh_user = cls.config.compute.ssh_user @@ -113,7 +101,7 @@ class BaseComputeTest(tempest.test.BaseTestCase): def tearDownClass(cls): cls.clear_images() cls.clear_servers() - cls.isolated_creds.clear_isolated_creds() + cls.clear_isolated_creds() super(BaseComputeTest, cls).tearDownClass() @classmethod diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py index 98694c59c5..cdf8638062 100644 --- a/tempest/api/volume/base.py +++ b/tempest/api/volume/base.py @@ -18,7 +18,6 @@ import time from tempest import clients -from tempest.common import isolated_creds from tempest.openstack.common import log as logging import tempest.test @@ -32,21 +31,12 @@ class BaseVolumeTest(tempest.test.BaseTestCase): @classmethod def setUpClass(cls): super(BaseVolumeTest, cls).setUpClass() - cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__) if not cls.config.service_available.cinder: skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) raise cls.skipException(skip_msg) - if cls.config.compute.allow_tenant_isolation: - creds = cls.isolated_creds.get_primary_creds() - username, tenant_name, password = creds - os = clients.Manager(username=username, - password=password, - tenant_name=tenant_name, - interface=cls._interface) - else: - os = clients.Manager(interface=cls._interface) + os = cls.get_client_manager() cls.os = os cls.volumes_client = os.volumes_client @@ -69,7 +59,7 @@ class BaseVolumeTest(tempest.test.BaseTestCase): def tearDownClass(cls): cls.clear_snapshots() cls.clear_volumes() - cls.isolated_creds.clear_isolated_creds() + cls.clear_isolated_creds() super(BaseVolumeTest, cls).tearDownClass() @classmethod diff --git a/tempest/test.py b/tempest/test.py index 8ce7af87a8..d665119d8f 100644 --- a/tempest/test.py +++ b/tempest/test.py @@ -26,6 +26,7 @@ import testresources import testtools from tempest import clients +from tempest.common import isolated_creds from tempest import config from tempest import exceptions from tempest.openstack.common import log as logging @@ -218,6 +219,34 @@ class BaseTestCase(testtools.TestCase, self.useFixture(fixtures.LoggerFixture(nuke_handlers=False, format=log_format)) + @classmethod + def get_client_manager(cls): + """ + Returns an Openstack client manager + """ + cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__) + + force_tenant_isolation = getattr(cls, 'force_tenant_isolation', None) + if (cls.config.compute.allow_tenant_isolation or + force_tenant_isolation): + creds = cls.isolated_creds.get_primary_creds() + username, tenant_name, password = creds + os = clients.Manager(username=username, + password=password, + tenant_name=tenant_name, + interface=cls._interface) + else: + os = clients.Manager(interface=cls._interface) + return os + + @classmethod + def clear_isolated_creds(cls): + """ + Clears isolated creds if set + """ + if getattr(cls, 'isolated_creds'): + cls.isolated_creds.clear_isolated_creds() + @classmethod def _get_identity_admin_client(cls): """