def phantom_rps_schedule(scenario_path): def parse_phantom_schedule(rps_line): steps = [] for step in " ".join(rps_line.split("\n")).split(")"): line = step.strip() if not line: continue (name, params) = line.split("(") keys = { "step": ["a", "b", "step", "dur"], "line": ["a", "b", "dur"], "const": ["a", "dur"] } if name not in keys: params = { "load_gen": "phantom", "scenario_path": scenario_path } raise IniCtrlWarning("incorrect_rps_schedule", params) params = dict(zip(keys[name], params.split(","))) params["dur"] = duration2ms(params["dur"]) steps.append({"loadtype": name, "params": params}) return steps test_name = ini_manager.get_option_value(scenario_path, "salts_report", "test_name") if not test_name: params = {"scenario_path": scenario_path} raise IniCtrlWarning("no_test_name", params) dd = {"test_name": test_name} rps_line = ini_manager.get_option_value(scenario_path, "phantom", "rps_schedule") dd["steps"] = parse_phantom_schedule(rps_line) return dd
def jmeter_duration(key, default_value=None): value = ini_manager.get_option_value(scenario_path, "jmeter", key, default_value) if value is None: params = {"scenario_path": scenario_path, "key": key} raise IniCtrlWarning("undefined_duration", params) return 1000 * int(value)
def jmeter_rps_schedule(scenario_path): def jmeter_duration(key, default_value=None): value = ini_manager.get_option_value(scenario_path, "jmeter", key, default_value) if value is None: params = {"scenario_path": scenario_path, "key": key} raise IniCtrlWarning("undefined_duration", params) return 1000 * int(value) try: value = ini_manager.get_option_value(scenario_path, "jmeter", "rps1", SCENARIO_RPS_DEFAULT) rps = int(value) test_name = ini_manager.get_option_value(scenario_path, "salts_report", "test_name") if not test_name: params = {"scenario_path": scenario_path} raise IniCtrlWarning("no_test_name", params) return { "test_name": test_name, "steps": [{ "loadtype": "line", "params": { "a": 1, "b": rps, "dur": jmeter_duration("rampup") } }, { "loadtype": "const", "params": { "a": rps, "dur": jmeter_duration("testlen") } }, { "loadtype": "line", "params": { "a": rps, "b": 1, "dur": jmeter_duration("rampdown", 0) } }] } except ValueError: params = {"load_gen": "jmeter", "scenario_path": scenario_path} raise IniCtrlWarning("incorrect_rps_schedule", params)
def phantom_target_info(scenario_path): addr = {"hostname": "", "port": 8000} target_info = ini_manager.get_option_value(scenario_path, "phantom", "address", "") if target_info: targ = target_info.split(":") addr["hostname"] = targ[0] if len(targ) >= 2: addr["port"] = targ[1] if not addr["hostname"]: params = {"load_gen": "phantom", "scenario_path": scenario_path} raise IniCtrlWarning("undefined_target", params) return addr
def jmeter_target_info(scenario_path): addr = {"hostname": "", "port": 8000, "s": ""} target_info = ini_manager.get_option_value(scenario_path, "jmeter", "hostname", "") # Another name of JMeter target option if not target_info: target_info = ini_manager.get_option_value(scenario_path, "jmeter", "host", "") if target_info: targ = target_info.split(":") addr["hostname"] = targ[0] if len(targ) == 1: addr["port"] = ini_manager.get_option_value( scenario_path, "jmeter", "port", addr["port"]) addr["s"] = "1" # target и port д.б. сохранены в разных опциях else: addr["port"] = targ[1] if not addr["hostname"]: params = {"load_gen": "jmeter", "scenario_path": scenario_path} raise IniCtrlWarning("undefined_target", params) return addr