create-station: Add logger and exit code handling.

And add note for improvement to station_profile logic.

Signed-off-by: Ben Greear <greearb@candelatech.com>
This commit is contained in:
Ben Greear
2022-02-01 05:56:52 -08:00
committed by shivam
parent 169203b57b
commit 80b236ccb4
2 changed files with 29 additions and 5 deletions

View File

@@ -367,7 +367,6 @@ class StationProfile:
def admin_up(self): def admin_up(self):
for eid in self.station_names: for eid in self.station_names:
self.local_realm.admin_up(eid) self.local_realm.admin_up(eid)
time.sleep(0.005)
def admin_down(self): def admin_down(self):
for sta_name in self.station_names: for sta_name in self.station_names:
@@ -393,6 +392,8 @@ class StationProfile:
debug=debug_) debug=debug_)
# Checks for errors in initialization values and creates specified number of stations using init parameters # Checks for errors in initialization values and creates specified number of stations using init parameters
# TODO: Add option to check if stations exist already. If they do, then warn user, and set MAC to 'NA' so that is
# is not attempted to be mofidified when submitting the create-station URL request.
def create(self, radio, def create(self, radio,
num_stations=0, num_stations=0,
sta_names_=None, sta_names_=None,

View File

@@ -7,9 +7,11 @@ import os
import importlib import importlib
import argparse import argparse
import pprint import pprint
import logging
logger = logging.getLogger(__name__)
if sys.version_info[0] != 3: if sys.version_info[0] != 3:
print("This script requires Python 3") logger.critical("This script requires Python 3")
exit(1) exit(1)
@@ -20,6 +22,7 @@ LFCliBase = lfcli_base.LFCliBase
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
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
class CreateStation(Realm): class CreateStation(Realm):
@@ -95,13 +98,20 @@ class CreateStation(Realm):
retries=self.set_txo_data["retries"], retries=self.set_txo_data["retries"],
sgi=self.set_txo_data["sgi"], sgi=self.set_txo_data["sgi"],
) )
self.station_profile.create(
if self.station_profile.create(
radio=self.radio, radio=self.radio,
sta_names_=self.sta_list, sta_names_=self.sta_list,
debug=self.debug) debug=self.debug):
self._pass("Stations created.")
else:
self._fail("Stations not properly created.")
if self.up: if self.up:
self.station_profile.admin_up() self.station_profile.admin_up()
# TODO: Add check for whether stations went admin up or not.
self._pass("PASS: Station build finished") self._pass("PASS: Station build finished")
@@ -145,6 +155,12 @@ def main():
action='append') action='append')
args = parser.parse_args() args = parser.parse_args()
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to requested value
logger_config.set_level(level=args.log_level)
logger_config.set_json(json_file=args.lf_logger_config_json)
# if args.debug: # if args.debug:
# pprint.pprint(args) # pprint.pprint(args)
# time.sleep(5) # time.sleep(5)
@@ -182,7 +198,14 @@ def main():
_debug_on=args.debug) _debug_on=args.debug)
create_station.build() create_station.build()
# TODO: Add code to clean up the station, unless --noclean was specified.
if create_station.passes():
print('Created %s stations' % num_sta) print('Created %s stations' % num_sta)
create_station.exit_success()
else:
create_station.exit_fail()
if __name__ == "__main__": if __name__ == "__main__":