Browse Source

Merge "Add response schema validation for volume transfer"

changes/90/680790/8
Zuul 1 week ago
parent
commit
fa4796b999

+ 0
- 4
tempest/api/volume/test_volume_transfers.py View File

@@ -63,8 +63,6 @@ class VolumesTransfersTest(base.BaseVolumeTest):
63 63
         # Accept a volume transfer by alt_tenant
64 64
         body = self.alt_client.accept_volume_transfer(
65 65
             transfer_id, auth_key=auth_key)['transfer']
66
-        for key in ['id', 'name', 'links', 'volume_id']:
67
-            self.assertIn(key, body)
68 66
         waiters.wait_for_volume_resource_status(self.alt_volumes_client,
69 67
                                                 volume['id'], 'available')
70 68
         accepted_volume = self.alt_volumes_client.show_volume(
@@ -95,8 +93,6 @@ class VolumesTransfersTest(base.BaseVolumeTest):
95 93
         # elements, and look for the created transfer.
96 94
         transfers = self.client.list_volume_transfers(detail=True)['transfers']
97 95
         self.assertNotEmpty(transfers)
98
-        for transfer in transfers:
99
-            self.assertIn('created_at', transfer)
100 96
         volume_list = [transfer['volume_id'] for transfer in transfers]
101 97
         self.assertIn(volume['id'], volume_list,
102 98
                       'Transfer not found for volume %s' % volume['id'])

+ 129
- 0
tempest/lib/api_schema/response/volume/transfers.py View File

@@ -0,0 +1,129 @@
1
+# Copyright 2015 NEC Corporation.  All rights reserved.
2
+#
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+
15
+from tempest.lib.api_schema.response.compute.v2_1 import parameter_types
16
+
17
+create_volume_transfer = {
18
+    'status_code': [202],
19
+    'response_body': {
20
+        'type': 'object',
21
+        'properties': {
22
+            'transfer': {
23
+                'type': 'object',
24
+                'properties': {
25
+                    'auth_key': {'type': 'string'},
26
+                    'links': parameter_types.links,
27
+                    'created_at': parameter_types.date_time,
28
+                    'volume_id': {'type': 'string', 'format': 'uuid'},
29
+                    'id': {'type': 'string', 'format': 'uuid'},
30
+                    'name': {'type': ['string', 'null']}
31
+                },
32
+                'additionalProperties': False,
33
+                'required': ['auth_key', 'links', 'created_at',
34
+                             'volume_id', 'id', 'name']
35
+            }
36
+        },
37
+        'additionalProperties': False,
38
+        'required': ['transfer']
39
+    }
40
+}
41
+
42
+common_show_volume_transfer = {
43
+    'type': 'object',
44
+    'properties': {
45
+        'links': parameter_types.links,
46
+        'created_at': parameter_types.date_time,
47
+        'volume_id': {'type': 'string', 'format': 'uuid'},
48
+        'id': {'type': 'string', 'format': 'uuid'},
49
+        'name': {'type': ['string', 'null']}
50
+    },
51
+    'additionalProperties': False,
52
+    'required': ['links', 'created_at', 'volume_id', 'id', 'name']
53
+}
54
+
55
+show_volume_transfer = {
56
+    'status_code': [200],
57
+    'response_body': {
58
+        'type': 'object',
59
+        'properties': {
60
+            'transfer': common_show_volume_transfer
61
+        },
62
+        'additionalProperties': False,
63
+        'required': ['transfer']
64
+    }
65
+}
66
+
67
+list_volume_transfers_no_detail = {
68
+    'status_code': [200],
69
+    'response_body': {
70
+        'type': 'object',
71
+        'properties': {
72
+            'transfers': {
73
+                'type': 'array',
74
+                'items': {
75
+                    'type': 'object',
76
+                    'properties': {
77
+                        'volume_id': {'type': 'string', 'format': 'uuid'},
78
+                        'id': {'type': 'string', 'format': 'uuid'},
79
+                        'links': parameter_types.links,
80
+                        'name': {'type': ['string', 'null']}
81
+                    },
82
+                    'additionalProperties': False,
83
+                    'required': ['volume_id', 'id', 'links', 'name']
84
+                }
85
+            }
86
+        },
87
+        'additionalProperties': False,
88
+        'required': ['transfers'],
89
+    }
90
+}
91
+
92
+list_volume_transfers_with_detail = {
93
+    'status_code': [200],
94
+    'response_body': {
95
+        'type': 'object',
96
+        'properties': {
97
+            'transfers': {
98
+                'type': 'array',
99
+                'items': common_show_volume_transfer
100
+            }
101
+        },
102
+        'additionalProperties': False,
103
+        'required': ['transfers'],
104
+    }
105
+}
106
+
107
+delete_volume_transfer = {'status_code': [202]}
108
+
109
+accept_volume_transfer = {
110
+    'status_code': [202],
111
+    'response_body': {
112
+        'type': 'object',
113
+        'properties': {
114
+            'transfer': {
115
+                'type': 'object',
116
+                'properties': {
117
+                    'links': parameter_types.links,
118
+                    'volume_id': {'type': 'string', 'format': 'uuid'},
119
+                    'id': {'type': 'string', 'format': 'uuid'},
120
+                    'name': {'type': ['string', 'null']}
121
+                },
122
+                'additionalProperties': False,
123
+                'required': ['links', 'volume_id', 'id', 'name']
124
+            }
125
+        },
126
+        'additionalProperties': False,
127
+        'required': ['transfer']
128
+    }
129
+}

+ 8
- 5
tempest/lib/services/volume/v3/transfers_client.py View File

@@ -16,6 +16,7 @@
16 16
 from oslo_serialization import jsonutils as json
17 17
 from six.moves.urllib import parse as urllib
18 18
 
19
+from tempest.lib.api_schema.response.volume import transfers as schema
19 20
 from tempest.lib.common import rest_client
20 21
 
21 22
 
@@ -32,7 +33,7 @@ class TransfersClient(rest_client.RestClient):
32 33
         post_body = json.dumps({'transfer': kwargs})
33 34
         resp, body = self.post('os-volume-transfer', post_body)
34 35
         body = json.loads(body)
35
-        self.expected_success(202, resp.status)
36
+        self.validate_response(schema.create_volume_transfer, resp, body)
36 37
         return rest_client.ResponseBody(resp, body)
37 38
 
38 39
     def show_volume_transfer(self, transfer_id):
@@ -40,7 +41,7 @@ class TransfersClient(rest_client.RestClient):
40 41
         url = "os-volume-transfer/%s" % transfer_id
41 42
         resp, body = self.get(url)
42 43
         body = json.loads(body)
43
-        self.expected_success(200, resp.status)
44
+        self.validate_response(schema.show_volume_transfer, resp, body)
44 45
         return rest_client.ResponseBody(resp, body)
45 46
 
46 47
     def list_volume_transfers(self, detail=False, **params):
@@ -52,19 +53,21 @@ class TransfersClient(rest_client.RestClient):
52 53
         https://docs.openstack.org/api-ref/block-storage/v3/index.html#list-volume-transfers-and-details
53 54
         """
54 55
         url = 'os-volume-transfer'
56
+        schema_list_transfers = schema.list_volume_transfers_no_detail
55 57
         if detail:
56 58
             url += '/detail'
59
+            schema_list_transfers = schema.list_volume_transfers_with_detail
57 60
         if params:
58 61
             url += '?%s' % urllib.urlencode(params)
59 62
         resp, body = self.get(url)
60 63
         body = json.loads(body)
61
-        self.expected_success(200, resp.status)
64
+        self.validate_response(schema_list_transfers, resp, body)
62 65
         return rest_client.ResponseBody(resp, body)
63 66
 
64 67
     def delete_volume_transfer(self, transfer_id):
65 68
         """Delete a volume transfer."""
66 69
         resp, body = self.delete("os-volume-transfer/%s" % transfer_id)
67
-        self.expected_success(202, resp.status)
70
+        self.validate_response(schema.delete_volume_transfer, resp, body)
68 71
         return rest_client.ResponseBody(resp, body)
69 72
 
70 73
     def accept_volume_transfer(self, transfer_id, **kwargs):
@@ -78,5 +81,5 @@ class TransfersClient(rest_client.RestClient):
78 81
         post_body = json.dumps({'accept': kwargs})
79 82
         resp, body = self.post(url, post_body)
80 83
         body = json.loads(body)
81
-        self.expected_success(202, resp.status)
84
+        self.validate_response(schema.accept_volume_transfer, resp, body)
82 85
         return rest_client.ResponseBody(resp, body)

Loading…
Cancel
Save