summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-08-15 23:57:34 +0000
committerGerrit Code Review <review@openstack.org>2022-08-15 23:57:34 +0000
commite68640d611a8868ce524f623f0583e4b58f01f8e (patch)
tree5a7bdabba466aff55bf3123a5b1424846b2331eb
parent63563a50983c85df852654e908963eeb7331e3c8 (diff)
parentf46d9de45f8194a7d9bd308ccb0debab39a9570d (diff)
downloaddesignate-e68640d611a8868ce524f623f0583e4b58f01f8e.tar.gz
Merge "Add basic quotas api tests"
-rw-r--r--designate/api/v2/controllers/quotas.py16
-rw-r--r--designate/tests/test_api/test_v2/test_import_export.py4
-rw-r--r--designate/tests/test_api/test_v2/test_quotas.py159
-rw-r--r--designate/tests/test_api/test_v2/test_zone_transfers.py28
4 files changed, 183 insertions, 24 deletions
diff --git a/designate/api/v2/controllers/quotas.py b/designate/api/v2/controllers/quotas.py
index 9fbc6d3a..e4168c5e 100644
--- a/designate/api/v2/controllers/quotas.py
+++ b/designate/api/v2/controllers/quotas.py
@@ -39,17 +39,17 @@ class QuotasController(rest.RestController):
return DesignateAdapter.render('API_v2', quotas)
@pecan.expose(template='json:', content_type='application/json')
- def get_one(self, tenant_id):
+ def get_one(self, project_id):
context = pecan.request.environ['context']
- quotas = self.central_api.get_quotas(context, tenant_id)
+ quotas = self.central_api.get_quotas(context, project_id)
quotas = QuotaList.from_dict(quotas)
return DesignateAdapter.render('API_v2', quotas)
@pecan.expose(template='json:', content_type='application/json')
- def patch_one(self, tenant_id):
+ def patch_one(self, project_id):
"""Modify a Quota"""
request = pecan.request
context = request.environ['context']
@@ -60,7 +60,7 @@ class QuotasController(rest.RestController):
# this will raise only if KeystoneV3 endpoint is not found at all,
# or the creds are passing but the project is not found
if cfg.CONF['service:api'].quotas_verify_project_id:
- keystone.verify_project_id(context, tenant_id)
+ keystone.verify_project_id(context, project_id)
quotas = DesignateAdapter.parse('API_v2', body, QuotaList())
@@ -74,23 +74,23 @@ class QuotasController(rest.RestController):
"scoped tokens.")
for quota in quotas:
- self.central_api.set_quota(context, tenant_id, quota.resource,
+ self.central_api.set_quota(context, project_id, quota.resource,
quota.hard_limit)
- quotas = self.central_api.get_quotas(context, tenant_id)
+ quotas = self.central_api.get_quotas(context, project_id)
quotas = QuotaList.from_dict(quotas)
return DesignateAdapter.render('API_v2', quotas)
@pecan.expose(template=None, content_type='application/json')
- def delete_one(self, tenant_id):
+ def delete_one(self, project_id):
"""Reset to the Default Quotas"""
request = pecan.request
response = pecan.response
context = request.environ['context']
- self.central_api.reset_quotas(context, tenant_id)
+ self.central_api.reset_quotas(context, project_id)
response.status_int = 204
diff --git a/designate/tests/test_api/test_v2/test_import_export.py b/designate/tests/test_api/test_v2/test_import_export.py
index c8477f0f..a8af5f05 100644
--- a/designate/tests/test_api/test_v2/test_import_export.py
+++ b/designate/tests/test_api/test_v2/test_import_export.py
@@ -110,8 +110,8 @@ class APIV2ZoneImportExportTest(ApiV2TestCase):
self.policy({'zone_export': '@'})
get_response = self.adminclient.get('/zones/export/%s' %
- response.json['zone_id'],
- headers={'Accept': 'text/dns'})
+ response.json['zone_id'],
+ headers={'Accept': 'text/dns'})
exported_zonefile = get_response.body.decode('utf-8')
imported = dnszone.from_text(self.get_zonefile_fixture())
diff --git a/designate/tests/test_api/test_v2/test_quotas.py b/designate/tests/test_api/test_v2/test_quotas.py
new file mode 100644
index 00000000..be79981e
--- /dev/null
+++ b/designate/tests/test_api/test_v2/test_quotas.py
@@ -0,0 +1,159 @@
+# 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 oslo_log import log as logging
+
+from designate.tests.test_api.test_v2 import ApiV2TestCase
+
+LOG = logging.getLogger(__name__)
+
+
+class ApiV2QuotasTest(ApiV2TestCase):
+ def setUp(self):
+ super(ApiV2QuotasTest, self).setUp()
+
+ def test_get_quotas(self):
+ self.config(quota_api_export_size=1)
+
+ context = self.get_context(project_id='a')
+
+ result = self.client.get(
+ '/quotas/%s' % context.project_id, status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+ self.assertEqual(
+ {
+ 'zones': 10,
+ 'zone_recordsets': 500,
+ 'zone_records': 500,
+ 'recordset_records': 20,
+ 'api_export_size': 1
+ },
+ result.json
+ )
+
+ def test_get_all_quotas(self):
+ self.config(quota_zone_recordsets=1)
+
+ result = self.client.get(
+ '/quotas', status=200,
+ )
+
+ self.assertEqual(
+ {
+ 'api_export_size': 1000,
+ 'recordset_records': 20,
+ 'zone_records': 500,
+ 'zone_recordsets': 1,
+ 'zones': 10
+ },
+ result.json
+ )
+
+ def test_set_quotas(self):
+ self.policy({'set_quota': '@'})
+
+ context = self.get_context(project_id='a')
+ self.client.patch_json(
+ '/quotas/%s' % context.project_id, {'zones': 123}, status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+
+ result = self.client.get(
+ '/quotas/%s' % context.project_id, status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+ self.assertEqual(
+ {
+ 'zones': 123,
+ 'zone_recordsets': 500,
+ 'zone_records': 500,
+ 'recordset_records': 20,
+ 'api_export_size': 1000
+ },
+ result.json
+ )
+
+ def test_set_quotas_with_verify_project_id(self):
+ self.config(
+ quotas_verify_project_id=True,
+ group='service:api'
+ )
+
+ self.policy({'set_quota': '@'})
+
+ context = self.get_context(project_id='a')
+ self.client.patch_json(
+ '/quotas/%s' % context.project_id, {'zones': 123}, status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+
+ result = self.client.get(
+ '/quotas/%s' % context.project_id, status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+ self.assertEqual(
+ {
+ 'zones': 123,
+ 'zone_recordsets': 500,
+ 'zone_records': 500,
+ 'recordset_records': 20,
+ 'api_export_size': 1000
+ },
+ result.json
+ )
+
+ def test_delete_quotas(self):
+ self.config(quota_zone_records=1)
+
+ self.policy({'set_quota': '@'})
+
+ context = self.get_context(project_id='a')
+
+ # Update recordset_records quota.
+ result = self.client.patch_json(
+ '/quotas/%s' % context.project_id, {'recordset_records': 123},
+ status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+ self.assertEqual(
+ {
+ 'zones': 10,
+ 'zone_recordsets': 500,
+ 'zone_records': 1,
+ 'recordset_records': 123,
+ 'api_export_size': 1000
+ },
+ result.json
+ )
+
+ # Delete quota.
+ self.client.delete(
+ '/quotas/%s' % context.project_id, status=204,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+
+ # Make sure we are back to the default quotas.
+ result = self.client.get(
+ '/quotas/%s' % context.project_id, status=200,
+ headers={'X-Test-Tenant-Id': context.project_id}
+ )
+ self.assertEqual(
+ {
+ 'zones': 10,
+ 'zone_recordsets': 500,
+ 'zone_records': 1,
+ 'recordset_records': 20,
+ 'api_export_size': 1000
+ },
+ result.json
+ )
diff --git a/designate/tests/test_api/test_v2/test_zone_transfers.py b/designate/tests/test_api/test_v2/test_zone_transfers.py
index 343a0a37..ae4e7ed6 100644
--- a/designate/tests/test_api/test_v2/test_zone_transfers.py
+++ b/designate/tests/test_api/test_v2/test_zone_transfers.py
@@ -28,7 +28,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_create_zone_transfer_request(self):
response = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
# Check the headers are what we expect
@@ -53,7 +53,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_create_zone_transfer_request_scoped(self):
response = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{'target_project_id': str(self.tenant_1_context.project_id)})
# Check the headers are what we expect
@@ -79,7 +79,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_create_zone_transfer_request_empty_body(self):
# Send an empty ("None") body
response = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
None)
# Check the headers are what we expect
@@ -88,7 +88,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_get_zone_transfer_request(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
response = self.client.get(
@@ -129,7 +129,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
self.assertEqual(0, len(response.json['transfer_requests']))
self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
data = self.client.get(
@@ -139,7 +139,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_update_zone_transfer_request(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
response = self.client.patch_json(
@@ -168,7 +168,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_delete_zone_transfer_request(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
response = self.client.delete(
@@ -180,7 +180,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_create_zone_transfer_accept(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
response = self.client.post_json(
@@ -216,7 +216,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_get_zone_transfer_accept(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
transfer_accept = self.client.post_json(
@@ -272,7 +272,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
self.assertEqual(0, len(response.json['transfer_accepts']))
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
self.client.post_json(
@@ -288,14 +288,14 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
self.assertEqual(1, len(data.json['transfer_accepts']))
def test_create_zone_transfer_request_deleting_zone(self):
- url = '/zones/%s/tasks/transfer_requests' % (self.zone.id)
+ url = '/zones/%s/tasks/transfer_requests' % self.zone.id
body = {}
self.client.delete('/zones/%s' % self.zone['id'], status=202)
self._assert_exception('bad_request', 400, self.client.post_json, url,
body)
def test_create_zone_transfer_accept_deleting_zone(self):
- url = '/zones/%s/tasks/transfer_requests' % (self.zone.id)
+ url = '/zones/%s/tasks/transfer_requests' % self.zone.id
body = {}
self.client.delete('/zones/%s' % self.zone['id'], status=202)
self._assert_exception('bad_request', 400, self.client.post_json, url,
@@ -304,7 +304,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
# Metadata tests
def test_metadata_exists_zone_transfer_accepts(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
self.client.post_json(
@@ -324,7 +324,7 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
def test_total_count_zone_transfer_accepts(self):
initial = self.client.post_json(
- '/zones/%s/tasks/transfer_requests' % (self.zone.id),
+ '/zones/%s/tasks/transfer_requests' % self.zone.id,
{})
self.client.post_json(