Do not schedule network when creating reserved DHCP port

If device_id is DEVICE_ID_RESERVED_DHCP_PORT, do not schedule
network nor notify to dhcp-agent.

Closes-Bug: #1327000
Change-Id: Idf88767596bf0fc31bf856a423d35cb1575b57f3
This commit is contained in:
Itsuro Oda 2014-06-05 14:32:13 +09:00
parent 7a5df446ee
commit bbea8c3495
3 changed files with 31 additions and 2 deletions

View File

@ -95,6 +95,9 @@ class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
'payload': payload})
return enabled_agents
def _is_reserved_dhcp_port(self, port):
return port.get('device_id') == constants.DEVICE_ID_RESERVED_DHCP_PORT
def _notify_agents(self, context, method, payload, network_id):
"""Notify all the agents that are hosting the network."""
# fanout is required as we do not know who is "listening"
@ -115,7 +118,9 @@ class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
context, [network_id])
# schedule the network first, if needed
schedule_required = method == 'port_create_end'
schedule_required = (
method == 'port_create_end' and
not self._is_reserved_dhcp_port(payload['port']))
if schedule_required:
agents = self._schedule_network(admin_ctx, network, agents)

View File

@ -124,8 +124,9 @@ class TestDhcpAgentNotifyAPI(base.BaseTestCase):
agent.admin_state_up = True
agent.heartbeat_timestamp = timeutils.utcnow()
g.return_value = [agent]
dummy_payload = {'port': {}}
self.notifier._notify_agents(mock.Mock(), method,
mock.ANY, 'foo_network_id')
dummy_payload, 'foo_network_id')
self.assertEqual(expected_scheduling, f.call_count)
self.assertEqual(expected_casts, self.mock_cast.call_count)

View File

@ -1158,6 +1158,29 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
for expected in expected_calls[DHCP_HOSTC]:
self.assertIn(expected, self.dhcp_notifier_cast.call_args_list)
def _is_schedule_network_called(self, device_id):
plugin = manager.NeutronManager.get_plugin()
notifier = plugin.agent_notifiers[constants.AGENT_TYPE_DHCP]
with contextlib.nested(
self.subnet(),
mock.patch.object(plugin,
'get_dhcp_agents_hosting_networks',
return_value=[]),
mock.patch.object(notifier,
'_schedule_network',
return_value=[])
) as (subnet, _, mock_sched):
with self.port(subnet=subnet, device_id=device_id):
return mock_sched.called
def test_reserved_dhcp_port_creation(self):
device_id = constants.DEVICE_ID_RESERVED_DHCP_PORT
self.assertFalse(self._is_schedule_network_called(device_id))
def test_unreserved_dhcp_port_creation(self):
device_id = 'not_reserved'
self.assertTrue(self._is_schedule_network_called(device_id))
class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
test_agent_ext_plugin.AgentDBTestMixIn,