Update zone status when recordsets are changed

When recordsets/records are created/updated/deleted,
update the zone's status/action to 'pending/update'.

Change-Id: I6f3035c215ee1180696b3bae4bdb6e03dc8f2849
Closes-Bug: 1420399
This commit is contained in:
Vinod Mangalpally 2015-02-12 14:42:38 -06:00
parent 86dddab7e3
commit 2d9d559295
2 changed files with 71 additions and 8 deletions

View File

@ -898,9 +898,10 @@ class Service(service.RPCService):
domain.status = 'PENDING'
if increment_serial:
# _increment_domain_serial increments and updates the domain
domain = self._increment_domain_serial(context, domain)
domain = self.storage.update_domain(context, domain)
else:
domain = self.storage.update_domain(context, domain)
return domain
@ -1048,7 +1049,9 @@ class Service(service.RPCService):
if recordset.records and len(recordset.records) > 0:
if increment_serial:
domain = self._increment_domain_serial(context, domain)
# update the zone's status and increment the serial
domain = self._update_domain_in_storage(
context, domain, increment_serial)
for record in recordset.records:
record.action = 'CREATE'
@ -1155,7 +1158,9 @@ class Service(service.RPCService):
self._is_valid_ttl(context, ttl)
if increment_serial:
domain = self._increment_domain_serial(context, domain)
# update the zone's status and increment the serial
domain = self._update_domain_in_storage(
context, domain, increment_serial)
if recordset.records:
for record in recordset.records:
@ -1201,7 +1206,9 @@ class Service(service.RPCService):
increment_serial=True):
if increment_serial:
domain = self._increment_domain_serial(context, domain)
# update the zone's status and increment the serial
domain = self._update_domain_in_storage(
context, domain, increment_serial)
if recordset.records:
for record in recordset.records:
@ -1259,7 +1266,9 @@ class Service(service.RPCService):
self._enforce_record_quota(context, domain, recordset)
if increment_serial:
domain = self._increment_domain_serial(context, domain)
# update the zone's status and increment the serial
domain = self._update_domain_in_storage(
context, domain, increment_serial)
record.action = 'CREATE'
record.status = 'PENDING'
@ -1357,7 +1366,9 @@ class Service(service.RPCService):
increment_serial=True):
if increment_serial:
domain = self._increment_domain_serial(context, domain)
# update the zone's status and increment the serial
domain = self._update_domain_in_storage(
context, domain, increment_serial)
record.action = 'UPDATE'
record.status = 'PENDING'
@ -1407,7 +1418,9 @@ class Service(service.RPCService):
increment_serial=True):
if increment_serial:
domain = self._increment_domain_serial(context, domain)
# update the zone's status and increment the serial
domain = self._update_domain_in_storage(
context, domain, increment_serial)
record.action = 'DELETE'
record.status = 'PENDING'

View File

@ -80,6 +80,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self.assertEqual('CREATE', response.json['recordset']['action'])
self.assertEqual('PENDING', response.json['recordset']['status'])
# Check the zone's status is as expected
response = self.client.get('/zones/%s' % self.domain['id'],
headers=[('Accept', 'application/json')])
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('zone', response.json)
self.assertEqual('UPDATE', response.json['zone']['action'])
self.assertEqual('PENDING', response.json['zone']['status'])
def test_create_recordset_invalid_id(self):
self._assert_invalid_uuid(self.client.post, '/zones/%s/recordsets')
@ -339,6 +349,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self.assertEqual('NONE', response.json['recordset']['action'])
self.assertEqual('ACTIVE', response.json['recordset']['status'])
# Check the zone's status is as expected
response = self.client.get('/zones/%s' % recordset['domain_id'],
headers=[('Accept', 'application/json')])
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('zone', response.json)
self.assertEqual('UPDATE', response.json['zone']['action'])
self.assertEqual('PENDING', response.json['zone']['status'])
def test_update_recordset_with_record_create(self):
# Create a recordset
recordset = self.create_recordset(self.domain, 'A')
@ -370,6 +390,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self.assertEqual('UPDATE', response.json['recordset']['action'])
self.assertEqual('PENDING', response.json['recordset']['status'])
# Check the zone's status is as expected
response = self.client.get('/zones/%s' % recordset['domain_id'],
headers=[('Accept', 'application/json')])
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('zone', response.json)
self.assertEqual('UPDATE', response.json['zone']['action'])
self.assertEqual('PENDING', response.json['zone']['status'])
def test_update_recordset_with_record_replace(self):
# Create a recordset with one record
recordset = self.create_recordset(self.domain, 'A')
@ -396,6 +426,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self.assertEqual(set(['192.0.2.201', '192.0.2.202']),
set(response.json['recordset']['records']))
# Check the zone's status is as expected
response = self.client.get('/zones/%s' % recordset['domain_id'],
headers=[('Accept', 'application/json')])
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('zone', response.json)
self.assertEqual('UPDATE', response.json['zone']['action'])
self.assertEqual('PENDING', response.json['zone']['status'])
def test_update_recordset_with_record_clear(self):
# Create a recordset with one record
recordset = self.create_recordset(self.domain, 'A')
@ -419,6 +459,16 @@ class ApiV2RecordSetsTest(ApiV2TestCase):
self.assertIn('records', response.json['recordset'])
self.assertEqual(0, len(response.json['recordset']['records']))
# Check the zone's status is as expected
response = self.client.get('/zones/%s' % recordset['domain_id'],
headers=[('Accept', 'application/json')])
# Check the headers are what we expect
self.assertEqual(200, response.status_int)
self.assertEqual('application/json', response.content_type)
self.assertIn('zone', response.json)
self.assertEqual('UPDATE', response.json['zone']['action'])
self.assertEqual('PENDING', response.json['zone']['status'])
def test_update_recordset_invalid_id(self):
self._assert_invalid_uuid(
self.client.put_json, '/zones/%s/recordsets/%s')