def main(): # This has --mgr, --mgr_port and --debug parser = LFCliBase.create_bare_argparse( prog="layer3_test.py", formatter_class=argparse.RawTextHelpFormatter, epilog="About This Script") # Adding More Arguments for custom use parser.add_argument('--ssid', help='--ssid of DUT', default="lexusdut") parser.add_argument('--passwd', help='--passwd of dut', default="[BLANK]") parser.add_argument('--radio', help='--radio to use on LANforge', default="wiphy1") parser.add_argument('--security', help='--security of dut', default="open") parser.add_argument('--session_id', help='--session_id is for websocket', default="local") parser.add_argument('--test_name', help='--test_name is for webconsole reports', default="Client Connectivity Test") parser.add_argument( '--num_clients', type=int, help='--num_sta is number of stations you want to create', default=2) parser.add_argument( '--pass_criteria', type=int, help='--pass_criteria is pass criteria for connection Time', default=50) args = parser.parse_args() # args.session_id = "local"; print(args) # Start Test obj = ConnectionTest(lfclient_host="192.168.200.15", lfclient_port=args.mgr_port, session_id=args.session_id, test_name=args.test_name, dut_ssid=args.ssid, dut_passwd=args.passwd, dut_security=args.security, num_sta=args.num_clients, radio=args.radio, pass_criteria=args.pass_criteria) obj.precleanup() obj.build() obj.start() obj.stop() obj.postcleanup()
def main(): parser = LFCliBase.create_bare_argparse(prog=__name__, description='''\ Example: ./port_probe.py --port 1.1.eth0 ''') parser.add_argument('--mode', help='Used to force mode of stations') parser.add_argument('--port_eid', help='EID of station to be used', default="1.1.eth0") args = parser.parse_args() probe = ProbePort2(lfhost=args.mgr, lfport=args.mgr_port, debug=args.debug, eid_str=args.port_eid) probe.run()
def main(): lfjson_host = "localhost" lfjson_port = 8080 param_string = " " for param in add_dut.dut_params: param_string += "%s, " % param.name flags_string = " " for flag in add_dut.dut_flags: flags_string += "%s, " % flag.name parser = LFCliBase.create_bare_argparse( prog='update_dut.py', formatter_class=argparse.RawTextHelpFormatter, description='''{file} -------------------- Generic command layout: python {file} --dut [DUT name] # update existing DUT record --entry [key,value] # update/add entry by specifying key and value --flag [flag,0|1] # toggle a flag on 1 or off 0 --notes "all lines of text" --notes "are replaced if any" --notes "line of text is submitted with --notes" --append "this appends a line of text" DUT Parameters: {params} DUT Flags: {flags} Command Line Example: python3 {file} --mgr 192.168.100.24 --update Pathfinder \ --entry MAC1,"00:00:ae:f0:b1:b9" \ --notes "build 2901" \ --flag STA_MODE,0 --flag AP_MODE,1 '''.format(file=__file__, params=param_string, flags=flags_string), epilog="See", ) parser.add_argument("--dut", type=str, help="name of DUT record") parser.add_argument("-p", "--param", type=str, action="append", help="name,value pair to set parameter") parser.add_argument( "-f", "--flag", type=str, action="append", help="name,1/0/True/False pair to turn parameter on or off") parser.add_argument("-n", "--notes", type=str, action="append", help="replace lines of notes in the record") parser.add_argument("-a", "--append", type=str, action="append", help="append lines of text to the record") args = parser.parse_args() if args.dut is None: raise ValueError("need a name for the dut: --dut something") update_dut = UpdateDUT(args.mgr, lfjson_port, _debug_on=args.debug) update_dut.name = args.dut if (args.param is not None): for param in args.param: if "," not in param: raise ValueError( "Invalid format for param: %s, please use key,value" % param) (name, value) = param.split(",") if (args.debug): print("name %s = %s" % (name, value)) if add_dut.dut_params.has(name): update_dut.params[name] = value else: raise ValueError("parameter %s not in dut_params" % name) flags_sum = 0 flags_mask_sum = 0 if (args.flag is not None): for flag in args.flag: if "," not in flag: raise ValueError( "Invalid format for flag: %s, please use flag,(0/1)" % param) (name, val_str) = flag.split(",") if (args.debug): print("name %s = %s" % (name, val_str)) if not add_dut.dut_flags.has(name): raise ValueError("flag %s not in add_dut.dut_flags" % name) on_off = (0, 1)[val_str == "1"] if (args.debug): print("name %s = %s" % (name, on_off)) flags_sum |= (0, add_dut.dut_flags.to_flag(name).value)[on_off] flags_mask_sum |= add_dut.dut_flags.to_flag(name).value if args.debug: print( "params %s; flags %s; mask %s" % (",".join(update_dut.params), hex(flags_sum), hex(flags_mask_sum))) if (args.notes is not None) and (len(args.notes) > 0): update_dut.notes = args.notes.copy() if (args.append is not None) and (len(args.append) > 0): update_dut.append = args.append.copy() update_dut.flags = flags_sum update_dut.flags_mask = flags_mask_sum update_dut.build() update_dut.start()
def main(): parser = LFCliBase.create_bare_argparse( prog='testgroup.py', formatter_class=argparse.RawTextHelpFormatter, epilog='''Control and query test groups\n''', description='''testgroup.py -------------------- Generic command example: ./testgroup.py --group_name group1 --add_group --add_cx l3_test1,l3_test2 --remove_cx l3_test3 --list_groups ./testgroup.py --group_name group1 --add_group --list_groups ''') parser.add_argument('--group_name', help='specify the name of the test group to use', default=None) parser.add_argument('--list_groups', help='list all existing test groups', action='store_true', default=False) tg_group = parser.add_mutually_exclusive_group() tg_group.add_argument('--add_group', help='add new test group', action='store_true', default=False) tg_group.add_argument('--del_group', help='delete test group', action='store_true', default=False) parser.add_argument('--show_group', help='show connections in current test group', action='store_true', default=False) cx_group = parser.add_mutually_exclusive_group() cx_group.add_argument('--start_group', help='start all cxs in chosen test group', default=None) cx_group.add_argument('--stop_group', help='stop all cxs in chosen test group', default=None) cx_group.add_argument('--quiesce_group', help='quiesce all cxs in chosen test groups', default=None) parser.add_argument('--add_cx', help='add cx to chosen test group', nargs='*', default=[]) parser.add_argument('--remove_cx', help='remove cx from chosen test group', nargs='*', default=[]) args = parser.parse_args() tg_action = None cx_action = None if args.add_group: tg_action = 'add' elif args.del_group: tg_action = 'del' if args.start_group: cx_action = 'start' elif args.stop_group: cx_action = 'stop' elif args.quiesce_group: cx_action = 'quiesce' tg = TestGroup(host=args.mgr, port=args.mgr_port, group_name=args.group_name, add_cx_list=args.add_cx, rm_cx_list=args.remove_cx, cx_action=cx_action, tg_action=tg_action, list_groups=args.list_groups, show_group=args.show_group) tg.do_tg_action() tg.update_cxs() tg.do_cx_action() tg.show_info()
if 'py-json' not in sys.path: sys.path.append(os.path.join(os.path.abspath('..'), 'py-json')) import argparse from LANforge.lfcli_base import LFCliBase from LANforge import LFUtils import realm parser = LFCliBase.create_bare_argparse( prog='scenario.py', formatter_class=argparse.RawTextHelpFormatter, epilog='''Load a database file and control test groups\n''', description='''scenario.py -------------------- Generic command example: python3 scenario.py --load db1 --action overwrite --clean_dut --clean_chambers python3 scenario.py --start test_group1 python3 scenario.py --quiesce test_group1 python3 scenario.py --stop test_group1 ''') group = parser.add_mutually_exclusive_group() parser.add_argument('--load', help='name of database to load', default=None) parser.add_argument('--action', help='action to take with database {overwrite | append}', default="overwrite")
def main(): parser = LFCliBase.create_bare_argparse( prog='test_fileio.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog= '''Creates FileIO endpoints which can be NFS, CIFS or iSCSI endpoints.''', description='''\ test_fileio.py: -------------------- Generic command layout: ./test_fileio.py --macvlan_parent <port> --num_ports <num ports> --use_macvlans --first_mvlan_ip <first ip in series> --netmask <netmask to use> --gateway <gateway ip addr> ./test_fileio.py --macvlan_parent eth2 --num_ports 3 --use_macvlans --first_mvlan_ip 192.168.92.13 --netmask 255.255.255.0 --gateway 192.168.92.1 ''') parser.add_argument('--num_stations', help='Number of stations to create', default=0) parser.add_argument('--radio', help='radio EID, e.g: 1.wiphy2') parser.add_argument('--ssid', help='SSID for stations to associate to') parser.add_argument('--passwd', '--password', '--key', help='WiFi passphrase/password/key') parser.add_argument( '--security', help='security type to use for ssid { wep | wpa | wpa2 | wpa3 | open }' ) parser.add_argument( '-u', '--upstream_port', help= 'non-station port that generates traffic: <resource>.<port>, e.g: 1.eth1', default='1.eth1') parser.add_argument('--test_duration', help='sets the duration of the test', default="5m") parser.add_argument('--fs_type', help='endpoint type', default="fe_nfs4") parser.add_argument('--min_rw_size', help='minimum read/write size', default=64 * 1024) parser.add_argument('--max_rw_size', help='maximum read/write size', default=64 * 1024) parser.add_argument('--min_file_size', help='minimum file size', default=50 * 1024 * 1024) parser.add_argument('--max_file_size', help='maximum file size', default=50 * 1024 * 1024) parser.add_argument('--min_read_rate_bps', help='minimum bps read rate', default=10e9) parser.add_argument('--max_read_rate_bps', help='maximum bps read rate', default=10e9) parser.add_argument('--min_write_rate_bps', help='minimum bps write rate', default=10e9) parser.add_argument('--max_write_rate_bps', help='maximum bps write rate', default="1G") parser.add_argument( '--directory', help='--directory directory to read/write in. Absolute path suggested', default="AUTO") parser.add_argument( '--server_mount', help= '--server_mount The server to mount, ex: 192.168.100.5/exports/test1', default="10.40.0.1:/var/tmp/test") parser.add_argument('--macvlan_parent', help='specifies parent port for macvlan creation', default=None) parser.add_argument('--first_port', help='specifies name of first port to be used', default=None) parser.add_argument('--num_ports', help='number of ports to create', default=1) parser.add_argument('--use_macvlans', help='will create macvlans', action='store_true', default=False) parser.add_argument( '--first_mvlan_ip', help='specifies first static ip address to be used or dhcp', default=None) parser.add_argument( '--netmask', help='specifies netmask to be used with static ip addresses', default=None) parser.add_argument( '--gateway', help='specifies default gateway to be used with static addressing', default=None) parser.add_argument( '--use_test_groups', help='will use test groups to start/stop instead of single endps/cxs', action='store_true', default=False) parser.add_argument('--read_only_test_group', help='specifies name to use for read only test group', default=None) parser.add_argument('--write_only_test_group', help='specifies name to use for write only test group', default=None) parser.add_argument('--mode', help='write,read,both', default='both', type=str) parser.add_argument( '--use_ports', help= 'list of comma separated ports to use with ips, \'=\' separates name and ip' '{ port_name1=ip_addr1,port_name1=ip_addr2 }', default=None) tg_group = parser.add_mutually_exclusive_group() tg_group.add_argument('--add_to_group', help='name of test group to add cxs to', default=None) tg_group.add_argument('--del_from_group', help='name of test group to delete cxs from', default=None) parser.add_argument( '--cxs', help= 'list of cxs to add/remove depending on use of --add_to_group or --del_from_group', default=None) args = parser.parse_args() update_group_args = {"name": None, "action": None, "cxs": None} if args.add_to_group is not None and args.cxs is not None: update_group_args['name'] = args.add_to_group update_group_args['action'] = "add" update_group_args['cxs'] = args.cxs elif args.del_from_group is not None and args.cxs is not None: update_group_args['name'] = args.del_from_group update_group_args['action'] = "del" update_group_args['cxs'] = args.cxs port_list = [] ip_list = [] if args.first_port is not None and args.use_ports is not None: if args.first_port.startswith("sta"): if (args.num_ports is not None) and (int(args.num_ports) > 0): start_num = int(args.first_port[3:]) num_ports = int(args.num_ports) port_list = LFUtils.port_name_series(prefix="sta", start_id=start_num, end_id=start_num + num_ports - 1, padding_number=10000, radio=args.radio) else: if (args.num_ports is not None) and args.macvlan_parent is not None and (int(args.num_ports) > 0) \ and args.macvlan_parent in args.first_port: start_num = int(args.first_port[args.first_port.index('#') + 1:]) num_ports = int(args.num_ports) port_list = LFUtils.port_name_series( prefix=args.macvlan_parent + "#", start_id=start_num, end_id=start_num + num_ports - 1, padding_number=100000, radio=args.radio) else: raise ValueError( "Invalid values for num_ports [%s], macvlan_parent [%s], and/or first_port [%s].\n" "first_port must contain parent port and num_ports must be greater than 0" % (args.num_ports, args.macvlan_parent, args.first_port)) else: if args.use_ports is None: num_ports = int(args.num_ports) if not args.use_macvlans: port_list = LFUtils.port_name_series(prefix="sta", start_id=0, end_id=num_ports - 1, padding_number=10000, radio=args.radio) else: port_list = LFUtils.port_name_series( prefix=args.macvlan_parent + "#", start_id=0, end_id=num_ports - 1, padding_number=100000, radio=args.radio) else: temp_list = args.use_ports.split(',') for port in temp_list: port_list.append(port.split('=')[0]) ip_list.append(port.split('=')[1]) if len(port_list) != len(ip_list): raise ValueError(temp_list, " ports must have matching ip addresses!") if args.first_mvlan_ip is not None: if args.first_mvlan_ip.lower() == "dhcp": dhcp = True else: dhcp = False else: dhcp = True # print(port_list) # exit(1) ip_test = FileIOTest(args.mgr, args.mgr_port, ssid=args.ssid, password=args.passwd, security=args.security, port_list=port_list, ip_list=ip_list, test_duration=args.test_duration, upstream_port=args.upstream_port, _debug_on=args.debug, macvlan_parent=args.macvlan_parent, use_macvlans=args.use_macvlans, first_mvlan_ip=args.first_mvlan_ip, netmask=args.netmask, gateway=args.gateway, dhcp=dhcp, fs_type=args.fs_type, min_rw_size=args.min_rw_size, max_rw_size=args.max_rw_size, min_file_size=args.min_file_size, max_file_size=args.max_file_size, min_read_rate_bps=args.min_read_rate_bps, max_read_rate_bps=args.max_read_rate_bps, min_write_rate_bps=args.min_write_rate_bps, max_write_rate_bps=args.max_write_rate_bps, directory=args.directory, server_mount=args.server_mount, num_ports=args.num_ports, use_test_groups=args.use_test_groups, write_only_test_group=args.write_only_test_group, read_only_test_group=args.read_only_test_group, update_group_args=update_group_args, mode=args.mode # want a mount options param ) ip_test.cleanup(port_list) ip_test.build() # exit(1) if not ip_test.passes(): print(ip_test.get_fail_message()) # ip_test.start(False, False) ip_test.stop() if not ip_test.passes(): print(ip_test.get_fail_message()) # exit(1) time.sleep(30) ip_test.cleanup(port_list) if ip_test.passes(): print( "Full test passed, all endpoints had increased bytes-rd throughout test duration" )
def main(): lfjson_port = 8080 parser = LFCliBase.create_bare_argparse( prog=__file__, # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, description=""" Test the status message passing functions of /status-msg: - create a session: PUT /status-msg/<new-session-id> - post message: POST /status-msg/<new-session-id> - list sessions: GET /status-msg/ - list messages for session: GET /status-msg/<new-session-id> - delete message: DELETE /status-msg/<new-session-id>/message-id - delete session: DELETE /status-msg/<new-session-id>/this - delete all messages in session: DELETE /status-msg/<new-session-id>/all """) parser.add_argument('--action', default="run_test", help=""" Actions can be: run_test : run a messaging test new : create new session update : add message to session, requires --session, --key, --message read : read message(s) from session, requires --session list : list messages from session delete : delete message, all messages using session/all or session using session/this """) parser.add_argument('--session', type=str, help='explicit session or session/message-id') parser.add_argument('--deep_clean', type=bool, help='remove all messages and all sessions') parser.add_argument('--key', type=str, help='how to key the message') parser.add_argument('--message', type=str, help='message to include') args = parser.parse_args() status_messages = TestStatusMessage(args.mgr, lfjson_port, _debug_on=False, _exit_on_error=False, _exit_on_fail=False) if args.action == "new": if args.session is not None: status_messages.json_put("/status-msg/"+args.session, {}) else: u = uuid1() status_messages.json_put("/status-msg/"+u, {}) print("created session /status-msg/"+u) return if args.action == "update": if args.session is None: print("requires --session") return if args.key is None: print("requires --key") return if args.message is None: print("requires --message") return status_messages.json_post("/status-msg/"+args.session, { "key": args.key, "content-type": "text/plain", "message": args.message }) return if args.action == "list": if args.session is None: response_o = status_messages.json_get("/status-msg/") pprint(response_o["sessions"]) else: response_o = status_messages.json_get("/status-msg/"+args.session) pprint(response_o["messages"]) return if args.action == "read": if args.session is None: print("requires --session") return response_o = status_messages.json_get("/status-msg/"+args.session) pprint(response_o) return if args.action == "delete": if args.session is None: print("requires --session") return response_o = status_messages.json_delete("/status-msg/"+args.session) pprint(response_o) return if args.action == "run_test": if args.deep_clean: status_messages.deep_clean = True status_messages.build() if not status_messages.passes(): print(status_messages.get_fail_message()) exit(1) status_messages.start(False, False) status_messages.stop() if not status_messages.passes(): print(status_messages.get_fail_message()) exit(1) status_messages.cleanup() if status_messages.passes(): print("Full test passed, all messages read and cleaned up") exit(0)
def main(): parser = LFCliBase.create_bare_argparse( prog=__file__, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ creates lots of stations across multiple radios. ''', description='''\ test_1k_clients_jedtest.py: -------------------- Generic command layout: python3 ./test_1k_clients_jedtest.py --mgr localhost --mgr_port 8080 --sta_per_radio 300 --test_duration 3m --a_min 1000 --side_b_min 1000 --side_a_max 0 --side_b_max 0 --debug ''') optional = parser.add_argument_group('optional arguments') required = parser.add_argument_group('required arguments') required.add_argument("--sta_per_radio", type=int, help="number of stations per radio") optional.add_argument("--test_duration", type=int, help="length of test duration") optional.add_argument("--a_min", type=int, help="length of test duration") optional.add_argument("--b_min", type=int, help="length of test duration") optional.add_argument("--b_max", type=int, help="length of test duration") optional.add_argument("--a_max", type=int, help="length of test duration") optional.add_argument( '-u', '--upstream_port', help= 'non-station port that generates traffic: <resource>.<port>, e.g: 1.eth1', default='1.eth1') args = parser.parse_args() kilo_test = Test1KClients(host=args.mgr, port=args.mgr_port, upstream=args.upstream_port, num_sta_=args.sta_per_radio, side_a_max_rate=args.a_max, side_a_min_rate=args.a_min, side_b_max_rate=args.b_max, side_b_min_rate=args.b_min, _debug_on=args.debug) kilo_test.pre_cleanup() kilo_test.build() if not kilo_test.passes(): kilo_test.exit_failed() kilo_test.start() if not kilo_test.passes(): kilo_test.exit_failed() kilo_test.stop() if not kilo_test.passes(): kilo_test.exit_failed() time.sleep(60) kilo_test.post_cleanup() kilo_test.exit_success()