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
(cherry picked from commit f59b6a4706
)
This commit is contained in:
parent
2e15b18679
commit
750a8e8327
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
from operator import attrgetter
|
||||
import random
|
||||
|
||||
import mock
|
||||
|
@ -500,7 +501,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()
|
||||
|
@ -513,8 +514,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)]
|
||||
|
|
Loading…
Reference in New Issue