Merge "Add response schema validation for volume capabilities"
diff --git a/tempest/api/volume/admin/test_backends_capabilities.py b/tempest/api/volume/admin/test_backends_capabilities.py
index affed6b..1351704 100644
--- a/tempest/api/volume/admin/test_backends_capabilities.py
+++ b/tempest/api/volume/admin/test_backends_capabilities.py
@@ -21,17 +21,6 @@
 
 class BackendsCapabilitiesAdminTestsJSON(base.BaseVolumeAdminTest):
 
-    CAPABILITIES = ('namespace',
-                    'vendor_name',
-                    'volume_backend_name',
-                    'pool_name',
-                    'driver_version',
-                    'storage_protocol',
-                    'display_name',
-                    'description',
-                    'visibility',
-                    'properties')
-
     @classmethod
     def resource_setup(cls):
         super(BackendsCapabilitiesAdminTestsJSON, cls).resource_setup()
@@ -44,12 +33,8 @@
     @decorators.idempotent_id('3750af44-5ea2-4cd4-bc3e-56e7e6caf854')
     def test_get_capabilities_backend(self):
         # Test backend properties
-        backend = self.admin_capabilities_client.show_backend_capabilities(
-            self.hosts[0])
-
-        # Verify getting capabilities parameters from a backend
-        for key in self.CAPABILITIES:
-            self.assertIn(key, backend)
+        # Check response schema
+        self.admin_capabilities_client.show_backend_capabilities(self.hosts[0])
 
     @decorators.idempotent_id('a9035743-d46a-47c5-9cb7-3c80ea16dea0')
     def test_compare_volume_stats_values(self):
diff --git a/tempest/lib/api_schema/response/volume/capabilities.py b/tempest/lib/api_schema/response/volume/capabilities.py
new file mode 100644
index 0000000..ec60fc3
--- /dev/null
+++ b/tempest/lib/api_schema/response/volume/capabilities.py
@@ -0,0 +1,55 @@
+# Copyright 2018 ZTE 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.
+
+property_info = {
+    'type': 'object',
+    'properties': {
+        'type': {'type': 'string'},
+        'description': {'type': 'string'},
+        'title': {'type': 'string'}
+    },
+    'additionalProperties': False,
+    'required': ['type', 'description', 'title']
+}
+
+show_backend_capabilities = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'pool_name': {'type': ['string', 'null']},
+            'description': {'type': ['string', 'null']},
+            'volume_backend_name': {'type': 'string'},
+            'namespace': {'type': 'string',
+                          'pattern': '^OS::Storage::Capabilities::.+$'},
+            'visibility': {'type': ['string', 'null']},
+            'driver_version': {'type': 'string'},
+            'vendor_name': {'type': 'string'},
+            'properties': {
+                'type': 'object',
+                'properties': {
+                    '^.+$': property_info
+                },
+            },
+            'storage_protocol': {'type': 'string'},
+            'replication_targets': {'type': 'array'},
+            'display_name': {'type': ['string', 'null']}
+        },
+        'additionalProperties': False,
+        'required': ['pool_name', 'volume_backend_name', 'namespace',
+                     'visibility', 'driver_version', 'vendor_name',
+                     'properties', 'storage_protocol', 'replication_targets',
+                     'display_name', 'description']
+    }
+}
diff --git a/tempest/lib/services/volume/v3/capabilities_client.py b/tempest/lib/services/volume/v3/capabilities_client.py
index ac2cd02..dc850a8 100644
--- a/tempest/lib/services/volume/v3/capabilities_client.py
+++ b/tempest/lib/services/volume/v3/capabilities_client.py
@@ -15,6 +15,7 @@
 
 from oslo_serialization import jsonutils as json
 
+from tempest.lib.api_schema.response.volume import capabilities as schema
 from tempest.lib.common import rest_client
 
 
@@ -30,5 +31,5 @@
         url = 'capabilities/%s' % host
         resp, body = self.get(url)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema.show_backend_capabilities, resp, body)
         return rest_client.ResponseBody(resp, body)