Browse Source

Merge "Add test for quota set for invalid project"

Zuul 7 months ago
parent
commit
b9a90dff11

+ 4
- 0
designate_tempest_plugin/config.py View File

@@ -77,6 +77,10 @@ DnsFeatureGroup = [
77 77
     cfg.BoolOpt('api_v2_quotas',
78 78
                 default=False,
79 79
                 help="Is the v2 quota API enabled."),
80
+    cfg.BoolOpt('api_v2_quotas_verify_project',
81
+                default=False,
82
+                help="Is project IDs verified when setting v2 quotas. "
83
+                "Must be set to True starting from Rocky release."),
80 84
     cfg.BoolOpt('bug_1573141_fixed',
81 85
                 default=True,
82 86
                 help="Is https://bugs.launchpad.net/designate/+bug/1573141 "

+ 31
- 3
designate_tempest_plugin/tests/api/v2/test_quotas.py View File

@@ -14,6 +14,7 @@
14 14
 from oslo_log import log as logging
15 15
 from tempest import config
16 16
 from tempest.lib import decorators
17
+from tempest.lib import exceptions as lib_exc
17 18
 
18 19
 from designate_tempest_plugin.tests import base
19 20
 from designate_tempest_plugin import data_utils as dns_data_utils
@@ -26,7 +27,7 @@ CONF = config.CONF
26 27
 
27 28
 class QuotasV2Test(base.BaseDnsV2Test):
28 29
 
29
-    credentials = ['primary', 'admin']
30
+    credentials = ['primary', 'admin', 'alt']
30 31
 
31 32
     @classmethod
32 33
     def setup_credentials(cls):
@@ -49,6 +50,7 @@ class QuotasV2Test(base.BaseDnsV2Test):
49 50
 
50 51
         cls.quotas_client = cls.os_primary.quotas_client
51 52
         cls.admin_client = cls.os_admin.quotas_client
53
+        cls.alt_client = cls.os_alt.quotas_client
52 54
 
53 55
     @decorators.idempotent_id('1dac991a-9e2e-452c-a47a-26ac37381ec5')
54 56
     def test_show_quotas(self):
@@ -105,8 +107,8 @@ class QuotasV2Test(base.BaseDnsV2Test):
105 107
     @decorators.idempotent_id('21e45d30-dbc1-4173-9d6b-9b6813ef514b')
106 108
     def test_reset_quotas_other_project(self):
107 109
 
108
-        # Use a fake project for this
109
-        project_id = '21e45d30-dbc1-4173-9d6b-9b6813ef514b'
110
+        LOG.info("Using 'alt' project id to set quotas on.")
111
+        project_id = self.alt_client.tenant_id
110 112
 
111 113
         _, original_quotas = self.admin_client.show_quotas(
112 114
             project_id=project_id, headers={'X-Auth-All-Projects': True})
@@ -128,3 +130,29 @@ class QuotasV2Test(base.BaseDnsV2Test):
128 130
             project_id=project_id, headers={'X-Auth-All-Projects': True})
129 131
 
130 132
         self.assertExpected(original_quotas, final_quotas, [])
133
+
134
+    @decorators.idempotent_id('9b09b3e2-7e88-4569-bce3-9be2f7ac70c4')
135
+    def test_update_quotas_invalid_project(self):
136
+
137
+        if not CONF.dns_feature_enabled.api_v2_quotas_verify_project:
138
+            raise self.skipException("Project ID in quotas "
139
+                                     "is not being verified.")
140
+
141
+        project_id = 'project-that-does-not-exist'
142
+
143
+        LOG.info("Updating quotas for non-existing %s ", project_id)
144
+
145
+        _, original_quotas = self.admin_client.show_quotas(
146
+            project_id=project_id, headers={'X-Auth-All-Projects': True})
147
+
148
+        quotas = dns_data_utils.rand_quotas()
149
+        request = quotas.copy()
150
+        request['project_id'] = project_id
151
+        request['headers'] = {'X-Auth-All-Projects': True}
152
+        with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_project', 400):
153
+            self.admin_client.update_quotas(**request)
154
+        self.addCleanup(self.admin_client.delete_quotas, project_id=project_id)
155
+
156
+        _, client_body = self.quotas_client.show_quotas()
157
+
158
+        self.assertExpected(original_quotas, client_body, [])

Loading…
Cancel
Save