Add response schema validation for volume groups

This is to add response schema validation for volume groups.

Change-Id: Ibc4c59f63e56ec6ea6f9a850d2340d8c91775532
partially-implements: blueprint volume-response-schema-validation
diff --git a/tempest/lib/api_schema/response/volume/groups.py b/tempest/lib/api_schema/response/volume/groups.py
new file mode 100644
index 0000000..cb31269
--- /dev/null
+++ b/tempest/lib/api_schema/response/volume/groups.py
@@ -0,0 +1,164 @@
+# Copyright 2015 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.
+
+from tempest.lib.api_schema.response.compute.v2_1 import parameter_types
+
+create_group = {
+    'status_code': [202],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'group': {
+                'type': 'object',
+                'properties': {
+                    'id': {'type': 'string', 'format': 'uuid'},
+                    'name': {'type': 'string'},
+                },
+                'additionalProperties': False,
+                'required': ['id', 'name']
+            }
+        },
+        'additionalProperties': False,
+        'required': ['group']
+    }
+}
+
+delete_group = {'status_code': [202]}
+
+show_group = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'group': {
+                'type': 'object',
+                'properties': {
+                    'status': {'type': 'string'},
+                    'description': {'type': ['string', 'null']},
+                    'availability_zone': {'type': 'string'},
+                    'created_at': parameter_types.date_time,
+                    'group_type': {'type': 'string', 'format': 'uuid'},
+                    'group_snapshot_id': {'type': ['string', 'null']},
+                    'source_group_id': {'type': ['string', 'null']},
+                    'volume_types': {
+                        'type': 'array',
+                        'items': {'type': 'string', 'format': 'uuid'}
+                    },
+                    'id': {'type': 'string', 'format': 'uuid'},
+                    'name': {'type': 'string'},
+                    # TODO(zhufl): volumes is added in 3.25, we should move it
+                    # to the 3.25 schema file when microversion is supported
+                    # in volume interfaces
+                    'volumes': {
+                        'type': 'array',
+                        'items': {'type': 'string', 'format': 'uuid'}
+                    },
+                    'replication_status': {'type': 'string'}
+                },
+                'additionalProperties': False,
+                'required': ['status', 'description', 'created_at',
+                             'group_type', 'volume_types', 'id', 'name']
+            }
+        },
+        'additionalProperties': False,
+        'required': ['group']
+    }
+}
+
+list_groups_no_detail = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'groups': {
+                'type': 'array',
+                'items': {
+                    'type': 'object',
+                    'properties': {
+                        'id': {'type': 'string', 'format': 'uuid'},
+                        'name': {'type': 'string'}
+                    },
+                    'additionalProperties': False,
+                    'required': ['id', 'name'],
+                }
+            }
+        },
+        'additionalProperties': False,
+        'required': ['groups'],
+    }
+}
+
+list_groups_with_detail = {
+    'status_code': [200],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'groups': {
+                'type': 'array',
+                'items': {
+                    'type': 'object',
+                    'properties': {
+                        'status': {'type': 'string'},
+                        'description': {'type': ['string', 'null']},
+                        'availability_zone': {'type': 'string'},
+                        'created_at': parameter_types.date_time,
+                        'group_type': {'type': 'string', 'format': 'uuid'},
+                        'group_snapshot_id': {'type': ['string', 'null']},
+                        'source_group_id': {'type': ['string', 'null']},
+                        'volume_types': {
+                            'type': 'array',
+                            'items': {'type': 'string', 'format': 'uuid'}
+                        },
+                        'id': {'type': 'string', 'format': 'uuid'},
+                        'name': {'type': 'string'},
+                        # TODO(zhufl): volumes is added in 3.25, we should
+                        # move it to the 3.25 schema file when microversion
+                        # is supported in volume interfaces
+                        'volumes': {
+                            'type': 'array',
+                            'items': {'type': 'string', 'format': 'uuid'}
+                        },
+                    },
+                    'additionalProperties': False,
+                    'required': ['status', 'description', 'created_at',
+                                 'group_type', 'volume_types', 'id', 'name']
+                }
+            }
+        },
+        'additionalProperties': False,
+        'required': ['groups'],
+    }
+}
+
+create_group_from_source = {
+    'status_code': [202],
+    'response_body': {
+        'type': 'object',
+        'properties': {
+            'group': {
+                'type': 'object',
+                'properties': {
+                    'id': {'type': 'string', 'format': 'uuid'},
+                    'name': {'type': 'string'},
+                },
+                'additionalProperties': False,
+                'required': ['id', 'name']
+            }
+        },
+        'additionalProperties': False,
+        'required': ['group']
+    }
+}
+update_group = {'status_code': [202]}
+reset_group_status = {'status_code': [202]}
diff --git a/tempest/lib/services/volume/v3/groups_client.py b/tempest/lib/services/volume/v3/groups_client.py
index ffae232..3d8523d 100644
--- a/tempest/lib/services/volume/v3/groups_client.py
+++ b/tempest/lib/services/volume/v3/groups_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 groups as schema
 from tempest.lib.common import rest_client
 from tempest.lib import exceptions as lib_exc
 from tempest.lib.services.volume import base_client
