Merge "Return complete response from compute/keypairs_client"
diff --git a/tempest/api/compute/keypairs/base.py b/tempest/api/compute/keypairs/base.py
index b742c8c..76e5573 100644
--- a/tempest/api/compute/keypairs/base.py
+++ b/tempest/api/compute/keypairs/base.py
@@ -33,6 +33,6 @@
         kwargs = {'name': keypair_name}
         if pub_key:
             kwargs.update({'public_key': pub_key})
-        body = self.client.create_keypair(**kwargs)
+        body = self.client.create_keypair(**kwargs)['keypair']
         self.addCleanup(self._delete_keypair, keypair_name)
         return body
diff --git a/tempest/api/compute/keypairs/test_keypairs.py b/tempest/api/compute/keypairs/test_keypairs.py
index 225af12..d10bf14 100644
--- a/tempest/api/compute/keypairs/test_keypairs.py
+++ b/tempest/api/compute/keypairs/test_keypairs.py
@@ -34,9 +34,7 @@
             key_list.append(keypair)
         # Fetch all keypairs and verify the list
         # has all created keypairs
-        fetched_list = self.client.list_keypairs()
-        # We need to remove the extra 'keypair' element in the
-        # returned dict. See comment in keypairs_client.list_keypairs()
+        fetched_list = self.client.list_keypairs()['keypairs']
         new_list = list()
         for keypair in fetched_list:
             new_list.append(keypair['keypair'])
@@ -65,7 +63,7 @@
         # Keypair should be created, Got details by name and deleted
         k_name = data_utils.rand_name('keypair')
         self._create_keypair(k_name)
