Merge "Provide more default clients for smoke tests."

This commit is contained in:
Jenkins 2012-09-13 17:28:33 +00:00 committed by Gerrit Code Review
commit 245d836a1c
5 changed files with 106 additions and 54 deletions

View File

@ -18,8 +18,10 @@
import logging
# Default client libs
import novaclient.client
import glance.client
import keystoneclient.v2_0.client
import novaclient.client
import quantumclient.v2_0.client
import tempest.config
from tempest import exceptions
@ -62,16 +64,7 @@ class Manager(object):
def __init__(self):
self.config = tempest.config.TempestConfig()
self.client = None
class DefaultClientManager(Manager):
"""
Manager class that indicates the client provided by the manager
is the default Python client that an OpenStack API provides.
"""
pass
self.client_attr_names = []
class FuzzClientManager(Manager):
@ -86,23 +79,42 @@ class FuzzClientManager(Manager):
pass
class ComputeDefaultClientManager(DefaultClientManager):
class DefaultClientManager(Manager):
"""
Manager that provides the default python-novaclient client object
to access the OpenStack Compute API.
Manager that provides the default clients to access the various
OpenStack APIs.
"""
NOVACLIENT_VERSION = '2'
def __init__(self):
super(ComputeDefaultClientManager, self).__init__()
username = self.config.compute.username
password = self.config.compute.password
tenant_name = self.config.compute.tenant_name
super(DefaultClientManager, self).__init__()
self.compute_client = self._get_compute_client()
self.image_client = self._get_image_client()
self.identity_client = self._get_identity_client()
self.network_client = self._get_network_client()
self.client_attr_names = [
'compute_client',
'image_client',
'identity_client',
'network_client',
]
def _get_compute_client(self, username=None, password=None,
tenant_name=None):
# Novaclient will not execute operations for anyone but the
# identified user, so a new client needs to be created for
# each user that operations need to be performed for.
if not username:
username = self.config.compute.username
if not password:
password = self.config.compute.password
if not tenant_name:
tenant_name = self.config.compute.tenant_name
if None in (username, password, tenant_name):
msg = ("Missing required credentials. "
msg = ("Missing required credentials for compute client. "
"username: %(username)s, password: %(password)s, "
"tenant_name: %(tenant_name)s") % locals()
raise exceptions.InvalidConfiguration(msg)
@ -113,19 +125,12 @@ class ComputeDefaultClientManager(DefaultClientManager):
client_args = (username, password, tenant_name, auth_url)
# Create our default Nova client to use in testing
self.client = novaclient.client.Client(self.NOVACLIENT_VERSION,
return novaclient.client.Client(self.NOVACLIENT_VERSION,
*client_args,
service_type=self.config.compute.catalog_type,
no_cache=True)
class GlanceDefaultClientManager(DefaultClientManager):
"""
Manager that provides the default glance client object to access
the OpenStack Images API
"""
def __init__(self):
super(GlanceDefaultClientManager, self).__init__()
def _get_image_client(self):
host = self.config.images.host
port = self.config.images.port
strategy = self.config.identity.strategy
@ -135,7 +140,7 @@ class GlanceDefaultClientManager(DefaultClientManager):
tenant_name = self.config.images.tenant_name
if None in (host, port, username, password, tenant_name):
msg = ("Missing required credentials. "
msg = ("Missing required credentials for image client. "
"host:%(host)s, port: %(port)s username: %(username)s, "
"password: %(password)s, "
"tenant_name: %(tenant_name)s") % locals()
@ -149,7 +154,46 @@ class GlanceDefaultClientManager(DefaultClientManager):
'auth_url': auth_url}
# Create our default Glance client to use in testing
self.client = glance.client.Client(host, port, creds=creds)
return glance.client.Client(host, port, creds=creds)
def _get_identity_client(self):
# This identity client is not intended to check the security
# of the identity service, so use admin credentials.
username = self.config.identity_admin.username
password = self.config.identity_admin.password
tenant_name = self.config.identity_admin.tenant_name
if None in (username, password, tenant_name):
msg = ("Missing required credentials for identity client. "
"username: %(username)s, password: %(password)s, "
"tenant_name: %(tenant_name)s") % locals()
raise exceptions.InvalidConfiguration(msg)
auth_url = self.config.identity.auth_url.rstrip('tokens')
return keystoneclient.v2_0.client.Client(username=username,
password=password,
tenant_name=tenant_name,
endpoint=auth_url)
def _get_network_client(self):
# TODO(mnewby) add network-specific auth configuration
username = self.config.compute.username
password = self.config.compute.password
tenant_name = self.config.compute.tenant_name
if None in (username, password, tenant_name):
msg = ("Missing required credentials for network client. "
"username: %(username)s, password: %(password)s, "
"tenant_name: %(tenant_name)s") % locals()
raise exceptions.InvalidConfiguration(msg)
auth_url = self.config.identity.auth_url.rstrip('tokens')
return quantumclient.v2_0.client.Client(username=username,
password=password,
tenant_name=tenant_name,
auth_url=auth_url)
class ComputeFuzzClientManager(FuzzClientManager):

View File

@ -38,10 +38,11 @@ class SmokeTest(object):
pass
class ComputeSmokeTest(test.ComputeDefaultClientTest, SmokeTest):
class DefaultClientSmokeTest(test.DefaultClientTest, SmokeTest):
"""
Base smoke test case class for OpenStack Compute API (Nova)
Base smoke test case class that provides the default clients to
access the various OpenStack APIs.
"""
@classmethod

View File

@ -38,7 +38,12 @@ class TestCase(unittest.TestCase):
def setUpClass(cls):
cls.manager = cls.manager_class()
cls.config = cls.manager.config
cls.client = cls.manager.client
for attr_name in cls.manager.client_attr_names:
# Ensure that pre-existing class attributes won't be
# accidentally overriden.
assert not hasattr(cls, attr_name)
client = getattr(cls.manager, attr_name)
setattr(cls, attr_name, client)
cls.resource_keys = {}
cls.resources = []
@ -57,14 +62,14 @@ class TestCase(unittest.TestCase):
del self.resource_keys[key]
class ComputeDefaultClientTest(TestCase):
class DefaultClientTest(TestCase):
"""
Base test case class for OpenStack Compute API (Nova)
that uses the novaclient libs for calling the API.
Base test case class that provides the default clients to access
the various OpenStack APIs.
"""
manager_class = manager.ComputeDefaultClientManager
manager_class = manager.DefaultClientManager
def status_timeout(self, things, thing_id, expected_status):
"""

View File

@ -25,7 +25,7 @@ from tempest import test
LOG = logging.getLogger(__name__)
class TestServerAdvancedOps(test.ComputeDefaultClientTest):
class TestServerAdvancedOps(test.DefaultClientTest):
"""
This test case stresses some advanced server instance operations:
@ -57,7 +57,7 @@ class TestServerAdvancedOps(test.ComputeDefaultClientTest):
i_name = rand_name('instance')
flavor_id = self.config.compute.flavor_ref
base_image_id = self.config.compute.image_ref
self.instance = self.client.servers.create(
self.instance = self.compute_client.servers.create(
i_name, base_image_id, flavor_id)
try:
self.assertEqual(self.instance.name, i_name)
@ -67,16 +67,16 @@ class TestServerAdvancedOps(test.ComputeDefaultClientTest):
self.assertEqual(self.instance.status, 'BUILD')
instance_id = self.get_resource('instance').id
self.status_timeout(self.client.servers, instance_id, 'ACTIVE')
self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
instance = self.get_resource('instance')
instance_id = instance.id
resize_flavor = self.config.compute.flavor_ref_alt
LOG.debug("Resizing instance %s from flavor %s to flavor %s",
instance.id, instance.flavor, resize_flavor)
instance.resize(resize_flavor)
self.status_timeout(self.client.servers, instance_id, 'VERIFY_RESIZE')
self.status_timeout(self.compute_client.servers, instance_id,
'VERIFY_RESIZE')
LOG.debug("Confirming resize of instance %s", instance_id)
instance.confirm_resize()
self.status_timeout(self.client.servers, instance_id, 'ACTIVE')
self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')

View File

@ -23,7 +23,7 @@ from tempest import smoke
LOG = logging.getLogger(__name__)
class TestServerBasicOps(smoke.ComputeSmokeTest):
class TestServerBasicOps(smoke.DefaultClientSmokeTest):
"""
This smoke test case follows this basic set of operations:
@ -39,7 +39,7 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
def test_001_create_keypair(self):
kp_name = rand_name('keypair-smoke')
self.keypair = self.client.keypairs.create(kp_name)
self.keypair = self.compute_client.keypairs.create(kp_name)
try:
self.assertEqual(self.keypair.id, kp_name)
self.set_resource('keypair', self.keypair)
@ -49,7 +49,8 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
def test_002_create_security_group(self):
sg_name = rand_name('secgroup-smoke')
sg_desc = sg_name + " description"
self.secgroup = self.client.security_groups.create(sg_name, sg_desc)
self.secgroup = self.compute_client.security_groups.create(sg_name,
sg_desc)
try:
self.assertEqual(self.secgroup.name, sg_name)
self.assertEqual(self.secgroup.description, sg_desc)
@ -76,8 +77,8 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
]
for ruleset in rulesets:
try:
self.client.security_group_rules.create(
self.secgroup.id, **ruleset)
self.compute_client.security_group_rules.create(
self.secgroup.id, **ruleset)
except:
self.fail("Failed to create rule in security group.")
@ -88,7 +89,7 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
create_kwargs = {
'key_name': self.get_resource('keypair').id
}
self.instance = self.client.servers.create(
self.instance = self.compute_client.servers.create(
i_name, base_image_id, flavor_id, **create_kwargs)
try:
self.assertEqual(self.instance.name, i_name)
@ -100,7 +101,7 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
def test_004_wait_on_active(self):
instance_id = self.get_resource('instance').id
self.status_timeout(self.client.servers, instance_id, 'ACTIVE')
self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
def test_005_pause_server(self):
instance = self.get_resource('instance')
@ -108,7 +109,7 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
LOG.debug("Pausing instance %s. Current status: %s",
instance_id, instance.status)
instance.pause()
self.status_timeout(self.client.servers, instance_id, 'PAUSED')
self.status_timeout(self.compute_client.servers, instance_id, 'PAUSED')
def test_006_unpause_server(self):
instance = self.get_resource('instance')
@ -116,7 +117,7 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
LOG.debug("Unpausing instance %s. Current status: %s",
instance_id, instance.status)
instance.unpause()
self.status_timeout(self.client.servers, instance_id, 'ACTIVE')
self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
def test_007_suspend_server(self):
instance = self.get_resource('instance')
@ -124,7 +125,8 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
LOG.debug("Suspending instance %s. Current status: %s",
instance_id, instance.status)
instance.suspend()
self.status_timeout(self.client.servers, instance_id, 'SUSPENDED')
self.status_timeout(self.compute_client.servers,
instance_id, 'SUSPENDED')
def test_008_resume_server(self):
instance = self.get_resource('instance')
@ -132,7 +134,7 @@ class TestServerBasicOps(smoke.ComputeSmokeTest):
LOG.debug("Resuming instance %s. Current status: %s",
instance_id, instance.status)
instance.resume()
self.status_timeout(self.client.servers, instance_id, 'ACTIVE')
self.status_timeout(self.compute_client.servers, instance_id, 'ACTIVE')
def test_099_terminate_instance(self):
instance = self.get_resource('instance')