Fix tempest tests
- The argument service doesn't exists anymore and set the value of the variable scope to None instead. - Make tests a little bit less flaky by using waiters inspired by tempest waiters Change-Id: Ic376f22d9244d3ddb8d9e8ed0e00c4a64f5cede5
This commit is contained in:
parent
2f6e86049b
commit
50d9681854
@ -19,6 +19,6 @@ from almanach.tests.tempest.services import almanach_client
|
||||
|
||||
class Manager(clients.Manager):
|
||||
|
||||
def __init__(self, credentials=None, service=None):
|
||||
super(Manager, self).__init__(credentials, service)
|
||||
def __init__(self, credentials=None):
|
||||
super(Manager, self).__init__(credentials)
|
||||
self.almanach_client = almanach_client.AlmanachClient(self.auth_provider)
|
||||
|
@ -17,7 +17,10 @@ from tempest.common import compute
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest.common import waiters
|
||||
from tempest import config
|
||||
from tempest.lib import exceptions
|
||||
from tempest.scenario import manager
|
||||
import time
|
||||
|
||||
|
||||
from almanach.tests.tempest import clients
|
||||
|
||||
@ -25,8 +28,9 @@ CONF = config.CONF
|
||||
|
||||
|
||||
class BaseAlmanachScenarioTest(manager.ScenarioTest):
|
||||
|
||||
credentials = ['primary', 'admin']
|
||||
notification_interval = 1
|
||||
notification_timeout = 30
|
||||
|
||||
@classmethod
|
||||
def setup_clients(cls):
|
||||
@ -89,4 +93,15 @@ class BaseAlmanachScenarioTest(manager.ScenarioTest):
|
||||
|
||||
def delete_test_server(self, server):
|
||||
self.os.servers_client.delete_server(server['id'])
|
||||
waiters.wait_for_server_termination(self.os.servers_client, server['id'])
|
||||
waiters.wait_for_server_termination(self.os.servers_client, server['id'], True)
|
||||
|
||||
def wait_for_notification(self, callback, *args):
|
||||
start_time = int(time.time())
|
||||
while True:
|
||||
if callback(*args):
|
||||
return
|
||||
|
||||
if int(time.time()) - start_time >= self.notification_timeout:
|
||||
raise exceptions.TimeoutException
|
||||
|
||||
time.sleep(self.notification_interval)
|
||||
|
@ -22,6 +22,8 @@ class TestServerRebuildScenario(base.BaseAlmanachScenarioTest):
|
||||
|
||||
def test_rebuild_server(self):
|
||||
server, flavor = self._rebuild_server()
|
||||
self.wait_for_notification(self._check_that_a_new_entity_is_created,
|
||||
server)
|
||||
|
||||
entities = self.get_tenant_entities(server['tenant_id'])
|
||||
self.assertEqual(2, len(entities))
|
||||
@ -44,6 +46,10 @@ class TestServerRebuildScenario(base.BaseAlmanachScenarioTest):
|
||||
self.assertEqual('linux', entities[1]['image_meta']['distro'])
|
||||
self.assertEqual('linux', entities[1]['os']['distro'])
|
||||
|
||||
def _check_that_a_new_entity_is_created(self, server):
|
||||
entities = self.get_tenant_entities(server['tenant_id'])
|
||||
return len(entities) == 2
|
||||
|
||||
def _rebuild_server(self):
|
||||
server, flavor = self.create_test_server(wait_until='ACTIVE')
|
||||
image = self._prepare_image()
|
||||
|
@ -22,6 +22,8 @@ class TestServerResizeScenario(base.BaseAlmanachScenarioTest):
|
||||
|
||||
def test_resize_server(self):
|
||||
server, initial_flavor, resized_flavor = self._resize_server()
|
||||
self.wait_for_notification(self._check_that_a_new_entity_is_created,
|
||||
server)
|
||||
|
||||
entities = self.get_tenant_entities(server['tenant_id'])
|
||||
self.assertEqual(2, len(entities))
|
||||
@ -44,6 +46,10 @@ class TestServerResizeScenario(base.BaseAlmanachScenarioTest):
|
||||
self.assertEqual(dict(), entities[0]['os'])
|
||||
self.assertEqual(dict(), entities[0]['image_meta'])
|
||||
|
||||
def _check_that_a_new_entity_is_created(self, server):
|
||||
entities = self.get_tenant_entities(server['tenant_id'])
|
||||
return len(entities) == 2
|
||||
|
||||
def _resize_server(self):
|
||||
flavors = self.flavors_client.list_flavors()['flavors']
|
||||
resized_flavor = flavors[1]
|
||||
|
@ -20,9 +20,9 @@ class TestServerSuppressionScenario(base.BaseAlmanachScenarioTest):
|
||||
def test_delete_server(self):
|
||||
server, flavor = self.create_test_server(wait_until='ACTIVE')
|
||||
self.delete_test_server(server)
|
||||
self.wait_for_notification(self._check_entity_is_closed, server)
|
||||
|
||||
entities = self.get_tenant_entities(server['tenant_id'])
|
||||
|
||||
self.assertEqual(1, len(entities))
|
||||
self.assertEqual(server['id'], entities[0]['entity_id'])
|
||||
self.assertEqual('instance', entities[0]['entity_type'])
|
||||
@ -30,3 +30,7 @@ class TestServerSuppressionScenario(base.BaseAlmanachScenarioTest):
|
||||
self.assertEqual(flavor['name'], entities[0]['flavor'])
|
||||
self.assertIsNotNone(entities[0]['start'])
|
||||
self.assertIsNotNone(entities[0]['end'])
|
||||
|
||||
def _check_entity_is_closed(self, server):
|
||||
entities = self.get_tenant_entities(server['tenant_id'])
|
||||
return len(entities) == 1 and entities[0]['end'] is not None
|
||||
|
@ -35,6 +35,7 @@ class TestVolumeAttachmentScenario(base.BaseAlmanachScenarioTest):
|
||||
|
||||
def test_attachment(self):
|
||||
self._attach_volume_to_server()
|
||||
self.wait_for_notification(self._check_that_volume_is_attached)
|
||||
|
||||
entities = self.get_tenant_entities(self._volume['os-vol-tenant-attr:tenant_id'])
|
||||
self.assertIsNotNone(entities[0]['start'])
|
||||
@ -43,11 +44,21 @@ class TestVolumeAttachmentScenario(base.BaseAlmanachScenarioTest):
|
||||
|
||||
self._detach_volume_from_server()
|
||||
|
||||
self.wait_for_notification(self._check_that_volume_is_detached)
|
||||
|
||||
entities = self.get_tenant_entities(self._volume['os-vol-tenant-attr:tenant_id'])
|
||||
self.assertIsNotNone(entities[0]['start'])
|
||||
self.assertIsNone(entities[0]['end'])
|
||||
self.assertFalse(self._server['id'] in entities[0]['attached_to'])
|
||||
|
||||
def _check_that_volume_is_attached(self):
|
||||
entities = self.get_tenant_entities(self._volume['os-vol-tenant-attr:tenant_id'])
|
||||
return len(entities) == 1 and self._server['id'] in entities[0]['attached_to']
|
||||
|
||||
def _check_that_volume_is_detached(self):
|
||||
entities = self.get_tenant_entities(self._volume['os-vol-tenant-attr:tenant_id'])
|
||||
return len(entities) == 1 and self._server['id'] not in entities[0]['attached_to']
|
||||
|
||||
def _attach_volume_to_server(self):
|
||||
self._volume = self.create_test_volume()
|
||||
self._server, _ = self.create_test_server(wait_until='ACTIVE')
|
||||
|
Loading…
Reference in New Issue
Block a user