Browse Source

Merge "Add response schema validation for volume quota_set"

changes/90/680790/1
Zuul 1 week ago
parent
commit
6cdbfe21c5

+ 7
- 16
tempest/api/volume/admin/test_volume_quotas.py View File

@@ -19,7 +19,6 @@ from tempest.lib import decorators
19 19
 
20 20
 QUOTA_KEYS = ['gigabytes', 'snapshots', 'volumes', 'backups',
21 21
               'backup_gigabytes', 'per_volume_gigabytes']
22
-QUOTA_USAGE_KEYS = ['reserved', 'limit', 'in_use']
23 22
 
24 23
 
25 24
 class VolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
@@ -55,17 +54,13 @@ class VolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
55 54
 
56 55
     @decorators.idempotent_id('59eada70-403c-4cef-a2a3-a8ce2f1b07a0')
57 56
     def test_list_quotas(self):
58
-        quotas = (self.admin_quotas_client.show_quota_set(self.demo_tenant_id)
59
-                  ['quota_set'])
60
-        for key in QUOTA_KEYS:
61
-            self.assertIn(key, quotas)
57
+        # Check response schema
58
+        self.admin_quotas_client.show_quota_set(self.demo_tenant_id)
62 59
 
63 60
     @decorators.idempotent_id('2be020a2-5fdd-423d-8d35-a7ffbc36e9f7')
64 61
     def test_list_default_quotas(self):
65
-        quotas = self.admin_quotas_client.show_default_quota_set(
66
-            self.demo_tenant_id)['quota_set']
67
-        for key in QUOTA_KEYS:
68
-            self.assertIn(key, quotas)
62
+        # Check response schema
63
+        self.admin_quotas_client.show_default_quota_set(self.demo_tenant_id)
69 64
 
70 65
     @decorators.idempotent_id('3d45c99e-cc42-4424-a56e-5cbd212b63a6')
71 66
     def test_update_all_quota_resources_for_tenant(self):
@@ -92,13 +87,9 @@ class VolumeQuotasAdminTestJSON(base.BaseVolumeAdminTest):
92 87
 
93 88
     @decorators.idempotent_id('18c51ae9-cb03-48fc-b234-14a19374dbed')
94 89
     def test_show_quota_usage(self):
95
-        quota_usage = self.admin_quotas_client.show_quota_set(
96
-            self.os_admin.credentials.tenant_id,
97
-            params={'usage': True})['quota_set']
98
-        for key in QUOTA_KEYS:
99
-            self.assertIn(key, quota_usage)
100
-            for usage_key in QUOTA_USAGE_KEYS:
101
-                self.assertIn(usage_key, quota_usage[key])
90
+        # Check response schema
91
+        self.admin_quotas_client.show_quota_set(
92
+            self.os_admin.credentials.tenant_id, params={'usage': True})
102 93
 
103 94
     @decorators.idempotent_id('874b35a9-51f1-4258-bec5-cd561b6690d3')
104 95
     def test_delete_quota(self):

+ 92
- 0
tempest/lib/api_schema/response/volume/quotas.py View File

@@ -0,0 +1,92 @@
1
+# Copyright 2019 ZTE 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
+import copy
16
+
17
+delete_quota_set = {
18
+    'status_code': [200],
19
+}
20
+
21
+quota_usage_info = {
22
+    'type': 'object',
23
+    'properties': {
24
+        'reserved': {'type': 'integer'},
25
+        'allocated': {'type': 'integer'},
26
+        'limit': {'type': 'integer'},
27
+        'in_use': {'type': 'integer'}
28
+    },
29
+    'additionalProperties': False,
30
+    # 'allocated' attribute is available only when nested quota is enabled.
31
+    'required': ['reserved', 'limit', 'in_use'],
32
+}
33
+
34
+show_quota_set = {
35
+    'status_code': [200],
36
+    'response_body': {
37
+        'type': 'object',
38
+        'properties': {
39
+            'quota_set': {
40
+                'type': 'object',
41
+                'properties': {
42
+                    'id': {'type': 'string', 'format': 'uuid'},
43
+                    'volumes': {'type': 'integer'},
44
+                    'snapshots': {'type': 'integer'},
45
+                    'backups': {'type': 'integer'},
46
+                    'groups': {'type': 'integer'},
47
+                    'per_volume_gigabytes': {'type': 'integer'},
48
+                    'gigabytes': {'type': 'integer'},
49
+                    'backup_gigabytes': {'type': 'integer'},
50
+                },
51
+                # for volumes_{volume_type}, etc
52
+                "additionalProperties": {'type': 'integer'},
53
+                'required': ['id', 'volumes', 'snapshots', 'backups',
54
+                             'per_volume_gigabytes', 'gigabytes',
55
+                             'backup_gigabytes', 'groups'],
56
+            }
57
+        },
58
+        'required': ['quota_set']
59
+    }
60
+}
61
+
62
+update_quota_set = copy.deepcopy(show_quota_set)
63
+update_quota_set['response_body']['properties']['quota_set'][
64
+    'required'].remove('id')
65
+
66
+show_quota_set_usage = {
67
+    'status_code': [200],
68
+    'response_body': {
69
+        'type': 'object',
70
+        'properties': {
71
+            'quota_set': {
72
+                'type': 'object',
73
+                'properties': {
74
+                    'id': {'type': 'string', 'format': 'uuid'},
75
+                    'volumes': quota_usage_info,
76
+                    'snapshots': quota_usage_info,
77
+                    'backups': quota_usage_info,
78
+                    'groups': quota_usage_info,
79
+                    'per_volume_gigabytes': quota_usage_info,
80
+                    'gigabytes': quota_usage_info,
81
+                    'backup_gigabytes': quota_usage_info,
82
+                },
83
+                # for volumes_{volume_type}, etc
84
+                "additionalProperties": quota_usage_info,
85
+                'required': ['id', 'volumes', 'snapshots', 'backups',
86
+                             'per_volume_gigabytes', 'gigabytes',
87
+                             'backup_gigabytes', 'groups'],
88
+            }
89
+        },
90
+        'required': ['quota_set']
91
+    }
92
+}

