Merge "Removing duplicates from columns_to_join list"

This commit is contained in:
Jenkins 2016-10-03 15:24:56 +00:00 committed by Gerrit Code Review
commit 11fd1470d3
2 changed files with 19 additions and 1 deletions

View File

@ -88,7 +88,13 @@ def _expected_cols(expected_attrs):
if complex_cols:
simple_cols.append('extra')
simple_cols = [x for x in simple_cols if x not in _INSTANCE_EXTRA_FIELDS]
return simple_cols + complex_cols
expected_cols = simple_cols + complex_cols
# NOTE(pumaranikar): expected_cols list can contain duplicates since
# caller appends column attributes to expected_attr without checking if
# it is already present in the list or not. Hence, we remove duplicates
# here, if any. The resultant list is sorted based on list index to
# maintain the insertion order.
return sorted(list(set(expected_cols)), key=expected_cols.index)
_NO_DATA_SENTINEL = object()

View File

@ -1877,6 +1877,18 @@ class TestInstanceObjectMisc(test.TestCase):
instance._expected_cols(['metadata',
'numa_topology']))
def test_expected_cols_no_duplicates(self):
expected_attr = ['metadata', 'system_metadata', 'info_cache',
'security_groups', 'info_cache', 'metadata',
'pci_devices', 'tags', 'extra', 'flavor']
result_list = instance._expected_cols(expected_attr)
self.assertEqual(len(result_list), len(set(expected_attr)))
self.assertEqual(['metadata', 'system_metadata', 'info_cache',
'security_groups', 'pci_devices', 'tags', 'extra',
'extra.flavor'], result_list)
def test_migrate_instance_keypairs(self):
ctxt = context.RequestContext('foo', 'bar')
key = objects.KeyPair(context=ctxt,