Check prop_diff contents after modifying it

It is not possible to add a DNS record alone to the Rackspace Cloud DNS
resource because the domain.update() method will be called with no
arguments.  Re-check the contents of prop_diff after modifying it to see
if calling domain.update() is necessary.

Change-Id: I04e313eab7f2d8971e9f12bfb402259b48757919
Closes-Bug: #1386886
This commit is contained in:
Jason Dunsmore 2014-10-28 16:06:26 -05:00
parent 0adaf22ab3
commit b1a697e74f
2 changed files with 44 additions and 0 deletions

View File

@ -177,6 +177,7 @@ class CloudDns(resource.Resource):
# handle records separately
records = prop_diff.pop(self.RECORDS, {})
if prop_diff:
# Handle top level domain properties
dom.update(**prop_diff)

View File

@ -277,3 +277,46 @@ class RackspaceDnsTest(common.HeatTestCase):
'data': '192.0.2.8',
'ttl': 3600}]
self.test_update(updateRecords=a_record)
def test_update_record_only(self):
"""Helper function for testing domain updates."""
fake_dns_instance = FakeDnsInstance()
t = template_format.parse(domain_only_template)
instance = self._setup_test_cloud_dns_instance('dnsinstance_update', t)
instance.resource_id = 4
update_records = [{'type': 'A',
'name': 'ftp.example.com',
'data': '192.0.2.8',
'ttl': 3600}]
mock_client = self.m.CreateMockAnything()
self.m.StubOutWithMock(instance, 'cloud_dns')
instance.cloud_dns().AndReturn(mock_client)
self.m.StubOutWithMock(mock_client, "get")
mock_domain = self.m.CreateMockAnything()
mock_client.get(fake_dns_instance.resource_id).AndReturn(mock_domain)
# mock_domain.update shouldn't be called in this scenario, so
# stub it out but don't record a call to it
self.m.StubOutWithMock(mock_domain, "update")
fake_records = list()
mock_domain.list_records().AndReturn(fake_records)
mock_domain.add_records([{
'comment': None,
'priority': None,
'type': 'A',
'name': 'ftp.example.com',
'data': '192.0.2.8',
'ttl': 3600}])
self.m.ReplayAll()
uprops = dict(instance.properties)
uprops['records'] = update_records
ut = rsrc_defn.ResourceDefinition(instance.name,
instance.type(),
uprops)
scheduler.TaskRunner(instance.update, ut)()
self.assertEqual((instance.UPDATE, instance.COMPLETE), instance.state)
self.m.VerifyAll()