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
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
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
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(