From 407ca42c8c700a6c1037c88782f6d007dfb2587e Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Tue, 29 Jul 2014 20:34:01 +0000 Subject: [PATCH] Check that router info is set before calling _update_arp_entry Change-Id: Ieec6fb01a7d48bed1042114c27527fe6ec2555e0 Closes-bug: #1350028 --- neutron/agent/l3_agent.py | 3 ++- neutron/tests/unit/test_l3_agent.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py index 9d7ec12195..cf66df7b1b 100644 --- a/neutron/agent/l3_agent.py +++ b/neutron/agent/l3_agent.py @@ -1478,7 +1478,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager): mac = arp_table['mac_address'] subnet_id = arp_table['subnet_id'] ri = self.router_info.get(router_id) - self._update_arp_entry(ri, ip, mac, subnet_id, 'add') + if ri: + self._update_arp_entry(ri, ip, mac, subnet_id, 'add') def del_arp_entry(self, context, payload): """Delete arp entry from router namespace. Called from RPC.""" diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index 4e229bb2d5..832da25905 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -624,6 +624,19 @@ class TestBasicRouterOperations(base.BaseTestCase): self.mock_ip_dev.neigh.add.assert_called_once_with( 4, '1.7.23.11', '00:11:22:33:44:55') + def test_add_arp_entry_no_routerinfo(self): + agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) + router = prepare_router_data(num_internal_ports=2) + subnet_id = _get_subnet_id(router[l3_constants.INTERFACE_KEY][0]) + arp_table = {'ip_address': '1.7.23.11', + 'mac_address': '00:11:22:33:44:55', + 'subnet_id': subnet_id} + + payload = {'arp_table': arp_table, 'router_id': router['id']} + agent._update_arp_entry = mock.Mock() + agent.add_arp_entry(None, payload) + self.assertFalse(agent._update_arp_entry.called) + def test_del_arp_entry(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) router = prepare_router_data(num_internal_ports=2)