From 36ee761dd0d671439323077e4f77a89071fdcd9c Mon Sep 17 00:00:00 2001 From: Edward Haas Date: Wed, 7 Oct 2020 20:13:12 +0300 Subject: [PATCH 1/2] nm, bridge, ovs: Collect only existing profiles During the reporting flow, connections that are in teardown process no longer point to a valid profile. Avoid collecting such profiles (in practice, these are actually `None` objects). Signed-off-by: Edward Haas Signed-off-by: Gris Ge --- libnmstate/nm/bridge.py | 6 +++--- libnmstate/nm/ovs.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libnmstate/nm/bridge.py b/libnmstate/nm/bridge.py index b885f7a..0ca6c2d 100644 --- a/libnmstate/nm/bridge.py +++ b/libnmstate/nm/bridge.py @@ -260,9 +260,9 @@ def _get_slave_profiles_by_name(master_device): for dev in master_device.get_slaves(): active_con = connection.get_device_active_connection(dev) if active_con: - slaves_profiles_by_name[ - dev.get_iface() - ] = active_con.props.connection + profile = active_con.props.connection + if profile: + slaves_profiles_by_name[dev.get_iface()] = profile return slaves_profiles_by_name diff --git a/libnmstate/nm/ovs.py b/libnmstate/nm/ovs.py index 2518773..eb373c3 100644 --- a/libnmstate/nm/ovs.py +++ b/libnmstate/nm/ovs.py @@ -279,5 +279,7 @@ def _get_slave_profiles(master_device, devices_info): if active_con: master = active_con.props.master if master and (master.get_iface() == master_device.get_iface()): - slave_profiles.append(active_con.props.connection) + profile = active_con.props.connection + if profile: + slave_profiles.append(profile) return slave_profiles -- 2.28.0 From caf638d75e57da8770cd884782475f1c5668fd6d Mon Sep 17 00:00:00 2001 From: Edward Haas Date: Wed, 7 Oct 2020 12:26:42 +0300 Subject: [PATCH 2/2] nm, ovs: Fix report crash when OVS has dup iface names In case of an existing OVS deployment which uses an identical name for the bridge, port and interface, libnmstate.show() exploded. It is now possible to report such deployments. Signed-off-by: Edward Haas Signed-off-by: Gris Ge --- libnmstate/nm/ovs.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/libnmstate/nm/ovs.py b/libnmstate/nm/ovs.py index eb373c3..d1f26ba 100644 --- a/libnmstate/nm/ovs.py +++ b/libnmstate/nm/ovs.py @@ -140,7 +140,12 @@ def get_port_by_slave(nmdev): def get_ovs_info(context, bridge_device, devices_info): - port_profiles = _get_slave_profiles(bridge_device, devices_info) + ovs_ports_info = ( + info + for info in devices_info + if is_ovs_port_type_id(info[1]["type_id"]) + ) + port_profiles = _get_slave_profiles(bridge_device, ovs_ports_info) ports = _get_bridge_ports_info(context, port_profiles, devices_info) options = _get_bridge_options(context, bridge_device) @@ -203,8 +208,21 @@ def _get_bridge_port_info(context, port_profile, devices_info): vlan_mode = port_setting.props.vlan_mode port_name = port_profile.get_interface_name() - port_device = context.get_nm_dev(port_name) - port_slave_profiles = _get_slave_profiles(port_device, devices_info) + port_device = next( + dev + for dev, devinfo in devices_info + if devinfo["name"] == port_name + and is_ovs_port_type_id(devinfo["type_id"]) + ) + devices_info_excluding_bridges_and_ports = ( + info + for info in devices_info + if not is_ovs_bridge_type_id(info[1]["type_id"]) + and not is_ovs_port_type_id(info[1]["type_id"]) + ) + port_slave_profiles = _get_slave_profiles( + port_device, devices_info_excluding_bridges_and_ports + ) port_slave_names = [c.get_interface_name() for c in port_slave_profiles] if port_slave_names: -- 2.28.0