mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 03:07:56 +00:00
test rig command and other improvements to automation
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ from scp import SCPClient
|
|||||||
import paramiko
|
import paramiko
|
||||||
from GrafanaRequest import GrafanaRequest
|
from GrafanaRequest import GrafanaRequest
|
||||||
import time
|
import time
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
|
||||||
class CSVReader:
|
class CSVReader:
|
||||||
@@ -45,6 +46,50 @@ class CSVReader:
|
|||||||
values.append(row[index])
|
values.append(row[index])
|
||||||
return values
|
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 + ('<table style="border:1px solid #ddd"><tr>')
|
||||||
|
for row in df:
|
||||||
|
for item in row:
|
||||||
|
html = html + ('<td style="border:1px solid #ddd">%s</td>' % item)
|
||||||
|
html = html + ('</tr>\n<tr>')
|
||||||
|
html = html + ('</table>')
|
||||||
|
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:
|
class GhostRequest:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@@ -176,6 +221,7 @@ class GhostRequest:
|
|||||||
)
|
)
|
||||||
if test_run is None:
|
if test_run is None:
|
||||||
test_run = sorted(folders)[0].split('/')[-1].strip('/')
|
test_run = sorted(folders)[0].split('/')[-1].strip('/')
|
||||||
|
print(folders)
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
print(folder)
|
print(folder)
|
||||||
ssh_pull = paramiko.SSHClient()
|
ssh_pull = paramiko.SSHClient()
|
||||||
@@ -196,6 +242,13 @@ class GhostRequest:
|
|||||||
print('target file %s' % target_file)
|
print('target file %s' % target_file)
|
||||||
df = csvreader.read_csv(file=target_file, sep='\t')
|
df = csvreader.read_csv(file=target_file, sep='\t')
|
||||||
csv_testbed = csvreader.get_column(df, 'test-rig')[0]
|
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<br />' % pass_fail['PASS']
|
||||||
|
text = text + 'Tests failed: %s<br />' % pass_fail['FAIL']
|
||||||
|
text = text + 'Percentage of tests passed: %s<br />' % (
|
||||||
|
pass_fail['PASS'] / (pass_fail['PASS'] + pass_fail['FAIL']))
|
||||||
|
|
||||||
print(csv_testbed)
|
print(csv_testbed)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -215,17 +268,17 @@ class GhostRequest:
|
|||||||
allow_agent=False,
|
allow_agent=False,
|
||||||
look_for_keys=False)
|
look_for_keys=False)
|
||||||
scp_push = SCPClient(ssh_push.get_transport())
|
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 = paramiko.Transport((ghost_host, port))
|
||||||
transport.connect(None, user_push, password_push)
|
transport.connect(None, user_push, password_push)
|
||||||
sftp = paramiko.sftp_client.SFTPClient.from_transport(transport)
|
sftp = paramiko.sftp_client.SFTPClient.from_transport(transport)
|
||||||
print(local_path)
|
print('Local Path: %s' % local_path)
|
||||||
try:
|
try:
|
||||||
sftp.mkdir(local_path)
|
sftp.mkdir(local_path)
|
||||||
scp_push.put(target_folder, recursive=True, remote_path=local_path)
|
|
||||||
except:
|
except:
|
||||||
print('folder %s already exists' % local_path)
|
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)
|
files = sftp.listdir(local_path + '/' + target_folder)
|
||||||
# print('Files: %s' % files)
|
# print('Files: %s' % files)
|
||||||
for file in files:
|
for file in files:
|
||||||
@@ -251,7 +304,17 @@ class GhostRequest:
|
|||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
snapshot = grafana.list_snapshots()[-1]
|
snapshot = grafana.list_snapshots()[-1]
|
||||||
print(snapshot)
|
print(snapshot)
|
||||||
text = text + '<iframe src="http://%s:3000/dashboard/snapshot/%s" width="100%s" height=1500></iframe>' % (grafana_host, snapshot['key'], '%')
|
text = text + '<iframe src="http://%s:3000/dashboard/snapshot/%s" width="100%s" height=1500></iframe><br />' % (
|
||||||
|
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()
|
now = date.now()
|
||||||
|
|
||||||
@@ -261,7 +324,8 @@ class GhostRequest:
|
|||||||
# create Grafana Dashboard
|
# create Grafana Dashboard
|
||||||
target_files = []
|
target_files = []
|
||||||
for folder in folders:
|
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,
|
grafana.create_custom_dashboard(target_csvs=target_files,
|
||||||
title=title)
|
title=title)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class lanforge_reports:
|
|||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
ssh.load_system_host_keys()
|
ssh.load_system_host_keys()
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
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:
|
with SCPClient(ssh.get_transport()) as scp:
|
||||||
scp.get(remote_path=report_location, local_path=local_path, recursive=True)
|
scp.get(remote_path=report_location, local_path=local_path, recursive=True)
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ class DataplaneTest(cv_test):
|
|||||||
raw_lines_file="",
|
raw_lines_file="",
|
||||||
sets=[],
|
sets=[],
|
||||||
graph_groups=None,
|
graph_groups=None,
|
||||||
report_dir=""
|
report_dir="",
|
||||||
|
test_rig=""
|
||||||
):
|
):
|
||||||
super().__init__(lfclient_host=lf_host, lfclient_port=lf_port)
|
super().__init__(lfclient_host=lf_host, lfclient_port=lf_port)
|
||||||
|
|
||||||
@@ -166,6 +167,7 @@ class DataplaneTest(cv_test):
|
|||||||
self.report_dir = report_dir
|
self.report_dir = report_dir
|
||||||
self.ssh_port = ssh_port
|
self.ssh_port = ssh_port
|
||||||
self.local_path = local_path
|
self.local_path = local_path
|
||||||
|
self.test_rig = test_rig
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
# Nothing to do at this time.
|
# Nothing to do at this time.
|
||||||
@@ -200,6 +202,8 @@ class DataplaneTest(cv_test):
|
|||||||
cfg_options.append("duration: " + self.duration)
|
cfg_options.append("duration: " + self.duration)
|
||||||
if self.dut != "":
|
if self.dut != "":
|
||||||
cfg_options.append("selected_dut: " + 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.
|
# 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 = args.raw_line,
|
||||||
raw_lines_file = args.raw_lines_file,
|
raw_lines_file = args.raw_lines_file,
|
||||||
sets = args.set,
|
sets = args.set,
|
||||||
graph_groups = args.graph_groups
|
graph_groups = args.graph_groups,
|
||||||
|
test_rig=args.test_rig
|
||||||
)
|
)
|
||||||
CV_Test.setup()
|
CV_Test.setup()
|
||||||
CV_Test.run()
|
CV_Test.run()
|
||||||
|
|||||||
@@ -353,7 +353,8 @@ class WiFiCapacityTest(cv_test):
|
|||||||
influx_host="localhost",
|
influx_host="localhost",
|
||||||
influx_port=8086,
|
influx_port=8086,
|
||||||
report_dir="",
|
report_dir="",
|
||||||
graph_groups=None
|
graph_groups=None,
|
||||||
|
test_rig=""
|
||||||
):
|
):
|
||||||
super().__init__(lfclient_host=lfclient_host, lfclient_port=lf_port)
|
super().__init__(lfclient_host=lfclient_host, lfclient_port=lf_port)
|
||||||
|
|
||||||
@@ -390,6 +391,7 @@ class WiFiCapacityTest(cv_test):
|
|||||||
self.influx_port = influx_port
|
self.influx_port = influx_port
|
||||||
self.report_dir = report_dir
|
self.report_dir = report_dir
|
||||||
self.graph_groups = graph_groups
|
self.graph_groups = graph_groups
|
||||||
|
self.test_rig = test_rig
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
if self.create_stations and self.stations != "":
|
if self.create_stations and self.stations != "":
|
||||||
@@ -445,6 +447,8 @@ class WiFiCapacityTest(cv_test):
|
|||||||
cfg_options.append("ul_rate: " + self.upload_rate)
|
cfg_options.append("ul_rate: " + self.upload_rate)
|
||||||
if self.download_rate != "":
|
if self.download_rate != "":
|
||||||
cfg_options.append("dl_rate: " + 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")
|
cfg_options.append("save_csv: 1")
|
||||||
|
|
||||||
@@ -550,7 +554,8 @@ def main():
|
|||||||
raw_lines=args.raw_line,
|
raw_lines=args.raw_line,
|
||||||
raw_lines_file=args.raw_lines_file,
|
raw_lines_file=args.raw_lines_file,
|
||||||
sets=args.set,
|
sets=args.set,
|
||||||
graph_groups=args.graph_groups
|
graph_groups=args.graph_groups,
|
||||||
|
test_rig=args.test_rig
|
||||||
)
|
)
|
||||||
WFC_Test.setup()
|
WFC_Test.setup()
|
||||||
WFC_Test.run()
|
WFC_Test.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user