Guard against deletion of a parent domain
Change-Id: I72f5529af37941daa2f86c5f0d50373e5947727f
This commit is contained in:
@@ -534,7 +534,12 @@ class Service(rpc_service.Service):
|
||||
|
||||
policy.check('delete_domain', context, target)
|
||||
|
||||
# Do we have any child domains?
|
||||
# Prevent deletion of a zone which has child zones
|
||||
criterion = {'parent_domain_id': domain_id}
|
||||
|
||||
if self.storage.count_domains(context, criterion) > 0:
|
||||
raise exceptions.DomainHasSubdomain('Please delete any subdomains'
|
||||
' before deleting this domain')
|
||||
|
||||
try:
|
||||
self.backend.delete_domain(context, domain)
|
||||
|
||||
@@ -80,8 +80,13 @@ class InvalidRecordLocation(Base):
|
||||
error_type = 'invalid_record_location'
|
||||
|
||||
|
||||
class DomainHasSubdomain(Base):
|
||||
error_code = 400
|
||||
error_type = 'domain_has_subdomain'
|
||||
|
||||
|
||||
class Forbidden(Base):
|
||||
error_code = 401
|
||||
error_code = 403
|
||||
error_type = 'forbidden'
|
||||
|
||||
|
||||
|
||||
@@ -660,6 +660,23 @@ class CentralServiceTest(CentralTestCase):
|
||||
self.assertEqual(payload['name'], domain['name'])
|
||||
self.assertEqual(payload['tenant_id'], domain['tenant_id'])
|
||||
|
||||
def test_delete_parentdomain(self):
|
||||
context = self.get_admin_context()
|
||||
|
||||
# Create the Parent Domain using fixture 0
|
||||
parent_domain = self.create_domain(fixture=0)
|
||||
|
||||
# Prepare values for the subdomain using fixture 1 as a base
|
||||
values = self.get_domain_fixture(1)
|
||||
values['name'] = 'www.%s' % parent_domain['name']
|
||||
|
||||
# Create the subdomain
|
||||
sub_domain = self.central_service.create_domain(context, values=values)
|
||||
|
||||
# Attempt to delete the parent domain
|
||||
with self.assertRaises(exceptions.DomainHasSubdomain):
|
||||
self.central_service.delete_domain(context, parent_domain['id'])
|
||||
|
||||
def test_count_domains(self):
|
||||
# in the beginning, there should be nothing
|
||||
domains = self.central_service.count_domains(self.admin_context)
|
||||
|
||||
Reference in New Issue
Block a user