def cli(name_or_id, scenario, detached, name, description, as_code, web_vu, sap_vu, citrix_vu, return_0): """run a test""" 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('v2/test_result/' + _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'])) # Sorry for that, post data are in the query string :'( :'( post_result = rest_crud.post( 'v2/tests/%s/start?%s' % (_id, 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']) if not detached: running_tools.wait(post_result['resultId'], not return_0) else: tools.print_json(post_result)
def resolve_user_data_metadata_name(user_data, key, value): config_resolvenames = config_global.get_attr('status.resolvenames') config_resolvenames = "" if config_resolvenames is None else str(config_resolvenames).lower() if config_resolvenames == 'false': return None resolver = None is_id = None name = None if key == 'result id': name = value resolver = Resolver("/test-results", rest_crud.base_endpoint_with_workspace) elif key == 'settings id': name = value resolver = Resolver("/tests", rest_crud.base_endpoint_with_workspace) elif key == 'workspace id': name = value resolver = Resolver("/workspaces", rest_crud.base_endpoint) is_id = True if resolver is not None: if is_id is None: is_id = tools.is_id(name) entity = tools.get_named_or_id(name, is_id, resolver) return entity["name"] return None
def cli(name, force): 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 get_id_by_name_or_id(name): if name == "cur": name = user_data.get_meta(meta_key) is_id = tools.is_id(name) __id = tools.get_id(name, __resolver, is_id) if not __id: __id = user_data.get_meta_required(meta_key) return __id
def get_endpoint(name: str): if name == "cur": name = user_data.get_meta(meta_key) is_id = tools.is_id(name) __id = tools.get_id(name, test_results.__resolver, is_id) if not __id: __id = user_data.get_meta_required(meta_key) return '#!result/%s/overview' % __id
def cli(command, name, rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern): """ 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 . """ 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)) user_data.set_meta(meta_key, id_created) 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)) 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)) user_data.set_meta(meta_key, __id) elif command == "delete": delete(__id) user_data.set_meta(meta_key, None)
def parse_to_id(name_or_id): val = name_or_id if val == "cur": val = user_data.get_meta(meta_key) is_id = tools.is_id(val) __id = tools.get_id(val, __resolver, is_id) if not __id: __id = user_data.get_meta_required(meta_key) return __id
def create_or_patch(name, rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file): is_id = tools.is_id(name) __id = tools.get_id(name, __resolver, is_id, True) if __id is None: logging.info('creating test-settings: ' + str(name)) __id = create(create_json(name, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file)) else: logging.info('Patching test-settings: ' + str(__id)) patch(__id, create_json(rename, description, scenario, controller_zone_id, lg_zone_ids, naming_pattern, file)) return __id
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 cli(command, name_or_id, path): """Upload and list scenario from settings""" 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) 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(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)