raise the first exception in flavors and security_group test

The exceptions raised in the finally block hides the exceptions raised
in the try block.

For example if a resource creation fails you would see the exception from the
resource deletion.

This change replaces the finally usage by addCleanup methods.

test_security_group_rules_create_delete removed because of a duplication.

Change-Id: Id69a3b7edd0933f4d5967bd8b84fb16a2095ab0a
diff --git a/tempest/tests/compute/admin/test_flavors.py b/tempest/tests/compute/admin/test_flavors.py
index 32b06f8..7957009 100644
--- a/tempest/tests/compute/admin/test_flavors.py
+++ b/tempest/tests/compute/admin/test_flavors.py
@@ -48,6 +48,11 @@
         cls.swap = 1024
         cls.rxtx = 2
 
+    def flavor_clean_up(self, flavor_id):
+        resp, body = self.client.delete_flavor(flavor_id)
+        self.assertEqual(resp.status, 202)
+        self.client.wait_for_resource_deletion(flavor_id)
+
     @attr(type='positive')
     def test_create_flavor(self):
         # Create a flavor and ensure it is listed
@@ -55,43 +60,37 @@
         flavor_name = rand_name(self.flavor_name_prefix)
         new_flavor_id = rand_int_id(start=1000)
 
-        try:
-            #Create the flavor
-            resp, flavor = self.client.create_flavor(flavor_name,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     new_flavor_id,
-                                                     ephemeral=self.ephemeral,
-                                                     swap=self.swap,
-                                                     rxtx=self.rxtx)
-            self.assertEqual(200, resp.status)
-            self.assertEqual(flavor['name'], flavor_name)
-            self.assertEqual(flavor['vcpus'], self.vcpus)
-            self.assertEqual(flavor['disk'], self.disk)
-            self.assertEqual(flavor['ram'], self.ram)
-            self.assertEqual(int(flavor['id']), new_flavor_id)
-            self.assertEqual(flavor['swap'], self.swap)
-            self.assertEqual(flavor['rxtx_factor'], self.rxtx)
-            self.assertEqual(flavor['OS-FLV-EXT-DATA:ephemeral'],
-                             self.ephemeral)
-            if self._interface == "xml":
-                XMLNS_OS_FLV_ACCESS = "http://docs.openstack.org/compute/ext/"\
-                    "flavor_access/api/v2"
-                key = "{" + XMLNS_OS_FLV_ACCESS + "}is_public"
-                self.assertEqual(flavor[key], "True")
-            if self._interface == "json":
-                self.assertEqual(flavor['os-flavor-access:is_public'], True)
+        #Create the flavor
+        resp, flavor = self.client.create_flavor(flavor_name,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 new_flavor_id,
+                                                 ephemeral=self.ephemeral,
+                                                 swap=self.swap,
+                                                 rxtx=self.rxtx)
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
+        self.assertEqual(200, resp.status)
+        self.assertEqual(flavor['name'], flavor_name)
+        self.assertEqual(flavor['vcpus'], self.vcpus)
+        self.assertEqual(flavor['disk'], self.disk)
+        self.assertEqual(flavor['ram'], self.ram)
+        self.assertEqual(int(flavor['id']), new_flavor_id)
+        self.assertEqual(flavor['swap'], self.swap)
+        self.assertEqual(flavor['rxtx_factor'], self.rxtx)
+        self.assertEqual(flavor['OS-FLV-EXT-DATA:ephemeral'],
+                         self.ephemeral)
+        if self._interface == "xml":
+            XMLNS_OS_FLV_ACCESS = "http://docs.openstack.org/compute/ext/"\
+                "flavor_access/api/v2"
+            key = "{" + XMLNS_OS_FLV_ACCESS + "}is_public"
+            self.assertEqual(flavor[key], "True")
+        if self._interface == "json":
+            self.assertEqual(flavor['os-flavor-access:is_public'], True)
 
