def cli(token, url, no_write, workspace, ssl_cert): """Store your token and API url of NeoLoad Web. The token is read from stdin if none is set. The default API url is "https://neoload-api.saas.neotys.com/" """ rest_crud.set_current_command() if not token: if sys.stdin.isatty(): token = click.prompt("Enter your token", None, True) else: token = input() url = url.strip() if url[-1] != '/': url += '/' __user_data = user_data.do_login(token, url, no_write, ssl_cert) if workspace is not None: if user_data.is_version_lower_than('2.5.0'): print( "WARNING: The workspace option works only since Neoload Web 2.5.0. The specified workspace is ignored." ) else: is_workspace_id = tools.is_mongodb_id(workspace) __id = tools.get_id(workspace, workspaces.__resolver, is_workspace_id) tools.use(__id, workspaces.meta_key, workspaces.__resolver) if sys.stdin.isatty(): print(__user_data)
def cli(command, name_or_id): """ ls # Lists workspaces . use # Remember the workspace you want to work on . """ rest_crud.set_current_command() if not command: print("command is mandatory. Please see neoload workspaces --help") return if user_data.is_version_lower_than('2.5.0'): print("ERROR: This commands works only since Neoload Web 2.5.0") return rest_crud.set_current_sub_command(command) if name_or_id == "cur": name_or_id = user_data.get_meta(meta_key) is_id = tools.is_mongodb_id(name_or_id) # avoid to make two requests if we have not id. if command == "ls": # The endpoint GET /workspaces/{workspaceId} is not yet implemented ws_filter = None if name_or_id is not None: ws_filter = "id={}".format(name_or_id) tools.ls(None, True, __resolver, ws_filter) return __id = tools.get_id(name_or_id, __resolver, is_id) if command == "use": tools.use(__id, meta_key, __resolver)
def cli(template, json_in, out_file, filter, report_type, name): """Generate builtin or custom Jinja reports based on test results data Example: neoload report --template builtin:transactions-csv See more templates, examples, filters with "neoload report" """ rest_crud.set_current_command() if all(v is None for v in [template, json_in, out_file, filter]): print_extended_help() tools.system_exit({'code': 1, 'message': ''}) return global gprint model = initialize_model(filter, template) logger = logging.getLogger() # if intent is to produce JSON directly to stdout, hide print statements if out_file is None: gprint = lambda msg: logger.info(msg) gprint("Export started: {}".format(datetime.now())) json_data = parse_source_data_spec(json_in, model, report_type, name) json_data['cli'] = { 'arguments': { 'template': template, 'json_in': json_in, 'out_file': out_file, 'filter': filter, 'report_type': report_type, 'name': name }, 'debug': logging.getLogger().level == logging.DEBUG, 'internals': { 'version': tools.compute_version() } } final_output = process_final_output(template, model.get("template_text"), json_data) if tools.__is_color_terminal(): final_output = displayer.colorize_text(final_output) if out_file is not None: set_file_text(out_file, final_output) if tools.is_user_interactive() and (out_file.lower().endswith(".html") or out_file.lower().endswith(".htm")): webbrowser.open_new_tab("file://" + out_file) else: print(final_output) gprint("Export ended: {}".format(datetime.now()))
def cli(name_or_id, return_0): """Wait the end of test""" rest_crud.set_current_command() if not name_or_id or name_or_id == "cur": name_or_id = user_data.get_meta(test_results.meta_key) id_ = tools.get_id(name_or_id, test_results.__resolver) running_tools.wait(id_, not return_0)
def cli(command, key_value): """View and set the user-defined properties. This properties is kept after logout. The format of KEY_VALUE: key1=value1 key2=value2. The empty value remove the key""" rest_crud.set_current_command() if command == 'set': for element in key_value: key, value = element.split('=') config_global.set_attr(key, treat_value(value)) elif command == 'ls': print("config file: " + config_global.get_config_file() + "\n") for k, v in config_global.list_attr(key_value): print(k + " = " + str(v))
def cli(name, force): """stop a test""" rest_crud.set_current_command() if not name or name == "cur": name = user_data.get_meta(test_results.meta_key) if not name: raise cli_exception.CliException('No test id is provided') if not tools.is_id(name): name = test_results.__resolver.resolve_name(name) running_tools.stop(name, force)
def cli(name_or_id, static_dynamic, human): """read of NeoLoad Web zones""" rest_crud.set_current_command() resp = get_zones() resp = [ elem for elem in resp if filter_result(elem, name_or_id, static_dynamic) ] if human: print_human(resp) else: tools.print_json(resp)
def cli(command, name, rename, description, quality_status, junit_file, file, filter): """ ls # Lists test results . summary # Display a summary of the result : SLAs and statistics . junitsla # Output SLA results to a file with junit format . put # Update the name, description or quality-status of the result . delete # Remove a result . use # Remember the test result you want to work on. Example : neoload | test-results use MyTest#1 ; neoload test-results summary . """ rest_crud.set_current_command() if not command: print("command is mandatory. Please see neoload tests-results --help") return rest_crud.set_current_sub_command(command) if name == "cur": name = user_data.get_meta(meta_key) is_id = tools.is_id(name) # avoid to make two requests if we have not id. if command == "ls": tools.ls(name, is_id, __resolver, filter, ['project', 'status', 'author', 'sort']) return __id = tools.get_id(name, __resolver, is_id) if command == "use": tools.use(__id, meta_key, __resolver) return if not __id: __id = user_data.get_meta_required(meta_key) system_exit = {'message': '', 'code': 0} if command == "summary": system_exit = summary(__id) elif command == "junitsla": junit(__id, junit_file) elif command == "delete": delete(__id) user_data.set_meta(meta_key, None) else: json_data = load_from_file(file) if file else create_json( rename, description, quality_status) if command == "put": put(__id, json_data) elif command == "patch": patch(__id, json_data) if command != "delete": user_data.set_meta(meta_key, __id) tools.system_exit(system_exit)
def get_command(self, ctx, name): """Dynamically get the command.""" ns = {} fn = os.path.join(plugin_folder, name.replace('-', '_') + '.py') rest_crud.set_current_command(name) if os.path.isfile(fn): with open(fn) as f: code = compile(f.read(), fn, 'exec') eval(code, ns, ns) return ns['cli'] else: raise cli_exception.CliException("\"" + name + "\" is not a neoload command")
def cli(command, name, rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file): """ ls # Lists test settings . create # Create a new test settings . put # Update all fields of a test settings . patch # Update only the selected fields of a test settings . delete # Remove a test settings and all associated test results . use # Remember the test settings you want to work on. Example : neoload | test-settings use MyTest ; neoload test-settings delete . createorpatch # Create a new test or patch an existing one; useful in CI . """ rest_crud.set_current_command() if not command: print("command is mandatory. Please see neoload tests-settings --help") return rest_crud.set_current_sub_command(command) if name == "cur": name = user_data.get_meta(meta_key) is_id = tools.is_id(name) # avoid to make two requests if we have not id. if command == "ls": tools.ls(name, is_id, __resolver) return elif command == "create": id_created = create(create_json(name, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file)) user_data.set_meta(meta_key, id_created) return elif command == "createorpatch": __id = create_or_patch(name, rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file) user_data.set_meta(meta_key, __id) return __id = tools.get_id(name, __resolver, is_id) if command == "use": tools.use(__id, meta_key, __resolver) return if not __id: __id = user_data.get_meta_required(meta_key) if command == "put": put(__id, create_json(rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file)) user_data.set_meta(meta_key, __id) elif command == "patch": patch(__id, create_json(rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file)) user_data.set_meta(meta_key, __id) elif command == "delete": delete(__id) user_data.set_meta(meta_key, None)
def cli(command, name_or_id, path, save): """Upload and list scenario from settings""" rest_crud.set_current_command() if not name_or_id or name_or_id == "cur": name_or_id = user_data.get_meta(test_settings.meta_key) if not tools.is_id(name_or_id): name_or_id = test_settings.__resolver.resolve_name(name_or_id) if command[:2] == "up": upload(path, name_or_id, save) elif command == "meta": meta_data(name_or_id) user_data.set_meta(test_settings.meta_key, name_or_id) rest_crud.set_current_sub_command(command)
def cli(command, name, stop, force, max_failure, stop_command): #, max_occurs): """Fails if certain conditions are met, such as per-run SLAs failed % of time""" rest_crud.set_current_command() if not command: tools.system_exit({'message': "command is mandatory. Please see neoload fastfail --help", 'code': 2}) return if max_failure < 0 or max_failure > 100: tools.system_exit({'message': "--max-failure percentage tolerance must be between 0 and 100", 'code': 2}) return __id = test_results.get_id_by_name_or_id(name) if __id is None: tools.system_exit({'message': "Could not resolve '" + name + "' to test ID.", 'code': 2}) return if command == "slas": monitor_loop(__id, stop, force, max_failure, stop_command) else: tools.system_exit({'message': "Invalid command. Please see neoload fastfail --help", 'code': 2})
def cli(name_or_id, scenario, detached, name, description, as_code, web_vu, sap_vu, citrix_vu, return_0): """run a test""" rest_crud.set_current_command() if not name_or_id or name_or_id == "cur": name_or_id = user_data.get_meta(test_settings.meta_key) is_id = tools.is_id(name_or_id) test_settings_json = tools.get_named_or_id(name_or_id, is_id, test_settings.__resolver) _id = test_settings_json['id'] if scenario: rest_crud.patch(test_settings.get_end_point(_id), {'scenarioName': scenario}) naming_pattern = name if name else test_settings_json[ 'testResultNamingPattern'] if not naming_pattern: naming_pattern = "#${runID}" naming_pattern = naming_pattern.replace( '${runID}', str(test_settings_json['nextRunId'])) hooks.trig("test.start", test_settings_json) # Sorry for that, post data are in the query string :'( :'( post_result = rest_crud.post( test_settings.get_end_point(_id) + '/start?' + create_data( naming_pattern, description, as_code, web_vu, sap_vu, citrix_vu), {}) user_data.set_meta(test_settings.meta_key, _id) user_data.set_meta(test_results.meta_key, post_result['resultId']) # Wait 5 seconds until the test result is created. time.sleep(5) if not detached: running_tools.wait(post_result['resultId'], not return_0) else: tools.print_json(post_result)