Merge "Fix getting dhcp agents for multiple networks"

This commit is contained in:
Jenkins
2016-06-03 03:42:19 +00:00
committed by Gerrit Code Review
2 changed files with 14 additions and 7 deletions

View File

@@ -335,12 +335,9 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
query = query.options(orm.contains_eager( query = query.options(orm.contains_eager(
NetworkDhcpAgentBinding.dhcp_agent)) NetworkDhcpAgentBinding.dhcp_agent))
query = query.join(NetworkDhcpAgentBinding.dhcp_agent) query = query.join(NetworkDhcpAgentBinding.dhcp_agent)
if len(network_ids) == 1: if network_ids:
query = query.filter( query = query.filter(
NetworkDhcpAgentBinding.network_id == network_ids[0]) NetworkDhcpAgentBinding.network_id.in_(network_ids))
elif network_ids:
query = query.filter(
NetworkDhcpAgentBinding.network_id in network_ids)
if admin_state_up is not None: if admin_state_up is not None:
query = query.filter(agents_db.Agent.admin_state_up == query = query.filter(agents_db.Agent.admin_state_up ==
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-a', 'host-b'], 1)
agents += self._create_and_set_agents_down(['host-c', 'host-d'], 1, agents += self._create_and_set_agents_down(['host-c', 'host-d'], 1,
admin_state_up=False) 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, agents = self.get_dhcp_agents_hosting_networks(self.ctx,
[self.network_id], networks,
**kwargs) **kwargs)
host_ids = set(a['host'] for a in agents) host_ids = set(a['host'] for a in agents)
self.assertEqual(expected, host_ids) self.assertEqual(expected, host_ids)
@@ -505,6 +507,14 @@ class TestDhcpSchedulerFilter(TestDhcpSchedulerBaseTestCase,
active=True, active=True,
admin_state_up=False) 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): class DHCPAgentAZAwareWeightSchedulerTestCase(TestDhcpSchedulerBaseTestCase):