]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not assume order of iptables_firewall method responses
authorCedric Brandily <zzelle@gmail.com>
Tue, 26 May 2015 17:54:22 +0000 (19:54 +0200)
committerCedric Brandily <zzelle@gmail.com>
Wed, 27 May 2015 09:42:13 +0000 (11:42 +0200)
This fixes the iptables_firewall group unit tests[1] that breaks with
a randomized PYTHONHASHSEED (see the bug report).

The test assumed that the _get_remote_sg_ids and
_determine_remote_sgs_to_remove methods from
neutron.agent.linux.iptables_firewall returned elements in a particular
order. Found with PYTHONHASHSEED=1.

The fix refactors the test case to handle unsorted responses from
_get_remote_sg_ids and _determine_remote_sgs_to_remove.

[1] neutron.tests.unit.agent.linux.test_iptables_firewall:
 test_prepare_port_filter_with_new_members
 test_prepare_port_filter_with_sg_no_member
 test_remove_port_filter_with_destroy_ipset_chain

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

neutron/tests/unit/agent/linux/test_iptables_firewall.py

index 77d98e8b185fd7ead5b1af2111d2fda879031933..077cc5092d8f30d0977d268f591640c2bca6f0c5 100644 (file)
@@ -1465,7 +1465,7 @@ class IptablesFirewallEnhancedIpsetTestCase(BaseIptablesFirewallTestCase):
             mock.call.set_members('fake_sgid', 'IPv6',
                                   ['fe80::1'])
         ]
-        self.firewall.ipset.assert_has_calls(calls)
+        self.firewall.ipset.assert_has_calls(calls, any_order=True)
 
     def _setup_fake_firewall_members_and_rules(self, firewall):
         firewall.sg_rules = self._fake_sg_rules()
@@ -1615,7 +1615,7 @@ class IptablesFirewallEnhancedIpsetTestCase(BaseIptablesFirewallTestCase):
             mock.call.destroy('fake_sgid', 'IPv4'),
             mock.call.destroy('fake_sgid', 'IPv6')]
 
-        self.firewall.ipset.assert_has_calls(calls)
+        self.firewall.ipset.assert_has_calls(calls, any_order=True)
 
     def test_prepare_port_filter_with_sg_no_member(self):
         self.firewall.sg_rules = self._fake_sg_rules()
@@ -1633,7 +1633,7 @@ class IptablesFirewallEnhancedIpsetTestCase(BaseIptablesFirewallTestCase):
                                        ['10.0.0.1', '10.0.0.2']),
                  mock.call.set_members('fake_sgid', 'IPv6', ['fe80::1'])]
 
-        self.firewall.ipset.assert_has_calls(calls)
+        self.firewall.ipset.assert_has_calls(calls, any_order=True)
 
     def test_filter_defer_apply_off_with_sg_only_ipv6_rule(self):
         self.firewall.sg_rules = self._fake_sg_rules()