diff options
| -rwxr-xr-x | bin/wwan_tests.py (renamed from bin/wwan_tests) | 96 | ||||
| -rw-r--r-- | units/wwan/jobs.pxu | 8 | ||||
| -rw-r--r-- | units/wwan/resource.pxu | 2 |
3 files changed, 60 insertions, 46 deletions
diff --git a/bin/wwan_tests b/bin/wwan_tests.py index 17389e57..c19c547e 100755 --- a/bin/wwan_tests +++ b/bin/wwan_tests.py @@ -1,11 +1,12 @@ #!/usr/bin/env python3 -# Copyright 2015 Canonical Ltd. +# Copyright 2015-2020 Canonical Ltd. # All rights reserved. # # Written by: # Jonathan Cave <jonathan.cave@canonical.com> # Po-Hsu Lin <po-hsu.lin@canonical.com> +import argparse import logging import os import subprocess @@ -13,7 +14,6 @@ import sys import time import dbus -from guacamole import Command TEST_IP = "8.8.8.8" @@ -56,7 +56,8 @@ class MMDbus(): if (excp.get_dbus_name() == "org.freedesktop.DBus.Error.ServiceUnknown"): logging.error(excp.get_dbus_message()) - logging.error("Note: wwan_tests requires ModemManager >=1.0") + logging.error( + "Note: wwan_tests.py requires ModemManager >=1.0") else: logging.error(excp.get_dbus_message()) return @@ -258,9 +259,10 @@ def _ping_test(if_name): return ret_code -class ThreeGppConnection(Command): +class ThreeGppConnection(): - def register_arguments(self, parser): + def invoked(self, ctx): + parser = argparse.ArgumentParser() parser.add_argument('wwan_control_if', type=str, help='The control interface for the device') parser.add_argument('wwan_net_if', type=str, @@ -269,14 +271,13 @@ class ThreeGppConnection(Command): help='The APN for data connection') parser.add_argument('wwan_setup_time', type=int, default=30, help='delay before ping test') - - def invoked(self, ctx): + args = parser.parse_args(sys.argv[2:]) ret_code = 1 try: - _create_3gpp_connection(ctx.args.wwan_control_if, ctx.args.apn) + _create_3gpp_connection(ctx.args.wwan_control_if, args.apn) _wwan_radio_on() - time.sleep(ctx.args.wwan_setup_time) - ret_code = _ping_test(ctx.args.wwan_net_if) + time.sleep(args.wwan_setup_time) + ret_code = _ping_test(args.wwan_net_if) except: pass _destroy_3gpp_connection() @@ -284,20 +285,28 @@ class ThreeGppConnection(Command): return ret_code -class CountModems(Command): +class CountModems(): - def invoked(self, ctx): - if ctx.args.use_cli: + def invoked(self): + parser = argparse.ArgumentParser() + parser.add_argument('--use-cli', action='store_true', + help="Use mmcli for all calls rather than dbus") + args = parser.parse_args(sys.argv[2:]) + if args.use_cli: mm = MMCLI() else: mm = MMDbus() print(len(mm.get_modem_ids())) -class Resources(Command): +class Resources(): - def invoked(self, ctx): - if ctx.args.use_cli: + def invoked(self): + parser = argparse.ArgumentParser() + parser.add_argument('--use-cli', action='store_true', + help="Use mmcli for all calls rather than dbus") + args = parser.parse_args(sys.argv[2:]) + if args.use_cli: mm = MMCLI() else: mm = MMDbus() @@ -332,55 +341,60 @@ class Resources(Command): print() -class SimPresent(Command): +class SimPresent(): - def register_arguments(self, parser): + def invoked(self): + parser = argparse.ArgumentParser() parser.add_argument('hw_id', type=str, help='The hardware ID of the modem whose attached' 'SIM we want to query') - - def invoked(self, ctx): - if ctx.args.use_cli: + parser.add_argument('--use-cli', action='store_true', + help="Use mmcli for all calls rather than dbus") + args = parser.parse_args(sys.argv[2:]) + if args.use_cli: mm = MMCLI() else: mm = MMDbus() - mm_id = mm.equipment_id_to_mm_id(ctx.args.hw_id) + mm_id = mm.equipment_id_to_mm_id(args.hw_id) if not mm.sim_present(mm_id): return 1 -class SimInfo(Command): +class SimInfo(): - def register_arguments(self, parser): + def invoked(self): + parser = argparse.ArgumentParser() parser.add_argument('hw_id', type=str, help='The hardware ID of the modem whose attached' 'SIM we want to query') - - def invoked(self, ctx): - if ctx.args.use_cli: + parser.add_argument('--use-cli', action='store_true', + help="Use mmcli for all calls rather than dbus") + args = parser.parse_args(sys.argv[2:]) + if args.use_cli: mm = MMCLI() else: mm = MMDbus() - mm_id = mm.equipment_id_to_mm_id(ctx.args.hw_id) + mm_id = mm.equipment_id_to_mm_id(args.hw_id) print("Operator: {}".format(mm.get_sim_operatorname(mm_id))) print("IMSI: {}".format(mm.get_sim_imsi(mm_id))) print("MCC/MNC: {}".format(mm.get_sim_operatoridentifier(mm_id))) print("ICCID: {}".format(mm.get_sim_simidentifier(mm_id))) -class WWANTests(Command): - - sub_commands = ( - ('count', CountModems), - ('resources', Resources), - ('3gpp-connection', ThreeGppConnection), - ('sim-present', SimPresent), - ('sim-info', SimInfo) - ) - - def register_arguments(self, parser): - parser.add_argument('--use-cli', action='store_true', - help="Use mmcli for all calls rather than dbus") +class WWANTests(): + + def main(self): + sub_commands = { + 'count': CountModems, + 'resources': Resources, + '3gpp-connection': ThreeGppConnection, + 'sim-present': SimPresent, + 'sim-info': SimInfo + } + parser = argparse.ArgumentParser() + parser.add_argument('subcommand', type=str, choices=sub_commands) + args = parser.parse_args(sys.argv[1:2]) + sub_commands[args.subcommand]().invoked() if __name__ == "__main__": diff --git a/units/wwan/jobs.pxu b/units/wwan/jobs.pxu index d18cdc31..b0313856 100644 --- a/units/wwan/jobs.pxu +++ b/units/wwan/jobs.pxu @@ -15,7 +15,7 @@ _purpose: plugin: shell user: root command: - COUNT=$(wwan_tests count) + COUNT=$(wwan_tests.py count) if [ $COUNT -eq 0 ]; then exit 1 fi @@ -38,7 +38,7 @@ _description: plugin: shell command: BEGIN_CONNECTION_TEST_TS=`date '+%Y-%m-%d %H:%M:%S'` - wwan_tests 3gpp-connection $WWAN_CONTROL_IF $WWAN_NET_IF $WWAN_APN ${{WWAN_SETUPTIME:-30}} + wwan_tests.py 3gpp-connection $WWAN_CONTROL_IF $WWAN_NET_IF $WWAN_APN ${{WWAN_SETUPTIME:-30}} RETVAL=$? if [ $RETVAL -ne 0 ]; then echo "==== Service units logs ====" @@ -64,7 +64,7 @@ _summary: Check if a SIM card is present in a slot connected to the modem _description: Check if a SIM card is present in a slot connected to the modem plugin: shell -command: wwan_tests sim-present {hw_id} +command: wwan_tests.py sim-present {hw_id} environ: LD_LIBRARY_PATH user: root estimated_duration: 10.0 @@ -90,7 +90,7 @@ _steps: 1. Start the test to automatically retrieve information from the SIM card _verification: Check the output, if as expected then mark the test as passed. -command: wwan_tests sim-info {hw_id} +command: wwan_tests.py sim-info {hw_id} environ: LD_LIBRARY_PATH user: root estimated_duration: 5s diff --git a/units/wwan/resource.pxu b/units/wwan/resource.pxu index a0e82ff8..0197f15e 100644 --- a/units/wwan/resource.pxu +++ b/units/wwan/resource.pxu @@ -11,7 +11,7 @@ category_id: wwan plugin: resource _summary: Gather device info about WWAN modems _description: Gather device info about WWAN modems -command: wwan_tests --use-cli resources +command: wwan_tests.py --use-cli resources user: root estimated_duration: 3s flags: preserve-locale |
