Merge pull request #963 from mwhudson/wlan-fixes

subiquitycore wlan fixes
This commit is contained in:
Michael Hudson-Doyle 2021-06-04 15:43:00 +12:00 committed by GitHub
commit 15f995096e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 20 deletions

View File

@ -154,5 +154,5 @@ parts:
build-packages: [python-setuptools, build-essential, libnl-3-dev, libnl-genl-3-dev, libnl-route-3-dev] build-packages: [python-setuptools, build-essential, libnl-3-dev, libnl-genl-3-dev, libnl-route-3-dev]
source: https://github.com/canonical/probert.git source: https://github.com/canonical/probert.git
source-type: git source-type: git
source-commit: 844c957b7f61f78bbd814cceef87f0d8eb218675 source-commit: abf7c7c399bdc9909a14194f579f2e53c226cb8e
requirements: [requirements.txt] requirements: [requirements.txt]

View File

@ -447,12 +447,20 @@ class BaseNetworkController(BaseController):
def set_wlan(self, dev_name: str, wlan: WLANConfig) -> None: def set_wlan(self, dev_name: str, wlan: WLANConfig) -> None:
device = self.model.get_netdev_by_name(dev_name) device = self.model.get_netdev_by_name(dev_name)
if wlan.ssid and not device.configured_ssid:
# Turn DHCP4 on by default when specifying an SSID for
# the first time...
device.config['dhcp4'] = True
device.set_ssid_psk(wlan.ssid, wlan.psk) device.set_ssid_psk(wlan.ssid, wlan.psk)
self.update_link(device) self.update_link(device)
self.apply_config()
def start_scan(self, dev_name: str) -> None: def start_scan(self, dev_name: str) -> None:
device = self.model.get_netdev_by_name(dev_name) device = self.model.get_netdev_by_name(dev_name)
self.observer.trigger_scan(device.ifindex) try:
self.observer.trigger_scan(device.ifindex)
except RuntimeError as r:
device.info.wlan['scan_state'] = 'error %s' % (r,)
self.update_link(device) self.update_link(device)
@abc.abstractmethod @abc.abstractmethod

View File

@ -82,8 +82,8 @@ class VLANConfig:
@attr.s(auto_attribs=True) @attr.s(auto_attribs=True)
class WLANConfig: class WLANConfig:
ssid: str ssid: Optional[str]
psk: str psk: Optional[str]
@attr.s(auto_attribs=True) @attr.s(auto_attribs=True)
@ -133,7 +133,7 @@ class NetDevInfo:
vlan: Optional[VLANConfig] vlan: Optional[VLANConfig]
bond: Optional[BondConfig] bond: Optional[BondConfig]
wlan: Optional[WLANConfig] wlan: Optional[WLANStatus]
dhcp4: DHCPStatus dhcp4: DHCPStatus
dhcp6: DHCPStatus dhcp6: DHCPStatus
@ -421,11 +421,18 @@ class NetworkModel(object):
def new_link(self, ifindex, link): def new_link(self, ifindex, link):
log.debug("new_link %s %s %s", ifindex, link.name, link.type) log.debug("new_link %s %s %s", ifindex, link.name, link.type)
if link.type in NETDEV_IGNORED_IFACE_TYPES: if link.type in NETDEV_IGNORED_IFACE_TYPES:
log.debug('ignoring based on type')
return return
if not self.support_wlan and link.type == "wlan": if not self.support_wlan and link.type == "wlan":
log.debug('ignoring based on support_wlan')
return return
if link.is_virtual and ( is_virtual = link.is_virtual
link.type not in NETDEV_ALLOWED_VIRTUAL_IFACE_TYPES): if link.type == "wlan":
# mac80211_hwsim nics show up as virtual but we pretend
# they are real for testing purposes.
is_virtual = False
if is_virtual and link.type not in NETDEV_ALLOWED_VIRTUAL_IFACE_TYPES:
log.debug('ignoring based on is_virtual')
return return
dev = self.devices_by_name.get(link.name) dev = self.devices_by_name.get(link.name)
if dev is not None: if dev is not None:
@ -438,9 +445,10 @@ class NetworkModel(object):
dev.info = link dev.info = link
else: else:
config = self.config.config_for_device(link) config = self.config.config_for_device(link)
if link.is_virtual and not config: if is_virtual and not config:
# If we see a virtual device without there already # If we see a virtual device without there already
# being a config for it, we just ignore it. # being a config for it, we just ignore it.
log.debug('ignoring virtual device with no config')
return return
dev = NetworkDev(self, link.name, link.type) dev = NetworkDev(self, link.name, link.type)
dev.info = link dev.info = link