-            #Verify flavor is retrieved
-            resp, flavor = self.client.get_flavor_details(new_flavor_id)
-            self.assertEqual(resp.status, 200)
-            self.assertEqual(flavor['name'], flavor_name)
-
-        finally:
-            #Delete the flavor
-            resp, body = self.client.delete_flavor(new_flavor_id)
-            self.assertEqual(resp.status, 202)
-            self.client.wait_for_resource_deletion(new_flavor_id)
+        #Verify flavor is retrieved
+        resp, flavor = self.client.get_flavor_details(new_flavor_id)
+        self.assertEqual(resp.status, 200)
+        self.assertEqual(flavor['name'], flavor_name)
 
     @attr(type='positive')
     def test_create_flavor_verify_entry_in_list_details(self):
@@ -100,29 +99,23 @@
         flavor_name = rand_name(self.flavor_name_prefix)
         new_flavor_id = rand_int_id(start=1000)
 
-        try:
-            #Create the flavor
-            resp, flavor = self.client.create_flavor(flavor_name,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     new_flavor_id,
-                                                     ephemeral=self.ephemeral,
-                                                     swap=self.swap,
-                                                     rxtx=self.rxtx)
-            flag = False
-            #Verify flavor is retrieved
-            resp, flavors = self.client.list_flavors_with_detail()
-            self.assertEqual(resp.status, 200)
-            for flavor in flavors:
-                if flavor['name'] == flavor_name:
-                    flag = True
-            self.assertTrue(flag)
-
-        finally:
-            #Delete the flavor
-            resp, body = self.client.delete_flavor(new_flavor_id)
-            self.assertEqual(resp.status, 202)
-            self.client.wait_for_resource_deletion(new_flavor_id)
+        #Create the flavor
+        resp, flavor = self.client.create_flavor(flavor_name,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 new_flavor_id,
+                                                 ephemeral=self.ephemeral,
+                                                 swap=self.swap,
+                                                 rxtx=self.rxtx)
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
+        flag = False
+        #Verify flavor is retrieved
+        resp, flavors = self.client.list_flavors_with_detail()
+        self.assertEqual(resp.status, 200)
+        for flavor in flavors:
+            if flavor['name'] == flavor_name:
+                flag = True
+        self.assertTrue(flag)
 
     @attr(type='negative')
     def test_get_flavor_details_for_deleted_flavor(self):
@@ -138,11 +131,11 @@
                                                  ephemeral=self.ephemeral,
                                                  swap=self.swap,
                                                  rxtx=self.rxtx)
-        self.assertEquals(200, resp.status)
-
         # Delete the flavor
-        resp, _ = self.client.delete_flavor(new_flavor_id)
-        self.assertEqual(resp.status, 202)
+        new_flavor_id = flavor['id']
+        resp_delete, body = self.client.delete_flavor(new_flavor_id)
+        self.assertEquals(200, resp.status)
+        self.assertEquals(202, resp_delete.status)
 
         # Deleted flavors can be seen via detailed GET
         resp, flavor = self.client.get_flavor_details(new_flavor_id)
@@ -164,46 +157,40 @@
         flavor_name = rand_name(self.flavor_name_prefix)
         new_flavor_id = rand_int_id(start=1000)
 
-        try:
-            #Create the flavor
-            resp, flavor = self.client.create_flavor(flavor_name,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     new_flavor_id)
-            self.assertEqual(200, resp.status)
-            self.assertEqual(flavor['name'], flavor_name)
-            self.assertEqual(flavor['ram'], self.ram)
-            self.assertEqual(flavor['vcpus'], self.vcpus)
-            self.assertEqual(flavor['disk'], self.disk)
-            self.assertEqual(int(flavor['id']), new_flavor_id)
-            self.assertEqual(flavor['swap'], '')
-            self.assertEqual(int(flavor['rxtx_factor']), 1)
-            self.assertEqual(int(flavor['OS-FLV-EXT-DATA:ephemeral']), 0)
-            if self._interface == "xml":
-                XMLNS_OS_FLV_ACCESS = "http://docs.openstack.org/compute/ext/"\
-                    "flavor_access/api/v2"
-                key = "{" + XMLNS_OS_FLV_ACCESS + "}is_public"
-                self.assertEqual(flavor[key], "True")
-            if self._interface == "json":
-                self.assertEqual(flavor['os-flavor-access:is_public'], True)
+        #Create the flavor
+        resp, flavor = self.client.create_flavor(flavor_name,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 new_flavor_id)
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
+        self.assertEqual(200, resp.status)
+        self.assertEqual(flavor['name'], flavor_name)
+        self.assertEqual(flavor['ram'], self.ram)
+        self.assertEqual(flavor['vcpus'], self.vcpus)
+        self.assertEqual(flavor['disk'], self.disk)
+        self.assertEqual(int(flavor['id']), new_flavor_id)
+        self.assertEqual(flavor['swap'], '')
+        self.assertEqual(int(flavor['rxtx_factor']), 1)
+        self.assertEqual(int(flavor['OS-FLV-EXT-DATA:ephemeral']), 0)
+        if self._interface == "xml":
+            XMLNS_OS_FLV_ACCESS = "http://docs.openstack.org/compute/ext/"\
+                "flavor_access/api/v2"
+            key = "{" + XMLNS_OS_FLV_ACCESS + "}is_public"
+            self.assertEqual(flavor[key], "True")
+        if self._interface == "json":
+            self.assertEqual(flavor['os-flavor-access:is_public'], True)
 
