Merge "Refactor duplicate isolated creds code"

This commit is contained in:
Jenkins 2013-10-28 15:20:44 +00:00 committed by Gerrit Code Review
commit bb8232f7d5
3 changed files with 33 additions and 26 deletions

View File

@ -19,7 +19,6 @@ import time
from tempest.api import compute from tempest.api import compute
from tempest import clients 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 parse_image_id
from tempest.common.utils.data_utils import rand_name from tempest.common.utils.data_utils import rand_name
from tempest import exceptions from tempest import exceptions
@ -42,21 +41,10 @@ class BaseComputeTest(tempest.test.BaseTestCase):
if not cls.config.service_available.nova: if not cls.config.service_available.nova:
skip_msg = ("%s skipped as nova is not available" % cls.__name__) skip_msg = ("%s skipped as nova is not available" % cls.__name__)
raise cls.skipException(skip_msg) raise cls.skipException(skip_msg)
cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
if (cls.config.compute.allow_tenant_isolation or os = cls.get_client_manager()
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)
cls.os = os cls.os = os
cls.build_interval = cls.config.compute.build_interval cls.build_interval = cls.config.compute.build_interval
cls.build_timeout = cls.config.compute.build_timeout cls.build_timeout = cls.config.compute.build_timeout
cls.ssh_user = cls.config.compute.ssh_user cls.ssh_user = cls.config.compute.ssh_user
@ -113,7 +101,7 @@ class BaseComputeTest(tempest.test.BaseTestCase):
def tearDownClass(cls): def tearDownClass(cls):
cls.clear_images() cls.clear_images()
cls.clear_servers() cls.clear_servers()
cls.isolated_creds.clear_isolated_creds() cls.clear_isolated_creds()
super(BaseComputeTest, cls).tearDownClass() super(BaseComputeTest, cls).tearDownClass()
@classmethod @classmethod

View File

@ -18,7 +18,6 @@
import time import time
from tempest import clients from tempest import clients
from tempest.common import isolated_creds
from tempest.openstack.common import log as logging from tempest.openstack.common import log as logging
import tempest.test import tempest.test
@ -32,21 +31,12 @@ class BaseVolumeTest(tempest.test.BaseTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(BaseVolumeTest, cls).setUpClass() super(BaseVolumeTest, cls).setUpClass()
cls.isolated_creds = isolated_creds.IsolatedCreds(cls.__name__)
if not cls.config.service_available.cinder: if not cls.config.service_available.cinder:
skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) skip_msg = ("%s skipped as Cinder is not available" % cls.__name__)
raise cls.skipException(skip_msg) raise cls.skipException(skip_msg)
if cls.config.compute.allow_tenant_isolation: os = cls.get_client_manager()
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)
cls.os = os cls.os = os
cls.volumes_client = os.volumes_client cls.volumes_client = os.volumes_client
@ -69,7 +59,7 @@ class BaseVolumeTest(tempest.test.BaseTestCase):
def tearDownClass(cls): def tearDownClass(cls):
cls.clear_snapshots() cls.clear_snapshots()
cls.clear_volumes() cls.clear_volumes()
cls.isolated_creds.clear_isolated_creds() cls.clear_isolated_creds()
super(BaseVolumeTest, cls).tearDownClass() super(BaseVolumeTest, cls).tearDownClass()
@classmethod @classmethod

View File

@ -26,6 +26,7 @@ import testresources
import testtools import testtools
from tempest import clients from tempest import clients
from tempest.common import isolated_creds
from tempest import config from tempest import config
from tempest import exceptions from tempest import exceptions
from tempest.openstack.common import log as logging from tempest.openstack.common import log as logging
@ -219,6 +220,34 @@ class BaseTestCase(testtools.TestCase,
format=log_format, format=log_format,
level=None)) 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 @classmethod
def _get_identity_admin_client(cls): def _get_identity_admin_client(cls):
""" """