From f59b6a470620eaf53c98f4d98801789c95ed9a26 Mon Sep 17 00:00:00 2001 From: Bernard Cafarelli Date: Fri, 9 Aug 2019 10:26:13 +0200 Subject: [PATCH] Fix sort issue in test_dhcp_agent_scheduler.test_filter_bindings The test creates a list of networks, and then acts on a list of NetworkDhcpAgentBindings obtained from get_objects() not guaranteed to follow the original build order (based on the network_ids list) Make sure that returned list is sorted on network_id, and network_ids itself sorted so both lists match Change-Id: I9b07255988f7ba6609af1961b3429c3ce12d5186 Closes-Bug: #1839595 --- neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py index 0790931c1fd..a67b36f8dfd 100644 --- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py @@ -14,6 +14,7 @@ # limitations under the License. import datetime +from operator import attrgetter import random import mock @@ -498,7 +499,7 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase, def test_filter_bindings(self): self.ctx = context.get_admin_context() dhcp_agt_ids = self._create_dhcp_agents() - network_ids = self._create_test_networks(num_net=4) + network_ids = sorted(self._create_test_networks(num_net=4)) ndab_obj1 = network_obj.NetworkDhcpAgentBinding(self.ctx, network_id=network_ids[0], dhcp_agent_id=dhcp_agt_ids[0]) ndab_obj1.create() @@ -511,8 +512,9 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase, ndab_obj4 = network_obj.NetworkDhcpAgentBinding(self.ctx, network_id=network_ids[3], dhcp_agent_id=dhcp_agt_ids[1]) ndab_obj4.create() - bindings_objs = network_obj.NetworkDhcpAgentBinding.get_objects( - self.ctx) + bindings_objs = sorted(network_obj.NetworkDhcpAgentBinding.get_objects( + self.ctx), key=attrgetter('network_id')) + with mock.patch.object(self, 'agent_starting_up', side_effect=[True, False]): res = [b for b in self._filter_bindings(None, bindings_objs)]