-            #Verify flavor is retrieved
-            resp, flavor = self.client.get_flavor_details(new_flavor_id)
-            self.assertEqual(resp.status, 200)
-            self.assertEqual(flavor['name'], flavor_name)
-            #Check if flavor is present in list
-            resp, flavors = self.client.list_flavors_with_detail()
-            self.assertEqual(resp.status, 200)
-            for flavor in flavors:
-                if flavor['name'] == flavor_name:
-                    flag = True
-            self.assertTrue(flag)
-
-        finally:
-            #Delete the flavor
-            resp, body = self.client.delete_flavor(new_flavor_id)
-            self.assertEqual(resp.status, 202)
-            self.client.wait_for_resource_deletion(new_flavor_id)
+        #Verify flavor is retrieved
+        resp, flavor = self.client.get_flavor_details(new_flavor_id)
+        self.assertEqual(resp.status, 200)
+        self.assertEqual(flavor['name'], flavor_name)
+        #Check if flavor is present in list
+        resp, flavors = self.client.list_flavors_with_detail()
+        self.assertEqual(resp.status, 200)
+        for flavor in flavors:
+            if flavor['name'] == flavor_name:
+                flag = True
+        self.assertTrue(flag)
 
     @attr(type='positive')
     def test_flavor_not_public_verify_entry_not_in_list_details(self):
@@ -213,25 +200,21 @@
         flavor_name = rand_name(self.flavor_name_prefix)
         new_flavor_id = rand_int_id(start=1000)
 
-        try:
-            #Create the flavor
-            resp, flavor = self.client.create_flavor(flavor_name,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     new_flavor_id,
-                                                     is_public="False")
-            flag = False
-            #Verify flavor is retrieved
-            resp, flavors = self.client.list_flavors_with_detail()
-            self.assertEqual(resp.status, 200)
-            for flavor in flavors:
-                if flavor['name'] == flavor_name:
-                    flag = True
-            self.assertFalse(flag)
-        finally:
-            #Delete the flavor
-            resp, body = self.client.delete_flavor(new_flavor_id)
-            self.assertEqual(resp.status, 202)
+        #Create the flavor
+        resp, flavor = self.client.create_flavor(flavor_name,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 new_flavor_id,
+                                                 is_public="False")
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
+        flag = False
+        #Verify flavor is retrieved
+        resp, flavors = self.client.list_flavors_with_detail()
+        self.assertEqual(resp.status, 200)
+        for flavor in flavors:
+            if flavor['name'] == flavor_name:
+                flag = True
+        self.assertFalse(flag)
 
     def test_list_public_flavor_with_other_user(self):
         #Create a Flavor with public access.
@@ -239,76 +222,65 @@
         flavor_name = rand_name(self.flavor_name_prefix)
         new_flavor_id = rand_int_id(start=1000)
 
-        try:
             #Create the flavor
