From a1d679678daa560c86bb84303aee6163296ec653 Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Tue, 26 May 2015 13:14:11 +0000 Subject: [PATCH] Force order of dhcp.needs_resync_reasons dictionary elements This fixes the test_periodoc_resync_helper unit test that breaks with a randomized PYTHONHASHSEED (see the bug report). The test assumed that the dhcp.needs_resync_reasons dictionary from neutron.agent.dhcp.agent had elements in a particular order. Found with PYTHONHASHSEED=2. The fix refactors the test case to force a sorted dhcp.needs_resync_reasons dictionary. 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. Change-Id: Ia7fc2c3e605d92d8497d44e28054bdda613cebf2 --- neutron/tests/unit/agent/dhcp/test_agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py index afc7cf7d2..ebbcca297 100644 --- a/neutron/tests/unit/agent/dhcp/test_agent.py +++ b/neutron/tests/unit/agent/dhcp/test_agent.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import collections import copy import sys import uuid @@ -404,7 +405,8 @@ class TestDhcpAgent(base.BaseTestCase): def test_periodoc_resync_helper(self): with mock.patch.object(dhcp_agent.eventlet, 'sleep') as sleep: dhcp = dhcp_agent.DhcpAgent(HOSTNAME) - dhcp.needs_resync_reasons = {'a': 'reason1', 'b': 'reason2'} + dhcp.needs_resync_reasons = collections.OrderedDict( + (('a', 'reason1'), ('b', 'reason2'))) with mock.patch.object(dhcp, 'sync_state') as sync_state: sync_state.side_effect = RuntimeError with testtools.ExpectedException(RuntimeError): -- 2.45.2