-        keypair_detail = self.client.show_keypair(k_name)
+        keypair_detail = self.client.show_keypair(k_name)['keypair']
         self.assertIn('name', keypair_detail)
         self.assertIn('public_key', keypair_detail)
         self.assertEqual(keypair_detail['name'], k_name,
diff --git a/tempest/api/orchestration/base.py b/tempest/api/orchestration/base.py
index 6578680..f2c59f3 100644
--- a/tempest/api/orchestration/base.py
+++ b/tempest/api/orchestration/base.py
@@ -96,7 +96,7 @@
     @classmethod
     def _create_keypair(cls, name_start='keypair-heat-'):
         kp_name = data_utils.rand_name(name_start)
-        body = cls.keypairs_client.create_keypair(name=kp_name)
+        body = cls.keypairs_client.create_keypair(name=kp_name)['keypair']
         cls.keypairs.append(kp_name)
         return body
 
diff --git a/tempest/cmd/cleanup_service.py b/tempest/cmd/cleanup_service.py
index 4d9755d..3550842 100644
--- a/tempest/cmd/cleanup_service.py
+++ b/tempest/cmd/cleanup_service.py
@@ -245,7 +245,7 @@
 
     def list(self):
         client = self.client
-        keypairs = client.list_keypairs()
+        keypairs = client.list_keypairs()['keypairs']
         LOG.debug("List count, %s Keypairs" % len(keypairs))
         return keypairs
 
diff --git a/tempest/common/validation_resources.py b/tempest/common/validation_resources.py
index 14730cf..d018aed 100644
--- a/tempest/common/validation_resources.py
+++ b/tempest/common/validation_resources.py
@@ -48,8 +48,8 @@
     if validation_resources:
         if validation_resources['keypair']:
             keypair_name = data_utils.rand_name('keypair')
-            validation_data['keypair'] = \
-                os.keypairs_client.create_keypair(name=keypair_name)
+            validation_data.update(os.keypairs_client.create_keypair(
+                name=keypair_name))
             LOG.debug("Validation resource key %s created" % keypair_name)
         add_rule = False
         if validation_resources['security_group']:
diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py
index 5d9880b..766042e 100644
--- a/tempest/scenario/manager.py
+++ b/tempest/scenario/manager.py
@@ -145,7 +145,7 @@
         # We don't need to create a keypair by pubkey in scenario
         body = client.create_keypair(name=name)
         self.addCleanup(client.delete_keypair, name)
-        return body
+        return body['keypair']
 
     def create_server(self, name=None, image=None, flavor=None,
                       wait_on_boot=True, wait_on_delete=True,
diff --git a/tempest/services/compute/json/keypairs_client.py b/tempest/services/compute/json/keypairs_client.py
index e51671f..2e22bc6 100644
--- a/tempest/services/compute/json/keypairs_client.py
+++ b/tempest/services/compute/json/keypairs_client.py
@@ -24,26 +24,21 @@
     def list_keypairs(self):
         resp, body = self.get("os-keypairs")
         body = json.loads(body)
-        # Each returned keypair is embedded within an unnecessary 'keypair'
-        # element which is a deviation from other resources like floating-ips,
-        # servers, etc. A bug?
-        # For now we shall adhere to the spec, but the spec for keypairs
-        # is yet to be found
         self.validate_response(schema.list_keypairs, resp, body)
-        return service_client.ResponseBodyList(resp, body['keypairs'])
+        return service_client.ResponseBody(resp, body)
 
     def show_keypair(self, keypair_name):
         resp, body = self.get("os-keypairs/%s" % keypair_name)
         body = json.loads(body)
         self.validate_response(schema.get_keypair, resp, body)
-        return service_client.ResponseBody(resp, body['keypair'])
+        return service_client.ResponseBody(resp, body)
 
     def create_keypair(self, **kwargs):
         post_body = json.dumps({'keypair': kwargs})
         resp, body = self.post("os-keypairs", body=post_body)
         body = json.loads(body)
         self.validate_response(schema.create_keypair, resp, body)
-        return service_client.ResponseBody(resp, body['keypair'])
+        return service_client.ResponseBody(resp, body)
 
     def delete_keypair(self, keypair_name):
         resp, body = self.delete("os-keypairs/%s" % keypair_name)
diff --git a/tempest/stress/actions/volume_attach_verify.py b/tempest/stress/actions/volume_attach_verify.py
index 5d1dd36..038569a 100644
--- a/tempest/stress/actions/volume_attach_verify.py
+++ b/tempest/stress/actions/volume_attach_verify.py
@@ -26,7 +26,8 @@
 
     def _create_keypair(self):
         keyname = data_utils.rand_name("key")
-        self.key = self.manager.keypairs_client.create_keypair(name=keyname)
+        self.key = (self.manager.keypairs_client.create_keypair(name=keyname)
+                    ['keypair'])
 
     def _delete_keypair(self):
         self.manager.keypairs_client.delete_keypair(self.key['name'])
diff --git a/tempest/stress/cleanup.py b/tempest/stress/cleanup.py
index bf65616..c60f45a 100644
--- a/tempest/stress/cleanup.py
+++ b/tempest/stress/cleanup.py
@@ -40,7 +40,7 @@
         except Exception:
             pass
 
-    keypairs = admin_manager.keypairs_client.list_keypairs()
+    keypairs = admin_manager.keypairs_client.list_keypairs()['keypairs']
     LOG.info("Cleanup::remove %s keypairs" % len(keypairs))
     for k in keypairs:
         try:
diff --git a/tempest/tests/services/compute/test_keypairs_client.py b/tempest/tests/services/compute/test_keypairs_client.py
index a0022b4..8a0edd0 100644
--- a/tempest/tests/services/compute/test_keypairs_client.py
+++ b/tempest/tests/services/compute/test_keypairs_client.py
@@ -25,12 +25,12 @@
 
 class TestKeyPairsClient(base.TestCase):
 
-    FAKE_KEYPAIR = {
+    FAKE_KEYPAIR = {"keypair": {
         "public_key": "ssh-rsa foo Generated-by-Nova",
         "name": u'\u2740(*\xb4\u25e1`*)\u2740',
         "user_id": "525d55f98980415ba98e634972fa4a10",
         "fingerprint": "76:24:66:49:d7:ca:6e:5c:77:ea:8e:bb:9c:15:5f:98"
-        }
+        }}
 
     def setUp(self):
         super(TestKeyPairsClient, self).setUp()
@@ -42,7 +42,7 @@
         body = '{"keypairs": []}'
         if bytes_body:
             body = body.encode('utf-8')
-        expected = []
+        expected = {"keypairs": []}
         response = (httplib2.Response({'status': 200}), body)
         self.useFixture(mockpatch.Patch(
             'tempest.common.service_client.ServiceClient.get',
@@ -57,14 +57,14 @@
 
     def _test_show_keypair(self, bytes_body=False):
         fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR)
-        fake_keypair.update({
+        fake_keypair["keypair"].update({
             "deleted": False,
             "created_at": "2015-07-22T04:53:52.000000",
             "updated_at": None,
             "deleted_at": None,
             "id": 1
             })
-        serialized_body = json.dumps({"keypair": fake_keypair})
+        serialized_body = json.dumps(fake_keypair)
         if bytes_body:
             serialized_body = serialized_body.encode('utf-8')
 
@@ -83,8 +83,8 @@
 
     def _test_create_keypair(self, bytes_body=False):
         fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR)
-        fake_keypair.update({"private_key": "foo"})
-        serialized_body = json.dumps({"keypair": fake_keypair})
+        fake_keypair["keypair"].update({"private_key": "foo"})
+        serialized_body = json.dumps(fake_keypair)
         if bytes_body:
             serialized_body = serialized_body.encode('utf-8')