-            resp, flavor = self.client.create_flavor(flavor_name,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     new_flavor_id,
-                                                     is_public="True")
-            flag = False
-            self.new_client = self.flavors_client
-            #Verify flavor is retrieved with new user
-            resp, flavors = self.new_client.list_flavors_with_detail()
-            self.assertEqual(resp.status, 200)
-            for flavor in flavors:
-                if flavor['name'] == flavor_name:
-                    flag = True
-            self.assertTrue(flag)
-        finally:
-            #Delete the flavor
-            resp, body = self.client.delete_flavor(new_flavor_id)
-            self.assertEqual(resp.status, 202)
-            self.client.wait_for_resource_deletion(new_flavor_id)
+        resp, flavor = self.client.create_flavor(flavor_name,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 new_flavor_id,
+                                                 is_public="True")
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
+        flag = False
+        self.new_client = self.flavors_client
+        #Verify flavor is retrieved with new user
+        resp, flavors = self.new_client.list_flavors_with_detail()
+        self.assertEqual(resp.status, 200)
+        for flavor in flavors:
+            if flavor['name'] == flavor_name:
+                flag = True
+        self.assertTrue(flag)
 
     @attr(type='positive')
     def test_is_public_string_variations(self):
-        try:
-            flavor_id_not_public = rand_int_id(start=1000)
-            flavor_name_not_public = rand_name(self.flavor_name_prefix)
-            flavor_id_public = rand_int_id(start=1000)
-            flavor_name_public = rand_name(self.flavor_name_prefix)
+        flavor_id_not_public = rand_int_id(start=1000)
+        flavor_name_not_public = rand_name(self.flavor_name_prefix)
+        flavor_id_public = rand_int_id(start=1000)
+        flavor_name_public = rand_name(self.flavor_name_prefix)
 
-            # Create a non public flavor
-            resp, flavor = self.client.create_flavor(flavor_name_not_public,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     flavor_id_not_public,
-                                                     is_public="False")
+        # Create a non public flavor
+        resp, flavor = self.client.create_flavor(flavor_name_not_public,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 flavor_id_not_public,
+                                                 is_public="False")
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
 
-            # Create a public flavor
-            resp, flavor = self.client.create_flavor(flavor_name_public,
-                                                     self.ram, self.vcpus,
-                                                     self.disk,
-                                                     flavor_id_public,
-                                                     is_public="True")
+        # Create a public flavor
+        resp, flavor = self.client.create_flavor(flavor_name_public,
+                                                 self.ram, self.vcpus,
+                                                 self.disk,
+                                                 flavor_id_public,
+                                                 is_public="True")
+        self.addCleanup(self.flavor_clean_up, flavor['id'])
 
-            def _flavor_lookup(flavors, flavor_name):
-                for flavor in flavors:
-                    if flavor['name'] == flavor_name:
-                        return flavor
-                return None
+        def _flavor_lookup(flavors, flavor_name):
+            for flavor in flavors:
+                if flavor['name'] == flavor_name:
+                    return flavor
+            return None
 
-            def _test_string_variations(variations, flavor_name):
-                for string in variations:
-                    params = {'is_public': string}
-                    r, flavors = self.client.list_flavors_with_detail(params)
-                    self.assertEqual(r.status, 200)
-                    flavor = _flavor_lookup(flavors, flavor_name)
-                    self.assertNotEqual(flavor, None)
+        def _test_string_variations(variations, flavor_name):
+            for string in variations:
+                params = {'is_public': string}
+                r, flavors = self.client.list_flavors_with_detail(params)
+                self.assertEqual(r.status, 200)
+                flavor = _flavor_lookup(flavors, flavor_name)
+                self.assertNotEqual(flavor, None)
 
-            _test_string_variations(['f', 'false', 'no', '0'],
-                                    flavor_name_not_public)
+        _test_string_variations(['f', 'false', 'no', '0'],
+                                flavor_name_not_public)
 
-            _test_string_variations(['t', 'true', 'yes', '1'],
-                                    flavor_name_public)
-
-        finally:
-            # Delete flavors
-            for flavor_id in [flavor_id_not_public, flavor_id_public]:
-                resp, body = self.client.delete_flavor(flavor_id)
-                self.assertEqual(resp.status, 202)
-                self.client.wait_for_resource_deletion(flavor_id)
+        _test_string_variations(['t', 'true', 'yes', '1'],
+                                flavor_name_public)
 
     @attr(type='negative')
     def test_invalid_is_public_string(self):
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 99d9a5d..c2032d4 100644
--- a/tempest/tests/compute/security_groups/test_security_group_rules.py
+++ b/tempest/tests/compute/security_groups/test_security_group_rules.py
@@ -33,30 +33,24 @@
     def test_security_group_rules_create(self):
         # Positive test: Creation of Security Group rule
         # should be successfull
