Merge "Full response for v2 IdentityClient methods"
diff --git a/tempest/api/identity/admin/v2/test_roles.py b/tempest/api/identity/admin/v2/test_roles.py
index 1babc45..0b28a07 100644
--- a/tempest/api/identity/admin/v2/test_roles.py
+++ b/tempest/api/identity/admin/v2/test_roles.py
@@ -76,7 +76,7 @@
         self.data.setup_test_role()
         role_id = self.data.role['id']
         role_name = self.data.role['name']
-        body = self.client.get_role(role_id)
+        body = self.client.get_role(role_id)['role']
         self.assertEqual(role_id, body['id'])
         self.assertEqual(role_name, body['name'])
 
diff --git a/tempest/api/identity/admin/v2/test_tenants.py b/tempest/api/identity/admin/v2/test_tenants.py
index f828f66..9fff5f3 100644
--- a/tempest/api/identity/admin/v2/test_tenants.py
+++ b/tempest/api/identity/admin/v2/test_tenants.py
@@ -32,7 +32,7 @@
             self.data.tenants.append(tenant)
             tenants.append(tenant)
         tenant_ids = map(lambda x: x['id'], tenants)
-        body = self.client.list_tenants()
+        body = self.client.list_tenants()['tenants']
         found = [t for t in body if t['id'] in tenant_ids]
         self.assertEqual(len(found), len(tenants), 'Tenants not created')
 
@@ -40,7 +40,7 @@
             self.client.delete_tenant(tenant['id'])
             self.data.tenants.remove(tenant)
 
-        body = self.client.list_tenants()
+        body = self.client.list_tenants()['tenants']
         found = [tenant for tenant in body if tenant['id'] in tenant_ids]
         self.assertFalse(any(found), 'Tenants failed to delete')
 
diff --git a/tempest/api/identity/base.py b/tempest/api/identity/base.py
index 2db73f5..7b23e66 100644
--- a/tempest/api/identity/base.py
+++ b/tempest/api/identity/base.py
@@ -48,6 +48,10 @@
     def get_tenant_by_name(cls, name):
         try:
             tenants = cls.client.list_tenants()
+            # TODO(jswarren): always retrieve 'tenants' value
+            # once both clients return full response objects
+            if 'tenants' in tenants:
+                tenants = tenants['tenants']
         except AttributeError:
             tenants = cls.client.list_projects()['projects']
         tenant = [t for t in tenants if t['name'] == name]
diff --git a/tempest/cmd/account_generator.py b/tempest/cmd/account_generator.py
index 0360146..e05cab3 100755
--- a/tempest/cmd/account_generator.py
+++ b/tempest/cmd/account_generator.py
@@ -160,7 +160,7 @@
                 raise exceptions.TempestException(
                     "Role: %s - doesn't exist" % r
                 )
-    existing = [x['name'] for x in identity_admin.list_tenants()]
+    existing = [x['name'] for x in identity_admin.list_tenants()['tenants']]
     for tenant in resources['tenants']:
         if tenant not in existing:
             identity_admin.create_tenant(tenant)
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index 2e96c81..4d9755d 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -889,7 +889,7 @@
 
     def list(self):
         client = self.client
-        tenants = client.list_tenants()
+        tenants = client.list_tenants()['tenants']
         if not self.is_save_state:
             tenants = [tenant for tenant in tenants if (tenant['id']
                        not in self.saved_state_json['tenants'].keys()
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index 740363b..71aacbd 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -274,7 +274,7 @@
     Don't create the tenants if they already exist.
     """
     admin = keystone_admin()
-    body = admin.identity.list_tenants()
+    body = admin.identity.list_tenants()['tenants']
     existing = [x['name'] for x in body]
     for tenant in tenants:
         if tenant not in existing:
diff --git a/tempest/services/identity/v2/json/identity_client.py b/tempest/services/identity/v2/json/identity_client.py
index c9345e0..e6416d6 100644
--- a/tempest/services/identity/v2/json/identity_client.py
+++ b/tempest/services/identity/v2/json/identity_client.py
@@ -56,7 +56,7 @@
         resp, body = self.get('OS-KSADM/roles/%s' % role_id)
         self.expected_success(200, resp.status)
         body = json.loads(body)
-        return service_client.ResponseBody(resp, body['role'])
+        return service_client.ResponseBody(resp, body)
 
     def create_tenant(self, name, **kwargs):
         """
@@ -125,10 +125,10 @@
         resp, body = self.get('tenants')
         self.expected_success(200, resp.status)
         body = json.loads(body)
-        return service_client.ResponseBodyList(resp, body['tenants'])
+        return service_client.ResponseBody(resp, body)
 
     def get_tenant_by_name(self, tenant_name):
-        tenants = self.list_tenants()
+        tenants = self.list_tenants()['tenants']
         for tenant in tenants:
             if tenant['name'] == tenant_name:
                 return tenant
diff --git a/tempest/stress/cleanup.py b/tempest/stress/cleanup.py
index 2675a1c..bf65616 100644
--- a/tempest/stress/cleanup.py
+++ b/tempest/stress/cleanup.py
@@ -72,7 +72,7 @@
         if user['name'].startswith("stress_user"):
             admin_manager.identity_client.delete_user(user['id'])
 
-    tenants = admin_manager.identity_client.list_tenants()
+    tenants = admin_manager.identity_client.list_tenants()['tenants']
     LOG.info("Cleanup::remove %s tenants" % len(tenants))
     for tenant in tenants:
         if tenant['name'].startswith("stress_tenant"):
diff --git a/tempest/tests/cmd/test_javelin.py b/tempest/tests/cmd/test_javelin.py
index 3a3e46e..d1dee54 100644
--- a/tempest/tests/cmd/test_javelin.py
+++ b/tempest/tests/cmd/test_javelin.py
@@ -85,7 +85,7 @@
 class TestCreateResources(JavelinUnitTest):
     def test_create_tenants(self):
 
-        self.fake_client.identity.list_tenants.return_value = []
+        self.fake_client.identity.list_tenants.return_value = {'tenants': []}
         self.useFixture(mockpatch.PatchObject(javelin, "keystone_admin",
                                               return_value=self.fake_client))
 
@@ -95,8 +95,8 @@
         mocked_function.assert_called_once_with(self.fake_object['name'])
 
     def test_create_duplicate_tenant(self):
-        self.fake_client.identity.list_tenants.return_value = [
-            {'name': self.fake_object['name']}]
+        self.fake_client.identity.list_tenants.return_value = {'tenants': [
+            {'name': self.fake_object['name']}]}
         self.useFixture(mockpatch.PatchObject(javelin, "keystone_admin",
                                               return_value=self.fake_client))