Fix for KeyError: 'gw_port_host' on l3_agent
The dictionary field 'gw_port_host' was added for DVR routers and is used by the scheduler and l3_agent to schedule where the SNAT port for a DVR router will be hosted. In some code flows on the l3_agent, this field is checked to determine what the agent should do if the host matches its own or not. Recently it has been seen that the router data sent from the scheduler is missing this field in some cases. This causes the agent to throw a KeyError and not function properly. This patch will make the l3_agent more robust and less fragile by calling 'get' instead of assuming the field will be there. More work may be needed on the scheduler side to see why this field is missing. That is why I am marking this as a partial-fix for now. But this patch will make the l3_agent less prone to errors and therefore an improvement. Change-Id: Ib26ccfa7b945cb4e8f2ec4adc5e6ae91cbaae02e Partial-Bug: #1394043
This commit is contained in:
parent
d4569d31d9
commit
3813e4cf3b
@ -666,7 +666,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
||||
self.routes_updated(ri)
|
||||
# Process SNAT rules for external gateway
|
||||
if (not ri.router['distributed'] or
|
||||
ex_gw_port and ri.router['gw_port_host'] == self.host):
|
||||
ex_gw_port and self.get_gw_port_host(ri.router) == self.host):
|
||||
ri.perform_snat_action(self._handle_router_snat_rules,
|
||||
interface_name)
|
||||
|
||||
@ -956,6 +956,13 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
||||
def get_snat_interfaces(self, ri):
|
||||
return ri.router.get(l3_constants.SNAT_ROUTER_INTF_KEY, [])
|
||||
|
||||
def get_gw_port_host(self, router):
|
||||
host = router.get('gw_port_host')
|
||||
if not host:
|
||||
LOG.debug("gw_port_host missing from router: %s",
|
||||
router['id'])
|
||||
return host
|
||||
|
||||
def get_floating_ips(self, ri):
|
||||
"""Filter Floating IPs to be hosted on this agent."""
|
||||
floating_ips = ri.router.get(l3_constants.FLOATINGIP_KEY, [])
|
||||
@ -1011,7 +1018,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
||||
['ip_address'], p, id_name)
|
||||
|
||||
if (self.conf.agent_mode == 'dvr_snat' and
|
||||
ri.router['gw_port_host'] == self.host):
|
||||
self.get_gw_port_host(ri.router) == self.host):
|
||||
self._create_dvr_gateway(ri, ex_gw_port, interface_name,
|
||||
snat_ports)
|
||||
for port in snat_ports:
|
||||
@ -1038,7 +1045,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
||||
preserve_ips = []
|
||||
if ri.router['distributed']:
|
||||
if (self.conf.agent_mode == 'dvr_snat' and
|
||||
ri.router['gw_port_host'] == self.host):
|
||||
self.get_gw_port_host(ri.router) == self.host):
|
||||
ns_name = self.get_snat_ns_name(ri.router['id'])
|
||||
else:
|
||||
# no centralized SNAT gateway for this node/agent
|
||||
@ -1121,7 +1128,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
||||
self._snat_redirect_remove(ri, p, internal_interface)
|
||||
|
||||
if self.conf.agent_mode == 'dvr_snat' and (
|
||||
ri.router['gw_port_host'] == self.host):
|
||||
self.get_gw_port_host(ri.router) == self.host):
|
||||
ns_name = self.get_snat_ns_name(ri.router['id'])
|
||||
else:
|
||||
# not hosting agent - no work to do
|
||||
@ -1232,7 +1239,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
|
||||
self._snat_redirect_add(ri, sn_port['fixed_ips'][0]
|
||||
['ip_address'], port, interface_name)
|
||||
if (self.conf.agent_mode == 'dvr_snat' and
|
||||
ri.router['gw_port_host'] == self.host):
|
||||
self.get_gw_port_host(ri.router) == self.host):
|
||||
ns_name = self.get_snat_ns_name(ri.router['id'])
|
||||
self._set_subnet_info(sn_port)
|
||||
interface_name = (
|
||||
|
Loading…
x
Reference in New Issue
Block a user