Add test for quota set for invalid project
this also adds a feature flag "api_v2_quotas_verify_project" (False by
default) enabling which will enable this test.
Change-Id: Icdc1b9ae419c3634ab2c55005f33fed624706176
Related-Bug: #1760822
(cherry picked from commit 60e5372a46f588633d68d453c829c397363ed7c2)
diff --git a/designate_tempest_plugin/config.py b/designate_tempest_plugin/config.py
index 565d5c3..c82421a 100644
--- a/designate_tempest_plugin/config.py
+++ b/designate_tempest_plugin/config.py
@@ -74,6 +74,10 @@
cfg.BoolOpt('api_v2_quotas',
default=False,
help="Is the v2 quota API enabled."),
+ cfg.BoolOpt('api_v2_quotas_verify_project',
+ default=False,
+ help="Is project IDs verified when setting v2 quotas. "
+ "Must be set to True starting from Rocky release."),
cfg.BoolOpt('bug_1573141_fixed',
default=False,
help="Is https://bugs.launchpad.net/designate/+bug/1573141 "
diff --git a/designate_tempest_plugin/tests/api/v2/test_quotas.py b/designate_tempest_plugin/tests/api/v2/test_quotas.py
index 254e4b5..d35f4c3 100644
--- a/designate_tempest_plugin/tests/api/v2/test_quotas.py
+++ b/designate_tempest_plugin/tests/api/v2/test_quotas.py
@@ -14,6 +14,7 @@
from oslo_log import log as logging
from tempest import config
from tempest.lib import decorators
+from tempest.lib import exceptions as lib_exc
from designate_tempest_plugin.tests import base
from designate_tempest_plugin import data_utils as dns_data_utils
@@ -26,7 +27,7 @@
class QuotasV2Test(base.BaseDnsV2Test):
- credentials = ['primary', 'admin']
+ credentials = ['primary', 'admin', 'alt']
@classmethod
def skip_checks(cls):
@@ -43,6 +44,7 @@
cls.quotas_client = cls.os_primary.quotas_client
cls.admin_client = cls.os_admin.quotas_client
+ cls.alt_client = cls.os_alt.quotas_client
@decorators.idempotent_id('1dac991a-9e2e-452c-a47a-26ac37381ec5')
def test_show_quotas(self):
@@ -99,8 +101,8 @@
@decorators.idempotent_id('21e45d30-dbc1-4173-9d6b-9b6813ef514b')
def test_reset_quotas_other_project(self):
- # Use a fake project for this
- project_id = '21e45d30-dbc1-4173-9d6b-9b6813ef514b'
+ LOG.info("Using 'alt' project id to set quotas on.")
+ project_id = self.alt_client.tenant_id
_, original_quotas = self.admin_client.show_quotas(
project_id=project_id, headers={'X-Auth-All-Projects': True})
@@ -122,3 +124,29 @@
project_id=project_id, headers={'X-Auth-All-Projects': True})
self.assertExpected(original_quotas, final_quotas, [])
+
+ @decorators.idempotent_id('9b09b3e2-7e88-4569-bce3-9be2f7ac70c4')
+ def test_update_quotas_invalid_project(self):
+
+ if not CONF.dns_feature_enabled.api_v2_quotas_verify_project:
+ raise self.skipException("Project ID in quotas "
+ "is not being verified.")
+
+ project_id = 'project-that-does-not-exist'
+
+ LOG.info("Updating quotas for non-existing %s ", project_id)
+
+ _, original_quotas = self.admin_client.show_quotas(
+ project_id=project_id, headers={'X-Auth-All-Projects': True})
+
+ quotas = dns_data_utils.rand_quotas()
+ request = quotas.copy()
+ request['project_id'] = project_id
+ request['headers'] = {'X-Auth-All-Projects': True}
+ with self.assertRaisesDns(lib_exc.BadRequest, 'invalid_project', 400):
+ self.admin_client.update_quotas(**request)
+ self.addCleanup(self.admin_client.delete_quotas, project_id=project_id)
+
+ _, client_body = self.quotas_client.show_quotas()
+
+ self.assertExpected(original_quotas, client_body, [])