def make_storage_dir_struct(cfg): utils.mkdirs_if_unxists(cfg.results_dir) utils.mkdirs_if_unxists(cfg.sensor_storage) utils.mkdirs_if_unxists(cfg.hwinfo_directory) utils.mkdirs_if_unxists(cfg.results_storage)
def run_tests(cfg, test_block, nodes): """ Run test from test block """ test_nodes = [node for node in nodes if 'testnode' in node.roles] not_test_nodes = [node for node in nodes if 'testnode' not in node.roles] if len(test_nodes) == 0: logger.error("No test nodes found") return for name, params in test_block.items(): results = [] # iterate over all node counts limit = params.get('node_limit', len(test_nodes)) if isinstance(limit, (int, long)): vm_limits = [limit] else: list_or_tpl = isinstance(limit, (tuple, list)) all_ints = list_or_tpl and all( isinstance(climit, (int, long)) for climit in limit) if not all_ints: msg = "'node_limit' parameter ion config should" + \ "be either int or list if integers, not {0!r}".format(limit) raise ValueError(msg) vm_limits = limit for vm_count in vm_limits: # select test nodes if vm_count == 'all': curr_test_nodes = test_nodes unused_nodes = [] else: curr_test_nodes = test_nodes[:vm_count] unused_nodes = test_nodes[vm_count:] if 0 == len(curr_test_nodes): continue results_path = generate_result_dir_name(cfg.results_storage, name, params) utils.mkdirs_if_unxists(results_path) # suspend all unused virtual nodes if cfg.settings.get('suspend_unused_vms', True): suspend_ctx = suspend_vm_nodes_ctx(unused_nodes) else: suspend_ctx = utils.empty_ctx() with suspend_ctx: resumable_nodes_ids = [ node.os_vm_id for node in curr_test_nodes if node.os_vm_id is not None ] if len(resumable_nodes_ids) != 0: logger.debug("Check and unpause {0} nodes".format( len(resumable_nodes_ids))) start_vms.unpause(resumable_nodes_ids) sens_nodes = curr_test_nodes + not_test_nodes with sensors_info_util(cfg, sens_nodes) as sensor_data: test_cls = TOOL_TYPE_MAPPER[name] remote_dir = cfg.default_test_local_folder.format( name=name) test_cfg = TestConfig(test_cls.__name__, params=params, test_uuid=cfg.run_uuid, nodes=test_nodes, log_directory=results_path, remote_dir=remote_dir) t_start = time.time() res = test_cls(test_cfg).run() t_end = time.time() # save sensor data if sensor_data is not None: fname = "{0}_{1}.csv".format(int(t_start), int(t_end)) fpath = os.path.join(cfg.sensor_storage, fname) with open(fpath, "w") as fd: fd.write("\n\n".join(sensor_data)) results.append(res) yield name, results
def run_tests(cfg, test_block, nodes): """ Run test from test block """ test_nodes = [node for node in nodes if "testnode" in node.roles] not_test_nodes = [node for node in nodes if "testnode" not in node.roles] if len(test_nodes) == 0: logger.error("No test nodes found") return for name, params in test_block.items(): results = [] # iterate over all node counts limit = params.get("node_limit", len(test_nodes)) if isinstance(limit, (int, long)): vm_limits = [limit] else: list_or_tpl = isinstance(limit, (tuple, list)) all_ints = list_or_tpl and all(isinstance(climit, (int, long)) for climit in limit) if not all_ints: msg = ( "'node_limit' parameter ion config should" + "be either int or list if integers, not {0!r}".format(limit) ) raise ValueError(msg) vm_limits = limit for vm_count in vm_limits: # select test nodes if vm_count == "all": curr_test_nodes = test_nodes unused_nodes = [] else: curr_test_nodes = test_nodes[:vm_count] unused_nodes = test_nodes[vm_count:] if 0 == len(curr_test_nodes): continue results_path = generate_result_dir_name(cfg.results_storage, name, params) utils.mkdirs_if_unxists(results_path) # suspend all unused virtual nodes if cfg.settings.get("suspend_unused_vms", True): suspend_ctx = suspend_vm_nodes_ctx(unused_nodes) else: suspend_ctx = utils.empty_ctx() with suspend_ctx: resumable_nodes_ids = [node.os_vm_id for node in curr_test_nodes if node.os_vm_id is not None] if len(resumable_nodes_ids) != 0: logger.debug("Check and unpause {0} nodes".format(len(resumable_nodes_ids))) start_vms.unpause(resumable_nodes_ids) sens_nodes = curr_test_nodes + not_test_nodes with sensors_info_util(cfg, sens_nodes) as sensor_data: test_cls = TOOL_TYPE_MAPPER[name] remote_dir = cfg.default_test_local_folder.format(name=name) test_cfg = TestConfig( test_cls.__name__, params=params, test_uuid=cfg.run_uuid, nodes=test_nodes, log_directory=results_path, remote_dir=remote_dir, ) t_start = time.time() res = test_cls(test_cfg).run() t_end = time.time() # save sensor data if sensor_data is not None: fname = "{0}_{1}.csv".format(int(t_start), int(t_end)) fpath = os.path.join(cfg.sensor_storage, fname) with open(fpath, "w") as fd: fd.write("\n\n".join(sensor_data)) results.append(res) yield name, results