From c2cc40708abb745a0113830244ace06140d60174 Mon Sep 17 00:00:00 2001 From: Matthew Stidham Date: Thu, 6 May 2021 10:38:31 -0700 Subject: [PATCH] Properly load scenario, run wifi capacity test, scp kpi file to localhost, and save to grafana. Signed-off-by: Matthew Stidham --- py-json/cv_test_manager.py | 17 ++-- py-scripts/csv_to_influx.py | 15 +--- py-scripts/lf_wifi_capacity_test.py | 50 +++++++----- py-scripts/wifi_cap_to_grafana.py | 121 ++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+), 42 deletions(-) create mode 100755 py-scripts/wifi_cap_to_grafana.py diff --git a/py-json/cv_test_manager.py b/py-json/cv_test_manager.py index 8dfed5a5..83690dae 100644 --- a/py-json/cv_test_manager.py +++ b/py-json/cv_test_manager.py @@ -66,10 +66,11 @@ class cv_test(Realm): def __init__(self, lfclient_host="localhost", lfclient_port=8080, + report_dir="" ): super().__init__(lfclient_host=lfclient_host, lfclient_port=lfclient_port) - self.report_dir="" + self.report_dir = report_dir # Add a config line to a text blob. Will create new text blob # if none exists already. @@ -321,7 +322,7 @@ class cv_test(Realm): exit(1) not_running = 0 - while (True): + while True: cmd = "cv get_and_close_dialog" dialog = self.run_cv_cmd(cmd); if dialog[0]["LAST"]["response"] != "NO-DIALOG": @@ -330,16 +331,18 @@ class cv_test(Realm): check = self.get_report_location(instance_name) location = json.dumps(check[0]["LAST"]["response"]) - if location != "\"Report Location:::\"": - location = location.replace("Report Location:::", "") - location = location.strip("\"") + if location != '\"Report Location:::\"': + print(location) + location = location.replace('\"Report Location:::', '') + location = location.replace('\"', '') report = lf_rpt() print(location) + self.report_dir = location try: if pull_report: + print(lf_host) report.pull_reports(hostname=lf_host, username=lf_user, password=lf_password, report_location=location) - self.report_dir=location except: raise Exception("Could not find Reports") break @@ -357,7 +360,7 @@ class cv_test(Realm): self.delete_instance(instance_name) # Clean up any remaining popups. - while (True): + while True: dialog = self.run_cv_cmd(cmd); if dialog[0]["LAST"]["response"] != "NO-DIALOG": print("Popup Dialog:\n") diff --git a/py-scripts/csv_to_influx.py b/py-scripts/csv_to_influx.py index df924b5b..a2f2c160 100755 --- a/py-scripts/csv_to_influx.py +++ b/py-scripts/csv_to_influx.py @@ -19,7 +19,6 @@ if 'py-json' not in sys.path: sys.path.append(os.path.join(os.path.abspath('..'), 'py-json')) import argparse -from realm import Realm import datetime def influx_add_parser_args(parser): @@ -32,11 +31,8 @@ def influx_add_parser_args(parser): help='--influx_tag Can add more than one of these.', default=[]) -class CSVtoInflux(Realm): +class CSVtoInflux(): def __init__(self, - lfclient_host="localhost", - lfclient_port=8080, - debug=False, _exit_on_error=False, _exit_on_fail=False, _proxy_str=None, @@ -44,15 +40,8 @@ class CSVtoInflux(Realm): influxdb=None, _influx_tag=[], target_csv=None): - super().__init__(lfclient_host=lfclient_host, - lfclient_port=lfclient_port, - debug_=debug, - _exit_on_error=_exit_on_error, - _exit_on_fail=_exit_on_fail, - _proxy_str=_proxy_str, - _capture_signal_list=_capture_signal_list) self.influxdb = influxdb - self.target_csv = target_csv + self.target_csv = target_csv.replace('/home/lanforge/html-reports/', '') self.influx_tag = _influx_tag # Submit data to the influx db if configured to do so. diff --git a/py-scripts/lf_wifi_capacity_test.py b/py-scripts/lf_wifi_capacity_test.py index e7525b18..0cd35a24 100755 --- a/py-scripts/lf_wifi_capacity_test.py +++ b/py-scripts/lf_wifi_capacity_test.py @@ -315,13 +315,14 @@ if sys.version_info[0] != 3: if 'py-json' not in sys.path: sys.path.append(os.path.join(os.path.abspath('..'), 'py-json')) -from cv_test_manager import cv_test as cvtest +from cv_test_manager import cv_test from cv_test_manager import * from LANforge import LFUtils -class WiFiCapacityTest(cvtest): + +class WiFiCapacityTest(cv_test): def __init__(self, - lf_host="localhost", + lfclient_host="localhost", lf_port=8080, lf_user="lanforge", lf_password="lanforge", @@ -348,13 +349,16 @@ class WiFiCapacityTest(cvtest): raw_lines=[], raw_lines_file="", sets=[], + influx_host="localhost", + influx_port=8086, + report_dir="" ): - super().__init__(lfclient_host=lf_host, lfclient_port=lf_port) + super().__init__(lfclient_host=lfclient_host, lfclient_port=lf_port) - self.lf_host = lf_host + self.lfclient_host = lfclient_host self.lf_port = lf_port self.lf_user = lf_user - self.lf_password =lf_password + self.lf_password = lf_password self.station_profile = self.new_station_profile() self.pull_report = pull_report self.load_old_cfg = load_old_cfg @@ -370,7 +374,7 @@ class WiFiCapacityTest(cvtest): self.upstream = upstream self.sort = sort self.stations = stations - self.create_stations =create_stations + self.create_stations = create_stations self.security = security self.ssid = ssid self.paswd = paswd @@ -380,6 +384,9 @@ class WiFiCapacityTest(cvtest): self.raw_lines = raw_lines self.raw_lines_file = raw_lines_file self.sets = sets + self.influx_host = influx_host, + self.influx_port = influx_port + self.report_dir=report_dir def setup(self): if self.create_stations and self.stations != "": @@ -391,7 +398,6 @@ class WiFiCapacityTest(cvtest): self.wait_for_ip(station_list=sta) print("stations created") - def run(self): self.sync_cv() time.sleep(2) @@ -403,10 +409,9 @@ class WiFiCapacityTest(cvtest): # Test related settings cfg_options = [] - eid = LFUtils.name_to_eid(self.upstream) - port = "%i.%i.%s"%(eid[0], eid[1], eid[2]) - + port = "%i.%i.%s" % (eid[0], eid[1], eid[2]) + port_list = [port] if self.stations == "": stas = self.station_map() # See realm @@ -454,7 +459,7 @@ class WiFiCapacityTest(cvtest): self.create_and_run_test(self.load_old_cfg, self.test_name, self.instance_name, self.config_name, self.sets, - self.pull_report, self.lf_host, self.lf_user, self.lf_password, + self.pull_report, self.lfclient_host, self.lf_user, self.lf_password, cv_cmds) self.rm_text_blob(self.config_name, blob_test) # To delete old config with same name @@ -463,7 +468,6 @@ class WiFiCapacityTest(cvtest): def main(): - parser = argparse.ArgumentParser( description=""" ./lf_wifi_capacity_test.py --mgr localhost --port 8080 --lf_user lanforge --lf_password lanforge \ @@ -507,11 +511,13 @@ def main(): help="ssid Security type") parser.add_argument("-paswd", "--paswd", default="[BLANK]", help="ssid Password") + parser.add_argument("--report_dir",default="") + parser.add_argument("--scenario",default="") args = parser.parse_args() cv_base_adjust_parser(args) - WFC_Test = WiFiCapacityTest(lf_host=args.mgr, + WFC_Test = WiFiCapacityTest(lfclient_host=args.mgr, lf_port=args.port, lf_user=args.lf_user, lf_password=args.lf_password, @@ -529,15 +535,15 @@ def main(): sort=args.sort, stations=args.stations, create_stations=args.create_stations, - radio =args.radio, + radio=args.radio, ssid=args.ssid, - security =args.security, - paswd =args.paswd, - enables = args.enable, - disables = args.disable, - raw_lines = args.raw_line, - raw_lines_file = args.raw_lines_file, - sets = args.set + security=args.security, + paswd=args.paswd, + enables=args.enable, + disables=args.disable, + raw_lines=args.raw_line, + raw_lines_file=args.raw_lines_file, + sets=args.set, ) WFC_Test.setup() WFC_Test.run() diff --git a/py-scripts/wifi_cap_to_grafana.py b/py-scripts/wifi_cap_to_grafana.py new file mode 100755 index 00000000..c4183047 --- /dev/null +++ b/py-scripts/wifi_cap_to_grafana.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 + +import sys +import os +import argparse + +if sys.version_info[0] != 3: + print("This script requires Python 3") + exit(1) + +if 'py-json' not in sys.path: + sys.path.append(os.path.join(os.path.abspath('..'), 'py-json')) + sys.path.append(os.path.join(os.path.abspath('..'), 'py-dashboard')) + +from LANforge.lfcli_base import LFCliBase +from LANforge import LFUtils +import json +from csv_to_grafana import CSVtoInflux +from create_l3 import CreateL3 +from lf_wifi_capacity_test import WiFiCapacityTest +from cv_test_manager import * + +def main(): + parser = argparse.ArgumentParser( + prog='wifi_cap_to_grafana.py', + formatter_class=argparse.RawTextHelpFormatter, + epilog='''Run Wifi Capacity and record results to Grafana''', + description='''\ + wifi_cap_to_grafana.py + ------------------ + ./wifi_cap_to_grafana.py + --num_stations + --grafana_token + --influx_host + --influx_org + --influx_token + --influx_bucket + --target_csv + --panel_name''' + ) + + cv_add_base_parser(parser) # see cv_test_manager.py + + parser.add_argument("-b", "--batch_size", type=str, default="", + help="station increment ex. 1,2,3") + parser.add_argument("-l", "--loop_iter", type=str, default="", + help="Loop iteration ex. 1") + parser.add_argument("-p", "--protocol", type=str, default="", + help="Protocol ex.TCP-IPv4") + parser.add_argument("-d", "--duration", type=str, default="", + help="duration in ms. ex. 5000") + parser.add_argument("--download_rate", type=str, default="1Gbps", + help="Select requested download rate. Kbps, Mbps, Gbps units supported. Default is 1Gbps") + parser.add_argument("--upload_rate", type=str, default="10Mbps", + help="Select requested upload rate. Kbps, Mbps, Gbps units supported. Default is 10Mbps") + parser.add_argument("--sort", type=str, default="interleave", + help="Select station sorting behaviour: none | interleave | linear Default is interleave.") + parser.add_argument("-s", "--stations", type=str, default="", + help="If specified, these stations will be used. If not specified, all available stations will be selected. Example: 1.1.sta001,1.1.wlan0,...") + parser.add_argument("-cs", "--create_stations", default=False, action='store_true', + help="create stations in lanforge (by default: False)") + parser.add_argument('--a_min', help='--a_min bps rate minimum for side_a', default=256000) + parser.add_argument('--b_min', help='--b_min bps rate minimum for side_b', default=256000) + parser.add_argument('--number_template', help='Start the station numbering with a particular number. Default is 0000', + default=0000) + parser.add_argument('--mode', help='Used to force mode of stations') + parser.add_argument('--ap', help='Used to force a connection to a particular AP') + parser.add_argument("-radio", "--radio", default="wiphy0", + help="create stations in lanforge at this radio (by default: wiphy0)") + parser.add_argument("-ssid", "--ssid", default="", + help="ssid name") + parser.add_argument("-security", "--security", default="open", + help="ssid Security type") + parser.add_argument("-passwd", "--passwd", default="[BLANK]", + help="ssid Password") + parser.add_argument("--num_stations", default=2) + parser.add_argument("--mgr_port", default=8080) + parser.add_argument("--upstream_port", default="1.1.eth1") + parser.add_argument("--debug", default=False) + parser.add_argument("--scenario", help="", default=None) + args = parser.parse_args() + + + cv_base_adjust_parser(args) + + # Run WiFi Capacity Test + wifi_capacity = WiFiCapacityTest(lfclient_host=args.mgr, + lf_port=args.mgr_port, + lf_user=args.lf_user, + lf_password=args.lf_password, + instance_name=args.instance_name, + config_name=args.config_name, + upstream=args.upstream_port, + batch_size=args.batch_size, + loop_iter=args.loop_iter, + protocol=args.protocol, + duration=args.duration, + pull_report=args.pull_report, + load_old_cfg=args.load_old_cfg, + download_rate=args.download_rate, + upload_rate=args.upload_rate, + sort=args.sort, + stations=args.stations, + create_stations=args.create_stations, + radio=args.radio, + ssid=args.ssid, + security=args.security, + paswd=args.passwd, + enables=args.enable, + disables=args.disable, + raw_lines=args.raw_line, + raw_lines_file=args.raw_lines_file, + sets=args.set) + wifi_capacity.apply_cv_scenario(args.scenario) + wifi_capacity.build_cv_scenario() + wifi_capacity.setup() + wifi_capacity.run() + wifi_capacity.check_influx_kpi(args) + +if __name__ == "__main__": + main() \ No newline at end of file