]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not assume order of get_sync_data_metering response elements
authorCedric Brandily <zzelle@gmail.com>
Tue, 26 May 2015 22:23:09 +0000 (00:23 +0200)
committerCedric Brandily <zzelle@gmail.com>
Wed, 27 May 2015 06:37:20 +0000 (08:37 +0200)
This fixes the test_add_metering_label_rpc_call[1] unit tests that breaks
with a randomized PYTHONHASHSEED (see the bug report).

The test assumed that the get_sync_data_metering[2] had response
elements in a particular order. Found with PYTHONHASHSEED=1.

The fix refactors the test_add_metering_label_rpc_call test case to handle
an unsorted get_sync_data_metering response. The fix defines the class
UnorderedList[3] which is equal to any permutation of itself.

Partial-bug: #1348818

Note: There are several other unrelated unit tests that also break with
a randomized PYTHONHASHSEED, but they are not addressed here. They will
be addressed in separate patches.

[1] neutron.tests.unit.services.metering.test_metering_plugin:
 TestMeteringPluginL3AgentScheduler
 TestMeteringPluginL3AgentSchedulerServicePlugin
[2] neutron.services.metering.metering_plugin.MeteringPlugin
[3] neutron.tests.tools

Change-Id: I5d42b827bc72dcacd38eaa2377ce16c47a9e7dbb

neutron/tests/tools.py
neutron/tests/unit/services/metering/test_metering_plugin.py

index 449dd574ae5870a3204b24df2de14ac554bbb2f7..c9b80b70ee9003021e0b763a3f19a4823a2b8244 100644 (file)
@@ -89,3 +89,15 @@ def fail(msg=None):
     testcase instance (usefully for reducing coupling).
     """
     raise unittest.TestCase.failureException(msg)
+
+
+class UnorderedList(list):
+    """A list that is equals to any permutation of itself."""
+
+    def __eq__(self, other):
+        if not isinstance(other, list):
+            return False
+        return sorted(self) == sorted(other)
+
+    def __neq__(self, other):
+        return not self == other
index 408ea1921b50fa9d17b1f9d1c8fc6f53dd721795..87de80297686fb6fb0e7b2d2bbe996d5cd2c5bf9 100644 (file)
@@ -25,6 +25,7 @@ from neutron import manager
 from neutron.openstack.common import uuidutils
 from neutron.plugins.common import constants
 from neutron.tests.common import helpers
+from neutron.tests import tools
 from neutron.tests.unit.db.metering import test_metering_db
 from neutron.tests.unit.db import test_db_base_plugin_v2
 from neutron.tests.unit.extensions import test_l3
@@ -371,7 +372,8 @@ class TestMeteringPluginL3AgentScheduler(
                              set_context=True):
                 with self.metering_label(tenant_id=self.tenant_id,
                                          set_context=True):
-                    self.mock_add.assert_called_with(self.ctx, expected)
+                    self.mock_add.assert_called_with(
+                        self.ctx, tools.UnorderedList(expected))
 
 
 class TestMeteringPluginL3AgentSchedulerServicePlugin(