Merge "add the version requirement for testtools"
diff --git a/tempest/services/image/json/image_client.py b/tempest/services/image/json/image_client.py
index e9276aa..f119664 100644
--- a/tempest/services/image/json/image_client.py
+++ b/tempest/services/image/json/image_client.py
@@ -176,11 +176,21 @@
url = '/' + url
self.http.raw_request('DELETE', url)
- def image_list(self, params=None):
+ def image_list(self, **kwargs):
url = 'v1/images'
- if params:
- url += '?%s' % urllib.urlencode(params)
+ if len(kwargs) > 0:
+ url += '?%s' % urllib.urlencode(kwargs)
+
+ resp, body = self.get(url)
+ body = json.loads(body)
+ return resp, body['images']
+
+ def image_list_detail(self, **kwargs):
+ url = 'v1/images/detail'
+
+ if len(kwargs) > 0:
+ url += '?%s' % urllib.urlencode(kwargs)
resp, body = self.get(url)
body = json.loads(body)
diff --git a/tempest/tests/compute/floating_ips/test_floating_ips_actions.py b/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
index 0f63016..d9f9613 100644
--- a/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/tests/compute/floating_ips/test_floating_ips_actions.py
@@ -114,42 +114,26 @@
# Negative test:Deletion of a nonexistent floating IP
# from project should fail
- #Deleting the non existent floating IP
- try:
- resp, body = self.client.delete_floating_ip(self.non_exist_id)
- except Exception:
- pass
- else:
- self.fail('Should not be able to delete a nonexistent floating IP')
+ # Deleting the non existent floating IP
+ self.assertRaises(exceptions.NotFound, self.client.delete_floating_ip,
+ self.non_exist_id)
@attr(type='negative')
def test_associate_nonexistant_floating_ip(self):
# Negative test:Association of a non existent floating IP
# to specific server should fail
- #Associating non existent floating IP
- try:
- resp, body = \
- self.client.associate_floating_ip_to_server("0.0.0.0",
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to associate'
- ' a nonexistent floating IP')
+ # Associating non existent floating IP
+ self.assertRaises(exceptions.NotFound,
+ self.client.associate_floating_ip_to_server,
+ "0.0.0.0", self.server_id)
@attr(type='negative')
def test_dissociate_nonexistant_floating_ip(self):
# Negative test:Dissociation of a non existent floating IP should fail
- #Dissociating non existent floating IP
- try:
- resp, body = \
- self.client.disassociate_floating_ip_from_server("0.0.0.0",
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to dissociate'
- ' a nonexistent floating IP')
+ # Dissociating non existent floating IP
+ self.assertRaises(exceptions.NotFound,
+ self.client.disassociate_floating_ip_from_server,
+ "0.0.0.0", self.server_id)
@attr(type='positive')
def test_associate_already_associated_floating_ip(self):
@@ -171,38 +155,24 @@
self.client.associate_floating_ip_to_server(self.floating_ip,
self.new_server_id)
- #Make sure no longer associated with old server
- try:
- self.client.disassociate_floating_ip_from_server(
- self.floating_ip,
- self.server_id)
- except (exceptions.NotFound, exceptions.BadRequest):
- pass
- else:
- self.fail('The floating IP should be associated to the second '
- 'server')
+ self.addCleanup(self.servers_client.delete_server, self.new_server_id)
if (resp['status'] is not None):
- #Dissociation of the floating IP associated in this method
- resp, _ = \
- self.client.disassociate_floating_ip_from_server(
- self.floating_ip,
- self.new_server_id)
- #Deletion of server created in this method
- resp, body = self.servers_client.delete_server(self.new_server_id)
+ self.addCleanup(self.client.disassociate_floating_ip_from_server,
+ self.floating_ip,
+ self.new_server_id)
+
+ # Make sure no longer associated with old server
+ self.assertRaises((exceptions.NotFound, exceptions.BadRequest),
+ self.client.disassociate_floating_ip_from_server,
+ self.floating_ip, self.server_id)
@attr(type='negative')
def test_associate_ip_to_server_without_passing_floating_ip(self):
# Negative test:Association of empty floating IP to specific server
# should raise NotFound exception
- try:
- resp, body =\
- self.client.associate_floating_ip_to_server('',
- self.server_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Association of floating IP to specific server'
- ' with out passing floating IP should raise BadRequest')
+ self.assertRaises(exceptions.NotFound,
+ self.client.associate_floating_ip_to_server,
+ '', self.server_id)
class FloatingIPsTestXML(FloatingIPsTestJSON):
diff --git a/tempest/tests/compute/floating_ips/test_list_floating_ips.py b/tempest/tests/compute/floating_ips/test_list_floating_ips.py
index 11b9465..b795909 100644
--- a/tempest/tests/compute/floating_ips/test_list_floating_ips.py
+++ b/tempest/tests/compute/floating_ips/test_list_floating_ips.py
@@ -90,14 +90,8 @@
non_exist_id = rand_name('999')
if non_exist_id not in floating_ip_id:
break
- try:
- resp, body = \
- self.client.get_floating_ip_details(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to GET the details from a'
- 'nonexistant floating IP')
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_floating_ip_details, non_exist_id)
class FloatingIPDetailsTestXML(FloatingIPDetailsTestJSON):
diff --git a/tempest/tests/compute/images/test_image_metadata.py b/tempest/tests/compute/images/test_image_metadata.py
index fa69395..311ee8e 100644
--- a/tempest/tests/compute/images/test_image_metadata.py
+++ b/tempest/tests/compute/images/test_image_metadata.py
@@ -111,68 +111,41 @@
def test_list_nonexistant_image_metadata(self):
# Negative test: List on nonexistant image
# metadata should not happen
- try:
- resp, resp_metadata = self.client.list_image_metadata(999)
- except exceptions.NotFound:
- pass
- else:
- self.fail('List on nonexistant image metadata should'
- 'not happen')
+ self.assertRaises(exceptions.NotFound, self.client.list_image_metadata,
+ 999)
@attr(type='negative')
def test_update_nonexistant_image_metadata(self):
# Negative test:An update should not happen for a nonexistant image
meta = {'key1': 'alt1', 'key2': 'alt2'}
- try:
- resp, metadata = self.client.update_image_metadata(999, meta)
- except exceptions.NotFound:
- pass
- else:
- self.fail('An update shouldnt happen for nonexistant image')
+ self.assertRaises(exceptions.NotFound,
+ self.client.update_image_metadata, 999, meta)
@attr(type='negative')
def test_get_nonexistant_image_metadata_item(self):
# Negative test: Get on nonexistant image should not happen
- try:
- resp, metadata = self.client.get_image_metadata_item(999, 'key2')
- except exceptions.NotFound:
- pass
- else:
- self.fail('Get on nonexistant image should not happen')
+ self.assertRaises(exceptions.NotFound,
+ self.client.get_image_metadata_item, 999, 'key2')
@attr(type='negative')
def test_set_nonexistant_image_metadata(self):
# Negative test: Metadata should not be set to a nonexistant image
meta = {'key1': 'alt1', 'key2': 'alt2'}
- try:
- resp, meta = self.client.set_image_metadata(999, meta)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Metadata should not be set to a nonexistant image')
+ self.assertRaises(exceptions.NotFound, self.client.set_image_metadata,
+ 999, meta)
@attr(type='negative')
def test_set_nonexistant_image_metadata_item(self):
# Negative test: Metadata item should not be set to a
# nonexistant image
meta = {'key1': 'alt'}
- try:
- resp, body = self.client.set_image_metadata_item(999, 'key1', meta)
- resp, metadata = self.client.list_image_metadata(999)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Metadata item should not be set to a nonexistant image')
+ self.assertRaises(exceptions.NotFound,
+ self.client.set_image_metadata_item, 999, 'key1',
+ meta)
@attr(type='negative')
def test_delete_nonexistant_image_metadata_item(self):
# Negative test: Shouldnt be able to delete metadata
- # item from nonexistant image
- try:
- resp, body = self.client.delete_image_metadata_item(999, 'key1')
- resp, metadata = self.client.list_image_metadata(999)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to delete metadata item from a'
- 'nonexistant image')
+ # item from nonexistant image
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_image_metadata_item, 999, 'key1')
diff --git a/tempest/tests/compute/images/test_images.py b/tempest/tests/compute/images/test_images.py
index 1e90202..a61cef6 100644
--- a/tempest/tests/compute/images/test_images.py
+++ b/tempest/tests/compute/images/test_images.py
@@ -133,40 +133,24 @@
@attr(type='negative')
def test_create_image_specify_uuid_35_characters_or_less(self):
# Return an error if Image ID passed is 35 characters or less
- try:
- snapshot_name = rand_name('test-snap-')
- test_uuid = ('a' * 35)
- self.assertRaises(exceptions.NotFound, self.client.create_image,
- test_uuid, snapshot_name)
- except Exception:
- self.fail("Should return 404 Not Found if server uuid is 35"
- " characters or less")
+ snapshot_name = rand_name('test-snap-')
+ test_uuid = ('a' * 35)
+ self.assertRaises(exceptions.NotFound, self.client.create_image,
+ test_uuid, snapshot_name)
@attr(type='negative')
def test_create_image_specify_uuid_37_characters_or_more(self):
# Return an error if Image ID passed is 37 characters or more
- try:
- snapshot_name = rand_name('test-snap-')
- test_uuid = ('a' * 37)
- self.assertRaises(exceptions.NotFound, self.client.create_image,
- test_uuid, snapshot_name)
- except Exception:
- self.fail("Should return 404 Not Found if server uuid is 37"
- " characters or more")
+ snapshot_name = rand_name('test-snap-')
+ test_uuid = ('a' * 37)
+ self.assertRaises(exceptions.NotFound, self.client.create_image,
+ test_uuid, snapshot_name)
@attr(type='negative')
def test_delete_image_with_invalid_image_id(self):
# An image should not be deleted with invalid image id
- try:
- # Delete an image with invalid image id
- resp, _ = self.client.delete_image('!@$%^&*()')
-
- except exceptions.NotFound:
- pass
-
- else:
- self.fail("DELETE image request should rasie NotFound exception "
- "when requested with invalid image")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image,
+ '!@$%^&*()')
@attr(type='negative')
def test_delete_non_existent_image(self):
@@ -179,44 +163,25 @@
@attr(type='negative')
def test_delete_image_blank_id(self):
# Return an error while trying to delete an image with blank Id
-
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- '')
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for blank image id")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image, '')
@attr(type='negative')
def test_delete_image_non_hex_string_id(self):
# Return an error while trying to delete an image with non hex id
-
image_id = '11a22b9-120q-5555-cc11-00ab112223gj'
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- image_id)
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for non hex image")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image,
+ image_id)
@attr(type='negative')
def test_delete_image_negative_image_id(self):
# Return an error while trying to delete an image with negative id
-
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- -1)
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for negative image id")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)
@attr(type='negative')
def test_delete_image_id_is_over_35_character_limit(self):
# Return an error while trying to delete image with id over limit
-
- try:
- self.assertRaises(exceptions.NotFound, self.client.delete_image,
- '11a22b9-120q-5555-cc11-00ab112223gj-3fac')
- except Exception:
- self.fail("Did not return HTTP 404 NotFound for image id that "
- "exceeds 35 character ID length limit")
+ self.assertRaises(exceptions.NotFound, self.client.delete_image,
+ '11a22b9-120q-5555-cc11-00ab112223gj-3fac')
class ImagesTestXML(ImagesTestJSON):
diff --git a/tempest/tests/compute/images/test_images_oneserver.py b/tempest/tests/compute/images/test_images_oneserver.py
index 6d3f043..d89b6dd 100644
--- a/tempest/tests/compute/images/test_images_oneserver.py
+++ b/tempest/tests/compute/images/test_images_oneserver.py
@@ -61,40 +61,28 @@
@testtools.skip("Until Bug 1006725 is fixed")
def test_create_image_specify_multibyte_character_image_name(self):
# Return an error if the image name has multi-byte characters
- try:
- snapshot_name = rand_name('\xef\xbb\xbf')
- self.assertRaises(exceptions.BadRequest,
- self.client.create_image, self.server['id'],
- snapshot_name)
- except Exception:
- self.fail("Should return 400 Bad Request if multi byte characters"
- " are used for image name")
+ snapshot_name = rand_name('\xef\xbb\xbf')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_image, self.server['id'],
+ snapshot_name)
@attr(type='negative')
@testtools.skip("Until Bug 1005423 is fixed")
def test_create_image_specify_invalid_metadata(self):
# Return an error when creating image with invalid metadata
- try:
- snapshot_name = rand_name('test-snap-')
- meta = {'': ''}
- self.assertRaises(exceptions.BadRequest, self.client.create_image,
- self.server['id'], snapshot_name, meta)
-
- except Exception:
- self.fail("Should raise 400 Bad Request if meta data is invalid")
+ snapshot_name = rand_name('test-snap-')
+ meta = {'': ''}
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server['id'], snapshot_name, meta)
@attr(type='negative')
@testtools.skip("Until Bug 1005423 is fixed")
def test_create_image_specify_metadata_over_limits(self):
# Return an error when creating image with meta data over 256 chars
- try:
- snapshot_name = rand_name('test-snap-')
- meta = {'a' * 260: 'b' * 260}
- self.assertRaises(exceptions.OverLimit, self.client.create_image,
- self.server['id'], snapshot_name, meta)
-
- except Exception:
- self.fail("Should raise 413 Over Limit if meta data was too long")
+ snapshot_name = rand_name('test-snap-')
+ meta = {'a' * 260: 'b' * 260}
+ self.assertRaises(exceptions.OverLimit, self.client.create_image,
+ self.server['id'], snapshot_name, meta)
@attr(type='negative')
@testtools.skipUnless(compute.MULTI_USER,
@@ -151,38 +139,28 @@
def test_create_second_image_when_first_image_is_being_saved(self):
# Disallow creating another image when first image is being saved
- try:
- # Create first snapshot
- snapshot_name = rand_name('test-snap-')
- resp, body = self.client.create_image(self.server['id'],
- snapshot_name)
- self.assertEqual(202, resp.status)
- image_id = parse_image_id(resp['location'])
- self.image_ids.append(image_id)
+ # Create first snapshot
+ snapshot_name = rand_name('test-snap-')
+ resp, body = self.client.create_image(self.server['id'],
+ snapshot_name)
+ self.assertEqual(202, resp.status)
+ image_id = parse_image_id(resp['location'])
+ self.image_ids.append(image_id)
- # Create second snapshot
- alt_snapshot_name = rand_name('test-snap-')
- self.client.create_image(self.server['id'],
- alt_snapshot_name)
- except exceptions.Duplicate:
- self.client.wait_for_image_status(image_id, 'ACTIVE')
-
- else:
- self.fail("Should not allow creating an image when another image "
- "of the server is still being saved")
+ # Create second snapshot
+ alt_snapshot_name = rand_name('test-snap-')
+ self.assertRaises(exceptions.Duplicate, self.client.create_image,
+ self.server['id'], alt_snapshot_name)
+ self.client.wait_for_image_status(image_id, 'ACTIVE')
@attr(type='negative')
@testtools.skip("Until Bug 1004564 is fixed")
def test_create_image_specify_name_over_256_chars(self):
# Return an error if snapshot name over 256 characters is passed
- try:
- snapshot_name = rand_name('a' * 260)
- self.assertRaises(exceptions.BadRequest, self.client.create_image,
- self.server['id'], snapshot_name)
- except Exception:
- self.fail("Should return 400 Bad Request if image name is over 256"
- " characters")
+ snapshot_name = rand_name('a' * 260)
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ self.server['id'], snapshot_name)
@attr(type='negative')
def test_delete_image_that_is_not_yet_active(self):
diff --git a/tempest/tests/compute/images/test_list_image_filters.py b/tempest/tests/compute/images/test_list_image_filters.py
index 5038a65..472f7fb 100644
--- a/tempest/tests/compute/images/test_list_image_filters.py
+++ b/tempest/tests/compute/images/test_list_image_filters.py
@@ -225,9 +225,4 @@
@attr(type='negative')
def test_get_nonexistant_image(self):
# Negative test: GET on non existant image should fail
- try:
- resp, image = self.client.get_image(999)
- except Exception:
- pass
- else:
- self.fail('GET on non existant image should fail')
+ self.assertRaises(exceptions.NotFound, self.client.get_image, 999)
diff --git a/tempest/tests/compute/keypairs/test_keypairs.py b/tempest/tests/compute/keypairs/test_keypairs.py
index aefc5ff..b48b439 100644
--- a/tempest/tests/compute/keypairs/test_keypairs.py
+++ b/tempest/tests/compute/keypairs/test_keypairs.py
@@ -134,48 +134,32 @@
# Keypair should not be created with a non RSA public key
k_name = rand_name('keypair-')
pub_key = "ssh-rsa JUNK nova@ubuntu"
- try:
- resp, _ = self.client.create_keypair(k_name, pub_key)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Expected BadRequest for invalid public key')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_keypair, k_name, pub_key)
@attr(type='negative')
@testtools.skip("Skipped until the Bug #1086980 is resolved")
def test_keypair_delete_nonexistant_key(self):
# Non-existant key deletion should throw a proper error
k_name = rand_name("keypair-non-existant-")
- try:
- resp, _ = self.client.delete_keypair(k_name)
- except exceptions.NotFound:
- pass
- else:
- self.fail('nonexistent key')
+ self.assertRaises(exceptions.NotFound, self.client.delete_keypair,
+ k_name)
@attr(type='negative')
def test_create_keypair_with_empty_public_key(self):
# Keypair should not be created with an empty public key
k_name = rand_name("keypair-")
pub_key = ' '
- try:
- resp, _ = self.client.create_keypair(k_name, pub_key)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Expected BadRequest for empty public key')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name, pub_key)
@attr(type='negative')
def test_create_keypair_when_public_key_bits_exceeds_maximum(self):
# Keypair should not be created when public key bits are too long
k_name = rand_name("keypair-")
pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu'
- try:
- resp, _ = self.client.create_keypair(k_name, pub_key)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Expected BadRequest for too long public key')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name, pub_key)
@attr(type='negative')
def test_create_keypair_with_duplicate_name(self):
@@ -184,47 +168,30 @@
resp, _ = self.client.create_keypair(k_name)
self.assertEqual(200, resp.status)
#Now try the same keyname to ceate another key
- try:
- resp, _ = self.client.create_keypair(k_name)
- #Expect a HTTP 409 Conflict Error
- except exceptions.Duplicate:
- pass
- else:
- self.fail('duplicate name')
+ self.assertRaises(exceptions.Duplicate, self.client.create_keypair,
+ k_name)
resp, _ = self.client.delete_keypair(k_name)
self.assertEqual(202, resp.status)
@attr(type='negative')
def test_create_keypair_with_empty_name_string(self):
# Keypairs with name being an empty string should not be created
- try:
- resp, _ = self.client.create_keypair('')
- except exceptions.BadRequest:
- pass
- else:
- self.fail('empty string')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ '')
@attr(type='negative')
def test_create_keypair_with_long_keynames(self):
# Keypairs with name longer than 255 chars should not be created
k_name = 'keypair-'.ljust(260, '0')
- try:
- resp, _ = self.client.create_keypair(k_name)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('too long')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name)
@attr(type='negative')
def test_create_keypair_invalid_name(self):
# Keypairs with name being an invalid name should not be created
k_name = 'key_/.\@:'
- try:
- resp, _ = self.client.create_keypair(k_name)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('invalid name')
+ self.assertRaises(exceptions.BadRequest, self.client.create_keypair,
+ k_name)
class KeyPairsTestXML(KeyPairsTestJSON):
diff --git a/tempest/tests/compute/security_groups/test_security_group_rules.py b/tempest/tests/compute/security_groups/test_security_group_rules.py
index 5063fd3..32ac52b 100644
--- a/tempest/tests/compute/security_groups/test_security_group_rules.py
+++ b/tempest/tests/compute/security_groups/test_security_group_rules.py
@@ -135,21 +135,14 @@
def test_security_group_rules_create_with_invalid_id(self):
# Negative test: Creation of Security Group rule should FAIL
# with invalid Parent group id
- #Adding rules to the invalid Security Group id
+ # Adding rules to the invalid Security Group id
parent_group_id = rand_name('999')
ip_protocol = 'tcp'
from_port = 22
to_port = 22
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Security Group rule should not be created '
- 'with invalid parent group id')
+ self.assertRaises(exceptions.NotFound,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_create_with_invalid_ip_protocol(self):
@@ -165,18 +158,11 @@
ip_protocol = rand_name('999')
from_port = 22
to_port = 22
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group rule should not be created '
- 'with invalid ip_protocol')
- #Deleting the Security Group created in this method
- resp, _ = self.client.delete_security_group(securitygroup['id'])
+
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_create_with_invalid_from_port(self):
@@ -192,18 +178,10 @@
ip_protocol = 'tcp'
from_port = rand_name('999')
to_port = 22
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group rule should not be created'
- 'with invalid from_port')
- #Deleting the Security Group created in this method
- resp, _ = self.client.delete_security_group(securitygroup['id'])
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_create_with_invalid_to_port(self):
@@ -219,30 +197,18 @@
ip_protocol = 'tcp'
from_port = 22
to_port = rand_name('999')
- try:
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group rule should not be created'
- 'with invalid from_port')
- #Deleting the Security Group created in this method
- resp, _ = self.client.delete_security_group(securitygroup['id'])
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
def test_security_group_rules_delete_with_invalid_id(self):
# Negative test: Deletion of Security Group rule should be FAIL
# with invalid rule id
- try:
- self.client.delete_security_group_rule(rand_name('999'))
- except exceptions.NotFound:
- pass
- else:
- self.fail('Security Group Rule should not be deleted '
- 'with nonexistant rule id')
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group_rule,
+ rand_name('999'))
class SecurityGroupRulesTestXML(SecurityGroupRulesTestJSON):
diff --git a/tempest/tests/compute/security_groups/test_security_groups.py b/tempest/tests/compute/security_groups/test_security_groups.py
index c086280..e5b0380 100644
--- a/tempest/tests/compute/security_groups/test_security_groups.py
+++ b/tempest/tests/compute/security_groups/test_security_groups.py
@@ -116,100 +116,60 @@
non_exist_id = rand_name('999')
if non_exist_id not in security_group_id:
break
- try:
- resp, body = \
- self.client.get_security_group(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to GET the details from a '
- 'nonexistant Security Group')
+ self.assertRaises(exceptions.NotFound, self.client.get_security_group,
+ non_exist_id)
@attr(type='negative')
def test_security_group_create_with_invalid_group_name(self):
# Negative test: Security Group should not be created with group name
# as an empty string/with white spaces/chars more than 255
s_description = rand_name('description-')
- #Create Security Group with empty string as group name
- try:
- resp, _ = self.client.create_security_group("", s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with EMPTY Name')
- #Create Security Group with white space in group name
- try:
- resp, _ = self.client.create_security_group(" ", s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with WHITE SPACE in Name')
- #Create Security Group with group name longer than 255 chars
+ # Create Security Group with empty string as group name
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, "", s_description)
+ # Create Security Group with white space in group name
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, " ",
+ s_description)
+ # Create Security Group with group name longer than 255 chars
s_name = 'securitygroup-'.ljust(260, '0')
- try:
- resp, _ = self.client.create_security_group(s_name, s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with more than 255 chars in Name')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name,
+ s_description)
@attr(type='negative')
def test_security_group_create_with_invalid_group_description(self):
# Negative test:Security Group should not be created with description
# as an empty string/with white spaces/chars more than 255
s_name = rand_name('securitygroup-')
- #Create Security Group with empty string as description
- try:
- resp, _ = self.client.create_security_group(s_name, "")
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with EMPTY Description')
- #Create Security Group with white space in description
- try:
- resp, _ = self.client.create_security_group(s_name, " ")
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with WHITE SPACE in Description')
- #Create Security Group with group description longer than 255 chars
+ # Create Security Group with empty string as description
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name, "")
+ # Create Security Group with white space in description
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name, " ")
+ # Create Security Group with group description longer than 255 chars
s_description = 'description-'.ljust(260, '0')
- try:
- resp, _ = self.client.create_security_group(s_name, s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with more than 255 chars in Description')
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name,
+ s_description)
@attr(type='negative')
def test_security_group_create_with_duplicate_name(self):
# Negative test:Security Group with duplicate name should not
# be created
- try:
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
- resp, security_group =\
+ s_name = rand_name('securitygroup-')
+ s_description = rand_name('description-')
+ resp, security_group =\
self.client.create_security_group(s_name, s_description)
- self.assertEqual(200, resp.status)
- #Now try the Security Group with the same 'Name'
- try:
- resp, _ =\
- self.client.create_security_group(s_name, s_description)
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Security Group should not be created '
- 'with duplicate Group Name')
- finally:
- #Delete the Security Group created in this method
- resp, _ = self.client.delete_security_group(security_group['id'])
- self.assertEqual(202, resp.status)
+ self.assertEqual(200, resp.status)
+
+ self.addCleanup(self.client.delete_security_group,
+ security_group['id'])
+ # Now try the Security Group with the same 'Name'
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group, s_name,
+ s_description)
@attr(type='negative')
def test_delete_nonexistant_security_group(self):
@@ -223,25 +183,15 @@
non_exist_id = rand_name('999')
if non_exist_id not in security_group_id:
break
- try:
- resp, body = self.client.delete_security_group(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to delete a nonexistant '
- 'Security Group')
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group, non_exist_id)
@attr(type='negative')
def test_delete_security_group_without_passing_id(self):
# Negative test:Deletion of a Security Group with out passing ID
# should Fail
- try:
- resp, body = self.client.delete_security_group('')
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to delete a Security Group'
- 'with out passing ID')
+ self.assertRaises(exceptions.NotFound,
+ self.client.delete_security_group, '')
def test_server_security_groups(self):
# Checks that security groups may be added and linked to a server
diff --git a/tempest/tests/compute/servers/test_create_server.py b/tempest/tests/compute/servers/test_create_server.py
index 3c8aeda..aaab9fa 100644
--- a/tempest/tests/compute/servers/test_create_server.py
+++ b/tempest/tests/compute/servers/test_create_server.py
@@ -46,24 +46,17 @@
personality = [{'path': '/test.txt',
'contents': base64.b64encode(file_contents)}]
cls.client = cls.servers_client
- cli_resp = cls.client.create_server(cls.name,
- cls.image_ref,
- cls.flavor_ref,
- meta=cls.meta,
- accessIPv4=cls.accessIPv4,
- accessIPv6=cls.accessIPv6,
- personality=personality,
- disk_config=cls.disk_config)
+ cli_resp = cls.create_server(name=cls.name,
+ meta=cls.meta,
+ accessIPv4=cls.accessIPv4,
+ accessIPv6=cls.accessIPv6,
+ personality=personality,
+ disk_config=cls.disk_config)
cls.resp, cls.server_initial = cli_resp
cls.password = cls.server_initial['adminPass']
cls.client.wait_for_server_status(cls.server_initial['id'], 'ACTIVE')
resp, cls.server = cls.client.get_server(cls.server_initial['id'])
- @classmethod
- def tearDownClass(cls):
- cls.client.delete_server(cls.server_initial['id'])
- super(ServersTestJSON, cls).tearDownClass()
-
@attr(type='smoke')
def test_create_server_response(self):
# Check that the required fields are returned with values
diff --git a/tempest/tests/compute/servers/test_server_addresses.py b/tempest/tests/compute/servers/test_server_addresses.py
index b811d52..c69f68d 100644
--- a/tempest/tests/compute/servers/test_server_addresses.py
+++ b/tempest/tests/compute/servers/test_server_addresses.py
@@ -43,26 +43,15 @@
@attr(type='negative', category='server-addresses')
def test_list_server_addresses_invalid_server_id(self):
# List addresses request should fail if server id not in system
-
- try:
- self.client.list_addresses('999')
- except exceptions.NotFound:
- pass
- else:
- self.fail('The server rebuild for a non existing server should not'
- ' be allowed')
+ self.assertRaises(exceptions.NotFound, self.client.list_addresses,
+ '999')
@attr(type='negative', category='server-addresses')
def test_list_server_addresses_by_network_neg(self):
# List addresses by network should fail if network name not valid
-
- try:
- self.client.list_addresses_by_network(self.server['id'], 'invalid')
- except exceptions.NotFound:
- pass
- else:
- self.fail('The server rebuild for a non existing server should not'
- ' be allowed')
+ self.assertRaises(exceptions.NotFound,
+ self.client.list_addresses_by_network,
+ self.server['id'], 'invalid')
@attr(type='smoke', category='server-addresses')
def test_list_server_addresses(self):
diff --git a/tempest/tests/compute/volumes/test_volumes_negative.py b/tempest/tests/compute/volumes/test_volumes_negative.py
index c0fa565..306b93b 100644
--- a/tempest/tests/compute/volumes/test_volumes_negative.py
+++ b/tempest/tests/compute/volumes/test_volumes_negative.py
@@ -39,18 +39,13 @@
non_exist_id = rand_name('999')
if non_exist_id not in volume_id_list:
break
- #Trying to GET a non existant volume
- try:
- resp, body = self.client.get_volume(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to GET the details from a '
- 'nonexistant volume')
+ # Trying to GET a non existant volume
+ self.assertRaises(exceptions.NotFound, self.client.get_volume,
+ non_exist_id)
def test_volume_delete_nonexistant_volume_id(self):
# Negative: Should not be able to delete nonexistant Volume
- #Creating nonexistant volume id
+ # Creating nonexistant volume id
volume_id_list = list()
resp, body = self.client.list_volumes()
for i in range(len(body)):
@@ -59,13 +54,9 @@
non_exist_id = rand_name('999')
if non_exist_id not in volume_id_list:
break
- #Trying to DELETE a non existant volume
- try:
- resp, body = self.client.delete_volume(non_exist_id)
- except exceptions.NotFound:
- pass
- else:
- self.fail('Should not be able to DELETE a nonexistant volume')
+ # Trying to DELETE a non existant volume
+ self.assertRaises(exceptions.NotFound, self.client.delete_volume,
+ non_exist_id)
def test_create_volume_with_invalid_size(self):
# Negative: Should not be able to create volume with invalid size
diff --git a/tempest/tests/identity/admin/test_roles.py b/tempest/tests/identity/admin/test_roles.py
index 53c5b0d..f71bed0 100644
--- a/tempest/tests/identity/admin/test_roles.py
+++ b/tempest/tests/identity/admin/test_roles.py
@@ -95,15 +95,9 @@
role1_id = body.get('id')
self.assertTrue('status' in resp)
self.assertTrue(resp['status'].startswith('2'))
-
- try:
- resp, body = self.client.create_role(role_name)
- # this should raise an exception
- self.fail('Should not be able to create a duplicate role name.'
- ' %s' % role_name)
- except exceptions.Duplicate:
- pass
- self.client.delete_role(role1_id)
+ self.addCleanup(self.client.delete_role, role1_id)
+ self.assertRaises(exceptions.Duplicate, self.client.create_role,
+ role_name)
def test_assign_user_role(self):
# Assign a role to a user on a tenant
diff --git a/tempest/tests/identity/admin/test_tenants.py b/tempest/tests/identity/admin/test_tenants.py
index a3c9246..8155eb5 100644
--- a/tempest/tests/identity/admin/test_tenants.py
+++ b/tempest/tests/identity/admin/test_tenants.py
@@ -151,14 +151,10 @@
self.data.tenants.append(tenant)
tenant1_id = body.get('id')
- try:
- resp, body = self.client.create_tenant(tenant_name)
- # this should have raised an exception
- self.fail('Should not be able to create a duplicate tenant name')
- except exceptions.Duplicate:
- pass
- self.client.delete_tenant(tenant1_id)
- self.data.tenants.remove(tenant)
+ self.addCleanup(self.client.delete_tenant, tenant1_id)
+ self.addCleanup(self.data.tenants.remove, tenant)
+ self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
+ tenant_name)
@attr(type='negative')
def test_create_tenant_by_unauthorized_user(self):
diff --git a/tempest/tests/image/test_images.py b/tempest/tests/image/test_images.py
index 6ac852e..84bb650 100644
--- a/tempest/tests/image/test_images.py
+++ b/tempest/tests/image/test_images.py
@@ -16,15 +16,11 @@
# under the License.
import cStringIO as StringIO
-import random
-
-import tempest.test
-
-from tempest.test import attr
-
from tempest import clients
from tempest import exceptions
+import tempest.test
+from tempest.test import attr
class CreateRegisterImagesTest(tempest.test.BaseTestCase):
@@ -47,21 +43,13 @@
@attr(type='negative')
def test_register_with_invalid_container_format(self):
# Negative tests for invalid data supplied to POST /images
- try:
- resp, body = self.client.create_image('test', 'wrong', 'vhd')
- except exceptions.BadRequest:
- pass
- else:
- self.fail('Invalid container format should not be accepted')
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ 'test', 'wrong', 'vhd')
@attr(type='negative')
def test_register_with_invalid_disk_format(self):
- try:
- resp, body = self.client.create_image('test', 'bare', 'wrong')
- except exceptions.BadRequest:
- pass
- else:
- self.fail("Invalid disk format should not be accepted")
+ self.assertRaises(exceptions.BadRequest, self.client.create_image,
+ 'test', 'bare', 'wrong')
@attr(type='image')
def test_register_then_upload(self):
@@ -121,12 +109,27 @@
# We add a few images here to test the listing functionality of
# the images API
- for x in xrange(0, 10):
- # We make even images remote and odd images standard
- if x % 2 == 0:
- cls.created_images.append(cls._create_remote_image(x))
- else:
- cls.created_images.append(cls._create_standard_image(x))
+ img1 = cls._create_remote_image('one', 'bare', 'raw')
+ img2 = cls._create_remote_image('two', 'ami', 'ami')
+ img3 = cls._create_remote_image('dup', 'bare', 'raw')
+ img4 = cls._create_remote_image('dup', 'bare', 'raw')
+ img5 = cls._create_standard_image('1', 'ami', 'ami', 42)
+ img6 = cls._create_standard_image('2', 'ami', 'ami', 142)
+ img7 = cls._create_standard_image('33', 'bare', 'raw', 142)
+ img8 = cls._create_standard_image('33', 'bare', 'raw', 142)
+ cls.created_set = set(cls.created_images)
+ # 4x-4x remote image
+ cls.remote_set = set((img1, img2, img3, img4))
+ cls.standard_set = set((img5, img6, img7, img8))
+ # 5x bare, 3x ami
+ cls.bare_set = set((img1, img3, img4, img7, img8))
+ cls.ami_set = set((img2, img5, img6))
+ # 1x with size 42
+ cls.size42_set = set((img5,))
+ # 3x with size 142
+ cls.size142_set = set((img6, img7, img8))
+ # dup named
+ cls.dup_set = set((img3, img4))
@classmethod
def tearDownClass(cls):
@@ -135,31 +138,36 @@
cls.client.wait_for_resource_deletion(image_id)
@classmethod
- def _create_remote_image(cls, x):
+ def _create_remote_image(cls, name, container_format, disk_format):
"""
Create a new remote image and return the ID of the newly-registered
image
"""
- name = 'New Remote Image %s' % x
- location = 'http://example.com/someimage_%s.iso' % x
- resp, body = cls.client.create_image(name, 'bare', 'raw',
- is_public=True,
- location=location)
- image_id = body['id']
+ name = 'New Remote Image %s' % name
+ location = 'http://example.com/someimage_%s.iso' % name
+ resp, image = cls.client.create_image(name,
+ container_format, disk_format,
+ is_public=True,
+ location=location)
+ image_id = image['id']
+ cls.created_images.append(image_id)
return image_id
@classmethod
- def _create_standard_image(cls, x):
+ def _create_standard_image(cls, name, container_format,
+ disk_format, size):
"""
Create a new standard image and return the ID of the newly-registered
image. Note that the size of the new image is a random number between
1024 and 4096
"""
- image_file = StringIO.StringIO('*' * random.randint(1024, 4096))
- name = 'New Standard Image %s' % x
- resp, body = cls.client.create_image(name, 'bare', 'raw',
- is_public=True, data=image_file)
- image_id = body['id']
+ image_file = StringIO.StringIO('*' * size)
+ name = 'New Standard Image %s' % name
+ resp, image = cls.client.create_image(name,
+ container_format, disk_format,
+ is_public=True, data=image_file)
+ image_id = image['id']
+ cls.created_images.append(image_id)
return image_id
@attr(type='image')
@@ -168,5 +176,69 @@
resp, images_list = self.client.image_list()
self.assertEqual(resp['status'], '200')
image_list = map(lambda x: x['id'], images_list)
- for image in self.created_images:
- self.assertTrue(image in image_list)
+ for image_id in self.created_images:
+ self.assertTrue(image_id in image_list)
+
+ @attr(type='image')
+ def test_index_disk_format(self):
+ resp, images_list = self.client.image_list(disk_format='ami')
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertEqual(image['disk_format'], 'ami')
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.ami_set <= result_set)
+ self.assertFalse(self.created_set - self.ami_set <= result_set)
+
+ @attr(type='image')
+ def test_index_container_format(self):
+ resp, images_list = self.client.image_list(container_format='bare')
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertEqual(image['container_format'], 'bare')
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.bare_set <= result_set)
+ self.assertFalse(self.created_set - self.bare_set <= result_set)
+
+ @attr(type='image')
+ def test_index_max_size(self):
+ resp, images_list = self.client.image_list(size_max=42)
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertTrue(image['size'] <= 42)
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.size42_set <= result_set)
+ self.assertFalse(self.created_set - self.size42_set <= result_set)
+
+ @attr(type='image')
+ def test_index_min_size(self):
+ resp, images_list = self.client.image_list(size_min=142)
+ self.assertEqual(resp['status'], '200')
+ for image in images_list:
+ self.assertTrue(image['size'] >= 142)
+ result_set = set(map(lambda x: x['id'], images_list))
+ self.assertTrue(self.size142_set <= result_set)
+ self.assertFalse(self.size42_set <= result_set)
+
+ @attr(type='image')
+ def test_index_status_active_detail(self):
+ resp, images_list = self.client.image_list_detail(status='active',
+ sort_key='size',
+ sort_dir='desc')
+ self.assertEqual(resp['status'], '200')
+ top_size = images_list[0]['size'] # We have non-zero sized images
+ for image in images_list:
+ size = image['size']
+ self.assertTrue(size <= top_size)
+ top_size = size
+ self.assertEqual(image['status'], 'active')
+
+ @attr(type='image')
+ def test_index_name(self):
+ resp, images_list = self.client.image_list_detail(
+ name='New Remote Image dup')
+ self.assertEqual(resp['status'], '200')
+ result_set = set(map(lambda x: x['id'], images_list))
+ for image in images_list:
+ self.assertEqual(image['name'], 'New Remote Image dup')
+ self.assertTrue(self.dup_set <= result_set)
+ self.assertFalse(self.created_set - self.dup_set <= result_set)