Merge "Add response schema validation for volume services"
diff --git a/tempest/lib/api_schema/response/volume/services.py b/tempest/lib/api_schema/response/volume/services.py
new file mode 100644
index 0000000..70de878
--- /dev/null
+++ b/tempest/lib/api_schema/response/volume/services.py
@@ -0,0 +1,92 @@
+# 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.
+import copy
+
+from tempest.lib.api_schema.response.compute.v2_1 import parameter_types
+
+list_services = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'services': {
+                'type': 'array',
+                'items': {
+                    'type': 'object',
+                    'properties': {
+                        'binary': {'type': 'string'},
+                        'disabled_reason': {'type': ['string', 'null']},
+                        'host': {'type': 'string'},
+                        'state': {'enum': ['up', 'down']},
+                        'status': {'enum': ['enabled', 'disabled']},
+                        'frozen': {'type': 'boolean'},
+                        'updated_at': parameter_types.date_time,
+                        'zone': {'type': 'string'},
+                        # TODO(zhufl): cluster is added in 3.7, we should move
+                        # it to the 3.7 schema file when microversion is
+                        # supported in volume interfaces
+                        'cluster': {'type': 'string'},
+                        'replication_status': {'type': 'string'},
+                        'active_backend_id': {'type': ['string', 'null']},
+                        'backend_state': {'type': 'string'},
+                    },
+                    'additionalProperties': False,
+                    'required': ['binary', 'disabled_reason', 'host', 'state',
+                                 'status', 'updated_at', 'zone']
+                }
+            }
+        },
+        'additionalProperties': False,
+        'required': ['services']
+    }
+}
+
+enable_service = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'disabled': {'type': 'boolean'},
+            'status': {'enum': ['enabled', 'disabled']},
+            'host': {'type': 'string'},
+            'service': {'type': 'string'},
+            'binary': {'type': 'string'},
+            'disabled_reason': {'type': ['string', 'null']}
+        },
+        'additionalProperties': False,
+        'required': ['disabled', 'status', 'host', 'service',
+                     'binary', 'disabled_reason']
+    }
+}
+
+disable_service = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'disabled': {'type': 'boolean'},
+            'status': {'enum': ['enabled', 'disabled']},
+            'host': {'type': 'string'},
+            'service': {'type': 'string'},
+            'binary': {'type': 'string'},
+        },
+        'additionalProperties': False,
+        'required': ['disabled', 'status', 'host', 'service', 'binary']
+    }
+}
+
+disable_log_reason = copy.deepcopy(enable_service)
+
+freeze_host = {'status_code': [200]}
+thaw_host = {'status_code': [200]}
diff --git a/tempest/lib/services/volume/v3/services_client.py b/tempest/lib/services/volume/v3/services_client.py
index c4a511c..8bc82c9 100644
--- a/tempest/lib/services/volume/v3/services_client.py
+++ b/tempest/lib/services/volume/v3/services_client.py
@@ -16,6 +16,7 @@
 from oslo_serialization import jsonutils as json
 from six.moves.urllib import parse as urllib
 
+from tempest.lib.api_schema.response.volume import services as schema
 from tempest.lib.common import rest_client
 
 
@@ -35,7 +36,7 @@
 
         resp, body = self.get(url)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema.list_services, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def enable_service(self, **kwargs):
@@ -48,7 +49,7 @@
         put_body = json.dumps(kwargs)
         resp, body = self.put('os-services/enable', put_body)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema.enable_service, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def disable_service(self, **kwargs):
@@ -61,7 +62,7 @@
         put_body = json.dumps(kwargs)
         resp, body = self.put('os-services/disable', put_body)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema.disable_service, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def disable_log_reason(self, **kwargs):
@@ -74,7 +75,7 @@
         put_body = json.dumps(kwargs)
         resp, body = self.put('os-services/disable-log-reason', put_body)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema.disable_log_reason, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def freeze_host(self, **kwargs):
@@ -85,8 +86,8 @@
         https://docs.openstack.org/api-ref/block-storage/v3/#freeze-a-cinder-backend-host
         """
         put_body = json.dumps(kwargs)
-        resp, _ = self.put('os-services/freeze', put_body)
-        self.expected_success(200, resp.status)
+        resp, body = self.put('os-services/freeze', put_body)
+        self.validate_response(schema.freeze_host, resp, body)
         return rest_client.ResponseBody(resp)
 
     def thaw_host(self, **kwargs):
@@ -97,6 +98,6 @@
         https://docs.openstack.org/api-ref/block-storage/v3/#thaw-a-cinder-backend-host
         """
         put_body = json.dumps(kwargs)
-        resp, _ = self.put('os-services/thaw', put_body)
-        self.expected_success(200, resp.status)
+        resp, body = self.put('os-services/thaw', put_body)
+        self.validate_response(schema.thaw_host, resp, body)
         return rest_client.ResponseBody(resp)