-        try:
-            #Creating a Security Group to add rules to it
-            s_name = rand_name('securitygroup-')
-            s_description = rand_name('description-')
-            resp, securitygroup = \
-                self.client.create_security_group(s_name, s_description)
-            securitygroup_id = securitygroup['id']
-            #Adding rules to the created Security Group
-            parent_group_id = securitygroup['id']
-            ip_protocol = 'tcp'
-            from_port = 22
-            to_port = 22
-            resp, rule = \
-                self.client.create_security_group_rule(parent_group_id,
-                                                       ip_protocol,
-                                                       from_port,
-                                                       to_port)
-            self.assertEqual(200, resp.status)
-        finally:
-            #Deleting the Security Group rule, created in this method
-            group_rule_id = rule['id']
-            self.client.delete_security_group_rule(group_rule_id)
-            #Deleting the Security Group created in this method
-            resp, _ = self.client.delete_security_group(securitygroup_id)
+        #Creating a Security Group to add rules to it
+        s_name = rand_name('securitygroup-')
+        s_description = rand_name('description-')
+        resp, securitygroup = \
+            self.client.create_security_group(s_name, s_description)
+        securitygroup_id = securitygroup['id']
+        self.addCleanup(self.client.delete_security_group, securitygroup_id)
+        #Adding rules to the created Security Group
+        ip_protocol = 'tcp'
+        from_port = 22
+        to_port = 22
+        resp, rule = \
+            self.client.create_security_group_rule(securitygroup_id,
+                                                   ip_protocol,
+                                                   from_port,
+                                                   to_port)
+        self.addCleanup(self.client.delete_security_group_rule, rule['id'])
+        self.assertEqual(200, resp.status)
 
     @attr(type='positive')
     def test_security_group_rules_create_with_optional_arguments(self):
@@ -64,75 +58,38 @@
         # with optional arguments
         # should be successfull
 
-        rule_id = None
         secgroup1 = None
         secgroup2 = None
