From d1e4351b70a7a140f2f0f2372c794a42e65b9c95 Mon Sep 17 00:00:00 2001 From: Matthew Stidham Date: Thu, 24 Jun 2021 16:53:22 -0700 Subject: [PATCH] test rig command and other improvements to automation Signed-off-by: Matthew Stidham --- py-dashboard/GhostRequest.py | 76 ++++++++++++++++++++++++++--- py-json/cv_test_reports.py | 2 +- py-scripts/lf_dataplane_test.py | 9 +++- py-scripts/lf_wifi_capacity_test.py | 9 +++- 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/py-dashboard/GhostRequest.py b/py-dashboard/GhostRequest.py index 993f8764..8ebaf300 100644 --- a/py-dashboard/GhostRequest.py +++ b/py-dashboard/GhostRequest.py @@ -21,6 +21,7 @@ from scp import SCPClient import paramiko from GrafanaRequest import GrafanaRequest import time +from collections import Counter class CSVReader: @@ -45,6 +46,50 @@ class CSVReader: values.append(row[index]) return values + def get_columns(self, df, targets): + target_index = [] + for item in targets: + target_index.append(df[0].index(item)) + results = [] + for row in df: + row_data = [] + for x in target_index: + row_data.append(row[x]) + results.append(row_data) + return results + + def to_html(self, df): + html = '' + html = html + ('') + for row in df: + for item in row: + html = html + ('' % item) + html = html + ('\n') + html = html + ('
%s
') + return html + + def filter_df(self, df, column, expression, target): + target_index = df[0].index(column) + counter = 0 + targets = [0] + for row in df: + try: + if expression == 'less than': + if float(row[target_index]) <= target: + targets.append(counter) + counter += 1 + else: + counter += 1 + if expression == 'greater than': + if float(row[target_index]) >= target: + targets.append(counter) + counter += 1 + else: + counter += 1 + except: + counter += 1 + return list(map(df.__getitem__, targets)) + class GhostRequest: def __init__(self, @@ -176,6 +221,7 @@ class GhostRequest: ) if test_run is None: test_run = sorted(folders)[0].split('/')[-1].strip('/') + print(folders) for folder in folders: print(folder) ssh_pull = paramiko.SSHClient() @@ -196,6 +242,13 @@ class GhostRequest: print('target file %s' % target_file) df = csvreader.read_csv(file=target_file, sep='\t') csv_testbed = csvreader.get_column(df, 'test-rig')[0] + pass_fail = Counter(csvreader.get_column(df, 'pass/fail')) + if pass_fail['PASS'] + pass_fail['FAIL'] > 0: + text = text + 'Tests passed: %s
' % pass_fail['PASS'] + text = text + 'Tests failed: %s
' % pass_fail['FAIL'] + text = text + 'Percentage of tests passed: %s
' % ( + pass_fail['PASS'] / (pass_fail['PASS'] + pass_fail['FAIL'])) + print(csv_testbed) except: pass @@ -215,17 +268,17 @@ class GhostRequest: allow_agent=False, look_for_keys=False) scp_push = SCPClient(ssh_push.get_transport()) - local_path = '/home/%s/%s/%s/%s' % (user_push, customer, testbed, test_run) + local_path = '/home/%s/%s/%s' % (user_push, customer, testbed) transport = paramiko.Transport((ghost_host, port)) transport.connect(None, user_push, password_push) sftp = paramiko.sftp_client.SFTPClient.from_transport(transport) - print(local_path) + print('Local Path: %s' % local_path) try: sftp.mkdir(local_path) - scp_push.put(target_folder, recursive=True, remote_path=local_path) except: print('folder %s already exists' % local_path) - print(target_folder) + scp_push.put(target_folder, recursive=True, remote_path=local_path) + print(local_path + '/' + target_folder) files = sftp.listdir(local_path + '/' + target_folder) # print('Files: %s' % files) for file in files: @@ -251,7 +304,17 @@ class GhostRequest: time.sleep(3) snapshot = grafana.list_snapshots()[-1] print(snapshot) - text = text + '' % (grafana_host, snapshot['key'], '%') + text = text + '
' % ( + grafana_host, snapshot['key'], '%') + + results = csvreader.get_columns(df,['short-description','numeric-score','test details','test-priority']) + + low_priority = csvreader.to_html(csvreader.filter_df(results, 'test-priority', 'less than', 94)) + high_priority = csvreader.to_html(csvreader.filter_df(results, 'test-priority', 'greater than', 95)) + + text = text + 'High priority results: %s' % high_priority + + text = text + 'Low priority results: %s' % low_priority now = date.now() @@ -261,7 +324,8 @@ class GhostRequest: # create Grafana Dashboard target_files = [] for folder in folders: - target_files.append(folder.strip('/home/lanforge/html-reports/') + '/kpi.csv') + print(folder) + target_files.append(folder.split('/')[-1] + '/kpi.csv') grafana.create_custom_dashboard(target_csvs=target_files, title=title) diff --git a/py-json/cv_test_reports.py b/py-json/cv_test_reports.py index e385057d..4589b18b 100644 --- a/py-json/cv_test_reports.py +++ b/py-json/cv_test_reports.py @@ -9,7 +9,7 @@ class lanforge_reports: ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(hostname=hostname, username=username, password=password, port=port) + ssh.connect(hostname=hostname, username=username, password=password, port=port, allow_agent=False, look_for_keys=False) with SCPClient(ssh.get_transport()) as scp: scp.get(remote_path=report_location, local_path=local_path, recursive=True) diff --git a/py-scripts/lf_dataplane_test.py b/py-scripts/lf_dataplane_test.py index 40b44f1a..987f0f0f 100755 --- a/py-scripts/lf_dataplane_test.py +++ b/py-scripts/lf_dataplane_test.py @@ -138,7 +138,8 @@ class DataplaneTest(cv_test): raw_lines_file="", sets=[], graph_groups=None, - report_dir="" + report_dir="", + test_rig="" ): super().__init__(lfclient_host=lf_host, lfclient_port=lf_port) @@ -166,6 +167,7 @@ class DataplaneTest(cv_test): self.report_dir = report_dir self.ssh_port = ssh_port self.local_path = local_path + self.test_rig = test_rig def setup(self): # Nothing to do at this time. @@ -200,6 +202,8 @@ class DataplaneTest(cv_test): cfg_options.append("duration: " + self.duration) if self.dut != "": cfg_options.append("selected_dut: " + self.dut) + if self.test_rig != "": + cfg_options.append("test_rig: " + self.test_rig) # We deleted the scenario earlier, now re-build new one line at a time. @@ -386,7 +390,8 @@ def main(): raw_lines = args.raw_line, raw_lines_file = args.raw_lines_file, sets = args.set, - graph_groups = args.graph_groups + graph_groups = args.graph_groups, + test_rig=args.test_rig ) CV_Test.setup() CV_Test.run() diff --git a/py-scripts/lf_wifi_capacity_test.py b/py-scripts/lf_wifi_capacity_test.py index 24364cc6..cde82781 100755 --- a/py-scripts/lf_wifi_capacity_test.py +++ b/py-scripts/lf_wifi_capacity_test.py @@ -353,7 +353,8 @@ class WiFiCapacityTest(cv_test): influx_host="localhost", influx_port=8086, report_dir="", - graph_groups=None + graph_groups=None, + test_rig="" ): super().__init__(lfclient_host=lfclient_host, lfclient_port=lf_port) @@ -390,6 +391,7 @@ class WiFiCapacityTest(cv_test): self.influx_port = influx_port self.report_dir = report_dir self.graph_groups = graph_groups + self.test_rig = test_rig def setup(self): if self.create_stations and self.stations != "": @@ -445,6 +447,8 @@ class WiFiCapacityTest(cv_test): cfg_options.append("ul_rate: " + self.upload_rate) if self.download_rate != "": cfg_options.append("dl_rate: " + self.download_rate) + if self.test_rig != "": + cfg_options.append("test_rig: " + self.test_rig) cfg_options.append("save_csv: 1") @@ -550,7 +554,8 @@ def main(): raw_lines=args.raw_line, raw_lines_file=args.raw_lines_file, sets=args.set, - graph_groups=args.graph_groups + graph_groups=args.graph_groups, + test_rig=args.test_rig ) WFC_Test.setup() WFC_Test.run()