+ 8
- 4
tempest/lib/services/volume/v3/quotas_client.py View File

@@ -16,6 +16,7 @@
16 16
 from oslo_serialization import jsonutils
17 17
 from six.moves.urllib import parse as urllib
18 18
 
19
+from tempest.lib.api_schema.response.volume import quotas as schema
19 20
 from tempest.lib.common import rest_client
20 21
 
21 22
 
@@ -27,8 +28,8 @@ class QuotasClient(rest_client.RestClient):
27 28
 
28 29
         url = 'os-quota-sets/%s/defaults' % tenant_id
29 30
         resp, body = self.get(url)
30
-        self.expected_success(200, resp.status)
31 31
         body = jsonutils.loads(body)
32
+        self.validate_response(schema.show_quota_set, resp, body)
32 33
         return rest_client.ResponseBody(resp, body)
33 34
 
34 35
     def show_quota_set(self, tenant_id, params=None):
@@ -39,8 +40,11 @@ class QuotasClient(rest_client.RestClient):
39 40
             url += '?%s' % urllib.urlencode(params)
40 41
 
41 42
         resp, body = self.get(url)
42
-        self.expected_success(200, resp.status)
43 43
         body = jsonutils.loads(body)
44
+        if params and params.get('usage', False):
45
+            self.validate_response(schema.show_quota_set_usage, resp, body)
46
+        else:
47
+            self.validate_response(schema.show_quota_set, resp, body)
44 48
         return rest_client.ResponseBody(resp, body)
45 49
 
46 50
     def update_quota_set(self, tenant_id, **kwargs):
@@ -52,12 +56,12 @@ class QuotasClient(rest_client.RestClient):
52 56
         """
53 57
         put_body = jsonutils.dumps({'quota_set': kwargs})
54 58
         resp, body = self.put('os-quota-sets/%s' % tenant_id, put_body)
55
-        self.expected_success(200, resp.status)
56 59
         body = jsonutils.loads(body)
60
+        self.validate_response(schema.update_quota_set, resp, body)
57 61
         return rest_client.ResponseBody(resp, body)
58 62
 
59 63
     def delete_quota_set(self, tenant_id):
60 64
         """Delete the tenant's quota set."""
61 65
         resp, body = self.delete('os-quota-sets/%s' % tenant_id)
62
-        self.expected_success(200, resp.status)
66
+        self.validate_response(schema.delete_quota_set, resp, body)
63 67
         return rest_client.ResponseBody(resp, body)

+ 15
- 4
tempest/tests/lib/services/volume/v3/test_quotas_client.py View File

@@ -20,15 +20,26 @@ from tempest.tests.lib.services import base
20 20
 class TestQuotasClient(base.BaseServiceTest):
21 21
     FAKE_QUOTAS = {
22 22
         "quota_set": {
23
+            "id": '730a1cbd-68ca-4d68-8e09-d603f2dfa72b',
23 24
             "gigabytes": 5,
24 25
             "snapshots": 10,
25
-            "volumes": 20
26
+            "volumes": 20,
27
+            'backups': 10,
28
+            'groups': 10,
29
+            'per_volume_gigabytes': 1000,
30
+            'backup_gigabytes': 2000
26 31
         }
27 32
     }
28 33
 
29
-    FAKE_UPDATE_QUOTAS_REQUEST = {
34
+    FAKE_UPDATE_QUOTAS_RESPONSE = {
30 35
         "quota_set": {
31
-            "security_groups": 45
36
+            "gigabytes": 6,
37
+            "snapshots": 11,
38
+            "volumes": 21,
39
+            'backups': 11,
40
+            'groups': 11,
41
+            'per_volume_gigabytes': 1001,
42
+            'backup_gigabytes': 2001
32 43
         }
33 44
     }
34 45
 
@@ -57,7 +68,7 @@ class TestQuotasClient(base.BaseServiceTest):
57 68
         self.check_service_client_function(
58 69
             self.client.update_quota_set,
59 70
             'tempest.lib.common.rest_client.RestClient.put',
60
-            self.FAKE_UPDATE_QUOTAS_REQUEST,
71
+            self.FAKE_UPDATE_QUOTAS_RESPONSE,
61 72
             bytes_body, tenant_id="fake_tenant")
62 73
 
63 74
     def test_show_default_quota_set_with_str_body(self):

Loading…
Cancel
Save