Merge "Fix bug in update_zone with recordsets"

This commit is contained in:
Zuul 2023-05-31 00:28:38 +00:00 committed by Gerrit Code Review
commit d8b019942f
2 changed files with 34 additions and 13 deletions

View File

@ -574,28 +574,26 @@ class SQLAlchemyStorage(base.SQLAlchemy):
self.create_zone_master(context, zone.id, attr)
if zone.obj_attr_is_set('recordsets'):
existing = self.find_recordsets(context, {'zone_id': zone.id})
data = {}
for rrset in existing:
data[rrset.name, rrset.type] = rrset
existing = {}
for rrset in self.find_recordsets(context, {'zone_id': zone.id}):
existing[rrset.name, rrset.type] = rrset
keep = set()
for rrset in zone.recordsets:
current = data.get((rrset.name, rrset.type))
if current:
current.update(rrset)
current.records = rrset.records
self.update_recordset(context, current)
keep.add(current.id)
existing_recordset = existing.get((rrset.name, rrset.type))
if existing_recordset:
existing_recordset.update(rrset)
existing_recordset.records = rrset.records
existing_recordset.obj_reset_changes(['zone_name'])
self.update_recordset(context, existing_recordset)
keep.add(existing_recordset.id)
else:
self.create_recordset(context, zone.id, rrset)
keep.add(rrset.id)
if zone.type == 'SECONDARY':
# Purge anything that shouldn't be there :P
for i in set([i.id for i in data.values()]) - keep:
for i in set([i.id for i in existing.values()]) - keep:
self.delete_recordset(context, i)
if tenant_id_changed:

View File

@ -917,6 +917,29 @@ class SqlalchemyStorageTest(TestCase):
# Ensure the version column was incremented
self.assertEqual(2, zone.version)
def test_update_zone_new_recordset_with_existing(self):
zone = self.create_zone(name='example.org.')
recordset1 = self.create_recordset(zone)
recordset2 = objects.RecordSet(
name='www.example.org.', type='A',
records=objects.RecordList(objects=[
objects.Record(data='192.0.2.1'),
])
)
zone.name = 'example.net.'
zone.recordsets = objects.RecordSetList(
objects=[recordset1, recordset2]
)
# Perform the update
self.storage.update_zone(self.admin_context, zone)
recordsets = self.storage.find_recordsets(
self.admin_context, {'zone_id': zone['id']}
)
self.assertEqual(4, len(recordsets))
def test_update_zone_new_recordset(self):
zone = self.create_zone(name='example.org.')