Follow latest Tempest framework

Tempest has changed its test framework, but blazar's scenario test
doesn't follow the changes. It causes some scenario test errors.

This patch makes the blazar's scenario test follow up-to-date Tempest
framework.

Change-Id: I1bfe5c5fc61c8036d3e016f3efb8ec2703745848
Depends-On: I0e57f4ee4655a8658419bfaaffad524369ee10b9
This commit is contained in:
Masahito Muroi 2016-12-09 19:21:38 +09:00
parent 5ad2ad4824
commit a6dd9b89dd
4 changed files with 27 additions and 38 deletions

View File

@ -14,7 +14,7 @@ To run all the blazar tests, add the following to the tox.ini file located at TE
[testenv:blazar] [testenv:blazar]
sitepackages = True sitepackages = True
commands = commands =
bash tools/pretty_tox.sh '(^tempest\.(api|scenario|thirdparty|cli)\.test_resource_reservation) {posargs}' bash tools/pretty_tox.sh '(^tempest\.(api|scenario|thirdparty|cli)\.test_.*reservation) {posargs}'
Then, inside the TEMPEST_DIR, run: Then, inside the TEMPEST_DIR, run:
$ tox -eblazar $ tox -eblazar

View File

@ -54,7 +54,6 @@ class TempestConfigPrivateClimate(config.TempestConfigPrivate):
"""Climate's config wrap over standard config.""" """Climate's config wrap over standard config."""
def __init__(self, parse_conf=True): def __init__(self, parse_conf=True):
super(TempestConfigPrivateClimate, self).__init__()
config.register_opt_group(cfg.CONF, service_available_group, config.register_opt_group(cfg.CONF, service_available_group,
ServiceAvailableGroup) ServiceAvailableGroup)
config.register_opt_group(cfg.CONF, resource_reservation_group, config.register_opt_group(cfg.CONF, resource_reservation_group,

View File

@ -32,14 +32,14 @@ class ResourceReservationScenarioTest(manager.ScenarioTest):
"""Base class for resource reservation scenario tests.""" """Base class for resource reservation scenario tests."""
@classmethod @classmethod
def setUpClass(cls): def setup_clients(cls):
super(ResourceReservationScenarioTest, cls).setUpClass() super(ResourceReservationScenarioTest, cls).setup_clients()
if not CONF.service_available.climate: if not CONF.service_available.climate:
raise cls.skipException("Resource reservation support is required") raise cls.skipException("Resource reservation support is required")
creds = credentials.get_configured_credentials('identity_admin') creds = credentials.get_configured_admin_credentials('admin')
auth_prov = tempestmanager.get_auth_provider(creds) auth_prov = tempestmanager.get_auth_provider(creds)
cls.manager.reservation_client = ( cls.manager.resource_reservation_client = (
clients.ResourceReservationV1Client(auth_prov, clients.ResourceReservationV1Client(auth_prov,
'reservation', 'reservation',
CONF.identity.region)) CONF.identity.region))
@ -93,9 +93,9 @@ class ResourceReservationScenarioTest(manager.ScenarioTest):
def remove_image_snapshot(self, image_name): def remove_image_snapshot(self, image_name):
try: try:
image = filter(lambda i: image = filter(lambda i:
i.name == image_name, i['name'] == image_name,
self.compute_client.images.list()) self.image_client.list())
self.compute_client.images.delete(image) self.image_client.delete(image)
except Exception as e: except Exception as e:
LOG.info("Unable to delete %s snapshot. Exception: %s" LOG.info("Unable to delete %s snapshot. Exception: %s"
% (image_name, e.message)) % (image_name, e.message))

View File

@ -18,6 +18,7 @@ import json
import dateutil.parser import dateutil.parser
from oslo_log import log as logging from oslo_log import log as logging
from tempest.common import waiters
from tempest import config from tempest import config
from tempest import exceptions from tempest import exceptions
from tempest.scenario import resource_reservation_scenario as rrs from tempest.scenario import resource_reservation_scenario as rrs
@ -65,7 +66,6 @@ class TestResourceReservationScenario(rrs.ResourceReservationScenarioTest):
) )
def tearDown(self): def tearDown(self):
self.remove_resource('server')
super(TestResourceReservationScenario, self).tearDown() super(TestResourceReservationScenario, self).tearDown()
def add_keypair(self): def add_keypair(self):
@ -76,17 +76,19 @@ class TestResourceReservationScenario(rrs.ResourceReservationScenarioTest):
# Create server with lease_data # Create server with lease_data
create_kwargs = { create_kwargs = {
'key_name': self.keypair.id, 'key_name': self.keypair['name'],
'scheduler_hints': lease_data 'scheduler_hints': lease_data
} }
server = self.create_server(image=self.image_ref, server = self.create_server(image_id=self.image_ref,
flavor=self.flavor_ref, wait=wait, flavor=self.flavor_ref,
create_kwargs=create_kwargs) wait_until=wait,
self.set_resource('server', server) **create_kwargs)
self.server_id = server['id']
self.server_name = server['name']
def check_lease_creation(self, expected_lease_data): def check_lease_creation(self, expected_lease_data):
server = self.get_resource('server') server = self.servers_client.show_server(self.server_id)['server']
expected_lease_params = json.loads(expected_lease_data['lease_params']) expected_lease_params = json.loads(expected_lease_data['lease_params'])
# compare lease_data with data passed as parameter # compare lease_data with data passed as parameter
@ -115,14 +117,14 @@ class TestResourceReservationScenario(rrs.ResourceReservationScenarioTest):
# compare the resource id from the lease with the server.id attribute! # compare the resource id from the lease with the server.id attribute!
reservations = lease['reservations'] reservations = lease['reservations']
self.assertTrue(len(reservations) == 1) self.assertTrue(len(reservations) == 1)
self.assertEqual(server.id, reservations[0]['resource_id']) self.assertEqual(server['id'], reservations[0]['resource_id'])
self.assertEqual("virtual:instance", self.assertEqual("virtual:instance",
lease['reservations'][0]['resource_type']) lease['reservations'][0]['resource_type'])
def check_server_is_snapshoted(self): def check_server_is_snapshoted(self):
image_name = LEASE_IMAGE_PREFIX + self.get_resource('server').name image_name = LEASE_IMAGE_PREFIX + self.server_name
try: try:
images_list = self.compute_client.images.list() images_list = self.image_client.list()
self.assertNotEmpty( self.assertNotEmpty(
filter(lambda image: image.name == image_name, images_list)) filter(lambda image: image.name == image_name, images_list))
except Exception as e: except Exception as e:
@ -130,23 +132,9 @@ class TestResourceReservationScenario(rrs.ResourceReservationScenarioTest):
"Exception: %s" % (image_name, e.message)) "Exception: %s" % (image_name, e.message))
raise exceptions.NotFound(message) raise exceptions.NotFound(message)
def check_server_is_removed(self):
server_id = self.get_resource('server').id
self.delete_timeout(self.compute_client.servers, server_id)
def check_server_status(self, expected_status): def check_server_status(self, expected_status):
server_id = self.get_resource('server').id server = self.servers_client.show_server(self.server_id)['server']
server = self.compute_client.servers.get(server_id) self.assertEqual(expected_status, server['status'])
self.assertEqual(expected_status, server.status)
# update server resource reference
self.set_resource('server', server)
def wait_for_server_status(self, status):
self.status_timeout(
self.compute_client.servers,
self.get_resource('server').id, status)
self.check_server_status(status)
# TODO(cmart): add climate to services after pushing this code into tempest # TODO(cmart): add climate to services after pushing this code into tempest
@test.attr(type='slow') @test.attr(type='slow')
@ -168,7 +156,8 @@ class TestResourceReservationScenario(rrs.ResourceReservationScenarioTest):
self.check_server_status('SHELVED_OFFLOADED') self.check_server_status('SHELVED_OFFLOADED')
# now, wait until the server is active # now, wait until the server is active
self.wait_for_server_status('ACTIVE') waiters.wait_for_server_status(self.servers_client,
self.server_id, 'ACTIVE')
self.check_lease_creation(lease_data) self.check_lease_creation(lease_data)
# wait for lease end # wait for lease end
@ -177,10 +166,11 @@ class TestResourceReservationScenario(rrs.ResourceReservationScenarioTest):
# check server final status # check server final status
self.check_server_is_snapshoted() self.check_server_is_snapshoted()
self.check_server_is_removed() waiters.wait_for_server_termination(self.servers_client,
self.server_id)
# remove created snapshot # remove created snapshot
image_name = LEASE_IMAGE_PREFIX + self.get_resource('server').name image_name = LEASE_IMAGE_PREFIX + self.server_name
self.remove_image_snapshot(image_name) self.remove_image_snapshot(image_name)
# remove created lease # remove created lease