Merge "Add base classes for image tests."
diff --git a/tempest/services/compute/xml/common.py b/tempest/services/compute/xml/common.py
index bbc4e38..4b1b11a 100644
--- a/tempest/services/compute/xml/common.py
+++ b/tempest/services/compute/xml/common.py
@@ -100,7 +100,8 @@
"""
json = {}
for attr in node.keys():
- json[attr] = node.get(attr)
+ if not attr.startswith("xmlns"):
+ json[attr] = node.get(attr)
if not node.getchildren():
return node.text or json
for child in node.getchildren():
diff --git a/tempest/tests/compute/admin/test_quotas.py b/tempest/tests/compute/admin/test_quotas.py
index 7430a7c..7f64d15 100644
--- a/tempest/tests/compute/admin/test_quotas.py
+++ b/tempest/tests/compute/admin/test_quotas.py
@@ -122,15 +122,10 @@
resp, quota_set = self.adm_client.update_quota_set(self.demo_tenant_id,
cores=vcpu_quota)
- try:
- self.create_server()
- except exceptions.OverLimit:
- pass
- else:
- self.fail("Could create servers over the VCPU quota limit")
- finally:
- self.adm_client.update_quota_set(self.demo_tenant_id,
- cores=default_vcpu_quota)
+
+ self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+ cores=default_vcpu_quota)
+ self.assertRaises(exceptions.OverLimit, self.create_server)
def test_create_server_when_memory_quota_is_full(self):
# Disallow server creation when tenant's memory quota is full
@@ -140,15 +135,10 @@
self.adm_client.update_quota_set(self.demo_tenant_id,
ram=mem_quota)
- try:
- self.create_server()
- except exceptions.OverLimit:
- pass
- else:
- self.fail("Could create servers over the memory quota limit")
- finally:
- self.adm_client.update_quota_set(self.demo_tenant_id,
- ram=default_mem_quota)
+
+ self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+ ram=default_mem_quota)
+ self.assertRaises(exceptions.OverLimit, self.create_server)
#TODO(afazekas): Add test that tried to update the quota_set as a regular user
diff --git a/tempest/tests/compute/volumes/test_attach_volume.py b/tempest/tests/compute/volumes/test_attach_volume.py
index 2679312..7c1a2d1 100644
--- a/tempest/tests/compute/volumes/test_attach_volume.py
+++ b/tempest/tests/compute/volumes/test_attach_volume.py
@@ -28,6 +28,12 @@
_interface = 'json'
run_ssh = tempest.config.TempestConfig().compute.run_ssh
+ def __init__(self, *args, **kwargs):
+ super(AttachVolumeTestJSON, self).__init__(*args, **kwargs)
+ self.server = None
+ self.volume = None
+ self.attached = False
+
@classmethod
def setUpClass(cls):
super(AttachVolumeTestJSON, cls).setUpClass()
@@ -37,9 +43,13 @@
self.servers_client.detach_volume(server_id, volume_id)
self.volumes_client.wait_for_volume_status(volume_id, 'available')
- def _delete(self, server_id, volume_id):
- self.volumes_client.delete_volume(volume_id)
- self.servers_client.delete_server(server_id)
+ def _delete(self, server, volume):
+ if self.volume:
+ self.volumes_client.delete_volume(self.volume['id'])
+ self.volume = None
+ if self.server:
+ self.servers_client.delete_server(self.server['id'])
+ self.server = None
def _create_and_attach(self):
name = rand_name('server')
@@ -49,6 +59,7 @@
self.image_ref,
self.flavor_ref,
adminPass='password')
+ self.server = server
self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
# Record addresses so that we can ssh later
@@ -58,6 +69,7 @@
# Create a volume and wait for it to become ready
resp, volume = self.volumes_client.create_volume(1,
display_name='test')
+ self.volume = volume
self.volumes_client.wait_for_volume_status(volume['id'], 'available')
# Attach the volume to the server
@@ -65,18 +77,18 @@
device='/dev/%s' % self.device)
self.volumes_client.wait_for_volume_status(volume['id'], 'in-use')
- return server, volume
+ self.attached = True
@attr(type='positive')
@testtools.skipIf(not run_ssh, 'SSH required for this test')
def test_attach_detach_volume(self):
# Stop and Start a server with an attached volume, ensuring that
# the volume remains attached.
- server, volume = self._create_and_attach()
-
- attached = True
-
try:
+ self._create_and_attach()
+ server = self.server
+ volume = self.volume
+
self.servers_client.stop(server['id'])
self.servers_client.wait_for_server_status(server['id'], 'SHUTOFF')
@@ -101,10 +113,12 @@
self.ssh_user, server['adminPass'])
partitions = linux_client.get_partitions()
self.assertFalse(self.device in partitions)
+ except Exception:
+ self.fail("The test_attach_detach_volume is faild!")
finally:
- if attached:
+ if self.attached:
self._detach(server['id'], volume['id'])
- self._delete(server['id'], volume['id'])
+ self._delete(self.server, self.volume)
class AttachVolumeTestXML(AttachVolumeTestJSON):