From 3043e7b8b9c2efa445e331a7b722f0a10305e45c Mon Sep 17 00:00:00 2001 From: Sam Betts Date: Mon, 20 Oct 2014 10:59:13 +0100 Subject: [PATCH] Ensure test_agent_manager handles random hashseeds Several tests in test_agent_manager.py fail when tox is run using the hashseed 2701526934, this is down to the nature of using dictionaries and sets in Python causing some function calls and function arguments to be out of order. This patch fixes this by either specifying that assert_has_calls does not need to assert the order, just that the calls were made, or by letting the unit test get affected in the same way as the code, e.g. add variables to a dict so they are ordered by the python hashing algorithms in the same way as they would be in the real code. Change-Id: If83d1f33c187eab45c2a65fd50fd70cce011c9e7 Partial-Bug: 1348818 --- .../loadbalancer/agent/test_agent_manager.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/neutron/tests/unit/services/loadbalancer/agent/test_agent_manager.py b/neutron/tests/unit/services/loadbalancer/agent/test_agent_manager.py index 4e28429026..8f63b62223 100644 --- a/neutron/tests/unit/services/loadbalancer/agent/test_agent_manager.py +++ b/neutron/tests/unit/services/loadbalancer/agent/test_agent_manager.py @@ -67,7 +67,7 @@ class TestManager(base.BaseTestCase): self.rpc_mock.update_pool_stats.assert_has_calls([ mock.call('1', mock.ANY), mock.call('2', mock.ANY) - ]) + ], any_order=True) def test_collect_stats_exception(self): self.driver_mock.get_stats.side_effect = Exception @@ -91,8 +91,10 @@ class TestManager(base.BaseTestCase): self.assertEqual(len(reloaded), len(reload.mock_calls)) self.assertEqual(len(destroyed), len(destroy.mock_calls)) - reload.assert_has_calls([mock.call(i) for i in reloaded]) - destroy.assert_has_calls([mock.call(i) for i in destroyed]) + reload.assert_has_calls([mock.call(i) for i in reloaded], + any_order=True) + destroy.assert_has_calls([mock.call(i) for i in destroyed], + any_order=True) self.assertFalse(self.mgr.needs_resync) def test_sync_state_all_known(self): @@ -187,7 +189,8 @@ class TestManager(base.BaseTestCase): def test_remove_orphans(self): self.mgr.remove_orphans() - self.driver_mock.remove_orphans.assert_called_once_with(['1', '2']) + orphans = {'1': "Fake", '2': "Fake"} + self.driver_mock.remove_orphans.assert_called_once_with(orphans.keys()) def test_create_vip(self): vip = {'id': 'id1', 'pool_id': '1'} @@ -364,4 +367,4 @@ class TestManager(base.BaseTestCase): payload = {'admin_state_up': False} self.mgr.agent_updated(mock.Mock(), payload) self.driver_mock.undeploy_instance.assert_has_calls( - [mock.call('1'), mock.call('2')]) + [mock.call('1'), mock.call('2')], any_order=True)