Merge "Refactor duplicate isolated creds code"
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 37573c4..5679a45 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -19,7 +19,6 @@
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 @@
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 @@
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 98694c5..cdf8638 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 @@
@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 @@
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 fd897cd..edba709 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -26,6 +26,7 @@
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
@@ -220,6 +221,34 @@
level=None))
@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):
"""
Returns an instance of the Identity Admin API client