Check create/delete keypair attribute of Nova APIs

This patch adds the JSON Schema for response of Nova V2 & V3
create & delete keypair APIs and validate the response with
added JSON Schema to block the backward incompatibility change
in the future.

The response body of V2 & V3 create_keypairs APIs is same and
given below:

{
    "keypair": {
        "fingerprint": "%(fingerprint)s",
        "name": "%(keypair_name)s",
        "public_key": "%(public_key)s",
        "user_id": "fake",
        "private_key": "%(private_key)s"
    }
}

Response status code differ for create and delete keypairs

V2 - create_keypair = 200
V2 - delete_keypair = 202
V3 - create_keypair = 201
V3 - delete_keypair = 204

Partially implements blueprint nova-api-attribute-test

Change-Id: I179f0f11a43324d81ecbb41c0eae2f7072e8979a
diff --git a/tempest/api_schema/compute/keypairs.py b/tempest/api_schema/compute/keypairs.py
index 8973c02..b8f905f 100644
--- a/tempest/api_schema/compute/keypairs.py
+++ b/tempest/api_schema/compute/keypairs.py
@@ -39,3 +39,27 @@
         'required': ['keypairs']
     }
 }
+
+create_keypair = {
+    'type': 'object',
+    'properties': {
+        'keypair': {
+            'type': 'object',
+            'properties': {
+                'fingerprint': {'type': 'string'},
+                'name': {'type': 'string'},
+                'public_key': {'type': 'string'},
+                # NOTE: Now the type of 'user_id' is integer, but here
+                # allows 'string' also because we will be able to change
+                # it to 'uuid' in the future.
+                'user_id': {'type': ['integer', 'string']},
+                'private_key': {'type': 'string'}
+            },
+            # When create keypair API is being called with 'Public key'
+            # (Importing keypair) then, response body does not contain
+            # 'private_key' So it is not defined as 'required'
+            'required': ['fingerprint', 'name', 'public_key', 'user_id']
+        }
+    },
+    'required': ['keypair']
+}
diff --git a/tempest/api_schema/compute/v2/keypairs.py b/tempest/api_schema/compute/v2/keypairs.py
index 3225b0d..9a025c3 100644
--- a/tempest/api_schema/compute/v2/keypairs.py
+++ b/tempest/api_schema/compute/v2/keypairs.py
@@ -12,6 +12,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from tempest.api_schema.compute import keypairs
+
 get_keypair = {
     'status_code': [200],
     'response_body': {
@@ -45,3 +47,12 @@
         'required': ['keypair']
     }
 }
+
+create_keypair = {
+    'status_code': [200],
+    'response_body': keypairs.create_keypair
+}
+
+delete_keypair = {
+    'status_code': [202],
+}
diff --git a/tempest/api_schema/compute/v3/keypairs.py b/tempest/api_schema/compute/v3/keypairs.py
index 0197c84..de5f4ba 100644
--- a/tempest/api_schema/compute/v3/keypairs.py
+++ b/tempest/api_schema/compute/v3/keypairs.py
@@ -12,6 +12,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from tempest.api_schema.compute import keypairs
+
 get_keypair = {
     'status_code': [200],
     'response_body': {
@@ -30,3 +32,12 @@
         'required': ['keypair']
     }
 }
+
+create_keypair = {
+    'status_code': [201],
+    'response_body': keypairs.create_keypair
+}
+
+delete_keypair = {
+    'status_code': [204],
+}
diff --git a/tempest/services/compute/json/keypairs_client.py b/tempest/services/compute/json/keypairs_client.py
index 71f235d..be93789 100644
--- a/tempest/services/compute/json/keypairs_client.py
+++ b/tempest/services/compute/json/keypairs_client.py
@@ -53,7 +53,10 @@
         post_body = json.dumps(post_body)
         resp, body = self.post("os-keypairs", body=post_body)
         body = json.loads(body)
+        self.validate_response(schema.create_keypair, resp, body)
         return resp, body['keypair']
 
     def delete_keypair(self, key_name):
-        return self.delete("os-keypairs/%s" % str(key_name))
+        resp, body = self.delete("os-keypairs/%s" % str(key_name))
+        self.validate_response(schema.delete_keypair, resp, body)
+        return resp, body
diff --git a/tempest/services/compute/v3/json/keypairs_client.py b/tempest/services/compute/v3/json/keypairs_client.py
index d315bc4..f090d7d 100644
--- a/tempest/services/compute/v3/json/keypairs_client.py
+++ b/tempest/services/compute/v3/json/keypairs_client.py
@@ -53,7 +53,10 @@
         post_body = json.dumps(post_body)
         resp, body = self.post("keypairs", body=post_body)
         body = json.loads(body)
+        self.validate_response(schema.create_keypair, resp, body)
         return resp, body['keypair']
 
     def delete_keypair(self, key_name):
-        return self.delete("keypairs/%s" % str(key_name))
+        resp, body = self.delete("keypairs/%s" % str(key_name))
+        self.validate_response(schema.delete_keypair, resp, body)
+        return resp, body