X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fcore%2Ftask.py;h=7e071bc0eab5cec50edd2d34d9568b22a93be9c5;hb=b2552579f300ec9f4c2b516eb44cac0efb3d4dd6;hp=2c67e736c6f3130dc4a8c3fb6df34a42d8aa3982;hpb=b39fe5457e846e734e980666bc209fb7c07a6bdc;p=yardstick.git diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index 2c67e736c..7e071bc0e 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -21,7 +21,6 @@ import ipaddress import time import logging import uuid -import errno import collections from six.moves import filter @@ -32,7 +31,6 @@ from yardstick.benchmark.runners import base as base_runner from yardstick.common.yaml_loader import yaml_load from yardstick.dispatcher.base import Base as DispatcherBase from yardstick.common.task_template import TaskTemplate -from yardstick.common.utils import source_env from yardstick.common import utils from yardstick.common import constants from yardstick.common.html_template import report_template @@ -70,8 +68,6 @@ class Task(object): # pragma: no cover self._set_log() - check_environment() - try: output_config = utils.parse_ini_file(config_file) except Exception: @@ -101,8 +97,8 @@ class Task(object): # pragma: no cover task_args = [args.task_args] task_args_fnames = [args.task_args_file] - LOG.info("\ntask_files:%s, \ntask_args:%s, \ntask_args_fnames:%s", - task_files, task_args, task_args_fnames) + LOG.debug("task_files:%s, task_args:%s, task_args_fnames:%s", + task_files, task_args, task_args_fnames) if args.parse_only: sys.exit(0) @@ -129,9 +125,10 @@ class Task(object): # pragma: no cover except KeyboardInterrupt: raise except Exception: - LOG.exception("Running test case %s failed!", case_name) + LOG.error('Testcase: "%s" FAILED!!!', case_name, exe_info=True) testcases[case_name] = {'criteria': 'FAIL', 'tc_data': []} else: + LOG.info('Testcase: "%s" SUCCESS!!!', case_name) testcases[case_name] = {'criteria': 'PASS', 'tc_data': data} if args.keep_deploy: @@ -143,7 +140,7 @@ class Task(object): # pragma: no cover context.undeploy() self.contexts = [] one_task_end_time = time.time() - LOG.info("task %s finished in %d secs", task_files[i], + LOG.info("Task %s finished in %d secs", task_files[i], one_task_end_time - one_task_start_time) result = self._get_format_result(testcases) @@ -152,14 +149,13 @@ class Task(object): # pragma: no cover self._generate_reporting(result) total_end_time = time.time() - LOG.info("total finished in %d secs", + LOG.info("Total finished in %d secs", total_end_time - total_start_time) scenario = scenarios[0] - print("To generate report execute => yardstick report generate ", - scenario['task_id'], scenario['tc']) - - print("Done, exiting") + LOG.info("To generate report, execute command " + "'yardstick report generate %(task_id)s %(tc)s'", scenario) + LOG.info("Task ALL DONE, exiting") return result def _generate_reporting(self, result): @@ -167,7 +163,7 @@ class Task(object): # pragma: no cover with open(constants.REPORTING_FILE, 'w') as f: f.write(env.from_string(report_template).render(result)) - LOG.info('yardstick reporting generate in %s', constants.REPORTING_FILE) + LOG.info("Report can be found in '%s'", constants.REPORTING_FILE) def _set_log(self): log_format = '%(asctime)s %(name)s %(filename)s:%(lineno)d %(levelname)s %(message)s' @@ -269,7 +265,7 @@ class Task(object): # pragma: no cover raise RuntimeError self.outputs.update(runner.get_output()) result.extend(runner.get_result()) - print("Runner ended, output in", output_file) + LOG.info("Runner ended, output in %s", output_file) else: # run serially for scenario in scenarios: @@ -277,11 +273,13 @@ class Task(object): # pragma: no cover runner = self.run_one_scenario(scenario, output_file) status = runner_join(runner) if status != 0: - LOG.error('Scenario: %s ERROR', scenario.get('type')) + LOG.error('Scenario NO.%s: "%s" ERROR!', + scenarios.index(scenario) + 1, + scenario.get('type')) raise RuntimeError self.outputs.update(runner.get_output()) result.extend(runner.get_result()) - print("Runner ended, output in", output_file) + LOG.info("Runner ended, output in %s", output_file) # Abort background runners for runner in background_runners: @@ -306,7 +304,7 @@ class Task(object): # pragma: no cover base_runner.Runner.terminate_all() if self.contexts: - print("Undeploying all contexts") + LOG.info("Undeploying all contexts") for context in self.contexts[::-1]: context.undeploy() @@ -330,23 +328,30 @@ class Task(object): # pragma: no cover # TODO support get multi hosts/vms info context_cfg = {} - if "host" in scenario_cfg: - context_cfg['host'] = Context.get_server(scenario_cfg["host"]) + server_name = scenario_cfg.get('options', {}).get('server_name', {}) - if "target" in scenario_cfg: - if is_ip_addr(scenario_cfg["target"]): - context_cfg['target'] = {} - context_cfg['target']["ipaddr"] = scenario_cfg["target"] + def config_context_target(cfg): + target = cfg['target'] + if is_ip_addr(target): + context_cfg['target'] = {"ipaddr": target} else: - context_cfg['target'] = Context.get_server( - scenario_cfg["target"]) - if self._is_same_heat_context(scenario_cfg["host"], - scenario_cfg["target"]): - context_cfg["target"]["ipaddr"] = \ - context_cfg["target"]["private_ip"] + context_cfg['target'] = Context.get_server(target) + if self._is_same_context(cfg["host"], target): + context_cfg['target']["ipaddr"] = context_cfg['target']["private_ip"] else: - context_cfg["target"]["ipaddr"] = \ - context_cfg["target"]["ip"] + context_cfg['target']["ipaddr"] = context_cfg['target']["ip"] + + host_name = server_name.get('host', scenario_cfg.get('host')) + if host_name: + context_cfg['host'] = Context.get_server(host_name) + + for item in [server_name, scenario_cfg]: + try: + config_context_target(item) + except KeyError: + pass + else: + break if "targets" in scenario_cfg: ip_list = [] @@ -356,8 +361,8 @@ class Task(object): # pragma: no cover context_cfg['target'] = {} else: context_cfg['target'] = Context.get_server(target) - if self._is_same_heat_context(scenario_cfg["host"], - target): + if self._is_same_context(scenario_cfg["host"], + target): ip_list.append(context_cfg["target"]["private_ip"]) else: ip_list.append(context_cfg["target"]["ip"]) @@ -367,24 +372,23 @@ class Task(object): # pragma: no cover context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg) context_cfg["networks"] = get_networks_from_nodes( context_cfg["nodes"]) + runner = base_runner.Runner.get(runner_cfg) - print("Starting runner of type '%s'" % runner_cfg["type"]) + LOG.info("Starting runner of type '%s'", runner_cfg["type"]) runner.run(scenario_cfg, context_cfg) return runner - def _is_same_heat_context(self, host_attr, target_attr): + def _is_same_context(self, host_attr, target_attr): """check if two servers are in the same heat context host_attr: either a name for a server created by yardstick or a dict with attribute name mapping when using external heat templates target_attr: either a name for a server created by yardstick or a dict with attribute name mapping when using external heat templates """ - host = None - target = None for context in self.contexts: - if context.__context_type__ != "Heat": + if context.__context_type__ not in {"Heat", "Kubernetes"}: continue host = context._get_server(host_attr) @@ -481,7 +485,7 @@ class TaskParser(object): # pragma: no cover def parse_task(self, task_id, task_args=None, task_args_file=None): """parses the task file and return an context and scenario instances""" - print("Parsing task config:", self.path) + LOG.info("Parsing task config: %s", self.path) try: kw = {} @@ -498,10 +502,9 @@ class TaskParser(object): # pragma: no cover input_task = f.read() rendered_task = TaskTemplate.render(input_task, **kw) except Exception as e: - print("Failed to render template:\n%(task)s\n%(err)s\n" - % {"task": input_task, "err": e}) + LOG.exception('Failed to render template:\n%s\n', input_task) raise e - print("Input task is:\n%s\n" % rendered_task) + LOG.debug("Input task is:\n%s\n", rendered_task) cfg = yaml_load(rendered_task) except IOError as ioerror: @@ -632,11 +635,11 @@ def get_networks_from_nodes(nodes): continue interfaces = node.get('interfaces', {}) for interface in interfaces.values(): - vld_id = interface.get('vld_id') - # mgmt network doesn't have vld_id - if not vld_id: + # vld_id is network_name + network_name = interface.get('network_name') + if not network_name: continue - network = Context.get_network({"vld_id": vld_id}) + network = Context.get_network(network_name) if network: networks[network['name']] = network return networks @@ -675,37 +678,25 @@ def parse_task_args(src_name, args): return kw -def check_environment(): - auth_url = os.environ.get('OS_AUTH_URL', None) - if not auth_url: - try: - source_env(constants.OPENRC) - except IOError as e: - if e.errno != errno.EEXIST: - raise - LOG.debug('OPENRC file not found') - - def change_server_name(scenario, suffix): - try: - host = scenario['host'] - except KeyError: - pass - else: - try: - host['name'] += suffix - except TypeError: - scenario['host'] += suffix - try: - target = scenario['target'] - except KeyError: - pass - else: + def add_suffix(cfg, key): try: - target['name'] += suffix - except TypeError: - scenario['target'] += suffix + value = cfg[key] + except KeyError: + pass + else: + try: + value['name'] += suffix + except TypeError: + cfg[key] += suffix + + server_name = scenario.get('options', {}).get('server_name', {}) + + add_suffix(scenario, 'host') + add_suffix(scenario, 'target') + add_suffix(server_name, 'host') + add_suffix(server_name, 'target') try: key = 'targets'