From 7fa8d60f246d36d5eef9cd54dc706b9a77972259 Mon Sep 17 00:00:00 2001 From: rossella Date: Fri, 9 May 2014 17:51:25 +0000 Subject: [PATCH] Return no active network if the agent has not been learnt yet Sometimes the agent message to get the active networks is processed before the agent is learnt by Neutron. Neutron throws an error, but it should simply return no network Change-Id: I6da0ca578cfe1fe0885138a5e2da76278f791491 Closes-bug: #1302838 --- neutron/db/agentschedulers_db.py | 10 ++++++++-- neutron/tests/unit/openvswitch/test_agent_scheduler.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py index aa8dfadb63b..2022dbe3ec7 100644 --- a/neutron/db/agentschedulers_db.py +++ b/neutron/db/agentschedulers_db.py @@ -23,6 +23,7 @@ from neutron.common import constants from neutron.common import utils from neutron.db import agents_db from neutron.db import model_base +from neutron.extensions import agent as ext_agent from neutron.extensions import dhcpagentscheduler from neutron.openstack.common import log as logging @@ -184,8 +185,13 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler return {'networks': []} def list_active_networks_on_active_dhcp_agent(self, context, host): - agent = self._get_agent_by_type_and_host( - context, constants.AGENT_TYPE_DHCP, host) + try: + agent = self._get_agent_by_type_and_host( + context, constants.AGENT_TYPE_DHCP, host) + except ext_agent.AgentNotFoundByTypeHost: + LOG.debug("DHCP Agent not found on host %s", host) + return [] + if not agent.admin_state_up: return [] query = context.session.query(NetworkDhcpAgentBinding.network_id) diff --git a/neutron/tests/unit/openvswitch/test_agent_scheduler.py b/neutron/tests/unit/openvswitch/test_agent_scheduler.py index ddc1cee8b3c..e1c5a669b19 100644 --- a/neutron/tests/unit/openvswitch/test_agent_scheduler.py +++ b/neutron/tests/unit/openvswitch/test_agent_scheduler.py @@ -576,6 +576,12 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): self.assertEqual(1, num_before_remove) self.assertEqual(0, num_after_remove) + def test_list_active_networks_on_not_registered_yet_dhcp_agent(self): + plugin = manager.NeutronManager.get_plugin() + nets = plugin.list_active_networks_on_active_dhcp_agent( + self.adminContext, host=DHCP_HOSTA) + self.assertEqual([], nets) + def test_reserved_port_after_network_remove_from_dhcp_agent(self): dhcp_hosta = { 'binary': 'neutron-dhcp-agent',