diff options
Diffstat (limited to 'yardstick/benchmark')
-rw-r--r-- | yardstick/benchmark/contexts/base.py | 4 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/dummy.py | 2 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/heat.py | 19 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/node.py | 2 | ||||
-rw-r--r-- | yardstick/benchmark/contexts/standalone.py | 2 | ||||
-rw-r--r-- | yardstick/benchmark/core/task.py | 218 | ||||
-rwxr-xr-x | yardstick/benchmark/runners/base.py | 21 |
7 files changed, 145 insertions, 123 deletions
diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py index 9f2b21537..0be2eee77 100644 --- a/yardstick/benchmark/contexts/base.py +++ b/yardstick/benchmark/contexts/base.py @@ -46,6 +46,10 @@ class Context(object): @abc.abstractmethod def undeploy(self): """Undeploy context.""" + self._delete_context() + + def _delete_context(self): + Context.list.remove(self) @abc.abstractmethod def _get_server(self, attr_name): diff --git a/yardstick/benchmark/contexts/dummy.py b/yardstick/benchmark/contexts/dummy.py index 0edc250f8..c658d3257 100644 --- a/yardstick/benchmark/contexts/dummy.py +++ b/yardstick/benchmark/contexts/dummy.py @@ -33,7 +33,7 @@ class DummyContext(Context): def undeploy(self): """don't need to undeploy""" - pass + super(DummyContext, self).undeploy() def _get_server(self, attr_name): return None diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 479548b34..571a769eb 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -58,6 +58,16 @@ class HeatContext(Context): get_short_key_uuid(self.key_uuid)]) super(HeatContext, self).__init__() + def assign_external_network(self, networks): + sorted_networks = sorted(networks.items()) + external_network = os.environ.get("EXTERNAL_NETWORK", "net04_ext") + have_external_network = [(name, net) + for name, net in sorted_networks if + net.get("external_network")] + # no external net defined, assign it to first network usig os.environ + if sorted_networks and not have_external_network: + sorted_networks[0][1]["external_network"] = external_network + def init(self, attrs): # pragma: no cover """initializes itself from the supplied arguments""" self.name = attrs["name"] @@ -84,9 +94,10 @@ class HeatContext(Context): for name, sgattrs in attrs.get( "server_groups", {}).items()] - for name, netattrs in attrs["networks"].items(): - network = Network(name, self, netattrs) - self.networks.append(network) + self.assign_external_network(attrs["networks"]) + + self.networks = [Network(name, self, netattrs) for name, netattrs in + sorted(attrs["networks"].items())] for name, serverattrs in attrs["servers"].items(): server = Server(name, self, serverattrs) @@ -257,6 +268,8 @@ class HeatContext(Context): except OSError: LOG.exception("Key filename %s", self.key_filename) + super(HeatContext, self).undeploy() + def _get_server(self, attr_name): """lookup server info by name from context attr_name: either a name for a server created by yardstick or a dict diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py index 6fa9aa99a..f8c38cb1c 100644 --- a/yardstick/benchmark/contexts/node.py +++ b/yardstick/benchmark/contexts/node.py @@ -89,6 +89,8 @@ class NodeContext(Context): for host, info in teardown.items(): self._execute_script(host, info) + super(NodeContext, self).undeploy() + def _get_server(self, attr_name): """lookup server info by name from context attr_name: a name for a server listed in nodes config file diff --git a/yardstick/benchmark/contexts/standalone.py b/yardstick/benchmark/contexts/standalone.py index eff700974..674e57f54 100644 --- a/yardstick/benchmark/contexts/standalone.py +++ b/yardstick/benchmark/contexts/standalone.py @@ -79,7 +79,7 @@ class StandaloneContext(Context): """don't need to undeploy""" # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config. - pass + super(StandaloneContext, self).undeploy() def _get_server(self, attr_name): """lookup server info by name from context diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index aecf5bf4a..2794d84f4 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -26,9 +26,11 @@ from yardstick.benchmark.contexts.base import Context from yardstick.benchmark.runners import base as base_runner from yardstick.common.task_template import TaskTemplate from yardstick.common.utils import source_env +from yardstick.common import utils from yardstick.common import constants output_file_default = "/tmp/yardstick.out" +config_file = '/etc/yardstick/yardstick.conf' test_cases_dir_default = "tests/opnfv/test_cases/" LOG = logging.getLogger(__name__) @@ -39,15 +41,21 @@ class Task(object): # pragma: no cover Set of commands to manage benchmark tasks. """ + def __init__(self): + self.config = {} + self.contexts = [] + def start(self, args, **kwargs): """Start a benchmark scenario.""" - atexit.register(atexit_handler) + atexit.register(self.atexit_handler) self.task_id = kwargs.get('task_id', str(uuid.uuid4())) check_environment() + self.config['yardstick'] = utils.parse_ini_file(config_file) + total_start_time = time.time() parser = TaskParser(args.inputfile[0]) @@ -70,8 +78,11 @@ class Task(object): # pragma: no cover for i in range(0, len(task_files)): one_task_start_time = time.time() parser.path = task_files[i] - scenarios, run_in_parallel, meet_precondition = parser.parse_task( - self.task_id, task_args[i], task_args_fnames[i]) + scenarios, run_in_parallel, meet_precondition, contexts = \ + parser.parse_task(self.task_id, task_args[i], + task_args_fnames[i]) + + self.contexts.extend(contexts) if not meet_precondition: LOG.info("meet_precondition is %s, please check envrionment", @@ -83,11 +94,11 @@ class Task(object): # pragma: no cover if args.keep_deploy: # keep deployment, forget about stack # (hide it for exit handler) - Context.list = [] + self.contexts = [] else: - for context in Context.list[::-1]: + for context in self.contexts[::-1]: context.undeploy() - Context.list = [] + self.contexts = [] one_task_end_time = time.time() LOG.info("task %s finished in %d secs", task_files[i], one_task_end_time - one_task_start_time) @@ -100,7 +111,7 @@ class Task(object): # pragma: no cover def _run(self, scenarios, run_in_parallel, output_file): """Deploys context and calls runners""" - for context in Context.list: + for context in self.contexts: context.deploy() background_runners = [] @@ -108,14 +119,14 @@ class Task(object): # pragma: no cover # Start all background scenarios for scenario in filter(_is_background_scenario, scenarios): scenario["runner"] = dict(type="Duration", duration=1000000000) - runner = run_one_scenario(scenario, output_file) + runner = self.run_one_scenario(scenario, output_file) background_runners.append(runner) runners = [] if run_in_parallel: for scenario in scenarios: if not _is_background_scenario(scenario): - runner = run_one_scenario(scenario, output_file) + runner = self.run_one_scenario(scenario, output_file) runners.append(runner) # Wait for runners to finish @@ -126,7 +137,7 @@ class Task(object): # pragma: no cover # run serially for scenario in scenarios: if not _is_background_scenario(scenario): - runner = run_one_scenario(scenario, output_file) + runner = self.run_one_scenario(scenario, output_file) runner_join(runner) print("Runner ended, output in", output_file) @@ -144,8 +155,91 @@ class Task(object): # pragma: no cover base_runner.Runner.release(runner) print("Background task ended") + def atexit_handler(self): + """handler for process termination""" + base_runner.Runner.terminate_all() + + if self.contexts: + print("Undeploying all contexts") + for context in self.contexts[::-1]: + context.undeploy() + + def run_one_scenario(self, scenario_cfg, output_file): + """run one scenario using context""" + runner_cfg = scenario_cfg["runner"] + runner_cfg['output_filename'] = output_file + + # TODO support get multi hosts/vms info + context_cfg = {} + if "host" in scenario_cfg: + context_cfg['host'] = Context.get_server(scenario_cfg["host"]) + + if "target" in scenario_cfg: + if is_ip_addr(scenario_cfg["target"]): + context_cfg['target'] = {} + context_cfg['target']["ipaddr"] = scenario_cfg["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"] + else: + context_cfg["target"]["ipaddr"] = \ + context_cfg["target"]["ip"] + + if "targets" in scenario_cfg: + ip_list = [] + for target in scenario_cfg["targets"]: + if is_ip_addr(target): + ip_list.append(target) + context_cfg['target'] = {} + else: + context_cfg['target'] = Context.get_server(target) + if self._is_same_heat_context(scenario_cfg["host"], + target): + ip_list.append(context_cfg["target"]["private_ip"]) + else: + ip_list.append(context_cfg["target"]["ip"]) + context_cfg['target']['ipaddr'] = ','.join(ip_list) + + if "nodes" in scenario_cfg: + context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg) + runner = base_runner.Runner.get(runner_cfg, self.config) + + print("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): + """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 + """ + return True + host = None + target = None + for context in self.contexts: + if context.__context_type__ != "Heat": + continue + + host = context._get_server(host_attr) + if host is None: + continue + + target = context._get_server(target_attr) + if target is None: + return False -# TODO: Move stuff below into TaskCommands class !? + # Both host and target is not None, then they are in the + # same heat context. + return True + + return False class TaskParser(object): # pragma: no cover @@ -265,6 +359,7 @@ class TaskParser(object): # pragma: no cover else: context_cfgs = [{"type": "Dummy"}] + contexts = [] name_suffix = '-{}'.format(task_id[:8]) for cfg_attrs in context_cfgs: try: @@ -272,20 +367,11 @@ class TaskParser(object): # pragma: no cover name_suffix) except KeyError: pass + # default to Heat context because we are testing OpenStack context_type = cfg_attrs.get("type", "Heat") - if "Heat" == context_type and "networks" in cfg_attrs: - # bugfix: if there are more than one network, - # only add "external_network" on first one. - # the name of netwrok should follow this rule: - # test, test2, test3 ... - # sort network with the length of network's name - sorted_networks = sorted(cfg_attrs["networks"]) - # config external_network based on env var - cfg_attrs["networks"][sorted_networks[0]]["external_network"] \ - = os.environ.get("EXTERNAL_NETWORK", "net04_ext") - context = Context.get(context_type) context.init(cfg_attrs) + contexts.append(context) run_in_parallel = cfg.get("run_in_parallel", False) @@ -304,7 +390,7 @@ class TaskParser(object): # pragma: no cover pass # TODO we need something better here, a class that represent the file - return cfg["scenarios"], run_in_parallel, meet_precondition + return cfg["scenarios"], run_in_parallel, meet_precondition, contexts def _check_schema(self, cfg_schema, schema_type): """Check if config file is using the correct schema type""" @@ -346,16 +432,6 @@ class TaskParser(object): # pragma: no cover return True -def atexit_handler(): - """handler for process termination""" - base_runner.Runner.terminate_all() - - if len(Context.list) > 0: - print("Undeploying all contexts") - for context in Context.list[::-1]: - context.undeploy() - - def is_ip_addr(addr): """check if string addr is an IP address""" try: @@ -371,34 +447,6 @@ def is_ip_addr(addr): return True -def _is_same_heat_context(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 Context.list: - if context.__context_type__ != "Heat": - continue - - host = context._get_server(host_attr) - if host is None: - continue - - target = context._get_server(target_attr) - if target is None: - return False - - # Both host and target is not None, then they are in the - # same heat context. - return True - - return False - - def _is_background_scenario(scenario): if "run_in_background" in scenario: return scenario["run_in_background"] @@ -406,54 +454,6 @@ def _is_background_scenario(scenario): return False -def run_one_scenario(scenario_cfg, output_file): - """run one scenario using context""" - runner_cfg = scenario_cfg["runner"] - runner_cfg['output_filename'] = output_file - - # TODO support get multi hosts/vms info - context_cfg = {} - if "host" in scenario_cfg: - context_cfg['host'] = Context.get_server(scenario_cfg["host"]) - - if "target" in scenario_cfg: - if is_ip_addr(scenario_cfg["target"]): - context_cfg['target'] = {} - context_cfg['target']["ipaddr"] = scenario_cfg["target"] - else: - context_cfg['target'] = Context.get_server(scenario_cfg["target"]) - if _is_same_heat_context(scenario_cfg["host"], - scenario_cfg["target"]): - context_cfg["target"]["ipaddr"] = \ - context_cfg["target"]["private_ip"] - else: - context_cfg["target"]["ipaddr"] = \ - context_cfg["target"]["ip"] - - if "targets" in scenario_cfg: - ip_list = [] - for target in scenario_cfg["targets"]: - if is_ip_addr(target): - ip_list.append(target) - context_cfg['target'] = {} - else: - context_cfg['target'] = Context.get_server(target) - if _is_same_heat_context(scenario_cfg["host"], target): - ip_list.append(context_cfg["target"]["private_ip"]) - else: - ip_list.append(context_cfg["target"]["ip"]) - context_cfg['target']['ipaddr'] = ','.join(ip_list) - - if "nodes" in scenario_cfg: - context_cfg["nodes"] = parse_nodes_with_context(scenario_cfg) - runner = base_runner.Runner.get(runner_cfg) - - print("Starting runner of type '%s'" % runner_cfg["type"]) - runner.run(scenario_cfg, context_cfg) - - return runner - - def parse_nodes_with_context(scenario_cfg): """paras the 'nodes' fields in scenario """ nodes = scenario_cfg["nodes"] diff --git a/yardstick/benchmark/runners/base.py b/yardstick/benchmark/runners/base.py index 5b9081523..7c76e42df 100755 --- a/yardstick/benchmark/runners/base.py +++ b/yardstick/benchmark/runners/base.py @@ -35,15 +35,18 @@ log = logging.getLogger(__name__) CONF = cfg.CONF -def _output_serializer_main(filename, queue): +def _output_serializer_main(filename, queue, config): """entrypoint for the singleton subprocess writing to outfile Use of this process enables multiple instances of a scenario without messing up the output file. """ - config = {} - config["type"] = CONF.dispatcher.capitalize() - config["file_path"] = filename - dispatcher = DispatcherBase.get(config) + out_type = config['yardstick'].get('DEFAULT', {}).get('dispatcher', 'file') + conf = { + 'type': out_type.capitalize(), + 'file_path': filename + } + + dispatcher = DispatcherBase.get(conf, config) while True: # blocks until data becomes available @@ -123,21 +126,21 @@ class Runner(object): return types @staticmethod - def get(config): + def get(runner_cfg, config): """Returns instance of a scenario runner for execution type. """ # if there is no runner, start the output serializer subprocess if not Runner.runners: log.debug("Starting dump process file '%s'", - config["output_filename"]) + runner_cfg["output_filename"]) Runner.queue = multiprocessing.Queue() Runner.dump_process = multiprocessing.Process( target=_output_serializer_main, name="Dumper", - args=(config["output_filename"], Runner.queue)) + args=(runner_cfg["output_filename"], Runner.queue, config)) Runner.dump_process.start() - return Runner.get_cls(config["type"])(config, Runner.queue) + return Runner.get_cls(runner_cfg["type"])(runner_cfg, Runner.queue) @staticmethod def release_dump_process(): |