Fix getting dhcp agents for multiple networks

The method to get dhcp agents for networks takes as a an argument
the ability to send a list of network_ids.  However, this method
is really only being used to send in a list of one network_id, but
there don't seem to be any usages where it is being used for many
network_ids.  Since its not being used, this hasn't been caught yet.

Change-Id: I6f07ed50b29448d279a4fd5f9d392af3a8490340
Closes-Bug: #1587973
This commit is contained in:
Brandon Logan 2016-06-01 11:10:08 -05:00
parent ddfe09c5dd
commit 6290af9cf9
2 changed files with 14 additions and 7 deletions

View File

@ -335,12 +335,9 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
query = query.options(orm.contains_eager(
NetworkDhcpAgentBinding.dhcp_agent))
query = query.join(NetworkDhcpAgentBinding.dhcp_agent)
if len(network_ids) == 1:
if network_ids:
query = query.filter(
NetworkDhcpAgentBinding.network_id == network_ids[0])
elif network_ids:
query = query.filter(
NetworkDhcpAgentBinding.network_id in network_ids)
NetworkDhcpAgentBinding.network_id.in_(network_ids))
if admin_state_up is not None:
query = query.filter(agents_db.Agent.admin_state_up ==
admin_state_up)

View File

@ -472,9 +472,11 @@ class TestDhcpSchedulerFilter(TestDhcpSchedulerBaseTestCase,
agents = self._create_and_set_agents_down(['host-a', 'host-b'], 1)
agents += self._create_and_set_agents_down(['host-c', 'host-d'], 1,
admin_state_up=False)
self._test_schedule_bind_network(agents, self.network_id)
networks = kwargs.pop('networks', [self.network_id])
for network in networks:
self._test_schedule_bind_network(agents, network)
agents = self.get_dhcp_agents_hosting_networks(self.ctx,
[self.network_id],
networks,
**kwargs)
host_ids = set(a['host'] for a in agents)
self.assertEqual(expected, host_ids)
@ -505,6 +507,14 @@ class TestDhcpSchedulerFilter(TestDhcpSchedulerBaseTestCase,
active=True,
admin_state_up=False)
def test_get_dhcp_agents_hosting_many_networks(self):
net_id = 'another-net-id'
self._save_networks([net_id])
networks = [net_id, self.network_id]
self._test_get_dhcp_agents_hosting_networks({'host-a', 'host-b',
'host-c', 'host-d'},
networks=networks)
class DHCPAgentAZAwareWeightSchedulerTestCase(TestDhcpSchedulerBaseTestCase):