From 789709f1db081222c2e4d21d287781e437b76a95 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Mon, 13 Jul 2015 10:53:04 +0100 Subject: [PATCH] Ensure RecordSet quotas are enforced Implement RecordSet's per domain, and Records per RecordSet quota enforcement. Change-Id: If7afc70cd1ebe2e18864859de51c6ccd15c6a43c Partial-Bug: 1471161 --- designate/central/service.py | 19 +++++++++---- designate/tests/test_central/test_service.py | 28 +++++++++++++++----- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/designate/central/service.py b/designate/central/service.py index 59c56d177..546b8e627 100644 --- a/designate/central/service.py +++ b/designate/central/service.py @@ -595,18 +595,27 @@ class Service(service.RPCService, service.Service): self.quota.limit_check(context, tenant_id, domains=count) def _enforce_recordset_quota(self, context, domain): - # TODO(kiall): Enforce RRSet Quotas - pass + # Ensure the recordsets per domain quota is OK + criterion = {'domain_id': domain.id} + count = self.storage.count_recordsets(context, criterion) + + self.quota.limit_check( + context, domain.tenant_id, domain_recordsets=count) def _enforce_record_quota(self, context, domain, recordset): # Ensure the records per domain quota is OK - criterion = {'domain_id': domain['id']} + criterion = {'domain_id': domain.id} count = self.storage.count_records(context, criterion) - self.quota.limit_check(context, domain['tenant_id'], + self.quota.limit_check(context, domain.tenant_id, domain_records=count) - # TODO(kiall): Enforce Records per RRSet Quotas + # Ensure the records per recordset quota is OK + criterion = {'recordset_id': recordset.id} + count = self.storage.count_records(context, criterion) + + self.quota.limit_check(context, domain.tenant_id, + recordset_records=count) # Misc Methods def get_absolute_limits(self, context): diff --git a/designate/tests/test_central/test_service.py b/designate/tests/test_central/test_service.py index eab3a5ac6..584c2de67 100644 --- a/designate/tests/test_central/test_service.py +++ b/designate/tests/test_central/test_service.py @@ -1063,15 +1063,16 @@ class CentralServiceTest(CentralTestCase): self.assertIsNotNone(recordset.records[1].id) self.assertThat(new_serial, GreaterThan(original_serial)) - # def test_create_recordset_over_quota(self): - # self.config(quota_domain_recordsets=1) + def test_create_recordset_over_quota(self): + # SOA, NS recordsets exist by default. + self.config(quota_domain_recordsets=3) - # domain = self.create_domain() + domain = self.create_domain() - # self.create_recordset(domain) + self.create_recordset(domain) - # with testtools.ExpectedException(exceptions.OverQuota): - # self.create_recordset(domain) + with testtools.ExpectedException(exceptions.OverQuota): + self.create_recordset(domain) def test_create_invalid_recordset_location_cname_at_apex(self): domain = self.create_domain() @@ -1595,7 +1596,8 @@ class CentralServiceTest(CentralTestCase): self.assertEqual(record['data'], values['data']) self.assertIn('status', record) - def test_create_record_over_quota(self): + def test_create_record_over_domain_quota(self): + # SOA and NS Records exist self.config(quota_domain_records=3) # Creating the domain automatically creates SOA & NS records @@ -1607,6 +1609,18 @@ class CentralServiceTest(CentralTestCase): with testtools.ExpectedException(exceptions.OverQuota): self.create_record(domain, recordset) + def test_create_record_over_recordset_quota(self): + self.config(quota_recordset_records=1) + + # Creating the domain automatically creates SOA & NS records + domain = self.create_domain() + recordset = self.create_recordset(domain) + + self.create_record(domain, recordset) + + with testtools.ExpectedException(exceptions.OverQuota): + self.create_record(domain, recordset) + def test_create_record_without_incrementing_serial(self): domain = self.create_domain() recordset = self.create_recordset(domain, type='A')