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
This commit is contained in:
Bernard Cafarelli 2019-08-09 10:26:13 +02:00
parent de54e3c3c6
commit f59b6a4706
No known key found for this signature in database
GPG Key ID: 9531F08245465A52
1 changed files with 5 additions and 3 deletions

View File

@ -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)]