Skip to content

Commit

Permalink
Provide more default clients for smoke tests.
Browse files Browse the repository at this point in the history
 * Refactored DefaultClientManager to support default clients
   for image, identity and network in addition to compute.  This
   change is intended to faciliate the creation of
   cross-functional smoke tests.
 * In support of bug 1043980

Change-Id: I45c0e6bf5fde41936df8838b7434c0b2074f4a02
  • Loading branch information
Maru Newby authored and openstack-gerrit committed Sep 6, 2012
1 parent d3e674e commit dec13ec
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 54 deletions.
104 changes: 74 additions & 30 deletions tempest/manager.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -113,19 +125,12 @@ def __init__(self):
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
Expand All @@ -135,7 +140,7 @@ def __init__(self):
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()
Expand All @@ -149,7 +154,46 @@ def __init__(self):
'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):
Expand Down
5 changes: 3 additions & 2 deletions tempest/smoke.py
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions tempest/test.py
Expand Up @@ -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 = []

Expand All @@ -57,14 +62,14 @@ def remove_resource(self, key):
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):
"""
Expand Down
12 changes: 6 additions & 6 deletions tempest/tests/compute/test_server_advanced_ops.py
Expand Up @@ -25,7 +25,7 @@
LOG = logging.getLogger(__name__)


class TestServerAdvancedOps(test.ComputeDefaultClientTest):
class TestServerAdvancedOps(test.DefaultClientTest):

"""
This test case stresses some advanced server instance operations:
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_resize_server_confirm(self):
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)
Expand All @@ -67,16 +67,16 @@ def test_resize_server_confirm(self):

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')
24 changes: 13 additions & 11 deletions tempest/tests/compute/test_server_basic_ops.py
Expand Up @@ -23,7 +23,7 @@
LOG = logging.getLogger(__name__)


class TestServerBasicOps(smoke.ComputeSmokeTest):
class TestServerBasicOps(smoke.DefaultClientSmokeTest):

"""
This smoke test case follows this basic set of operations:
Expand All @@ -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)
Expand All @@ -49,7 +49,8 @@ def test_001_create_keypair(self):
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)
Expand All @@ -76,8 +77,8 @@ def test_002_create_security_group(self):
]
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.")

Expand All @@ -88,7 +89,7 @@ def test_003_boot_instance(self):
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)
Expand All @@ -100,39 +101,40 @@ def test_003_boot_instance(self):

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')
instance_id = instance.id
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')
instance_id = instance.id
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')
instance_id = instance.id
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')
instance_id = instance.id
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')
Expand Down

0 comments on commit dec13ec

Please sign in to comment.