Validate get keypair attributes of Nova V2/V3 API
This patch adds the JSON Schema for response of Nova V2 & V3 GET
keypair API and validate the response with added JSON Schema to
block the backward incompatibility change in the future.
The response body of V2 GET keypair API is below:
{
"keypair": {
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnPe3MJhE
wcQNGZpYRaGYTwY9D9L3pr1c+eqJIP99mtrUuqTEp3/YPiAz
L0Dem/32WWPOV4DEc27NBMxrpOi9JJBssDq+6UdK5hMIwrZ/
6dZt+CPz+76LwxnR1vilVFocis+OC9ddntazV1wrAWGyYL9a
83vwcuTV01FJzSNlYV4hni2vxcgQPkbgt+ldYoTmBS9X3W5Qy
NrzuG53zHjkYjmz3tjiadZwgffDvjT3SBYWU3kBGy6gxIs5f/
wIvZUSUXGorOJNUw6FubMj4sLfE4cbHS6W72xs6bmEhqxyjSL
QK5fuHE1MgCCDPTd0vqXdbLnCZr6+l0HLI8lpDhd
Generated by Nova\n",
"name": "test_key",
"fingerprint": "52:53:dd:89:6a:73:c6:18:87:4b:1e:c1:4c:b8:
c3:c9",
"user_id": "93d29478a2454f418e0b835b8439aa90",
"deleted": false,
"created_at": "2014-03-17T06:49:35.000000",
"updated_at": null,
"deleted_at": null,
"id": 1
}
}
The response body of V3 GET keypair API is below:
{
"keypair": {
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnPe3MJhE
wcQNGZpYRaGYTwY9D9L3pr1c+eqJIP99mtrUuqTEp3/YPiAz
pL0Dem/32WWPOV4DEc27NBMxrpOi9JJBssDq+6UdK5hMIwrZ/
6dZt+CPz+76LwxnR1vilVFocis+OC9ddntazV1wrAWGyYL9a
83vwcuTV01FJzSNlYV4hni2vxcgQPkbgt+ldYoTmBS9X3W5Qy
/NrzuG53zHjkYjmz3tjiadZwgffDvjT3SBYWU3kBGy6gxIs5f
/wIvZUSUXGorOJNUw6FubMj4sLfE4cbHS6W72xs6bmEhqxyjS
LQK5fuHE1MgCCDPTd0vqXdbLnCZr6+l0HLI8lpDhd
Generated by Nova\n",
"name": "test_key",
"fingerprint": "52:53:dd:89:6a:73:c6:18:87:4b:1e:c1:4c:b8:
c3:c9"
}
}
Partially implements blueprint nova-api-attribute-test
Change-Id: Ie65776ec5f6a42df89c27d868b43c4ce105dd09b
diff --git a/tempest/api_schema/compute/v2/keypairs.py b/tempest/api_schema/compute/v2/keypairs.py
new file mode 100644
index 0000000..3225b0d
--- /dev/null
+++ b/tempest/api_schema/compute/v2/keypairs.py
@@ -0,0 +1,47 @@
+# Copyright 2014 NEC Corporation. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+get_keypair = {
+ 'status_code': [200],
+ 'response_body': {
+ 'type': 'object',
+ 'properties': {
+ 'keypair': {
+ 'type': 'object',
+ 'properties': {
+ 'public_key': {'type': 'string'},
+ 'name': {'type': 'string'},
+ 'fingerprint': {'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']},
+ 'deleted': {'type': 'boolean'},
+ 'created_at': {'type': 'string'},
+ 'updated_at': {'type': ['string', 'null']},
+ 'deleted_at': {'type': ['string', 'null']},
+ 'id': {'type': 'integer'}
+
+ },
+ # When we run the get keypair API, response body includes
+ # all the above mentioned attributes.
+ # But in Nova API sample file, response body includes only
+ # 'public_key', 'name' & 'fingerprint'. So only 'public_key',
+ # 'name' & 'fingerprint' are defined as 'required'.
+ 'required': ['public_key', 'name', 'fingerprint']
+ }
+ },
+ 'required': ['keypair']
+ }
+}
diff --git a/tempest/api_schema/compute/v3/keypairs.py b/tempest/api_schema/compute/v3/keypairs.py
new file mode 100644
index 0000000..0197c84
--- /dev/null
+++ b/tempest/api_schema/compute/v3/keypairs.py
@@ -0,0 +1,32 @@
+# Copyright 2014 NEC Corporation. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+get_keypair = {
+ 'status_code': [200],
+ 'response_body': {
+ 'type': 'object',
+ 'properties': {
+ 'keypair': {
+ 'type': 'object',
+ 'properties': {
+ 'public_key': {'type': 'string'},
+ 'name': {'type': 'string'},
+ 'fingerprint': {'type': 'string'}
+ },
+ 'required': ['public_key', 'name', 'fingerprint']
+ }
+ },
+ 'required': ['keypair']
+ }
+}
diff --git a/tempest/services/compute/json/keypairs_client.py b/tempest/services/compute/json/keypairs_client.py
index 28f3c31..889e2ed 100644
--- a/tempest/services/compute/json/keypairs_client.py
+++ b/tempest/services/compute/json/keypairs_client.py
@@ -15,6 +15,7 @@
import json
+from tempest.api_schema.compute.v2 import keypairs as schema
from tempest.common import rest_client
from tempest import config
@@ -40,6 +41,7 @@
def get_keypair(self, key_name):
resp, body = self.get("os-keypairs/%s" % str(key_name))
body = json.loads(body)
+ self.validate_response(schema.get_keypair, resp, body)
return resp, body['keypair']
def create_keypair(self, name, pub_key=None):
diff --git a/tempest/services/compute/v3/json/keypairs_client.py b/tempest/services/compute/v3/json/keypairs_client.py
index 9ca4885..f412e30 100644
--- a/tempest/services/compute/v3/json/keypairs_client.py
+++ b/tempest/services/compute/v3/json/keypairs_client.py
@@ -15,6 +15,7 @@
import json
+from tempest.api_schema.compute.v3 import keypairs as schema
from tempest.common import rest_client
from tempest import config
@@ -40,6 +41,7 @@
def get_keypair(self, key_name):
resp, body = self.get("keypairs/%s" % str(key_name))
body = json.loads(body)
+ self.validate_response(schema.get_keypair, resp, body)
return resp, body['keypair']
def create_keypair(self, name, pub_key=None):