mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-12-01 10:03:37 +00:00
Add logging to example_security_connection script.
And add some more error checking with potential to exit early if requested. Signed-off-by: Ben Greear <greearb@candelatech.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import importlib
|
import importlib
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
if sys.version_info[0] != 3:
|
if sys.version_info[0] != 3:
|
||||||
print("This script requires Python 3")
|
print("This script requires Python 3")
|
||||||
@@ -11,13 +12,16 @@ if sys.version_info[0] != 3:
|
|||||||
|
|
||||||
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
|
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
|
||||||
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
|
LFUtils = importlib.import_module("py-json.LANforge.LFUtils")
|
||||||
realm = importlib.import_module("py-json.realm")
|
realm = importlib.import_module("py-json.realm")
|
||||||
Realm = realm.Realm
|
Realm = realm.Realm
|
||||||
|
|
||||||
|
|
||||||
class IPv4Test(Realm):
|
class IPv4Test(Realm):
|
||||||
def __init__(self, ssid, security, password, sta_list=None, ap=None, mode=0, number_template="00000", host="localhost", port=8080, radio="wiphy0", _debug_on=False,
|
def __init__(self, ssid, security, password, sta_list=None, ap=None, mode=0, number_template="00000",
|
||||||
|
host="localhost", port=8080, radio="wiphy0", _debug_on=False,
|
||||||
_exit_on_error=False,
|
_exit_on_error=False,
|
||||||
_exit_on_fail=False):
|
_exit_on_fail=False):
|
||||||
super().__init__(host, port, debug_=_debug_on, _exit_on_fail=_exit_on_fail)
|
super().__init__(host, port, debug_=_debug_on, _exit_on_fail=_exit_on_fail)
|
||||||
@@ -51,27 +55,31 @@ class IPv4Test(Realm):
|
|||||||
self.station_profile.use_security(
|
self.station_profile.use_security(
|
||||||
self.security, self.ssid, self.password)
|
self.security, self.ssid, self.password)
|
||||||
self.station_profile.set_number_template(self.number_template)
|
self.station_profile.set_number_template(self.number_template)
|
||||||
print("Creating stations")
|
logger.info("Creating stations")
|
||||||
self.station_profile.set_command_flag(
|
self.station_profile.set_command_flag(
|
||||||
"add_sta", "create_admin_down", 1)
|
"add_sta", "create_admin_down", 1)
|
||||||
self.station_profile.set_command_param(
|
self.station_profile.set_command_param(
|
||||||
"set_port", "report_timer", 1500)
|
"set_port", "report_timer", 1500)
|
||||||
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
|
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
|
||||||
self.station_profile.create(
|
|
||||||
radio=self.radio, sta_names_=self.sta_list, debug=self.debug)
|
if self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug):
|
||||||
|
self._pass("Station build successful")
|
||||||
|
else:
|
||||||
|
self._fail("Station build was not successful")
|
||||||
|
|
||||||
self.station_profile.admin_up()
|
self.station_profile.admin_up()
|
||||||
if self.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30):
|
if self.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30):
|
||||||
self._pass("Station build finished")
|
self._pass("Stations went admin up and acquired IP address")
|
||||||
self.exit_success()
|
|
||||||
else:
|
else:
|
||||||
self._fail(
|
self._fail("Stations not able to acquire IP. Please check network input.")
|
||||||
"Stations not able to acquire IP. Please check network input.")
|
|
||||||
self.exit_fail()
|
|
||||||
|
|
||||||
def cleanup(self, sta_list):
|
def cleanup(self, sta_list):
|
||||||
self.station_profile.cleanup(sta_list)
|
self.station_profile.cleanup(sta_list)
|
||||||
LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=sta_list,
|
if LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=sta_list,
|
||||||
debug=self.debug)
|
debug=self.debug):
|
||||||
|
self._pass("Successfully deleted stations.")
|
||||||
|
else:
|
||||||
|
self._fail("Could not successfully delete stations")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -110,6 +118,14 @@ def main():
|
|||||||
'--ap', help='Add BSSID of access point to connect to')
|
'--ap', help='Add BSSID of access point to connect to')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# set up logger
|
||||||
|
logger_config = lf_logger_config.lf_logger_config()
|
||||||
|
|
||||||
|
# set the logger level to debug
|
||||||
|
if args.debug:
|
||||||
|
logger_config.set_level_debug()
|
||||||
|
|
||||||
num_sta = 2
|
num_sta = 2
|
||||||
if (args.num_stations is not None) and (int(args.num_stations) > 0):
|
if (args.num_stations is not None) and (int(args.num_stations) > 0):
|
||||||
num_stations_converted = int(args.num_stations)
|
num_stations_converted = int(args.num_stations)
|
||||||
@@ -124,7 +140,7 @@ def main():
|
|||||||
ssid=args.ssid, password=args.passwd,
|
ssid=args.ssid, password=args.passwd,
|
||||||
radio=args.radio, mode=args.mode,
|
radio=args.radio, mode=args.mode,
|
||||||
security=args.security, sta_list=station_list,
|
security=args.security, sta_list=station_list,
|
||||||
ap=args.ap)
|
ap=args.ap, _debug_on=args.debug)
|
||||||
ip_test.cleanup(station_list)
|
ip_test.cleanup(station_list)
|
||||||
ip_test.timeout = 60
|
ip_test.timeout = 60
|
||||||
ip_test.build()
|
ip_test.build()
|
||||||
|
|||||||
Reference in New Issue
Block a user