Merge "Update defaults for s3 materials paths/names"
diff --git a/cli/__init__.py b/cli/__init__.py
index cea0b62..e97fe3e 100644
--- a/cli/__init__.py
+++ b/cli/__init__.py
@@ -16,8 +16,11 @@
 #    under the License.
 
 import logging
+import shlex
+import subprocess
 
 from tempest.openstack.common import cfg
+import tempest.test
 
 LOG = logging.getLogger(__name__)
 
@@ -34,3 +37,45 @@
 cli_group = cfg.OptGroup(name='cli', title="cli Configuration Options")
 CONF.register_group(cli_group)
 CONF.register_opts(cli_opts, group=cli_group)
+
+
+class ClientTestBase(tempest.test.BaseTestCase):
+    @classmethod
+    def setUpClass(cls):
+        if not CONF.cli.enabled:
+            msg = "cli testing disabled"
+            raise cls.skipException(msg)
+        cls.identity = cls.config.identity
+        super(ClientTestBase, cls).setUpClass()
+
+    def __init__(self, *args, **kwargs):
+        super(ClientTestBase, self).__init__(*args, **kwargs)
+
+    def nova(self, action, flags='', params='', admin=True, fail_ok=False):
+        """Executes nova command for the given action."""
+        return self.cmd_with_auth(
+            'nova', action, flags, params, admin, fail_ok)
+
+    def cmd_with_auth(self, cmd, action, flags='', params='',
+                      admin=True, fail_ok=False):
+        """Executes given command with auth attributes appended."""
+        #TODO(jogo) make admin=False work
+        creds = ('--os-username %s --os-tenant-name %s --os-password %s '
+                 '--os-auth-url %s ' % (self.identity.admin_username,
+                 self.identity.admin_tenant_name, self.identity.admin_password,
+                 self.identity.uri))
+        flags = creds + ' ' + flags
+        return self.cmd(cmd, action, flags, params, fail_ok)
+
+    def cmd(self, cmd, action, flags='', params='', fail_ok=False):
+        """Executes specified command for the given action."""
+        cmd = ' '.join([CONF.cli.cli_dir + cmd,
+                        flags, action, params])
+        LOG.info("running: '%s'" % cmd)
+        cmd = shlex.split(cmd)
+        try:
+            result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+        except subprocess.CalledProcessError, e:
+            LOG.error("command output:\n%s" % e.output)
+            raise
+        return result
diff --git a/cli/simple_read_only/test_compute.py b/cli/simple_read_only/test_compute.py
index 073fde1..849ed6f 100644
--- a/cli/simple_read_only/test_compute.py
+++ b/cli/simple_read_only/test_compute.py
@@ -16,14 +16,12 @@
 #    under the License.
 
 import logging
-import shlex
 import subprocess
 
 import testtools
 
 import cli
 
-from tempest import config
 from tempest.openstack.common import cfg
 
 
@@ -33,7 +31,7 @@
 LOG = logging.getLogger(__name__)
 
 
-class SimpleReadOnlyNovaCLientTest(testtools.TestCase):
+class SimpleReadOnlyNovaClientTest(cli.ClientTestBase):
 
     """
     This is a first pass at a simple read only python-novaclient test. This
@@ -47,33 +45,6 @@
 
     """
 
