tempest for resource api changes
- added support for query in resource list - added support for resource count new api Story: 2004669 Task: 28653 Depends-On: https://review.openstack.org/627309 Change-Id: I98b7b0d74bf0e4977c4eb5147a23080f8e01f50a
This commit is contained in:
parent
7132e33590
commit
307b09bf9d
@ -43,14 +43,21 @@ class TestResource(BaseVitrageTempest):
|
||||
VProps.STATE,
|
||||
VProps.VITRAGE_AGGREGATED_STATE)
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestResource, cls).setUpClass()
|
||||
cls.instances = nova_utils.create_instances(num_instances=1,
|
||||
set_public_network=True)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(TestResource, cls).tearDownClass()
|
||||
nova_utils.delete_created_instances(cls.instances)
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_compare_cli_vs_api_resource_list(self):
|
||||
"""resource list """
|
||||
try:
|
||||
instances = nova_utils.create_instances(num_instances=1,
|
||||
set_public_network=True)
|
||||
self.assertThat(instances, IsNotEmpty(),
|
||||
'The instances list is empty')
|
||||
api_resources = self.vitrage_client.resource.list(
|
||||
all_tenants=True)
|
||||
|
||||
@ -63,8 +70,6 @@ class TestResource(BaseVitrageTempest):
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
finally:
|
||||
nova_utils.delete_all_instances()
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_default_resource_list(self):
|
||||
@ -73,17 +78,11 @@ class TestResource(BaseVitrageTempest):
|
||||
get the resources: network, instance, port
|
||||
"""
|
||||
try:
|
||||
instances = nova_utils.create_instances(num_instances=1,
|
||||
set_public_network=True)
|
||||
self.assertThat(instances, IsNotEmpty(),
|
||||
'The instances list is empty')
|
||||
resources = self.vitrage_client.resource.list(all_tenants=False)
|
||||
self.assertThat(resources, matchers.HasLength(3))
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
finally:
|
||||
nova_utils.delete_all_instances()
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_list_with_all_tenants(self):
|
||||
@ -92,13 +91,12 @@ class TestResource(BaseVitrageTempest):
|
||||
get the resources:
|
||||
|
||||
"""
|
||||
instances = None
|
||||
try:
|
||||
resources_before = self.vitrage_client.resource.list(
|
||||
all_tenants=True)
|
||||
instances = nova_utils.create_instances(num_instances=1,
|
||||
set_public_network=True)
|
||||
self.assertThat(instances, IsNotEmpty(),
|
||||
'The instances list is empty')
|
||||
resources = self.vitrage_client.resource.list(all_tenants=True)
|
||||
|
||||
self.assertEqual(len(resources_before) + 2, len(resources))
|
||||
@ -106,7 +104,8 @@ class TestResource(BaseVitrageTempest):
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
finally:
|
||||
nova_utils.delete_all_instances()
|
||||
if instances:
|
||||
nova_utils.delete_created_instances(instances)
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_list_with_existing_type(self):
|
||||
@ -115,10 +114,6 @@ class TestResource(BaseVitrageTempest):
|
||||
get the resource: one instance
|
||||
"""
|
||||
try:
|
||||
instances = nova_utils.create_instances(num_instances=1,
|
||||
set_public_network=True)
|
||||
self.assertThat(instances, IsNotEmpty(),
|
||||
'The instances list is empty')
|
||||
resources = self.vitrage_client.resource.list(
|
||||
resource_type=NOVA_INSTANCE_DATASOURCE,
|
||||
all_tenants=True)
|
||||
@ -126,17 +121,11 @@ class TestResource(BaseVitrageTempest):
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
finally:
|
||||
nova_utils.delete_all_instances()
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_list_with_no_existing_type(self):
|
||||
"""resource list with no existing type"""
|
||||
try:
|
||||
instances = nova_utils.create_instances(num_instances=1,
|
||||
set_public_network=True)
|
||||
self.assertThat(instances, IsNotEmpty(),
|
||||
'The instances list is empty')
|
||||
resources = self.vitrage_client.resource.list(
|
||||
resource_type=CINDER_VOLUME_DATASOURCE,
|
||||
all_tenants=True)
|
||||
@ -144,8 +133,59 @@ class TestResource(BaseVitrageTempest):
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
finally:
|
||||
nova_utils.delete_all_instances()
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_list_with_query_existing(self):
|
||||
try:
|
||||
resources = self.vitrage_client.resource.list(
|
||||
resource_type=NOVA_INSTANCE_DATASOURCE,
|
||||
all_tenants=True,
|
||||
query='{"==": {"name": "vm-0"}}'
|
||||
)
|
||||
self.assertThat(resources, matchers.HasLength(1))
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_list_with_query_none_existing(self):
|
||||
try:
|
||||
resources = self.vitrage_client.resource.list(
|
||||
resource_type=NOVA_INSTANCE_DATASOURCE,
|
||||
all_tenants=True,
|
||||
query='{"==": {"name": "kuku-does-not-exist"}}'
|
||||
)
|
||||
self.assertThat(resources, matchers.HasLength(0))
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_count(self):
|
||||
try:
|
||||
resources = self.vitrage_client.resource.count(
|
||||
resource_type=NOVA_INSTANCE_DATASOURCE,
|
||||
all_tenants=True,
|
||||
query='{"==": {"name": "vm-0"}}'
|
||||
)
|
||||
self.assertThat(resources, matchers.HasLength(1))
|
||||
self.assertEqual(1, resources[NOVA_INSTANCE_DATASOURCE])
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
|
||||
@utils.tempest_logger
|
||||
def test_resource_count_empty(self):
|
||||
try:
|
||||
resources = self.vitrage_client.resource.count(
|
||||
resource_type=NOVA_INSTANCE_DATASOURCE,
|
||||
all_tenants=True,
|
||||
query='{"==": {"name": "kuku-does-not-exist"}}'
|
||||
)
|
||||
self.assertThat(resources, matchers.HasLength(0))
|
||||
except Exception as e:
|
||||
self._handle_exception(e)
|
||||
raise
|
||||
|
||||
@unittest.skip("CLI tests are ineffective and not maintained")
|
||||
def test_compare_resource_show(self):
|
||||
|
@ -42,8 +42,7 @@ def create_instances(num_instances=1, set_public_network=False, name='vm'):
|
||||
if not success:
|
||||
LOG.warning("create instance failed, delete and retry %s",
|
||||
str(resources))
|
||||
for r in resources:
|
||||
delete_all_instances(id=r.id)
|
||||
delete_created_instances(resources)
|
||||
time.sleep(10)
|
||||
raise AssertionError("Unable to create vms, retries failed")
|
||||
|
||||
@ -59,6 +58,13 @@ def _create_instances(flavor, image, name, nics, num_instances):
|
||||
return success, resources
|
||||
|
||||
|
||||
def delete_created_instances(instances):
|
||||
if not instances:
|
||||
return
|
||||
for instance in instances:
|
||||
delete_all_instances(id=instance.id)
|
||||
|
||||
|
||||
def delete_all_instances(**kwargs):
|
||||
instances = TempestClients.nova().servers.list()
|
||||
instances_to_delete = g_utils.all_matches(instances, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user