]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Correct metadata ordering issue in tests
authorJuan Manuel Olle <juan.m.olle@intel.com>
Fri, 21 Mar 2014 19:46:03 +0000 (16:46 -0300)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 14:08:51 +0000 (22:08 +0800)
Some test including test_volume_get_all_filters
fails randomly because metadata is in a dict and
the items order is undefined.
The test comparison was changed to avoid unexpected
test results.

Change-Id: Ibb24d21cd05aa1eefb45b61c63de067b34fb1013
Closes-Bug: #1293792
(cherry picked from commit 4cc2366623743393f89a198581fcb69dc04d31cd)

cinder/tests/test_db_api.py

index 0e9d49cb5607c42336294c5bc3f205d0147856dc..e1a2077b3ca5b18ee58646c1fd3a93ecbd22337c 100644 (file)
@@ -481,17 +481,16 @@ class DBAPIVolumeTestCase(BaseTest):
             result = db.volume_get_all(self.ctxt, None, limit, sort_key,
                                        sort_dir, filters=filters)
         self.assertEqual(len(correct_order), len(result))
-        self.assertEqual(len(result), len(correct_order))
         for vol1, vol2 in zip(result, correct_order):
             for key in match_keys:
                 val1 = vol1.get(key)
                 val2 = vol2.get(key)
-                # metadata is a list, compare the 'key' and 'value' of each
+                # metadata is a dict, compare the 'key' and 'value' of each
                 if key == 'volume_metadata':
                     self.assertEqual(len(val1), len(val2))
-                    for m1, m2 in zip(val1, val2):
-                        self.assertEqual(m1.get('key'), m2.get('key'))
-                        self.assertEqual(m1.get('value'), m2.get('value'))
+                    val1_dict = dict((x.key, x.value) for x in val1)
+                    val2_dict = dict((x.key, x.value) for x in val2)
+                    self.assertDictMatch(val1_dict, val2_dict)
                 else:
                     self.assertEqual(val1, val2)