Make LLDP OVS agent driver more robust to json output

An issue was seen recently in which a bridge with a single port caused
an exception in the LLDP driver, as the json output did not match what
was expected.  In this case, the port was a simple uuid/value list
rather than a list of uuid/value lists.

ie.

["br-ex",["uuid","val1"]]

vs

["br-int",["set",[["uuid","val2"],["uuid","val3"]]]]

This commit adds a fix to handle  both cases, and also adds
robustness to gracefully catch similar issues of unexpected json
output.

Closes-Bug: #1802118
Change-Id: I73189f138a543f34e467f51e18544b521a00457c
Signed-off-by: Steven Webster <steven.webster@windriver.com>
This commit is contained in:
Steven Webster 2018-10-31 17:01:54 -04:00
parent b1ea8a6f7b
commit 5cd3d0dc02

View File

@ -46,8 +46,12 @@ class SysinvOVSAgentDriver(lldpd_driver.SysinvLldpdAgentDriver):
ports = ports['data']
for port in ports:
port_uuid = port[1][1]
interfaces = port[2][1]
try:
port_uuid = port[1][1]
interfaces = port[2][1]
except IndexError:
LOG.error("Unexpected port in LLDP port list: %r", port)
continue
if isinstance(interfaces, list):
for interface in interfaces:
@ -72,11 +76,25 @@ class SysinvOVSAgentDriver(lldpd_driver.SysinvLldpdAgentDriver):
bridges = bridges['data']
for bridge in bridges:
bridge_name = bridge[0]
port_set = bridge[1][1]
for port in port_set:
value = port[1]
port_bridge_map[value] = bridge_name
try:
bridge_name = bridge[0]
ports = bridge[1][1]
except IndexError:
LOG.error("Unexpected bridge in LLDP bridge list: %r", bridge)
continue
if isinstance(ports, list):
for port in ports:
try:
port_uuid = port[1]
except IndexError:
LOG.error("Unexpected port in LLDP bridge list: %r",
port)
continue
port_bridge_map[port_uuid] = bridge_name
else:
port_uuid = ports
port_bridge_map[port_uuid] = bridge_name
return port_bridge_map
@ -94,17 +112,17 @@ class SysinvOVSAgentDriver(lldpd_driver.SysinvLldpdAgentDriver):
def lldp_ovs_add_flows(self, brname, in_port, out_port):
cmd = ("ovs-ofctl add-flow {} in_port={},dl_dst={},dl_type={},"
"actions=output:{}".format(
brname, in_port, constants.LLDP_MULTICAST_ADDRESS,
constants.LLDP_ETHER_TYPE, out_port))
"actions=output:{}".format(brname, in_port,
constants.LLDP_MULTICAST_ADDRESS,
constants.LLDP_ETHER_TYPE, out_port))
output = self.run_cmd(cmd)
if not output:
return
cmd = ("ovs-ofctl add-flow {} in_port={},dl_dst={},dl_type={},"
"actions=output:{}".format(
brname, out_port, constants.LLDP_MULTICAST_ADDRESS,
constants.LLDP_ETHER_TYPE, in_port))
"actions=output:{}".format(brname, out_port,
constants.LLDP_MULTICAST_ADDRESS,
constants.LLDP_ETHER_TYPE, in_port))
output = self.run_cmd(cmd)
if not output:
return
@ -130,29 +148,53 @@ class SysinvOVSAgentDriver(lldpd_driver.SysinvLldpdAgentDriver):
data = data['data']
for interface in data:
name = interface[0]
uuid = interface[1][1]
type = interface[2]
other_config = interface[3]
try:
name = interface[0]
uuid = interface[1][1]
type = interface[2]
other_config = interface[3]
except IndexError:
LOG.error("Unexpected interface in LLDP interface list: %r",
interface)
continue
if type != 'internal':
continue
config_map = other_config[1]
if uuid not in interface_port_map:
continue
if interface_port_map[uuid] not in port_bridge_map:
continue
brname = port_bridge_map[interface_port_map[uuid]]
try:
config_map = other_config[1]
except IndexError:
LOG.error("Unexpected config map in LLDP interface list: %r",
config_map)
continue
for config in config_map:
key = config[0]
value = config[1]
if key != 'lldp_phy_peer':
try:
key = config[0]
value = config[1]
except IndexError:
LOG.error("Unexpected config in LLDP interface list: %r",
config)
continue
if key != 'lldp_phy_peer':
continue
phy_peer = value
brname = port_bridge_map[interface_port_map[uuid]]
if not self.lldp_ovs_lldp_flow_exists(brname, name):
LOG.info("Adding missing LLDP flow from %s to %s",
name, phy_peer)
self.lldp_ovs_add_flows(brname, name, phy_peer)
if not self.lldp_ovs_lldp_flow_exists(brname, value):
if not self.lldp_ovs_lldp_flow_exists(brname, phy_peer):
LOG.info("Adding missing LLDP flow from %s to %s",
phy_peer, name)
self.lldp_ovs_add_flows(brname, phy_peer, name)