lfcli_base: Fix whitespace

Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
Matthew Stidham
2021-12-06 11:24:32 -08:00
parent f9b3347138
commit 12f4263843

View File

@@ -17,7 +17,6 @@ if sys.version_info[0] != 3:
print("This script requires Python 3") print("This script requires Python 3")
exit() exit()
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../"))) sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../../")))
debug_printer = pprint.PrettyPrinter(indent=2) debug_printer = pprint.PrettyPrinter(indent=2)
@@ -30,17 +29,14 @@ if os.environ.get("LF_USE_AUTOGEN") == 1:
LFSession = lanforge_api.LFSession LFSession = lanforge_api.LFSession
class LFCliBase: class LFCliBase:
SHOULD_RUN = 0 # indicates normal operation
SHOULD_RUN = 0 # indicates normal operation SHOULD_QUIT = 1 # indicates to quit loops, close files, send SIGQUIT to threads and return
SHOULD_QUIT = 1 # indicates to quit loops, close files, send SIGQUIT to threads and return SHOULD_HALT = 2 # indicates to quit loops, send SIGABRT to threads and exit
SHOULD_HALT = 2 # indicates to quit loops, send SIGABRT to threads and exit
# - LOGGING - # - LOGGING -
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
# do not use `super(LFCLiBase,self).__init__(self, host, port, _debug) # do not use `super(LFCLiBase,self).__init__(self, host, port, _debug)
# that is py2 era syntax and will force self into the host variable, making you # that is py2 era syntax and will force self into the host variable, making you
# very confused. # very confused.
@@ -63,7 +59,7 @@ class LFCliBase:
self.proxy = {} self.proxy = {}
self.adjust_proxy(_proxy_str) self.adjust_proxy(_proxy_str)
if (_local_realm is not None): if _local_realm:
self.local_realm = _local_realm self.local_realm = _local_realm
# if (_debug): # if (_debug):
@@ -258,9 +254,9 @@ class LFCliBase:
if debug_: if debug_:
debug_printer.pprint(_data) debug_printer.pprint(_data)
json_response = lf_r.json_post(show_error=debug_, json_response = lf_r.json_post(show_error=debug_,
debug=debug_, debug=debug_,
response_json_list_=response_json_list_, response_json_list_=response_json_list_,
die_on_error_=self.exit_on_error) die_on_error_=self.exit_on_error)
if debug_ and (response_json_list_ is not None): if debug_ and (response_json_list_ is not None):
pprint.pprint(response_json_list_) pprint.pprint(response_json_list_)
except Exception as x: except Exception as x:
@@ -347,7 +343,7 @@ class LFCliBase:
def json_delete(self, _req_url, debug_=False): def json_delete(self, _req_url, debug_=False):
debug_ |= self.debug debug_ |= self.debug
if debug_: if debug_:
print("DELETE: "+_req_url) print("DELETE: " + _req_url)
json_response = None json_response = None
try: try:
# print("----- DELETE ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ") # print("----- DELETE ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ")
@@ -358,7 +354,7 @@ class LFCliBase:
die_on_error_=self.exit_on_error) die_on_error_=self.exit_on_error)
json_response = lf_r.json_delete(debug=debug_, die_on_error_=False) json_response = lf_r.json_delete(debug=debug_, die_on_error_=False)
print(json_response) print(json_response)
#debug_printer.pprint(json_response) # debug_printer.pprint(json_response)
if (json_response is None) and debug_: if (json_response is None) and debug_:
print("LFCliBase.json_delete: no entity/response, probabily status 404") print("LFCliBase.json_delete: no entity/response, probabily status 404")
return None return None
@@ -424,11 +420,11 @@ class LFCliBase:
print("Could not connect to LANforge GUI") print("Could not connect to LANforge GUI")
sys.exit(1) sys.exit(1)
#return ALL messages in list form # return ALL messages in list form
def get_result_list(self): def get_result_list(self):
return self.test_results return self.test_results
#return ALL fail messages in list form # return ALL fail messages in list form
def get_failed_result_list(self): def get_failed_result_list(self):
fail_list = [] fail_list = []
for result in self.test_results: for result in self.test_results:
@@ -436,7 +432,7 @@ class LFCliBase:
fail_list.append(result) fail_list.append(result)
return fail_list return fail_list
#return ALL pass messages in list form # return ALL pass messages in list form
def get_passed_result_list(self): def get_passed_result_list(self):
pass_list = [] pass_list = []
for result in self.test_results: for result in self.test_results:
@@ -455,7 +451,7 @@ class LFCliBase:
def get_all_message(self): def get_all_message(self):
return "\n".join(self.test_results) return "\n".join(self.test_results)
#determines if overall test passes via comparing passes vs. fails # determines if overall test passes via comparing passes vs. fails
def passes(self): def passes(self):
pass_counter = 0 pass_counter = 0
fail_counter = 0 fail_counter = 0
@@ -468,11 +464,11 @@ class LFCliBase:
return True return True
return False return False
#EXIT script with a fail # EXIT script with a fail
def exit_fail(self, message="%d out of %d tests failed. Exiting script with script failure."): def exit_fail(self, message="%d out of %d tests failed. Exiting script with script failure."):
total_len=len(self.get_result_list()) total_len = len(self.get_result_list())
fail_len=len(self.get_failed_result_list()) fail_len = len(self.get_failed_result_list())
print(message %(fail_len,total_len)) print(message % (fail_len, total_len))
sys.exit(1) sys.exit(1)
# use this inside the class to log a failure result and print it if wished # use this inside the class to log a failure result and print it if wished
@@ -483,17 +479,17 @@ class LFCliBase:
if self.exit_on_fail: if self.exit_on_fail:
sys.exit(1) sys.exit(1)
#EXIT script with a success # EXIT script with a success
def exit_success(self,message="%d out of %d tests passed successfully. Exiting script with script success."): def exit_success(self, message="%d out of %d tests passed successfully. Exiting script with script success."):
num_total=len(self.get_result_list()) num_total = len(self.get_result_list())
num_passing=len(self.get_passed_result_list()) num_passing = len(self.get_passed_result_list())
print(message %(num_passing,num_total)) print(message % (num_passing, num_total))
sys.exit(0) sys.exit(0)
def success(self,message="%d out of %d tests passed successfully."): def success(self, message="%d out of %d tests passed successfully."):
num_total=len(self.get_result_list()) num_total = len(self.get_result_list())
num_passing=len(self.get_passed_result_list()) num_passing = len(self.get_passed_result_list())
print(message %(num_passing,num_total)) print(message % (num_passing, num_total))
# use this inside the class to log a pass result and print if wished. # use this inside the class to log a pass result and print if wished.
def _pass(self, message, print_=False): def _pass(self, message, print_=False):
@@ -517,7 +513,6 @@ class LFCliBase:
# print("lfclibase::self.proxy: ") # print("lfclibase::self.proxy: ")
# pprint.pprint(self.proxy) # pprint.pprint(self.proxy)
@staticmethod @staticmethod
def logg2(level="debug", mesg=None): def logg2(level="debug", mesg=None):
if (mesg is None) or (mesg == ""): if (mesg is None) or (mesg == ""):
@@ -539,8 +534,8 @@ class LFCliBase:
""" """
if (mesg is None) or (mesg == "") or (level is None): if (mesg is None) or (mesg == "") or (level is None):
return return
userhome=os.path.expanduser('~') userhome = os.path.expanduser('~')
session = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':','-') session = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':', '-')
if filename is None: if filename is None:
if not os.path.isdir("%s/report-data/%s" % (userhome, session)): if not os.path.isdir("%s/report-data/%s" % (userhome, session)):
if not os.path.isdir('%s/report-data' % userhome): if not os.path.isdir('%s/report-data' % userhome):
@@ -557,7 +552,7 @@ class LFCliBase:
logging.warning(mesg) logging.warning(mesg)
elif level == "error": elif level == "error":
logging.error(mesg) logging.error(mesg)
@staticmethod @staticmethod
def parse_time(time_string): def parse_time(time_string):
if isinstance(time_string, str): if isinstance(time_string, str):
@@ -645,7 +640,7 @@ class LFCliBase:
optional = parser.add_argument_group('optional arguments') optional = parser.add_argument_group('optional arguments')
required = parser.add_argument_group('required arguments') required = parser.add_argument_group('required arguments')
#Optional Args # Optional Args
optional.add_argument('--mgr', optional.add_argument('--mgr',
default='localhost', default='localhost',
help='hostname for where LANforge GUI is running') help='hostname for where LANforge GUI is running')
@@ -687,13 +682,13 @@ class LFCliBase:
default=None, default=None,
help="Specify a file to send debug output to") help="Specify a file to send debug output to")
if more_optional is not None: if more_optional is not None:
for argument in more_optional: for argument in more_optional:
if 'default' in argument.keys(): if 'default' in argument.keys():
optional.add_argument(argument['name'], help=argument['help'], default=argument['default']) optional.add_argument(argument['name'], help=argument['help'], default=argument['default'])
else: else:
optional.add_argument(argument['name'], help=argument['help']) optional.add_argument(argument['name'], help=argument['help'])
#Required Args # Required Args
required.add_argument('--radio', required.add_argument('--radio',
help='radio EID, e.g: 1.wiphy2') help='radio EID, e.g: 1.wiphy2')
required.add_argument('--security', required.add_argument('--security',
@@ -736,7 +731,7 @@ class LFCliBase:
filename = open(filename, 'r') filename = open(filename, 'r')
return [line.split(',') for line in filename.readlines()] return [line.split(',') for line in filename.readlines()]
#Function creates random characters made of letters # Function creates random characters made of letters
@staticmethod @staticmethod
def random_chars(size, chars=None): def random_chars(size, chars=None):
if chars is None: if chars is None:
@@ -745,11 +740,11 @@ class LFCliBase:
@staticmethod @staticmethod
def get_milliseconds(timestamp): def get_milliseconds(timestamp):
return (timestamp - datetime.datetime(1970,1,1)).total_seconds()*1000 return (timestamp - datetime.datetime(1970, 1, 1)).total_seconds() * 1000
@staticmethod @staticmethod
def get_seconds(timestamp): def get_seconds(timestamp):
return (timestamp - datetime.datetime(1970,1,1)).total_seconds() return (timestamp - datetime.datetime(1970, 1, 1)).total_seconds()
@staticmethod @staticmethod
def replace_special_char(special_str): def replace_special_char(special_str):
@@ -770,4 +765,4 @@ class LFCliBase:
bgnAC : 11, bgnAC : 11,
abgnAX : 12, abgnAX : 12,
bgnAX : 13 bgnAX : 13
""" """