From dc911b8026a5cf949ca5a697bb802c495dc9ada2 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Thu, 29 Dec 2016 12:17:10 -0500 Subject: [PATCH] Fix assertion in test_instance_fault_get_by_instance The instance_fault_get_by_instance_uuids DB API method returns results sorted by created_at in descending order, so the newest fault should be at the front of the list for a given instance uuid in the resulting dict. However, the way the test for this was written the 'expected' list actually had the faults in order from oldest to newest. The reason this didn't fail the test was because it was using _assertEqualListsOfObjects to compare the results, which sorts the lists before comparing them, which is exactly NOT what we want when we care about the sort order of the results. The test is fixed by using _assertEqualOrderedListOfObjects which leaves the original sort order of the lists to compare and fixes the 'expected' list by inserting the newest faults at the front of the list. Change-Id: I58990194016447b05b42df76141a193595cdcb9c Related-Bug: #1632247 --- nova/tests/unit/db/test_db_api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 2cd240c95a..6c3303b3ae 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -4214,13 +4214,16 @@ class InstanceFaultTestCase(test.TestCase, ModelsObjectComparatorMixin): for code in fault_codes: fault_values = self._create_fault_values(uuid, code) fault = db.instance_fault_create(self.ctxt, fault_values) - expected[uuid].append(fault) + # We expect the faults to be returned ordered by created_at in + # descending order, so insert the newly created fault at the + # front of our list. + expected[uuid].insert(0, fault) # Ensure faults are saved faults = db.instance_fault_get_by_instance_uuids(self.ctxt, uuids) self.assertEqual(len(expected), len(faults)) for uuid in uuids: - self._assertEqualListsOfObjects(expected[uuid], faults[uuid]) + self._assertEqualOrderedListOfObjects(expected[uuid], faults[uuid]) def test_instance_faults_get_by_instance_uuids_no_faults(self): uuid = uuidsentinel.uuid1