diff --git a/py-json/cv_test_manager.py b/py-json/cv_test_manager.py index 66d52f18..878807b2 100644 --- a/py-json/cv_test_manager.py +++ b/py-json/cv_test_manager.py @@ -11,6 +11,7 @@ import json from pprint import pprint import argparse from cv_test_reports import lanforge_reports as lf_rpt +from csv_to_influx import * def cv_base_adjust_parser(args): if args.test_rig != "": @@ -52,6 +53,8 @@ def cv_add_base_parser(parser): parser.add_argument("--test_rig", default="", help="Specify the test rig info for reporting purposes, for instance: testbed-01") + influx_add_parser_args(parser) # csv_to_influx + class cv_test(Realm): def __init__(self, @@ -60,6 +63,7 @@ class cv_test(Realm): ): super().__init__(lfclient_host=lfclient_host, lfclient_port=lfclient_port) + self.report_dir="" # Add a config line to a text blob. Will create new text blob # if none exists already. @@ -242,6 +246,20 @@ class cv_test(Realm): # the text blob. time.sleep(5) + # load_old_config is boolean + # test_name is specific to the type of test being launched (Dataplane, tr398, etc) + # ChamberViewFrame.java has list of supported test names. + # instance_name is per-test instance, it does not matter much, just use the same name + # throughout the entire run of the test. + # config_name what to call the text-blob that configures the test. Does not matter much + # since we (re)create it during the run. + # sets: Arrany of [key,value] pairs. The key is the widget name, typically the label + # before the entry field. + # pull_report: Boolean, should we download the report to current working directory. + # lf_host: LANforge machine running the GUI. + # lf_password: Password for LANforge machine running the GUI. + # cv_cmds: Array of raw chamber-view commands, such as "cv click 'button-name'" + # These (and the sets) are applied after the test is created and before it is started. def create_and_run_test(self, load_old_cfg, test_name, instance_name, config_name, sets, pull_report, lf_host, lf_user, lf_password, cv_cmds): load_old = "false" @@ -299,6 +317,7 @@ class cv_test(Realm): if pull_report: 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 @@ -323,3 +342,30 @@ class cv_test(Realm): print(dialog[0]["LAST"]["response"]) else: break + + + # Takes cmd-line args struct or something that looks like it. + # See csv_to_influx.py::influx_add_parser_args for options, or --help. + def check_influx_kpi(self, args): + if self.report_dir == "": + # Nothing to report on. + return + + if args.influx_host == "": + # No influx configured, return. + return + + # lfjson_host would be if we are reading out of LANforge or some other REST + # source, which we are not. So dummy those out. + influxdb = RecordInflux(_lfjson_host = "", + _lfjson_port = "", + _influx_host = args.influx_host, + _influx_port = args.influx_port, + _influx_org = args.influx_org, + _influx_token = args.influx_token, + _influx_bucket = args.influx_bucket) + + csvtoinflux = CSVtoInflux(influxdb = influxdb, + target_csv = "%s/kpi.csv"%(self.report_dir), + _influx_tag = args.influx_tag) + csvtoinflux.post_to_influx() diff --git a/py-scripts/csv_to_influx.py b/py-scripts/csv_to_influx.py index 1d5e767b..715db62b 100755 --- a/py-scripts/csv_to_influx.py +++ b/py-scripts/csv_to_influx.py @@ -9,6 +9,7 @@ import sys import os from pprint import pprint +from influx2 import RecordInflux if sys.version_info[0] != 3: print("This script requires Python 3") @@ -21,6 +22,15 @@ import argparse from realm import Realm import datetime +def influx_add_parser_args(parser): + parser.add_argument('--influx_host', help='Hostname for the Influx database', default="") + parser.add_argument('--influx_port', help='IP Port for the Influx database', default=8086) + parser.add_argument('--influx_org', help='Organization for the Influx database', default="") + parser.add_argument('--influx_token', help='Token for the Influx database', default="") + parser.add_argument('--influx_bucket', help='Name of the Influx bucket', default="") + parser.add_argument('--influx_tag', action='append', nargs=2, + help='--influx_tag Can add more than one of these.', default=[]) + class CSVtoInflux(Realm): def __init__(self, @@ -125,27 +135,21 @@ python3 csv_to_influx.py --influx_host localhost --influx_org Candela --influx_t ''') - parser.add_argument('--influx_host', help='Hostname for the Influx database') - parser.add_argument('--influx_port', help='IP Port for the Influx database', default=8086) - parser.add_argument('--influx_org', help='Organization for the Influx database') - parser.add_argument('--influx_token', help='Token for the Influx database') - parser.add_argument('--influx_bucket', help='Name of the Influx bucket') - parser.add_argument('--target_csv', help='CSV file to record to influx database', required=True) - parser.add_argument('--influx_tag', action='append', nargs=2, - help='--influx_tag Can add more than one of these.', default=[]) + influx_add_parser_args(parser) + + # This argument is specific to this script, so not part of the generic influxdb parser args + # method above. + parser.add_argument('--target_csv', help='CSV file to record to influx database', default="") args = parser.parse_args() - influxdb = None - if args.influx_bucket is not None: - from influx2 import RecordInflux - influxdb = RecordInflux(_lfjson_host=lfjson_host, - _lfjson_port=lfjson_port, - _influx_host=args.influx_host, - _influx_port=args.influx_port, - _influx_org=args.influx_org, - _influx_token=args.influx_token, - _influx_bucket=args.influx_bucket) + influxdb = RecordInflux(_lfjson_host=lfjson_host, + _lfjson_port=lfjson_port, + _influx_host=args.influx_host, + _influx_port=args.influx_port, + _influx_org=args.influx_org, + _influx_token=args.influx_token, + _influx_bucket=args.influx_bucket) csvtoinflux = CSVtoInflux(influxdb=influxdb, target_csv=args.target_csv, diff --git a/py-scripts/lf_wifi_capacity_test.py b/py-scripts/lf_wifi_capacity_test.py index 9fab9443..351199cc 100755 --- a/py-scripts/lf_wifi_capacity_test.py +++ b/py-scripts/lf_wifi_capacity_test.py @@ -9,10 +9,16 @@ Note: To Run this script gui should be opened with Note: This is a test file which will run a wifi capacity test. ex. on how to run this script (if stations are available in lanforge): + The influx part can be skipped if you are not using influx/graphana. + ./lf_wifi_capacity_test.py --mgr localhost --port 8080 --lf_user lanforge --lf_password lanforge \ - --instance_name this_inst --config_name test_con --upstream 1.1.eth1 --batch_size 1 --loop_iter 1 \ - --protocol UDP-IPv4 --duration 6000 --pull_report --stations 1.1.sta0000,1.1.sta0002 \ - --test_rig Testbed-01 + --instance_name this_inst --config_name test_con --upstream 1.1.eth1 --batch_size 1 --loop_iter 1 \ + --protocol UDP-IPv4 --duration 6000 --pull_report --stations 1.1.sta0000,1.1.sta0002 \ + --test_rig Testbed-01 \ + --influx_host c7-graphana --influx_port 8086 --influx_org Candela \ + --influx_token=-u_Wd-L8o992701QF0c5UmqEp7w7Z7YOMaWLxOMgmHfATJGnQbbmYyNxHBR9PgD6taM_tcxqJl6U8DjU1xINFQ== \ + --influx_bucket ben --rates_are_totals --side_a_min_bps=20000 --side_b_min_bps=300000000 \ + --influx_tag testbed Ferndale-01 ex. on how to run this script (to create new stations): ./lf_wifi_capacity_test.py --mgr localhost --port 8080 --lf_user lanforge --lf_password lanforge \ @@ -21,6 +27,7 @@ Note: This is a test file which will run a wifi capacity test. --create_stations --radio wiphy0 --ssid test-ssid --security open --paswd [BLANK] \ --test_rig Testbed-01 + Note: --pull_report == If specified, this will pull reports from lanforge to your code directory, from where you are running this code @@ -529,6 +536,8 @@ def main(): WFC_Test.setup() WFC_Test.run() + WFC_Test.check_influx_kpi(args) + if __name__ == "__main__": main() diff --git a/py-scripts/test_l3_longevity.py b/py-scripts/test_l3_longevity.py index 967bcd98..e527d7a0 100755 --- a/py-scripts/test_l3_longevity.py +++ b/py-scripts/test_l3_longevity.py @@ -26,6 +26,7 @@ import sys import os from pprint import pprint +from csv_to_influx import * if sys.version_info[0] != 3: print("This script requires Python 3") @@ -1095,13 +1096,7 @@ python3 test_l3_longevity.py --cisco_ctlr 192.168.100.112 --cisco_dfs True --mgr parser.add_argument('--attenuators', help='--attenuators, comma separated list of attenuator module eids: shelf.resource.atten-serno.atten-idx', default="") parser.add_argument('--atten_vals', help='--atten_vals, comma separated list of attenuator settings in ddb units (1/10 of db)', default="") - parser.add_argument('--influx_host', help='Hostname for the Influx database') - parser.add_argument('--influx_port', help='IP Port for the Influx database', default=8086) - parser.add_argument('--influx_org', help='Organization for the Influx database') - parser.add_argument('--influx_token', help='Token for the Influx database') - parser.add_argument('--influx_bucket', help='Name of the Influx bucket') - parser.add_argument('--influx_tag', action='append', nargs=2, help='--influx_tag Can add more than one of these.') - + influx_add_parser_args(parser) parser.add_argument("--cap_ctl_out", help="--cap_ctl_out, switch the cisco controller output will be captured", action='store_true') parser.add_argument("--wait", help="--wait