Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parser to parse wifi interface name which is not start with phy (BugFix) #1390

Merged
merged 10 commits into from
Sep 20, 2024
4 changes: 4 additions & 0 deletions .github/workflows/tox-provider-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ jobs:
python-version: ${{ matrix.python }}
env:
PIP_TRUSTED_HOST: pypi.python.org pypi.org files.pythonhosted.org
- name: Install libsystemd-dev
run: |
sudo apt-get update
sudo apt-get install -y libsystemd-dev
- name: Install tox
run: pip install tox
- name: Run tox
Expand Down
4 changes: 2 additions & 2 deletions providers/base/units/wireless/nm-hotspot.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ category_id: wifi_ap
estimated_duration: 10
flags: preserve-locale also-after-suspend
requires:
wifi_interface_mode.{{ interface }}_AP == 'supported'
( wifi_interface_mode.interface == '{{ interface }}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{{ interface }}' and net_if_management.master_mode_managed_by == 'NetworkManager'
{%- if __on_ubuntucore__ %}
connections.slot == 'network-manager:service' and connections.plug == '{{ __system_env__["SNAP_NAME"] }}:network-manager'
Expand All @@ -39,7 +39,7 @@ category_id: wifi_ap
estimated_duration: 10
flags: preserve-locale also-after-suspend
requires:
wifi_interface_mode.{{ interface }}_AP == 'supported'
( wifi_interface_mode.interface == '{{ interface }}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{{ interface }}' and net_if_management.master_mode_managed_by == 'NetworkManager'
{%- if __on_ubuntucore__ %}
connections.slot == 'network-manager:service' and connections.plug == '{{ __system_env__["SNAP_NAME"] }}:network-manager'
Expand Down
58 changes: 29 additions & 29 deletions providers/base/units/wireless/wifi-ap.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ category_id: wifi_ap
_summary: Create open 802.11a Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -65,7 +65,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -81,7 +81,7 @@ category_id: wifi_ap
_summary: Create open 802.11b Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -138,7 +138,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -154,7 +154,7 @@ category_id: wifi_ap
_summary: Create open 802.11g Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -211,7 +211,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -227,7 +227,7 @@ category_id: wifi_ap
_summary: Create open 802.11ad Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -284,7 +284,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -300,7 +300,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11a Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -359,7 +359,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -375,7 +375,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11b Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{{ interface }}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -434,7 +434,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -450,7 +450,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11g Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -507,7 +507,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -523,7 +523,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11ad Wi-Fi AP on {interface} with no STA (Manual)
plugin: manual
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
_purpose:
Expand Down Expand Up @@ -582,7 +582,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand All @@ -598,7 +598,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11a Wi-Fi AP on {interface} with active STA (Manual)
plugin: user-interact-verify
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID
Expand Down Expand Up @@ -637,7 +637,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11a Wi-Fi Access Point on {interface} with active STA
plugin: shell
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID WIFI_AP_SETUPTIME
Expand Down Expand Up @@ -686,7 +686,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11b Wi-Fi AP on {interface} with active STA (Manual)
plugin: user-interact-verify
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID
Expand Down Expand Up @@ -725,7 +725,7 @@ category_id: wifi_ap
_summary: Create a WPA2 802.11b Wi-Fi Access Point on {interface} with active STA
plugin: shell
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID WIFI_AP_SETUPTIME
Expand Down Expand Up @@ -774,7 +774,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11g Wi-Fi AP on {interface} with active STA (Manual)
plugin: user-interact-verify
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID
Expand Down Expand Up @@ -813,7 +813,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11g Wi-Fi Access Point on {interface} with active STA
plugin: shell
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID WIFI_AP_SETUPTIME
Expand Down Expand Up @@ -862,7 +862,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11ad Wi-Fi AP on {interface} with active STA (Manual)
plugin: user-interact-verify
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID
Expand Down Expand Up @@ -901,7 +901,7 @@ category_id: wifi_ap
_summary: Create WPA2 802.11ad Wi-Fi Access Point on {interface} with active STA
plugin: shell
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: LD_LIBRARY_PATH OPEN_BG_SSID WIFI_AP_SETUPTIME
Expand Down Expand Up @@ -950,7 +950,7 @@ category_id: wifi_ap
_summary: Create Access Point on {interface} using wifi-ap.setup-wizard
plugin: shell
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 20.0
user: root
Expand Down Expand Up @@ -998,7 +998,7 @@ command:
echo "Rebooting"
reboot
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand Down Expand Up @@ -1035,7 +1035,7 @@ command:
sleep "${{WIFI_AP_SETUPTIME:-10}}"
reboot
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
estimated_duration: 120.0
environ: WIFI_AP_SETUPTIME
Expand Down Expand Up @@ -1067,7 +1067,7 @@ command:
exit 1;
fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
depends: wireless/wifi_ap_across_reboot_{interface}_setup
estimated_duration: 120.0
Expand All @@ -1093,7 +1093,7 @@ command:
wifi-ap.config set disabled=true
if [ "$RES" -eq 2 ]; then exit 0; else exit 1; fi
requires:
wifi_interface_mode.{interface}_AP == 'supported'
( wifi_interface_mode.interface == '{interface}' and wifi_interface_mode.AP == 'supported' )
net_if_management.device == '{interface}' and net_if_management.master_mode_managed_by == 'wifi-ap'
depends: wireless/wifi_ap_across_reboot_{interface}_setup_manual
estimated_duration: 120.0
Expand Down
68 changes: 68 additions & 0 deletions providers/resource/bin/wifi_interface_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
from subprocess import check_output
import re
from typing import List, Tuple, Dict


def get_interfaces() -> List[Tuple[str, str]]:
output = check_output(["iw", "dev"], universal_newlines=True)
device_pattern = r"phy#(\d+).*?Interface (\S+)"
if output:
matches = re.findall(device_pattern, output, re.DOTALL)
return [
(device_id, interface_name)
for device_id, interface_name in matches
]
raise SystemExit(0)


def get_wiphy_info() -> Dict[int, List[str]]:
# We can not use command "iw phy0 info" to get the infomation of sepcific
# interface.
# Because of "phy0" in command could be other pattern like "mwiphy0".
# And such pattern as "mwiphy0" will only show in the output of command
# "iw phy".
output = check_output(["iw", "phy"], universal_newlines=True)
if not output:
return []

Check warning on line 27 in providers/resource/bin/wifi_interface_mode.py

View check run for this annotation

Codecov / codecov/patch

providers/resource/bin/wifi_interface_mode.py#L27

Added line #L27 was not covered by tests

interfaces_info = (info.strip() for info in output.split("Wiphy"))
# drop empty sections
interfaces_info = filter(bool, interfaces_info)
index_re = re.compile(r"phy(\d+)")
wiphy_info = {}
supported_modes_re = re.compile(
r"Supported interface modes:\s*((?:\s*\*\s*[\w/-]+\s*)+)"
)
for interface_info in interfaces_info:
interface_id = index_re.search(interface_info).group(1)
match_modes = supported_modes_re.search(interface_info).group(1)

supported_modes = map(str.strip, match_modes.split("*"))
# remove first element because it is spaces before the first *
_ = next(supported_modes)
wiphy_info[interface_id] = list(supported_modes)
return wiphy_info


def print_supported_modes() -> str:
interfaces = get_interfaces()
wiphy_info = get_wiphy_info()
for wiphy_index, modes in wiphy_info.items():
interface = interfaces[int(wiphy_index)][1]
print("interface: {}".format(interface))
for mode in modes:
print(
"{}: supported".format(
mode.replace("-", "_").replace("/", "_")
)
)
print()


def main():
print_supported_modes()

Check warning on line 64 in providers/resource/bin/wifi_interface_mode.py

View check run for this annotation

Codecov / codecov/patch

providers/resource/bin/wifi_interface_mode.py#L64

Added line #L64 was not covered by tests


if __name__ == "__main__":
main()
7 changes: 1 addition & 6 deletions providers/resource/jobs/resource.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,7 @@ estimated_duration: 0.1
plugin: resource
category_id: information_gathering
command:
# shellcheck disable=SC2046
for i in $(iw dev | grep -oP 'Interface\s+\K\w+');
do iw phy phy$(iw dev "$i" info | grep -oP 'wiphy\s+\K\d+') info |
grep -Pzo '(?s)Supported interface modes:\n\K(\s+\*\s.*?\n)+' |
sed "s/.*\* \(.*\)/""$i""_\1: supported/" | tr -d '\000';
done
wifi_interface_mode.py
_summary: Create resource info for supported wifi interface modes

id: snap
Expand Down
Loading
Loading