Fix recordset changes so that they preserve object changes fields

Previous to this patch, the multiple actions on `recordset.records`
was causing the changes fields to lose changes.

Here's a log of the unit tests failing on master:
http://paste.openstack.org/show/543432/

Change-Id: I07832777595d45e6c941fcc9b80aa104ffab1645
This commit is contained in:
Tim Simmons 2016-07-25 16:05:05 +01:00
parent 24a66692df
commit 372057bddb
2 changed files with 71 additions and 3 deletions

View File

@ -105,13 +105,18 @@ class RecordSetAPIv2Adapter(base.APIv2Adapter):
del new_recordset['records'] del new_recordset['records']
# Remove deleted records if we have provided a records array # Remove deleted records if we have provided a records array
new_recordset_records = objects.RecordList()
if record_update: if record_update:
recordset.records[:] = [record for record in recordset.records for record in recordset.records:
if record.data not in records_to_rm] if record.data not in records_to_rm:
new_recordset_records.append(record)
# Add new records # Add new records
for record in records_to_add: for record in records_to_add:
recordset.records.append(objects.Record(data=record)) new_recordset_records.append(objects.Record(data=record))
# Do a single assignment, preserves the object change fields
recordset.records = new_recordset_records
return super(RecordSetAPIv2Adapter, cls)._parse_object( return super(RecordSetAPIv2Adapter, cls)._parse_object(
new_recordset, recordset, *args, **kwargs) new_recordset, recordset, *args, **kwargs)

View File

@ -23,6 +23,7 @@ import oslotest.base
import testtools import testtools
from designate import exceptions from designate import exceptions
from designate.objects.adapters import DesignateAdapter
from designate import objects from designate import objects
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -192,3 +193,65 @@ class RecordSetTest(oslotest.base.BaseTestCase):
with testtools.ExpectedException(exceptions.InvalidObject): with testtools.ExpectedException(exceptions.InvalidObject):
# TODO(Federico): check the attributes of the exception # TODO(Federico): check the attributes of the exception
rs.validate() rs.validate()
def test_parse_rrset_object_preserves_changes(self):
old_ip = '1.1.1.1'
new_ip = '8.8.8.8'
original_records = objects.RecordList(
objects=[
objects.Record(data=old_ip),
]
)
rs = objects.RecordSet(
name='www.example.org.', type='A',
records=original_records
)
body = {
'records': [
new_ip
]
}
rs = DesignateAdapter.parse('API_v2', body, rs)
self.assertIn('records', rs.obj_what_changed())
def get_data(record_list):
return set([r.data for r in record_list])
self.assertEqual(set([old_ip]),
get_data(rs.obj_get_original_value('records')))
self.assertEqual(set([new_ip]),
get_data(rs.obj_get_changes()['records']))
def test_parse_rrset_object_preserves_changes_multiple_rrs(self):
old_ips = ['1.1.1.1', '2.2.2.2']
new_ips = ['2.2.2.2', '8.8.8.8']
original_records = objects.RecordList(
objects=[
objects.Record(data=ip) for ip in old_ips
]
)
rs = objects.RecordSet(
name='www.example.org.', type='A',
records=original_records
)
body = {
'records': new_ips
}
rs = DesignateAdapter.parse('API_v2', body, rs)
self.assertIn('records', rs.obj_what_changed())
def get_data(record_list):
return set([r.data for r in record_list])
self.assertEqual(set(old_ips),
get_data(rs.obj_get_original_value('records')))
self.assertEqual(set(new_ips),
get_data(rs.obj_get_changes()['records']))