mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 08:58:03 +02:00
test/nm-service: create software devices on AddAndActivate()
This will be useful for testing VLAN bringup.
This commit is contained in:
parent
40fe0d6b94
commit
cff03568f4
1 changed files with 39 additions and 22 deletions
|
|
@ -1666,30 +1666,16 @@ class NetworkManager(ExportedObj):
|
||||||
raise BusErr.UnknownConnectionException("Connection not found")
|
raise BusErr.UnknownConnectionException("Connection not found")
|
||||||
|
|
||||||
con_hash = con_inst.con_hash
|
con_hash = con_inst.con_hash
|
||||||
con_type = NmUtil.con_hash_get_type(con_hash)
|
|
||||||
|
|
||||||
device = self.find_device_first(path=devpath)
|
device = self.find_device(devpath, con_hash)
|
||||||
if not device:
|
if device is None:
|
||||||
if con_type == NM.SETTING_WIRED_SETTING_NAME:
|
device = self.create_device(con_hash)
|
||||||
device = self.find_device_first(dev_type=WiredDevice)
|
if device:
|
||||||
elif con_type == NM.SETTING_WIRELESS_SETTING_NAME:
|
# Just created the device, it can start activating right away
|
||||||
device = self.find_device_first(dev_type=WifiDevice)
|
device.activation_state_change_delay_ms = 0
|
||||||
elif con_type == NM.SETTING_VLAN_SETTING_NAME:
|
|
||||||
ifname = con_hash[NM.SETTING_CONNECTION_SETTING_NAME]["interface-name"]
|
|
||||||
device = VlanDevice(ifname)
|
|
||||||
self.add_device(device)
|
self.add_device(device)
|
||||||
elif con_type == NM.SETTING_VPN_SETTING_NAME:
|
if device is None:
|
||||||
for ac in self.active_connections:
|
raise BusErr.UnknownDeviceException("Device not found")
|
||||||
if ac.is_vpn:
|
|
||||||
continue
|
|
||||||
if ac.device:
|
|
||||||
device = ac.device
|
|
||||||
break
|
|
||||||
|
|
||||||
if not device:
|
|
||||||
raise BusErr.UnknownDeviceException(
|
|
||||||
"No device found for the requested iface."
|
|
||||||
)
|
|
||||||
|
|
||||||
# See if we need secrets. For the moment, we only support WPA
|
# See if we need secrets. For the moment, we only support WPA
|
||||||
if "802-11-wireless-security" in con_hash:
|
if "802-11-wireless-security" in con_hash:
|
||||||
|
|
@ -1874,6 +1860,37 @@ class NetworkManager(ExportedObj):
|
||||||
raise BusErr.UnknownDeviceException("Device not found")
|
raise BusErr.UnknownDeviceException("Device not found")
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def find_device(self, devpath, con_hash):
|
||||||
|
device = self.find_device_first(path=devpath)
|
||||||
|
if device:
|
||||||
|
return device
|
||||||
|
|
||||||
|
con_type = NmUtil.con_hash_get_type(con_hash)
|
||||||
|
|
||||||
|
if con_type == NM.SETTING_WIRED_SETTING_NAME:
|
||||||
|
return self.find_device_first(dev_type=WiredDevice)
|
||||||
|
|
||||||
|
if con_type == NM.SETTING_WIRELESS_SETTING_NAME:
|
||||||
|
return self.find_device_first(dev_type=WifiDevice)
|
||||||
|
|
||||||
|
if con_type == NM.SETTING_VPN_SETTING_NAME:
|
||||||
|
for ac in self.active_connections:
|
||||||
|
if ac.is_vpn:
|
||||||
|
continue
|
||||||
|
if ac.device:
|
||||||
|
return ac.device
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def create_device(self, con_hash):
|
||||||
|
con_type = NmUtil.con_hash_get_type(con_hash)
|
||||||
|
|
||||||
|
if con_type == NM.SETTING_VLAN_SETTING_NAME:
|
||||||
|
ifname = con_hash[NM.SETTING_CONNECTION_SETTING_NAME]["interface-name"]
|
||||||
|
return VlanDevice(ifname)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def add_device(self, device):
|
def add_device(self, device):
|
||||||
if self.find_device_first(ident=device.ident, path=device.path) is not None:
|
if self.find_device_first(ident=device.ident, path=device.path) is not None:
|
||||||
raise TestError(
|
raise TestError(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue