From cb17b73ff6d3ca5050bf4db437e1689875c0ab75 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 19 Nov 2024 12:16:03 +0100 Subject: [PATCH] test/nm-service: create Vlan devices matching the parent by hwaddr This is how OCI VLANS will be looking up their parents. Make sure the mock is able to deal with this. --- tools/test-networkmanager-service.py | 52 ++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/tools/test-networkmanager-service.py b/tools/test-networkmanager-service.py index 79453cd87d..4e2ac07346 100755 --- a/tools/test-networkmanager-service.py +++ b/tools/test-networkmanager-service.py @@ -1725,7 +1725,6 @@ class NetworkManager(ExportedObj): out_signature="ooa{sv}", ) def AddAndActivateConnection2(self, con_hash, devpath, specific_object, options): - device = self.find_or_create_device(devpath, con_hash) conpath = gl.settings.AddConnection(con_hash) return (conpath, self.ActivateConnection(conpath, devpath, specific_object), []) @@ -1862,8 +1861,55 @@ class NetworkManager(ExportedObj): return self.find_device_first(dev_type=WifiDevice) if con_type == NM.SETTING_VLAN_SETTING_NAME: - ifname = con_hash[NM.SETTING_CONNECTION_SETTING_NAME]["interface-name"] - device = VlanDevice(ifname) + + iface = con_hash[NM.SETTING_CONNECTION_SETTING_NAME].get("interface-name") + parent_iface = con_hash[NM.SETTING_VLAN_SETTING_NAME].get("parent") + mac = con_hash[NM.SETTING_WIRED_SETTING_NAME].get("mac-address") + if mac is not None: + parent_hwaddr = "%02X:%02X:%02X:%02X:%02X:%02X" % ( + mac[0], + mac[1], + mac[2], + mac[3], + mac[4], + mac[5], + ) + + parent_ident = parent_iface if parent_iface is not None else _DEFAULT_ARG + parent_device = self.find_device_first( + dev_type=WiredDevice, hwaddr=parent_hwaddr, ident=parent_ident + ) + if parent_device is None: + parent_device = self.find_device_first( + dev_type=MacvlanDevice, hwaddr=parent_hwaddr, ident=parent_ident + ) + if parent_device is None: + raise BusErr.UnknownDeviceException("Parent device not found") + + if parent_hwaddr is None: + parent_hwaddr = parent_device.hwaddr + + mac = con_hash[NM.SETTING_WIRED_SETTING_NAME].get("cloned-mac-address") + if mac is not None: + hwaddr = "%02X:%02X:%02X:%02X:%02X:%02X" % ( + mac[0], + mac[1], + mac[2], + mac[3], + mac[4], + mac[5], + ) + + if parent_iface is None: + parent_iface = parent_device.ident + + if iface is None: + iface = "%s.%d" % ( + parent_iface, + con_hash[NM.SETTING_VLAN_SETTING_NAME]["id"], + ) + + device = VlanDevice(iface, mac=hwaddr) self.add_device(device) return device