-        try:
-            #Creating a Security Group to add rules to it
-            s_name = rand_name('securitygroup-')
-            s_description = rand_name('description-')
-            resp, securitygroup = \
-                self.client.create_security_group(s_name, s_description)
-            secgroup1 = securitygroup['id']
-            #Creating a Security Group so as to assign group_id to the rule
-            s_name2 = rand_name('securitygroup-')
-            s_description2 = rand_name('description-')
-            resp, securitygroup = \
-                self.client.create_security_group(s_name2, s_description2)
-            secgroup2 = securitygroup['id']
-            #Adding rules to the created Security Group with optional arguments
-            parent_group_id = secgroup1
-            ip_protocol = 'tcp'
-            from_port = 22
-            to_port = 22
-            cidr = '10.2.3.124/24'
-            group_id = secgroup2
-            resp, rule = \
-                self.client.create_security_group_rule(parent_group_id,
-                                                       ip_protocol,
-                                                       from_port,
-                                                       to_port,
-                                                       cidr=cidr,
-                                                       group_id=group_id)
-            rule_id = rule['id']
-            self.assertEqual(200, resp.status)
-        finally:
-            #Deleting the Security Group rule, created in this method
-            if rule_id:
-                self.client.delete_security_group_rule(rule_id)
-            #Deleting the Security Groups created in this method
-            if secgroup1:
-                self.client.delete_security_group(secgroup1)
-            if secgroup2:
-                self.client.delete_security_group(secgroup2)
-
-    @attr(type='positive')
-    def test_security_group_rules_create_delete(self):
-        # Positive test: Deletion of Security Group rule
-        # should be successfull
-        try:
-            #Creating a Security Group to add rule to it
-            s_name = rand_name('securitygroup-')
-            s_description = rand_name('description-')
-            resp, securitygroup = \
-                self.client.create_security_group(s_name, s_description)
-            securitygroup_id = securitygroup['id']
-            #Adding rules to the created Security Group
-            parent_group_id = securitygroup['id']
-            ip_protocol = 'tcp'
-            from_port = 22
-            to_port = 22
-            resp, rule = \
-                self.client.create_security_group_rule(parent_group_id,
-                                                       ip_protocol,
-                                                       from_port,
-                                                       to_port)
-        finally:
-            #Deleting the Security Group rule, created in this method
-            group_rule_id = rule['id']
-            self.client.delete_security_group_rule(group_rule_id)
-            #Deleting the Security Group created in this method
-            resp, _ = self.client.delete_security_group(securitygroup_id)
+        #Creating a Security Group to add rules to it
+        s_name = rand_name('securitygroup-')
+        s_description = rand_name('description-')
+        resp, securitygroup = \
+            self.client.create_security_group(s_name, s_description)
+        secgroup1 = securitygroup['id']
+        self.addCleanup(self.client.delete_security_group, secgroup1)
+        #Creating a Security Group so as to assign group_id to the rule
+        s_name2 = rand_name('securitygroup-')
+        s_description2 = rand_name('description-')
+        resp, securitygroup = \
+            self.client.create_security_group(s_name2, s_description2)
+        secgroup2 = securitygroup['id']
+        self.addCleanup(self.client.delete_security_group, secgroup2)
+        #Adding rules to the created Security Group with optional arguments
+        parent_group_id = secgroup1
+        ip_protocol = 'tcp'
+        from_port = 22
+        to_port = 22
+        cidr = '10.2.3.124/24'
+        group_id = secgroup2
+        resp, rule = \
+            self.client.create_security_group_rule(parent_group_id,
+                                                   ip_protocol,
+                                                   from_port,
+                                                   to_port,
+                                                   cidr=cidr,
+                                                   group_id=group_id)
+        self.addCleanup(self.client.delete_security_group_rule, rule['id'])
+        self.assertEqual(200, resp.status)
 
     @attr(type='negative')
     def test_security_group_rules_create_with_invalid_id(self):
diff --git a/tempest/tests/compute/security_groups/test_security_groups.py b/tempest/tests/compute/security_groups/test_security_groups.py
index 70a01a0..d0afde4 100644
--- a/tempest/tests/compute/security_groups/test_security_groups.py
+++ b/tempest/tests/compute/security_groups/test_security_groups.py
@@ -29,79 +29,80 @@
         super(SecurityGroupsTestJSON, cls).setUpClass()
         cls.client = cls.security_groups_client
 
+    def _delete_security_group(self, securitygroup_id):
+        resp, _ = self.client.delete_security_group(securitygroup_id)
+        self.assertEqual(202, resp.status)
+
     @attr(type='positive')
     def test_security_groups_create_list_delete(self):
         # Positive test:Should return the list of Security Groups
-        try:
-            #Create 3 Security Groups
-            security_group_list = list()
-            for i in range(3):
-                s_name = rand_name('securitygroup-')
-                s_description = rand_name('description-')
-                resp, securitygroup = \
-                    self.client.create_security_group(s_name, s_description)
-                self.assertEqual(200, resp.status)
-                security_group_list.append(securitygroup)
-            #Fetch all Security Groups and verify the list
-            #has all created Security Groups
-            resp, fetched_list = self.client.list_security_groups()
-            self.assertEqual(200, resp.status)
-            #Now check if all the created Security Groups are in fetched list
-            missing_sgs = \
-                [sg for sg in security_group_list if sg not in fetched_list]
-            self.assertFalse(missing_sgs,
-                             "Failed to find Security Group %s in fetched "
-                             "list" % ', '.join(m_group['name']
-                                                for m_group in missing_sgs))
-        finally:
-            #Delete all the Security Groups created in this method
-            for securitygroup in security_group_list:
-                resp, _ = \
-                    self.client.delete_security_group(securitygroup['id'])
-                self.assertEqual(202, resp.status)
-
-    @attr(type='positive')
-    def test_security_group_create_delete(self):
-        # Security Group should be created, verified and deleted
-        try:
+        #Create 3 Security Groups
+        security_group_list = list()
+        for i in range(3):
             s_name = rand_name('securitygroup-')
             s_description = rand_name('description-')
             resp, securitygroup = \
                 self.client.create_security_group(s_name, s_description)
             self.assertEqual(200, resp.status)
