]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not assume order of lvm.tun_ofports set elements
authorBradley Jones <jones.bradley@me.com>
Tue, 5 Aug 2014 16:55:44 +0000 (17:55 +0100)
committerBradley Jones <jones.bradley@me.com>
Wed, 8 Oct 2014 13:59:26 +0000 (14:59 +0100)
This fixes the test_fdb_add_flows unit test that breaks with a randomized PYTHONHASHSEED
(see the bug report).

The test assumed that the lvm.tun_ofports set had
elements in a particular order. Found with PYTHONHASHSEED=2455351445 and
1595538922.

The fix sorts the actions output string so that it is always sorted when the
outputs are compared.

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: I86b453a93f3ba09212709caf462cf3bfc5b21ee9

neutron/tests/unit/openvswitch/test_ovs_neutron_agent.py

index 64ba72a9058e54160f91375db76279964584047d..73d62b3dff2657c18228ea0d068fb53bc322dd72 100644 (file)
@@ -1049,6 +1049,20 @@ class TestOvsNeutronAgent(base.BaseTestCase):
                       {'2.2.2.2':
                        [[FAKE_MAC, FAKE_IP1],
                         n_const.FLOODING_ENTRY]}}}
+
+        class ActionMatcher(object):
+            def __init__(self, action_str):
+                self.ordered = self.order_ports(action_str)
+
+            def order_ports(self, action_str):
+                halves = action_str.split('output:')
+                ports = sorted(halves.pop().split(','))
+                halves.append(','.join(ports))
+                return 'output:'.join(halves)
+
+            def __eq__(self, other):
+                return self.ordered == self.order_ports(other)
+
         with contextlib.nested(
             mock.patch.object(self.agent.tun_br, 'deferred'),
             mock.patch.object(self.agent.tun_br, 'do_action_flows'),
@@ -1076,8 +1090,8 @@ class TestOvsNeutronAgent(base.BaseTestCase):
                                        'set_tunnel:seg1,output:2')]),
                 mock.call('mod', [dict(table=constants.FLOOD_TO_TUN,
                                        dl_vlan='vlan1',
-                                       actions='strip_vlan,'
-                                       'set_tunnel:seg1,output:1,2')]),
+                                       actions=ActionMatcher('strip_vlan,'
+                                       'set_tunnel:seg1,output:1,2'))]),
             ]
             do_action_flows_fn.assert_has_calls(expected_calls)