Stop keystone resource leaking even if an error occurs

In some test, if an error occurs in setUpClass(), some resources
are not deleted because of tearDownClass() is not called.
This commit fixes it.

 tempest/api
  +---- baremetal (unnecessary)
  +---- compute
  +---- data_processing (unnecessary)
  +---- database (unnecessary)
  +---- identity            <-- this patch
  +---- image (done)
  +---- network
  +---- object_storage
  +---- orchestration
  +---- queuing (unnecessary)
  +---- telemetry (unnecessary)
  +---- volume (done)

Partially Implements: blueprint stop-leaking

Change-Id: I7104b968b7c704d465ec8a5a3046f749566c1241
diff --git a/tempest/api/identity/admin/test_roles.py b/tempest/api/identity/admin/test_roles.py
index 5e78cce..81bc5de 100644
--- a/tempest/api/identity/admin/test_roles.py
+++ b/tempest/api/identity/admin/test_roles.py
@@ -17,13 +17,14 @@
 
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import test
 
 
 class RolesTestJSON(base.BaseIdentityV2AdminTest):
     _interface = 'json'
 
     @classmethod
+    @test.safe_setup
     def setUpClass(cls):
         super(RolesTestJSON, cls).setUpClass()
         for _ in moves.xrange(5):
@@ -46,7 +47,7 @@
                 found = True
         self.assertTrue(found, "assigned role was not in list")
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_list_roles(self):
         # Return a list of all roles
         resp, body = self.client.list_roles()
@@ -54,7 +55,7 @@
         self.assertTrue(any(found))
         self.assertEqual(len(found), len(self.data.roles))
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_role_create_delete(self):
         # Role should be created, verified, and deleted
         role_name = data_utils.rand_name(name='role-test-')
@@ -75,7 +76,7 @@
         found = [role for role in body if role['name'] == role_name]
         self.assertFalse(any(found))
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_assign_user_role(self):
         # Assign a role to a user on a tenant
         (user, tenant, role) = self._get_role_params()
@@ -83,7 +84,7 @@
         resp, roles = self.client.list_user_roles(tenant['id'], user['id'])
         self.assert_role_in_role_list(role, roles)
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_remove_user_role(self):
         # Remove a role assigned to a user on a tenant
         (user, tenant, role) = self._get_role_params()
@@ -93,7 +94,7 @@
                                                   user_role['id'])
         self.assertEqual(resp['status'], '204')
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_list_user_roles(self):
         # List roles assigned to a user on tenant
         (user, tenant, role) = self._get_role_params()
diff --git a/tempest/api/identity/admin/v3/test_credentials.py b/tempest/api/identity/admin/v3/test_credentials.py
index 5f22d43..4442f4a 100644
--- a/tempest/api/identity/admin/v3/test_credentials.py
+++ b/tempest/api/identity/admin/v3/test_credentials.py
@@ -15,13 +15,14 @@
 
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import test
 
 
 class CredentialsTestJSON(base.BaseIdentityV3AdminTest):
     _interface = 'json'
 
     @classmethod
+    @test.safe_setup
     def setUpClass(cls):
         super(CredentialsTestJSON, cls).setUpClass()
         cls.projects = list()
@@ -56,7 +57,7 @@
         resp, body = self.creds_client.delete_credential(cred_id)
         self.assertEqual(resp['status'], '204')
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_credentials_create_get_update_delete(self):
         keys = [data_utils.rand_name('Access-'),
                 data_utils.rand_name('Secret-')]
@@ -91,7 +92,7 @@
             self.assertEqual(update_body['blob'][value2],
                              get_body['blob'][value2])
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_credentials_list_delete(self):
         created_cred_ids = list()
         fetched_cred_ids = list()
diff --git a/tempest/api/identity/admin/v3/test_endpoints.py b/tempest/api/identity/admin/v3/test_endpoints.py
index 0e4d66b..dd3b576 100644
--- a/tempest/api/identity/admin/v3/test_endpoints.py
+++ b/tempest/api/identity/admin/v3/test_endpoints.py
@@ -15,13 +15,14 @@
 
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import test
 
 
 class EndPointsTestJSON(base.BaseIdentityV3AdminTest):
     _interface = 'json'
 
     @classmethod
+    @test.safe_setup
     def setUpClass(cls):
         super(EndPointsTestJSON, cls).setUpClass()
         cls.identity_client = cls.client
@@ -53,7 +54,7 @@
             cls.service_client.delete_service(s)
         super(EndPointsTestJSON, cls).tearDownClass()
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_list_endpoints(self):
         # Get a list of endpoints
         resp, fetched_endpoints = self.client.list_endpoints()
@@ -65,7 +66,7 @@
                          "Failed to find endpoint %s in fetched list" %
                          ', '.join(str(e) for e in missing_endpoints))
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_create_list_delete_endpoint(self):
         region = data_utils.rand_name('region')
         url = data_utils.rand_name('url')
@@ -91,7 +92,7 @@
         fetched_endpoints_id = [e['id'] for e in fetched_endpoints]
         self.assertNotIn(endpoint['id'], fetched_endpoints_id)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_update_endpoint(self):
         # Creating an endpoint so as to check update endpoint
         # with new values
diff --git a/tempest/api/identity/admin/v3/test_roles.py b/tempest/api/identity/admin/v3/test_roles.py
index 467d28b..c63231f 100644
--- a/tempest/api/identity/admin/v3/test_roles.py
+++ b/tempest/api/identity/admin/v3/test_roles.py
@@ -15,13 +15,14 @@
 
 from tempest.api.identity import base
 from tempest.common.utils import data_utils
-from tempest.test import attr
+from tempest import test
 
 
 class RolesV3TestJSON(base.BaseIdentityV3AdminTest):
     _interface = 'json'
 
     @classmethod
+    @test.safe_setup
     def setUpClass(cls):
         super(RolesV3TestJSON, cls).setUpClass()
         cls.fetched_role_ids = list()
@@ -68,7 +69,7 @@
         self.assertEqual(len(body), 1)
         self.assertIn(role_id, fetched_role_ids)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_role_create_update_get(self):
         r_name = data_utils.rand_name('Role-')
         resp, role = self.client.create_role(r_name)
@@ -90,7 +91,7 @@
         self.assertEqual(new_name, new_role['name'])
         self.assertEqual(updated_role['id'], new_role['id'])
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_grant_list_revoke_role_to_user_on_project(self):
         resp, _ = self.client.assign_user_role_on_project(
             self.project['id'], self.user_body['id'], self.role['id'])
@@ -109,7 +110,7 @@
             self.project['id'], self.user_body['id'], self.role['id'])
         self.assertEqual(resp['status'], '204')
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_grant_list_revoke_role_to_user_on_domain(self):
         resp, _ = self.client.assign_user_role_on_domain(
             self.domain['id'], self.user_body['id'], self.role['id'])
@@ -128,7 +129,7 @@
             self.domain['id'], self.user_body['id'], self.role['id'])
         self.assertEqual(resp['status'], '204')
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_grant_list_revoke_role_to_group_on_project(self):
         resp, _ = self.client.assign_group_role_on_project(
             self.project['id'], self.group_body['id'], self.role['id'])
@@ -147,7 +148,7 @@
             self.project['id'], self.group_body['id'], self.role['id'])
         self.assertEqual(resp['status'], '204')
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_grant_list_revoke_role_to_group_on_domain(self):
         resp, _ = self.client.assign_group_role_on_domain(
             self.domain['id'], self.group_body['id'], self.role['id'])