mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 20:27:54 +00:00
lf_check.py : white space only , pep8 (line length 150)
Signed-off-by: Chuck SmileyRekiere <chuck.smileyrekiere@candelatech.com>
This commit is contained in:
@@ -7,10 +7,11 @@ PURPOSE: lf_check.py run tests based on test rig json input, test dut json input
|
||||
|
||||
EXAMPLE:
|
||||
|
||||
./lf_check.py --json_rig <test rig json> --json_dut <dut_json> --json_test <tests json> --test_suite <suite_name> --path <path to results and db, db table>
|
||||
./lf_check.py --json_rig <test rig json> --json_dut <dut_json> --json_test <tests json> --test_suite <suite_name> --path <path to results> --production
|
||||
./lf_check.py --json_rig <rig_json> --json_dut <dut_json> --json_test <tests json> --test_suite <suite_name> --path <path to results>
|
||||
./lf_check.py --json_rig <rig_json> --json_dut <dut_json> --json_test <tests json> --test_suite <suite_name> --path <path to results> --production
|
||||
|
||||
./lf_check.py --json_rig ct_us_001_rig.json --json_dut ct_001_AX88U_dut.json --json_test ct_us_001_tests.json --suite "suite_wc_dp" --path '/home/lanforge/html-reports/ct-us-001'
|
||||
./lf_check.py --json_rig ct_us_001_rig.json --json_dut ct_001_AX88U_dut.json
|
||||
--json_test ct_us_001_tests.json --suite "suite_wc_dp" --path '/home/lanforge/html-reports/ct-us-001'
|
||||
|
||||
|
||||
rig is the LANforge
|
||||
@@ -86,6 +87,7 @@ Starting LANforge:
|
||||
|
||||
|
||||
'''
|
||||
|
||||
import datetime
|
||||
import sys
|
||||
import traceback
|
||||
@@ -112,7 +114,7 @@ import requests
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir))
|
||||
sys.path.insert(0, parent_dir_path)
|
||||
|
||||
# NOTE leave this line here for now
|
||||
from lf_report import lf_report
|
||||
|
||||
sys.path.append('/')
|
||||
@@ -177,7 +179,6 @@ class lf_check():
|
||||
self.lf_mgr_pass = "lanforge"
|
||||
self.upstream_port = ""
|
||||
|
||||
|
||||
# results
|
||||
self.database_sqlite = ""
|
||||
self.test_start_time = ""
|
||||
@@ -244,10 +245,13 @@ class lf_check():
|
||||
self.lf_mgr_user = "lanforge"
|
||||
self.lf_mgr_pass = "lanforge"
|
||||
'''
|
||||
|
||||
def get_lanforge_radio_information(self):
|
||||
# https://docs.python-requests.org/en/latest/
|
||||
# https://stackoverflow.com/questions/26000336/execute-curl-command-within-a-python-script - use requests
|
||||
# curl --user "lanforge:lanforge" -H 'Accept: application/json' http://192.168.100.116:8080/radiostatus/all | json_pp , where --user "USERNAME:PASSWORD"
|
||||
# curl --user "lanforge:lanforge" -H 'Accept: application/json'
|
||||
# http://192.168.100.116:8080/radiostatus/all | json_pp , where --user
|
||||
# "USERNAME:PASSWORD"
|
||||
request_command = 'http://{lfmgr}:{port}/radiostatus/all'.format(lfmgr=self.lf_mgr_ip, port=self.lf_mgr_port)
|
||||
request = requests.get(request_command, auth=(self.lf_mgr_user, self.lf_mgr_pass))
|
||||
print("radio request command: {request_command}".format(request_command=request_command))
|
||||
@@ -258,7 +262,6 @@ class lf_check():
|
||||
print("radio request.test: {text}".format(text=lanforge_radio_text))
|
||||
return lanforge_radio_json, lanforge_radio_text
|
||||
|
||||
|
||||
def get_lanforge_system_node_version(self):
|
||||
ssh = paramiko.SSHClient() # creating shh client object we use this object to connect to router
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # automatically adds the missing host key
|
||||
@@ -304,7 +307,8 @@ class lf_check():
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # automatically adds the missing host key
|
||||
ssh.connect(hostname=self.lf_mgr_ip, port=22, username=self.lf_mgr_user, password=self.lf_mgr_pass,
|
||||
allow_agent=False, look_for_keys=False, banner_timeout=600)
|
||||
stdin, stdout, stderr = ssh.exec_command('curl -H "Accept: application/json" http://{lanforge_ip}:8080 | json_pp | grep -A 7 "VersionInfo"'.format(lanforge_ip=self.lf_mgr_ip))
|
||||
stdin, stdout, stderr = ssh.exec_command(
|
||||
'curl -H "Accept: application/json" http://{lanforge_ip}:8080 | json_pp | grep -A 7 "VersionInfo"'.format(lanforge_ip=self.lf_mgr_ip))
|
||||
self.lanforge_gui_version_full = stdout.readlines()
|
||||
# print("lanforge_gui_version_full pre: {lanforge_gui_version_full}".format(lanforge_gui_version_full=self.lanforge_gui_version_full))
|
||||
self.lanforge_gui_version_full = [line.replace('\n', '') for line in self.lanforge_gui_version_full]
|
||||
@@ -328,7 +332,6 @@ class lf_check():
|
||||
time.sleep(1)
|
||||
return self.lanforge_gui_version_full, self.lanforge_gui_version, self.lanforge_gui_build_date, self.lanforge_gui_git_sha
|
||||
|
||||
|
||||
def send_results_email(self, report_file=None):
|
||||
if (report_file is None):
|
||||
print("No report file, not sending email.")
|
||||
@@ -600,7 +603,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
try:
|
||||
os.chdir(self.scripts_wd)
|
||||
# self.logger.info("Current Working Directory {}".format(os.getcwd()))
|
||||
except:
|
||||
except BaseException:
|
||||
self.logger.info("failed to change to {}".format(self.scripts_wd))
|
||||
|
||||
# no spaces after FACTORY_DFLT
|
||||
@@ -619,7 +622,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
def load_BLANK_database(self):
|
||||
try:
|
||||
os.chdir(self.scripts_wd)
|
||||
except:
|
||||
except BaseException:
|
||||
self.logger.info("failed to change to {}".format(self.scripts_wd))
|
||||
|
||||
# no spaces after FACTORY_DFLT
|
||||
@@ -638,7 +641,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
def load_custom_database(self, custom_db):
|
||||
try:
|
||||
os.chdir(self.scripts_wd)
|
||||
except:
|
||||
except BaseException:
|
||||
self.logger.info("failed to change to {}".format(self.scripts_wd))
|
||||
|
||||
# no spaces after FACTORY_DFLT
|
||||
@@ -684,13 +687,17 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
idx = "ssid_idx={}".format(ssid_idx_number) # index into the DUT network index
|
||||
print("idx: {}".format(idx))
|
||||
if 'SSID_USED' in args_list_element:
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace('SSID_USED', self.wireless_network_dict[idx]['SSID_USED'])
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace(
|
||||
'SSID_USED', self.wireless_network_dict[idx]['SSID_USED'])
|
||||
if 'SECURITY_USED' in args_list_element:
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace('SECURITY_USED', self.wireless_network_dict[idx]['SECURITY_USED'])
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace(
|
||||
'SECURITY_USED', self.wireless_network_dict[idx]['SECURITY_USED'])
|
||||
if 'SSID_PW_USED' in args_list_element:
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace('SSID_PW_USED', self.wireless_network_dict[idx]['SSID_PW_USED'])
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace(
|
||||
'SSID_PW_USED', self.wireless_network_dict[idx]['SSID_PW_USED'])
|
||||
if 'BSSID' in args_list_element:
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace('BSSID', self.wireless_network_dict[idx]['BSSID'])
|
||||
self.test_dict[test]['args_list'][index] = self.test_dict[test]['args_list'][index].replace(
|
||||
'BSSID', self.wireless_network_dict[idx]['BSSID'])
|
||||
|
||||
# use_ssid_idx is ephemeral and used only for variable replacement , remove
|
||||
tmp_idx = "use_ssid_idx={}".format(ssid_idx_number)
|
||||
@@ -700,7 +707,6 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
# leave in for checking the command line arguments
|
||||
print("self.test_dict[test]['args_list']: {}".format(self.test_dict[test]['args_list']))
|
||||
|
||||
|
||||
# Walk all the args in the args list then construct the arguments
|
||||
if self.test_dict[test]['args'] == "":
|
||||
self.test_dict[test]['args'] = self.test_dict[test]['args'].replace(self.test_dict[test]['args'],
|
||||
@@ -769,7 +775,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
self.test_dict[test]['load_db']).lower() != "skip":
|
||||
try:
|
||||
self.load_custom_database(self.test_dict[test]['load_db'])
|
||||
except:
|
||||
except BaseException:
|
||||
self.logger.info("custom database failed to load check existance and location: {}".format(
|
||||
self.test_dict[test]['load_db']))
|
||||
else:
|
||||
@@ -784,7 +790,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
try:
|
||||
self.load_custom_database(self.custom_db)
|
||||
self.logger.info("{} loaded between tests with scenario.py --load {}".format(self.custom_db, self.custom_db))
|
||||
except:
|
||||
except BaseException:
|
||||
self.logger.info("custom database failed to load check existance and location: {}".format(self.custom_db))
|
||||
else:
|
||||
self.logger.info("no db loaded between tests: {}".format(self.use_custom_db))
|
||||
@@ -792,7 +798,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
try:
|
||||
os.chdir(self.scripts_wd)
|
||||
# self.logger.info("Current Working Directory {}".format(os.getcwd()))
|
||||
except:
|
||||
except BaseException:
|
||||
self.logger.info("failed to change to {}".format(self.scripts_wd))
|
||||
cmd_args = "{}".format(self.test_dict[test]['args'])
|
||||
command = "./{} {}".format(self.test_dict[test]['command'], cmd_args)
|
||||
@@ -828,7 +834,7 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
process.terminate()
|
||||
self.test_result = "TIMEOUT"
|
||||
|
||||
except:
|
||||
except BaseException:
|
||||
print("No such file or directory with command: {}".format(command))
|
||||
self.logger.info("No such file or directory with command: {}".format(command))
|
||||
|
||||
@@ -873,10 +879,18 @@ NOTE: Diagrams are links in dashboard""".format(ip_qa=ip,qa_url=qa_url)
|
||||
meta_data_fd.write("test_tag {test_tag}\n".format(test_tag=test_tag))
|
||||
# LANforge information is a list thus [0]
|
||||
meta_data_fd.write('$ LANforge Information\n')
|
||||
meta_data_fd.write("lanforge_system_node {lanforge_system_node}\n".format(lanforge_system_node=self.lanforge_system_node_version[0]))
|
||||
meta_data_fd.write("lanforge_kernel_version {lanforge_kernel_version}\n".format(lanforge_kernel_version=self.lanforge_kernel_version[0]))
|
||||
meta_data_fd.write("lanforge_gui_version_full {lanforge_gui_version_full}\n".format(lanforge_gui_version_full=self.lanforge_gui_version_full))
|
||||
meta_data_fd.write("lanforge_server_version_full {lanforge_server_version_full}\n".format(lanforge_server_version_full=self.lanforge_server_version_full[0]))
|
||||
meta_data_fd.write(
|
||||
"lanforge_system_node {lanforge_system_node}\n".format(
|
||||
lanforge_system_node=self.lanforge_system_node_version[0]))
|
||||
meta_data_fd.write(
|
||||
"lanforge_kernel_version {lanforge_kernel_version}\n".format(
|
||||
lanforge_kernel_version=self.lanforge_kernel_version[0]))
|
||||
meta_data_fd.write(
|
||||
"lanforge_gui_version_full {lanforge_gui_version_full}\n".format(
|
||||
lanforge_gui_version_full=self.lanforge_gui_version_full))
|
||||
meta_data_fd.write(
|
||||
"lanforge_server_version_full {lanforge_server_version_full}\n".format(
|
||||
lanforge_server_version_full=self.lanforge_server_version_full[0]))
|
||||
meta_data_fd.close()
|
||||
|
||||
stderr_log_size = os.path.getsize(stderr_log_txt)
|
||||
@@ -1029,7 +1043,7 @@ note if all json data (rig,dut,tests) in same json file pass same json in for a
|
||||
print("args.json_rig {rig}".format(rig=args.json_rig))
|
||||
with open(args.json_rig, 'r') as json_rig_config:
|
||||
json_rig = json.load(json_rig_config)
|
||||
except:
|
||||
except BaseException:
|
||||
print("Error reading {}".format(args.json_rig))
|
||||
|
||||
json_dut = ""
|
||||
@@ -1037,7 +1051,7 @@ note if all json data (rig,dut,tests) in same json file pass same json in for a
|
||||
print("args.json_dut {dut}".format(dut=args.json_dut))
|
||||
with open(args.json_dut, 'r') as json_dut_config:
|
||||
json_dut = json.load(json_dut_config)
|
||||
except:
|
||||
except BaseException:
|
||||
print("Error reading {}".format(args.json_dut))
|
||||
|
||||
json_test = ""
|
||||
@@ -1045,7 +1059,7 @@ note if all json data (rig,dut,tests) in same json file pass same json in for a
|
||||
print("args.json_test {}".format(args.json_test))
|
||||
with open(args.json_test, 'r') as json_test_config:
|
||||
json_test = json.load(json_test_config)
|
||||
except:
|
||||
except BaseException:
|
||||
print("Error reading {}".format(args.json_test))
|
||||
|
||||
# Test-rig information information
|
||||
@@ -1116,33 +1130,33 @@ note if all json data (rig,dut,tests) in same json file pass same json in for a
|
||||
try:
|
||||
scripts_git_sha = check.get_scripts_git_sha()
|
||||
print("git_sha {sha}".format(sha=scripts_git_sha))
|
||||
except:
|
||||
except BaseException:
|
||||
print("git_sha read exception ")
|
||||
|
||||
try:
|
||||
lanforge_system_node_version = check.get_lanforge_system_node_version()
|
||||
print("lanforge_system_node_version {system_node_ver}".format(system_node_ver=lanforge_system_node_version))
|
||||
except:
|
||||
except BaseException:
|
||||
print("lanforge_system_node_version exception")
|
||||
|
||||
try:
|
||||
lanforge_kernel_version = check.get_lanforge_kernel_version()
|
||||
print("lanforge_kernel_version {kernel_ver}".format(kernel_ver=lanforge_kernel_version))
|
||||
except:
|
||||
except BaseException:
|
||||
print("lanforge_kernel_version exception, tests aborted check lanforge ip")
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
lanforge_server_version_full = check.get_lanforge_server_version()
|
||||
print("lanforge_server_version_full {lanforge_server_version_full}".format(lanforge_server_version_full=lanforge_server_version_full))
|
||||
except:
|
||||
except BaseException:
|
||||
print("lanforge_server_version exception, tests aborted check lanforge ip")
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
lanforge_gui_version_full, lanforge_gui_version, lanforge_gui_build_date, lanforge_gui_git_sha = check.get_lanforge_gui_version()
|
||||
print("lanforge_gui_version_full {lanforge_gui_version_full}".format(lanforge_gui_version_full=lanforge_gui_version_full))
|
||||
except:
|
||||
except BaseException:
|
||||
print("lanforge_gui_version exception, tests aborted check lanforge ip")
|
||||
exit(1)
|
||||
|
||||
@@ -1161,7 +1175,7 @@ note if all json data (rig,dut,tests) in same json file pass same json in for a
|
||||
driver = lanforge_radio_json[key]['driver'].split('Driver:', maxsplit=1)[-1].split(maxsplit=1)[0]
|
||||
try:
|
||||
firmware_version = lanforge_radio_json[key]['firmware version']
|
||||
except:
|
||||
except BaseException:
|
||||
print("5.4.3 radio fw version not in /radiostatus/all")
|
||||
firmware_version = "5.4.3 N/A"
|
||||
|
||||
@@ -1221,7 +1235,7 @@ note if all json data (rig,dut,tests) in same json file pass same json in for a
|
||||
print("html report: {}".format(html_report))
|
||||
try:
|
||||
report.write_pdf_with_timestamp()
|
||||
except:
|
||||
except BaseException:
|
||||
print("exception write_pdf_with_timestamp()")
|
||||
|
||||
print("lf_check_html_report: " + html_report)
|
||||
|
||||
Reference in New Issue
Block a user