Validate Volume attributes of Nova POST & GET API

This patch adds the JSON schema and validate the response
of Nova POST & GET Volume APIs with JSON schema to block
the backward incompatibility change in the future.

The response body of Nova POST & GET Volume is the following:

{
    "volume": {
        "attachments": [
            {
                "device": "/",
                "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
                "serverId": "3912f2b4-c5ba-4aec-9165-872876fe202e",
                "volumeId": "a26887c6-c47b-4654-abb5-dfadf7d3f803"
            }
        ],
        "availabilityZone": "zone1:host1",
        "createdAt": "2013-02-18T14:51:18.528085",
        "displayDescription": "Volume Description",
        "displayName": "Volume Name",
        "id": "a26887c6-c47b-4654-abb5-dfadf7d3f803",
        "metadata": {},
        "size": 100,
        "snapshotId": null,
        "status": "in-use",
        "volumeType": "Backup"
    }
}

Partially implements blueprint nova-api-attribute-test

Change-Id: I7b98b375b87577d9bb9cf80b2fedd3b65ad0cd72
diff --git a/tempest/api/compute/api_schema/v2/__init__.py b/tempest/api/compute/api_schema/v2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/api/compute/api_schema/v2/__init__.py
diff --git a/tempest/api/compute/api_schema/v2/volumes.py b/tempest/api/compute/api_schema/v2/volumes.py
new file mode 100644
index 0000000..446a446
--- /dev/null
+++ b/tempest/api/compute/api_schema/v2/volumes.py
@@ -0,0 +1,50 @@
+# 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_volume = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            # NOTE: Now the type of 'id' is integer, but here allows
+            # 'string' also because we will be able to change it to
+            # 'uuid' in the future.
+            'id': {'type': ['integer', 'string']},
+            'status': {'type': 'string'},
+            'displayName': {'type': ['string', 'null']},
+            'availabilityZone': {'type': 'string'},
+            'createdAt': {'type': 'string'},
+            'displayDescription': {'type': ['string', 'null']},
+            'volumeType': {'type': 'string'},
+            'snapshotId': {'type': ['string', 'null']},
+            'metadata': {'type': 'object'},
+            'size': {'type': 'integer'},
+            'attachments': {
+                'type': 'array',
+                'items': {
+                    'type': 'object',
+                    'properties': {
+                        'id': {'type': ['integer', 'string']},
+                        'device': {'type': 'string'},
+                        'volumeId': {'type': ['integer', 'string']},
+                        'serverId': {'type': ['integer', 'string']},
+                    },
+                },
+            },
+        },
+        'required': ['id', 'status', 'displayName', 'availabilityZone',
+                     'createdAt', 'displayDescription', 'volumeType',
+                     'snapshotId', 'metadata', 'size', 'attachments'],
+    },
+}
diff --git a/tempest/api/compute/volumes/test_volumes_get.py b/tempest/api/compute/volumes/test_volumes_get.py
index c3d6ba6..e7179cc 100644
--- a/tempest/api/compute/volumes/test_volumes_get.py
+++ b/tempest/api/compute/volumes/test_volumes_get.py
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from tempest.api.compute.api_schema.v2 import volumes as schema
 from tempest.api.compute import base
 from tempest.common.utils import data_utils
 from tempest import config
@@ -43,9 +44,7 @@
                                                  display_name=v_name,
                                                  metadata=metadata)
         self.addCleanup(self.delete_volume, volume['id'])
-        self.assertEqual(200, resp.status)
-        self.assertIn('id', volume)
-        self.assertIn('displayName', volume)
+        self.validate_response(schema.get_volume, resp, volume)
         self.assertEqual(volume['displayName'], v_name,
                          "The created volume name is not equal "
                          "to the requested name")
@@ -55,7 +54,7 @@
         self.client.wait_for_volume_status(volume['id'], 'available')
         # GET Volume
         resp, fetched_volume = self.client.get_volume(volume['id'])
-        self.assertEqual(200, resp.status)
+        self.validate_response(schema.get_volume, resp, fetched_volume)
         # Verification of details of fetched Volume
         self.assertEqual(v_name,
                          fetched_volume['displayName'],