-    @classmethod
-    def setUpClass(cls):
-        if not CONF.cli.enabled:
-            msg = "cli testing disabled"
-            raise cls.skipException(msg)
-        cls.identity = config.TempestConfig().identity
-        super(SimpleReadOnlyNovaCLientTest, cls).setUpClass()
-
-    #NOTE(jogo): This should eventually be moved into a base class
-    def nova(self, action, flags='', params='', admin=True, fail_ok=False):
-        """Executes nova command for the given action."""
-        #TODO(jogo) make admin=False work
-        creds = ('--os-username %s --os-tenant-name %s --os-password %s '
-                 '--os-auth-url %s ' % (self.identity.admin_username,
-                 self.identity.admin_tenant_name, self.identity.admin_password,
-                 self.identity.uri))
-        flags = creds + ' ' + flags
-        cmd = ' '.join([CONF.cli.cli_dir + 'nova', flags, action, params])
-        LOG.info("running: '%s'" % cmd)
-        cmd = shlex.split(cmd)
-        try:
-            result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
-        except subprocess.CalledProcessError, e:
-            LOG.error("command output:\n%s" % e.output)
-            raise
-        return result
-
     def test_admin_fake_action(self):
         self.assertRaises(subprocess.CalledProcessError,
                           self.nova,
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index 170a137..c582826 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -338,6 +338,11 @@
             return self.check_over_limit(resp_body, method, url, headers, body,
                                          depth, wait)
 
+        if resp.status == 422:
+            if parse_resp:
+                resp_body = self._parse_resp(resp_body)
+            raise exceptions.UnprocessableEntity(resp_body)
+
         if resp.status in (500, 501):
             message = resp_body
             if parse_resp:
diff --git a/tempest/exceptions.py b/tempest/exceptions.py
index 577aa13..235a2e7 100644
--- a/tempest/exceptions.py
+++ b/tempest/exceptions.py
@@ -94,6 +94,10 @@
     message = "Bad request"
 
 
+class UnprocessableEntity(RestClientException):
+    message = "Unprocessable entity"
+
+
 class AuthenticationFailure(RestClientException):
     message = ("Authentication with user %(user)s and password "
                "%(password)s failed")
diff --git a/tempest/services/botoclients.py b/tempest/services/botoclients.py
index 143257a..0870c96 100644
--- a/tempest/services/botoclients.py
+++ b/tempest/services/botoclients.py
@@ -17,7 +17,6 @@
 
 import ConfigParser
 import contextlib
-import re
 import types
 import urlparse
 
diff --git a/tempest/services/image/json/image_client.py b/tempest/services/image/json/image_client.py
index e9276aa..277075e 100644
--- a/tempest/services/image/json/image_client.py
+++ b/tempest/services/image/json/image_client.py
@@ -25,7 +25,6 @@
 from tempest.common import glance_http
 from tempest.common.rest_client import RestClient
 from tempest import exceptions
-from tempest import manager
 
 
 class ImageClientJSON(RestClient):
@@ -97,11 +96,11 @@
             return None
 
     def _get_http(self):
-        temp_manager = manager.DefaultClientManager()
-        keystone = temp_manager._get_identity_client()
-        token = keystone.auth_token
-        endpoint = keystone.service_catalog.url_for(service_type='image',
-                                                    endpoint_type='publicURL')
+        token, endpoint = self.keystone_auth(self.user,
+                                             self.password,
+                                             self.auth_url,
+                                             self.service,
+                                             self.tenant_name)
         dscv = self.config.identity.disable_ssl_certificate_validation
         return glance_http.HTTPClient(endpoint=endpoint, token=token,
                                       insecure=dscv)
@@ -170,17 +169,23 @@
 
     def delete_image(self, image_id):
         url = 'v1/images/%s' % image_id
-        try:
-            self.delete(url)
-        except exceptions.Unauthorized:
-            url = '/' + url
-            self.http.raw_request('DELETE', url)
+        self.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/test.py b/tempest/test.py
index 90793ac..e0639b6 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -58,12 +58,11 @@
 
 
 class TestCase(BaseTestCase):
-
-    """
-    Base test case class for all Tempest tests
+    """Base test case class for all Tempest tests
 
     Contains basic setup and convenience methods
     """
+
     manager_class = None
 
     @classmethod
diff --git a/tempest/testboto.py b/tempest/testboto.py
index 5625841..cee8843 100644
--- a/tempest/testboto.py
+++ b/tempest/testboto.py
@@ -17,16 +17,21 @@
 
 from contextlib import closing
 import logging
+import os
 import re
+import urlparse
 
 import boto
 from boto import ec2
 from boto import exception
 from boto import s3
+import keystoneclient.exceptions
 
+import tempest.clients
+from tempest.common.utils.file_utils import have_effective_read_access
+import tempest.config
 from tempest import exceptions
 import tempest.test
-import tempest.tests.boto
 from tempest.tests.boto.utils.wait import re_search_wait
 from tempest.tests.boto.utils.wait import state_wait
 from tempest.tests.boto.utils.wait import wait_exception
@@ -34,6 +39,71 @@
 LOG = logging.getLogger(__name__)
 
 
+def decision_maker():
+    A_I_IMAGES_READY = True  # ari,ami,aki
+    S3_CAN_CONNECT_ERROR = None
+    EC2_CAN_CONNECT_ERROR = None
+    secret_matcher = re.compile("[A-Za-z0-9+/]{32,}")  # 40 in other system
+    id_matcher = re.compile("[A-Za-z0-9]{20,}")
+
+    def all_read(*args):
+        return all(map(have_effective_read_access, args))
+
+    config = tempest.config.TempestConfig()
+    materials_path = config.boto.s3_materials_path
+    ami_path = materials_path + os.sep + config.boto.ami_manifest
+    aki_path = materials_path + os.sep + config.boto.aki_manifest
+    ari_path = materials_path + os.sep + config.boto.ari_manifest
+
+    A_I_IMAGES_READY = all_read(ami_path, aki_path, ari_path)
+    boto_logger = logging.getLogger('boto')
+    level = boto_logger.level
+    boto_logger.setLevel(logging.CRITICAL)  # suppress logging for these
+
+    def _cred_sub_check(connection_data):
+        if not id_matcher.match(connection_data["aws_access_key_id"]):
+            raise Exception("Invalid AWS access Key")
+        if not secret_matcher.match(connection_data["aws_secret_access_key"]):
+            raise Exception("Invalid AWS secret Key")
+        raise Exception("Unknown (Authentication?) Error")
+    openstack = tempest.clients.Manager()
+    try:
+        if urlparse.urlparse(config.boto.ec2_url).hostname is None:
+            raise Exception("Failed to get hostname from the ec2_url")
+        ec2client = openstack.ec2api_client
+        try:
+            ec2client.get_all_regions()
+        except exception.BotoServerError as exc:
+                if exc.error_code is None:
+                    raise Exception("EC2 target does not looks EC2 service")
+                _cred_sub_check(ec2client.connection_data)
+
+    except keystoneclient.exceptions.Unauthorized:
+        EC2_CAN_CONNECT_ERROR = "AWS credentials not set," +\
+                                " faild to get them even by keystoneclient"
+    except Exception as exc:
+        EC2_CAN_CONNECT_ERROR = str(exc)
+
+    try:
+        if urlparse.urlparse(config.boto.s3_url).hostname is None:
+            raise Exception("Failed to get hostname from the s3_url")
+        s3client = openstack.s3_client
+        try:
+            s3client.get_bucket("^INVALID*#()@INVALID.")
+        except exception.BotoServerError as exc:
+            if exc.status == 403:
+                _cred_sub_check(s3client.connection_data)
+    except Exception as exc:
+        S3_CAN_CONNECT_ERROR = str(exc)
+    except keystoneclient.exceptions.Unauthorized:
+        S3_CAN_CONNECT_ERROR = "AWS credentials not set," +\
+                               " faild to get them even by keystoneclient"
+    boto_logger.setLevel(level)
+    return {'A_I_IMAGES_READY': A_I_IMAGES_READY,
+            'S3_CAN_CONNECT_ERROR': S3_CAN_CONNECT_ERROR,
+            'EC2_CAN_CONNECT_ERROR': EC2_CAN_CONNECT_ERROR}
+
+
 class BotoExceptionMatcher(object):
     STATUS_RE = r'[45]\d\d'
     CODE_RE = '.*'  # regexp makes sense in group match
@@ -121,7 +191,7 @@
 class BotoTestCase(tempest.test.BaseTestCase):
     """Recommended to use as base class for boto related test."""
 
-    conclusion = tempest.tests.boto.generic_setup_package()
+    conclusion = decision_maker()
 
     @classmethod
     def setUpClass(cls):
@@ -130,13 +200,13 @@
         cls._resource_trash_bin = {}
         cls._sequence = -1
         if (hasattr(cls, "EC2") and
-            tempest.tests.boto.EC2_CAN_CONNECT_ERROR is not None):
+            cls.conclusion['EC2_CAN_CONNECT_ERROR'] is not None):
             raise cls.skipException("EC2 " + cls.__name__ + ": " +
-                                    tempest.tests.boto.EC2_CAN_CONNECT_ERROR)
+                                    cls.conclusion['EC2_CAN_CONNECT_ERROR'])
         if (hasattr(cls, "S3") and
-            tempest.tests.boto.S3_CAN_CONNECT_ERROR is not None):
+            cls.conclusion['S3_CAN_CONNECT_ERROR'] is not None):
             raise cls.skipException("S3 " + cls.__name__ + ": " +
-                                    tempest.tests.boto.S3_CAN_CONNECT_ERROR)
+                                    cls.conclusion['S3_CAN_CONNECT_ERROR'])
 
     @classmethod
     def addResourceCleanUp(cls, function, *args, **kwargs):
diff --git a/tempest/tests/boto/__init__.py b/tempest/tests/boto/__init__.py
index dd224d6..e69de29 100644
--- a/tempest/tests/boto/__init__.py
+++ b/tempest/tests/boto/__init__.py
@@ -1,94 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2012 OpenStack, LLC
-# All Rights Reserved.
-#
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
-#    not use this file except in compliance with the License. You may obtain
-#    a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#    Unless required by applicable law or agreed to in writing, software
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-#    License for the specific language governing permissions and limitations
-#    under the License.
-
-import logging
-import os
-import re
-import urlparse
-
-import boto.exception
-import keystoneclient.exceptions
-
-import tempest.clients
-from tempest.common.utils.file_utils import have_effective_read_access
-import tempest.config
-
-A_I_IMAGES_READY = True  # ari,ami,aki
-S3_CAN_CONNECT_ERROR = None
-EC2_CAN_CONNECT_ERROR = None
-
-
-def generic_setup_package():
-    global A_I_IMAGES_READY
-    global S3_CAN_CONNECT_ERROR
-    global EC2_CAN_CONNECT_ERROR
-    secret_matcher = re.compile("[A-Za-z0-9+/]{32,}")  # 40 in other system
-    id_matcher = re.compile("[A-Za-z0-9]{20,}")
-
-    def all_read(*args):
-        return all(map(have_effective_read_access, args))
-
-    config = tempest.config.TempestConfig()
-    materials_path = config.boto.s3_materials_path
-    ami_path = materials_path + os.sep + config.boto.ami_manifest
-    aki_path = materials_path + os.sep + config.boto.aki_manifest
-    ari_path = materials_path + os.sep + config.boto.ari_manifest
-
-    A_I_IMAGES_READY = all_read(ami_path, aki_path, ari_path)
-    boto_logger = logging.getLogger('boto')
-    level = boto_logger.level
-    boto_logger.setLevel(logging.CRITICAL)  # suppress logging for these
-
-    def _cred_sub_check(connection_data):
-        if not id_matcher.match(connection_data["aws_access_key_id"]):
-            raise Exception("Invalid AWS access Key")
-        if not secret_matcher.match(connection_data["aws_secret_access_key"]):
-            raise Exception("Invalid AWS secret Key")
-        raise Exception("Unknown (Authentication?) Error")
-    openstack = tempest.clients.Manager()
-    try:
-        if urlparse.urlparse(config.boto.ec2_url).hostname is None:
-            raise Exception("Failed to get hostname from the ec2_url")
-        ec2client = openstack.ec2api_client
-        try:
-            ec2client.get_all_regions()
-        except boto.exception.BotoServerError as exc:
-                if exc.error_code is None:
-                    raise Exception("EC2 target does not looks EC2 service")
-                _cred_sub_check(ec2client.connection_data)
-
-    except keystoneclient.exceptions.Unauthorized:
-        EC2_CAN_CONNECT_ERROR = "AWS credentials not set," +\
-                                " faild to get them even by keystoneclient"
-    except Exception as exc:
-        EC2_CAN_CONNECT_ERROR = str(exc)
-
-    try:
-        if urlparse.urlparse(config.boto.s3_url).hostname is None:
-            raise Exception("Failed to get hostname from the s3_url")
-        s3client = openstack.s3_client
-        try:
-            s3client.get_bucket("^INVALID*#()@INVALID.")
-        except boto.exception.BotoServerError as exc:
-            if exc.status == 403:
-                _cred_sub_check(s3client.connection_data)
-    except Exception as exc:
-        S3_CAN_CONNECT_ERROR = str(exc)
-    except keystoneclient.exceptions.Unauthorized:
-        S3_CAN_CONNECT_ERROR = "AWS credentials not set," +\
-                               " faild to get them even by keystoneclient"
-    boto_logger.setLevel(level)
diff --git a/tempest/tests/boto/test_ec2_instance_run.py b/tempest/tests/boto/test_ec2_instance_run.py
index 6b61c11..98fdc8b 100644
--- a/tempest/tests/boto/test_ec2_instance_run.py
+++ b/tempest/tests/boto/test_ec2_instance_run.py
@@ -17,15 +17,15 @@
 
 import logging
 
-from boto.exception import EC2ResponseError
+from boto import exception
 import testtools
 
 from tempest import clients
 from tempest.common.utils.data_utils import rand_name
 from tempest.common.utils.linux.remote_client import RemoteClient
+from tempest import exceptions
 from tempest.test import attr
 from tempest.testboto import BotoTestCase
-import tempest.tests.boto
 from tempest.tests.boto.utils.s3 import s3_upload_dir
 from tempest.tests.boto.utils.wait import re_search_wait
 from tempest.tests.boto.utils.wait import state_wait
@@ -39,7 +39,7 @@
     @classmethod
     def setUpClass(cls):
         super(InstanceRunTest, cls).setUpClass()
-        if not tempest.tests.boto.A_I_IMAGES_READY:
+        if not cls.conclusion['A_I_IMAGES_READY']:
             raise cls.skipException("".join(("EC2 ", cls.__name__,
                                     ": requires ami/aki/ari manifest")))
         cls.os = clients.Manager()
@@ -86,7 +86,8 @@
             if state != "available":
                 for _image in cls.images.itervalues():
                     cls.ec2_client.deregister_image(_image["image_id"])
-                raise EC2RegisterImageException(image_id=image["image_id"])
+                raise exceptions.EC2RegisterImageException(image_id=
+                                                           image["image_id"])
 
     @attr(type='smoke')
     def test_run_stop_terminate_instance(self):
@@ -129,7 +130,7 @@
             instance.update(validate=True)
         except ValueError:
             pass
-        except EC2ResponseError as exc:
+        except exception.EC2ResponseError as exc:
             if self.ec2_error_code.\
                 client.InvalidInstanceID.NotFound.match(exc):
                 pass
diff --git a/tempest/tests/boto/test_s3_ec2_images.py b/tempest/tests/boto/test_s3_ec2_images.py
index 1088b00..4068aba 100644
--- a/tempest/tests/boto/test_s3_ec2_images.py
+++ b/tempest/tests/boto/test_s3_ec2_images.py
@@ -23,7 +23,6 @@
 from tempest.common.utils.data_utils import rand_name
 from tempest.test import attr
 from tempest.testboto import BotoTestCase
-import tempest.tests.boto
 from tempest.tests.boto.utils.s3 import s3_upload_dir
 from tempest.tests.boto.utils.wait import state_wait
 
@@ -34,7 +33,7 @@
     @classmethod
     def setUpClass(cls):
         super(S3ImagesTest, cls).setUpClass()
-        if not tempest.tests.boto.A_I_IMAGES_READY:
+        if not cls.conclusion['A_I_IMAGES_READY']:
             raise cls.skipException("".join(("EC2 ", cls.__name__,
                                     ": requires ami/aki/ari manifest")))
         cls.os = clients.Manager()
diff --git a/tempest/tests/compute/admin/test_quotas.py b/tempest/tests/compute/admin/test_quotas.py
index d63f72f..7430a7c 100644
--- a/tempest/tests/compute/admin/test_quotas.py
+++ b/tempest/tests/compute/admin/test_quotas.py
@@ -152,6 +152,19 @@
 
 #TODO(afazekas): Add test that tried to update the quota_set as a regular user
 
+    @attr(type='negative')
+    def test_create_server_when_instances_quota_is_full(self):
+        #Once instances quota limit is reached, disallow server creation
+        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
+        default_instances_quota = quota_set['instances']
+        instances_quota = 0  # Set quota to zero to disallow server creation
+
+        self.adm_client.update_quota_set(self.demo_tenant_id,
+                                         instances=instances_quota)
+        self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id,
+                        instances=default_instances_quota)
+        self.assertRaises(exceptions.OverLimit, self.create_server)
+
 
 class QuotasAdminTestXML(QuotasAdminTestJSON):
     _interface = 'xml'
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..0ff81e1 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,25 @@
         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.UnprocessableEntity),
+                          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/test_live_block_migration.py b/tempest/tests/compute/test_live_block_migration.py
index dcd6a78..f2ec753 100644
--- a/tempest/tests/compute/test_live_block_migration.py
+++ b/tempest/tests/compute/test_live_block_migration.py
@@ -86,7 +86,7 @@
             if 'ACTIVE' == self._get_server_status(server_id):
                 return server_id
         else:
-            server = self.create_server()
+            _, server = self.create_server(wait_until="ACTIVE")
             server_id = server['id']
             self.password = server['adminPass']
             self.password = 'password'
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)
diff --git a/tools/pip-requires b/tools/pip-requires
index 5c45a49..220f1a6 100644
--- a/tools/pip-requires
+++ b/tools/pip-requires
@@ -1,7 +1,7 @@
 anyjson
 nose
 httplib2>=0.7.0
-testtools
+testtools>=0.9.29
 lxml
 boto>=2.2.1
 paramiko