X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Frunners%2Fbase.py;h=bf1a71cabdf491ce934d0237aae21089420cbc95;hb=03d764791eeb708ade47b5e2196b18ce04552dd1;hp=56a394e1c36beac9bc034f2d59e7a3ac16f01a27;hpb=791323df72d8bf4f4f4c32a1e7273721f2adc349;p=yardstick.git diff --git a/yardstick/benchmark/runners/base.py b/yardstick/benchmark/runners/base.py index 56a394e1c..bf1a71cab 100755 --- a/yardstick/benchmark/runners/base.py +++ b/yardstick/benchmark/runners/base.py @@ -1,12 +1,22 @@ -############################################################################## -# Copyright (c) 2015 Ericsson AB and others. +# Copyright 2014: Mirantis Inc. +# All Rights Reserved. # -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# yardstick comment: this is a modified copy of +# rally/rally/benchmark/runners/base.py +from __future__ import absolute_import import importlib import logging import multiprocessing @@ -26,10 +36,10 @@ CONF = cfg.CONF def _output_serializer_main(filename, queue): - '''entrypoint for the singleton subprocess writing to outfile + """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 @@ -46,7 +56,7 @@ def _output_serializer_main(filename, queue): def _execute_shell_command(command): - '''execute shell script with error handling''' + """execute shell script with error handling""" exitcode = 0 output = [] try: @@ -54,28 +64,28 @@ def _execute_shell_command(command): except Exception: exitcode = -1 output = traceback.format_exc() - log.error("exec command '%s' error:\n " % command) + log.error("exec command '%s' error:\n ", command) log.error(traceback.format_exc()) return exitcode, output def _single_action(seconds, command, queue): - '''entrypoint for the single action process''' + """entrypoint for the single action process""" log.debug("single action, fires after %d seconds (from now)", seconds) time.sleep(seconds) log.debug("single action: executing command: '%s'", command) ret_code, data = _execute_shell_command(command) if ret_code < 0: - log.error("single action error! command:%s" % command) + log.error("single action error! command:%s", command) queue.put({'single-action-data': data}) return - log.debug("single action data: \n%s" % data) + log.debug("single action data: \n%s", data) queue.put({'single-action-data': data}) def _periodic_action(interval, command, queue): - '''entrypoint for the periodic action process''' + """entrypoint for the periodic action process""" log.debug("periodic action, fires every: %d seconds", interval) time_spent = 0 while True: @@ -87,7 +97,7 @@ def _periodic_action(interval, command, queue): log.error("periodic action error! command:%s", command) queue.put({'periodic-action-data': data}) break - log.debug("periodic action data: \n%s" % data) + log.debug("periodic action data: \n%s", data) queue.put({'periodic-action-data': data}) @@ -98,7 +108,7 @@ class Runner(object): @staticmethod def get_cls(runner_type): - '''return class of specified type''' + """return class of specified type""" for runner in utils.itersubclasses(Runner): if runner_type == runner.__execution_type__: return runner @@ -106,7 +116,7 @@ class Runner(object): @staticmethod def get_types(): - '''return a list of known runner type (class) names''' + """return a list of known runner type (class) names""" types = [] for runner in utils.itersubclasses(Runner): types.append(runner) @@ -118,7 +128,7 @@ class Runner(object): """ # if there is no runner, start the output serializer subprocess if len(Runner.runners) == 0: - log.debug("Starting dump process file '%s'" % + log.debug("Starting dump process file '%s'", config["output_filename"]) Runner.queue = multiprocessing.Queue() Runner.dump_process = multiprocessing.Process( @@ -131,7 +141,7 @@ class Runner(object): @staticmethod def release_dump_process(): - '''Release the dumper process''' + """Release the dumper process""" log.debug("Stopping dump process") if Runner.dump_process: Runner.queue.put('_TERMINATE_') @@ -140,7 +150,7 @@ class Runner(object): @staticmethod def release(runner): - '''Release the runner''' + """Release the runner""" if runner in Runner.runners: Runner.runners.remove(runner) @@ -150,13 +160,13 @@ class Runner(object): @staticmethod def terminate(runner): - '''Terminate the runner''' + """Terminate the runner""" if runner.process and runner.process.is_alive(): runner.process.terminate() @staticmethod def terminate_all(): - '''Terminate all runners (subprocesses)''' + """Terminate all runners (subprocesses)""" log.debug("Terminating all runners") # release dumper process as some errors before any runner is created @@ -184,16 +194,16 @@ class Runner(object): Runner.runners.append(self) def run_post_stop_action(self): - '''run a potentially configured post-stop action''' + """run a potentially configured post-stop action""" if "post-stop-action" in self.config: command = self.config["post-stop-action"]["command"] - log.debug("post stop action: command: '%s'" % command) + log.debug("post stop action: command: '%s'", command) ret_code, data = _execute_shell_command(command) if ret_code < 0: log.error("post action error! command:%s", command) self.result_queue.put({'post-stop-action-data': data}) return - log.debug("post-stop data: \n%s" % data) + log.debug("post-stop data: \n%s", data) self.result_queue.put({'post-stop-action-data': data}) def run(self, scenario_cfg, context_cfg): @@ -210,13 +220,13 @@ class Runner(object): # run a potentially configured pre-start action if "pre-start-action" in self.config: command = self.config["pre-start-action"]["command"] - log.debug("pre start action: command: '%s'" % command) + log.debug("pre start action: command: '%s'", command) ret_code, data = _execute_shell_command(command) if ret_code < 0: log.error("pre-start action error! command:%s", command) self.result_queue.put({'pre-start-action-data': data}) return - log.debug("pre-start data: \n%s" % data) + log.debug("pre-start data: \n%s", data) self.result_queue.put({'pre-start-action-data': data}) if "single-shot-action" in self.config: @@ -240,7 +250,7 @@ class Runner(object): self._run_benchmark(cls, "run", scenario_cfg, context_cfg) def abort(self): - '''Abort the execution of a scenario''' + """Abort the execution of a scenario""" self.aborted.set() def join(self, timeout=None):