From: Cedric Brandily Date: Tue, 26 May 2015 22:23:09 +0000 (+0200) Subject: Do not assume order of get_sync_data_metering response elements X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=539738a8eeebcc9f22987fcb0a241c6b8c3d561a;p=openstack-build%2Fneutron-build.git Do not assume order of get_sync_data_metering response elements 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 --- diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index 449dd574a..c9b80b70e 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -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 diff --git a/neutron/tests/unit/services/metering/test_metering_plugin.py b/neutron/tests/unit/services/metering/test_metering_plugin.py index 408ea1921..87de80297 100644 --- a/neutron/tests/unit/services/metering/test_metering_plugin.py +++ b/neutron/tests/unit/services/metering/test_metering_plugin.py @@ -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(