-            self.assertTrue('id' in securitygroup)
-            securitygroup_id = securitygroup['id']
-            self.assertFalse(securitygroup_id is None)
-            self.assertTrue('name' in securitygroup)
-            securitygroup_name = securitygroup['name']
-            self.assertEqual(securitygroup_name, s_name,
-                             "The created Security Group name is "
-                             "not equal to the requested name")
-        finally:
-            #Delete Security Group created in this method
-            resp, _ = self.client.delete_security_group(securitygroup['id'])
-            self.assertEqual(202, resp.status)
+            self.addCleanup(self._delete_security_group,
+                            securitygroup['id'])
+            security_group_list.append(securitygroup)
+        #Fetch all Security Groups and verify the list
+        #has all created Security Groups
+        resp, fetched_list = self.client.list_security_groups()
+        self.assertEqual(200, resp.status)
+        #Now check if all the created Security Groups are in fetched list
+        missing_sgs = \
+            [sg for sg in security_group_list if sg not in fetched_list]
+        self.assertFalse(missing_sgs,
+                         "Failed to find Security Group %s in fetched "
+                         "list" % ', '.join(m_group['name']
+                                            for m_group in missing_sgs))
+
+    #TODO(afazekas): scheduled for delete,
+    #test_security_group_create_get_delete covers it
+    @attr(type='positive')
+    def test_security_group_create_delete(self):
+        # Security Group should be created, verified and deleted
+        s_name = rand_name('securitygroup-')
+        s_description = rand_name('description-')
+        resp, securitygroup = \
+            self.client.create_security_group(s_name, s_description)
+        self.assertTrue('id' in securitygroup)
+        securitygroup_id = securitygroup['id']
+        self.addCleanup(self._delete_security_group,
+                        securitygroup_id)
+        self.assertEqual(200, resp.status)
+        self.assertFalse(securitygroup_id is None)
+        self.assertTrue('name' in securitygroup)
+        securitygroup_name = securitygroup['name']
+        self.assertEqual(securitygroup_name, s_name,
+                         "The created Security Group name is "
+                         "not equal to the requested name")
 
     @attr(type='positive')
     def test_security_group_create_get_delete(self):
         # Security Group should be created, fetched and deleted
-        try:
-            s_name = rand_name('securitygroup-')
-            s_description = rand_name('description-')
-            resp, securitygroup = \
-                self.client.create_security_group(s_name, s_description)
-            self.assertEqual(200, resp.status)
-            #Now fetch the created Security Group by its 'id'
-            resp, fetched_group = \
-                self.client.get_security_group(securitygroup['id'])
-            self.assertEqual(200, resp.status)
-            self.assertEqual(securitygroup, fetched_group,
-                             "The fetched Security Group is different "
-                             "from the created Group")
-        finally:
-            #Delete the Security Group created in this method
-            resp, _ = self.client.delete_security_group(securitygroup['id'])
-            self.assertEqual(202, resp.status)
+        s_name = rand_name('securitygroup-')
+        s_description = rand_name('description-')
+        resp, securitygroup = \
+            self.client.create_security_group(s_name, s_description)
+        self.addCleanup(self._delete_security_group,
+                        securitygroup['id'])
+
+        self.assertEqual(200, resp.status)
+        self.assertTrue('name' in securitygroup)
+        securitygroup_name = securitygroup['name']
+        self.assertEqual(securitygroup_name, s_name,
+                         "The created Security Group name is "
+                         "not equal to the requested name")
+        #Now fetch the created Security Group by its 'id'
+        resp, fetched_group = \
+            self.client.get_security_group(securitygroup['id'])
+        self.assertEqual(200, resp.status)
+        self.assertEqual(securitygroup, fetched_group,
+                         "The fetched Security Group is different "
+                         "from the created Group")
 
     @attr(type='negative')
     def test_security_group_get_nonexistant_group(self):