View File

@ -84,9 +84,10 @@ class NetworkConfigureWLANStretchy(Stretchy):
self.psk_row = self.form.psk._table self.psk_row = self.form.psk._table
self.ssid_row.bind(self.psk_row) self.ssid_row.bind(self.psk_row)
self.error = Text("")
self.inputs = Pile(self._build_iface_inputs()) self.inputs = Pile(self._build_iface_inputs())
self.error = Text("")
widgets = [ widgets = [
self.inputs, self.inputs,
Padding.center_79(Color.info_error(self.error)), Padding.center_79(Color.info_error(self.error)),
@ -104,11 +105,7 @@ class NetworkConfigureWLANStretchy(Stretchy):
while not self.inputs.contents[fp][0].selectable(): while not self.inputs.contents[fp][0].selectable():
fp -= 1 fp -= 1
self.inputs.focus_position = fp self.inputs.focus_position = fp
try: self.parent.controller.start_scan(self.dev_info.name)
self.parent.controller.start_scan(self.dev_info)
except RuntimeError as r:
log.exception("start_scan failed")
self.error.set_text("%s" % (r,))
def _build_iface_inputs(self): def _build_iface_inputs(self):
visible_ssids = self.dev_info.wlan.visible_ssids visible_ssids = self.dev_info.wlan.visible_ssids
@ -118,8 +115,12 @@ class NetworkConfigureWLANStretchy(Stretchy):
else: else:
networks_btn = disabled(menu_btn("No visible networks")) networks_btn = disabled(menu_btn("No visible networks"))
if not self.dev_info.wlan.scan_state: scan_state = self.dev_info.wlan.scan_state
if scan_state:
scan_btn = menu_btn("Scan for networks", on_press=self.start_scan) scan_btn = menu_btn("Scan for networks", on_press=self.start_scan)
elif scan_state.startswith('error'):
self.error.set_text('scan failed: %s' % (scan_state,))
scan_btn = disabled(menu_btn("Scanning for networks failed"))
else: else:
scan_btn = disabled(menu_btn("Scanning for networks")) scan_btn = disabled(menu_btn("Scanning for networks"))
@ -138,15 +139,13 @@ class NetworkConfigureWLANStretchy(Stretchy):
return col return col
def update_link(self, dev_info): def update_link(self, dev_info):
if dev_info.name != self.dev_info.name:
return
self.dev_info = dev_info self.dev_info = dev_info
self.inputs.contents = [(obj, ('pack', None)) self.inputs.contents = [(obj, ('pack', None))
for obj in self._build_iface_inputs()] for obj in self._build_iface_inputs()]
def done(self, sender): def done(self, sender):
if self.dev_info.wlan.config.ssid is None and self.form.ssid.value:
# Turn DHCP4 on by default when specifying an SSID for
# the first time...
self.parent.controller.enable_dhcp(self.dev_info, 4)
if self.form.ssid.value: if self.form.ssid.value:
ssid = self.form.ssid.value ssid = self.form.ssid.value
else: else:
@ -157,7 +156,7 @@ class NetworkConfigureWLANStretchy(Stretchy):
psk = None psk = None
self.parent.controller.set_wlan( self.parent.controller.set_wlan(
self.dev_info, WLANConfig(ssid=ssid, psk=psk)) self.dev_info, WLANConfig(ssid=ssid, psk=psk))
self.parent.update_link(self.dev_info) self.parent.update_link(self.dev_info.name)
self.parent.remove_overlay() self.parent.remove_overlay()
def cancel(self, sender=None): def cancel(self, sender=None):