summaryrefslogtreecommitdiff
diff options
authorPMR <pmr@pmr-lander>2019-04-25 14:15:32 +0000
committerPMR <pmr@pmr-lander>2019-04-25 14:15:32 +0000
commitbaaffdd2176149c6cae6b16135769e7308a917d1 (patch)
treea732c0e250d5b633f8b511627620214c206659eb
parent0a494e59a5fab963d4058b984eb5b17307708b76 (diff)
parentfb20d35070de4b02faefc3f20f6b1dcf08245a20 (diff)
Merge #364908 from ~jocave/plainbox-provider-checkbox:nmcli-hotspot-testssnap-2019-05-06T1143
-rwxr-xr-xbin/wifi_nmcli_test.py45
-rw-r--r--units/wireless/nm-hotspot.pxu42
2 files changed, 87 insertions, 0 deletions
diff --git a/bin/wifi_nmcli_test.py b/bin/wifi_nmcli_test.py
index 45b8624..971b363 100755
--- a/bin/wifi_nmcli_test.py
+++ b/bin/wifi_nmcli_test.py
@@ -159,6 +159,43 @@ def secured_connection(args):
return rc
+def hotspot(args):
+ print_head("Create Wi-Fi hotspot")
+ cmd = ("nmcli c add type wifi ifname {} con-name TEST_CON autoconnect no"
+ " ssid CHECKBOX_AP".format(args.device))
+ print_cmd(cmd)
+ retcode = sp.call(cmd, shell=True)
+ if retcode != 0:
+ print("Connection creation failed\n")
+ return retcode
+ cmd = ("nmcli c modify TEST_CON 802-11-wireless.mode ap ipv4.method shared"
+ " 802-11-wireless.band {}".format(args.band))
+ print_cmd(cmd)
+ retcode = sp.call(cmd, shell=True)
+ if retcode != 0:
+ print("Set band failed\n")
+ return retcode
+ cmd = "nmcli c modify TEST_CON wifi-sec.key-mgmt wpa-psk"
+ print_cmd(cmd)
+ retcode = sp.call(cmd, shell=True)
+ if retcode != 0:
+ print("Set key-mgmt failed\n")
+ return retcode
+ cmd = "nmcli connection modify TEST_CON wifi-sec.psk \"ubuntu1234\""
+ print_cmd(cmd)
+ retcode = sp.call(cmd, shell=True)
+ if retcode != 0:
+ print("Set PSK failed\n")
+ return retcode
+ cmd = "nmcli connection up TEST_CON"
+ print_cmd(cmd)
+ retcode = sp.call(cmd, shell=True)
+ if retcode != 0:
+ print("Failed to bring up connection\n")
+ print()
+ return retcode
+
+
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='WiFi connection test using mmcli')
@@ -185,6 +222,14 @@ if __name__ == '__main__':
parser_secured.add_argument('essid', type=str, help='ESSID')
parser_secured.add_argument('psk', type=str, help='Pre-Shared Key')
parser_secured.set_defaults(func=secured_connection)
+
+ parser_ap = subparsers.add_parser(
+ 'ap', help='Test creation of a hotspot')
+ parser_ap.add_argument(
+ 'device', type=str, help='Device name e.g. wlan0')
+ parser_ap.add_argument('band', type=str, help='Band')
+ parser_ap.set_defaults(func=hotspot)
+
args = parser.parse_args()
cleanup_nm_connections()
diff --git a/units/wireless/nm-hotspot.pxu b/units/wireless/nm-hotspot.pxu
new file mode 100644
index 0000000..5ffbe2b
--- /dev/null
+++ b/units/wireless/nm-hotspot.pxu
@@ -0,0 +1,42 @@
+
+unit: template
+template-resource: device
+template-filter: device.category == 'WIRELESS' and device.interface != 'UNKNOWN'
+template-engine: jinja2
+template-unit: job
+id: wireless/nmcli_wifi_ap_bg_{{ interface }}
+_summary: Create 802.11b/g Wi-Fi AP on {{ interface }} using NetworkManager
+command:
+ net_driver_info $NET_DRIVER_INFO
+ wifi_nmcli_test.py ap {{ interface }} bg
+plugin: shell
+category_id: com.canonical.plainbox::wireless
+estimated_duration: 10
+flags: preserve-locale also-after-suspend
+requires:
+ {%- if __on_ubuntucore__ %}
+ connections.slot == 'network-manager:service' and connections.plug == '{{ __system_env__["SNAP_NAME"] }}:network-manager'
+ {%- else %}
+ executable.name == 'nmcli'
+ {% endif -%}
+
+unit: template
+template-resource: device
+template-filter: device.category == 'WIRELESS' and device.interface != 'UNKNOWN'
+template-engine: jinja2
+template-unit: job
+id: wireless/nmcli_wifi_ap_a_{{ interface }}
+_summary: Create 802.11a Wi-Fi AP on {{ interface }} using NetworkManager
+command:
+ net_driver_info $NET_DRIVER_INFO
+ wifi_nmcli_test.py ap {{ interface }} a
+plugin: shell
+category_id: com.canonical.plainbox::wireless
+estimated_duration: 10
+flags: preserve-locale also-after-suspend
+requires:
+ {%- if __on_ubuntucore__ %}
+ connections.slot == 'network-manager:service' and connections.plug == '{{ __system_env__["SNAP_NAME"] }}:network-manager'
+ {%- else %}
+ executable.name == 'nmcli'
+ {% endif -%} \ No newline at end of file