@@ -23,6 +24,7 @@
 
 class GroupsClient(base_client.BaseClient):
     """Client class to send CRUD Volume Group API requests"""
+    api_version = 'v3'
 
     def create_group(self, **kwargs):
         """Creates a group.
@@ -35,7 +37,7 @@
         post_body = json.dumps({'group': kwargs})
         resp, body = self.post('groups', post_body)
         body = json.loads(body)
-        self.expected_success(202, resp.status)
+        self.validate_response(schema.create_group, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def delete_group(self, group_id, delete_volumes=True):
@@ -49,7 +51,7 @@
         post_body = json.dumps({'delete': post_body})
         resp, body = self.post('groups/%s/action' % group_id,
                                post_body)
-        self.expected_success(202, resp.status)
+        self.validate_response(schema.delete_group, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def show_group(self, group_id):
@@ -62,7 +64,7 @@
         url = "groups/%s" % str(group_id)
         resp, body = self.get(url)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema.show_group, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def list_groups(self, detail=False, **params):
@@ -74,13 +76,15 @@
         https://docs.openstack.org/api-ref/block-storage/v3/#list-groups-with-details
         """
         url = "groups"
+        schema_list_groups = schema.list_groups_no_detail
         if detail:
             url += "/detail"
+            schema_list_groups = schema.list_groups_with_detail
         if params:
             url += '?%s' % urllib.urlencode(params)
         resp, body = self.get(url)
         body = json.loads(body)
-        self.expected_success(200, resp.status)
+        self.validate_response(schema_list_groups, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def create_group_from_source(self, **kwargs):
@@ -93,7 +97,7 @@
         post_body = json.dumps({'create-from-src': kwargs})
         resp, body = self.post('groups/action', post_body)
         body = json.loads(body)
-        self.expected_success(202, resp.status)
+        self.validate_response(schema.create_group_from_source, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def update_group(self, group_id, **kwargs):
@@ -105,7 +109,7 @@
         """
         put_body = json.dumps({'group': kwargs})
         resp, body = self.put('groups/%s' % group_id, put_body)
-        self.expected_success(202, resp.status)
+        self.validate_response(schema.update_group, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def reset_group_status(self, group_id, status_to_set):
@@ -116,7 +120,7 @@
         """
         post_body = json.dumps({'reset_status': {'status': status_to_set}})
         resp, body = self.post('groups/%s/action' % group_id, post_body)
-        self.expected_success(202, resp.status)
+        self.validate_response(schema.reset_group_status, resp, body)
         return rest_client.ResponseBody(resp, body)
 
     def is_resource_deleted(self, id):