diff options
Diffstat (limited to 'yardstick')
122 files changed, 702 insertions, 383 deletions
diff --git a/yardstick/__init__.py b/yardstick/__init__.py index 5c279c800..3ae915c18 100644 --- a/yardstick/__init__.py +++ b/yardstick/__init__.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import os import sys diff --git a/yardstick/benchmark/__init__.py b/yardstick/benchmark/__init__.py index 8b292ac30..898013fa6 100644 --- a/yardstick/benchmark/__init__.py +++ b/yardstick/benchmark/__init__.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import yardstick.common.utils as utils utils.import_modules_from_package("yardstick.benchmark.contexts") diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py index 76a828811..054ce4236 100644 --- a/yardstick/benchmark/contexts/base.py +++ b/yardstick/benchmark/contexts/base.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import abc import six diff --git a/yardstick/benchmark/contexts/dummy.py b/yardstick/benchmark/contexts/dummy.py index 6901b2617..0e76b5a82 100644 --- a/yardstick/benchmark/contexts/dummy.py +++ b/yardstick/benchmark/contexts/dummy.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging from yardstick.benchmark.contexts.base import Context diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 29c47b39a..0b2fbdcd6 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -7,20 +7,28 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import +from __future__ import print_function + +import collections +import logging import os import sys import uuid -import pkg_resources + import paramiko +import pkg_resources from yardstick.benchmark.contexts.base import Context -from yardstick.benchmark.contexts.model import Server -from yardstick.benchmark.contexts.model import PlacementGroup from yardstick.benchmark.contexts.model import Network +from yardstick.benchmark.contexts.model import PlacementGroup +from yardstick.benchmark.contexts.model import Server from yardstick.benchmark.contexts.model import update_scheduler_hints from yardstick.orchestrator.heat import HeatTemplate, get_short_key_uuid from yardstick.definitions import YARDSTICK_ROOT_PATH +LOG = logging.getLogger(__name__) + class HeatContext(Context): '''Class that represents a context in the logical model''' @@ -193,7 +201,7 @@ class HeatContext(Context): def deploy(self): '''deploys template into a stack using cloud''' - print "Deploying context '%s'" % self.name + print("Deploying context '%s'" % self.name) heat_template = HeatTemplate(self.name, self.template_file, self.heat_parameters) @@ -214,29 +222,29 @@ class HeatContext(Context): for server in self.servers: if len(server.ports) > 0: # TODO(hafe) can only handle one internal network for now - port = server.ports.values()[0] + port = list(server.ports.values())[0] server.private_ip = self.stack.outputs[port["stack_name"]] if server.floating_ip: server.public_ip = \ self.stack.outputs[server.floating_ip["stack_name"]] - print "Context '%s' deployed" % self.name + print("Context '%s' deployed" % self.name) def undeploy(self): '''undeploys stack from cloud''' if self.stack: - print "Undeploying context '%s'" % self.name + print("Undeploying context '%s'" % self.name) self.stack.delete() self.stack = None - print "Context '%s' undeployed" % self.name + print("Context '%s' undeployed" % self.name) if os.path.exists(self.key_filename): try: os.remove(self.key_filename) os.remove(self.key_filename + ".pub") - except OSError, e: - print ("Error: %s - %s." % (e.key_filename, e.strerror)) + except OSError: + LOG.exception("Key filename %s", self.key_filename) def _get_server(self, attr_name): '''lookup server info by name from context @@ -247,7 +255,7 @@ class HeatContext(Context): 'yardstick.resources', 'files/yardstick_key-' + get_short_key_uuid(self.key_uuid)) - if type(attr_name) is dict: + if isinstance(attr_name, collections.Mapping): cname = attr_name["name"].split(".")[1] if cname != self.name: return None diff --git a/yardstick/benchmark/contexts/model.py b/yardstick/benchmark/contexts/model.py index d31f4afc0..1d0a5a133 100644 --- a/yardstick/benchmark/contexts/model.py +++ b/yardstick/benchmark/contexts/model.py @@ -10,12 +10,15 @@ """ Logical model """ +from __future__ import absolute_import +from six.moves import range class Object(object): '''Base class for classes in the logical model Contains common attributes and methods ''' + def __init__(self, name, context): # model identities and reference self.name = name @@ -61,6 +64,7 @@ class PlacementGroup(Object): class Router(Object): '''Class that represents a router in the logical model''' + def __init__(self, name, network_name, context, external_gateway_info): super(self.__class__, self).__init__(name, context) diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py index 78bce8259..6db51cccb 100644 --- a/yardstick/benchmark/contexts/node.py +++ b/yardstick/benchmark/contexts/node.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import sys import os import yaml @@ -49,11 +50,11 @@ class NodeContext(Context): self.nodes.extend(cfg["nodes"]) self.controllers.extend([node for node in cfg["nodes"] - if node["role"] == "Controller"]) + if node["role"] == "Controller"]) self.computes.extend([node for node in cfg["nodes"] - if node["role"] == "Compute"]) + if node["role"] == "Compute"]) self.baremetals.extend([node for node in cfg["nodes"] - if node["role"] == "Baremetal"]) + if node["role"] == "Baremetal"]) LOG.debug("Nodes: %r", self.nodes) LOG.debug("Controllers: %r", self.controllers) LOG.debug("Computes: %r", self.computes) diff --git a/yardstick/benchmark/core/plugin.py b/yardstick/benchmark/core/plugin.py index da12ce438..3080f5dd9 100644 --- a/yardstick/benchmark/core/plugin.py +++ b/yardstick/benchmark/core/plugin.py @@ -10,6 +10,7 @@ """ Handler for yardstick command 'plugin' """ from __future__ import print_function +from __future__ import absolute_import import os import sys import yaml @@ -182,7 +183,7 @@ class PluginParser(object): and a deployment instance """ - print ("Parsing plugin config:", self.path) + print("Parsing plugin config:", self.path) try: kw = {} @@ -191,10 +192,10 @@ class PluginParser(object): input_plugin = f.read() rendered_plugin = TaskTemplate.render(input_plugin, **kw) except Exception as e: - print(("Failed to render template:\n%(plugin)s\n%(err)s\n") + print("Failed to render template:\n%(plugin)s\n%(err)s\n" % {"plugin": input_plugin, "err": e}) raise e - print(("Input plugin is:\n%s\n") % rendered_plugin) + print("Input plugin is:\n%s\n" % rendered_plugin) cfg = yaml.load(rendered_plugin) except IOError as ioerror: diff --git a/yardstick/benchmark/core/runner.py b/yardstick/benchmark/core/runner.py index e8dd21a12..5f8132da8 100644 --- a/yardstick/benchmark/core/runner.py +++ b/yardstick/benchmark/core/runner.py @@ -9,6 +9,8 @@ """ Handler for yardstick command 'runner' """ +from __future__ import absolute_import +from __future__ import print_function from yardstick.benchmark.runners.base import Runner from yardstick.benchmark.core import print_hbar @@ -26,11 +28,11 @@ class Runners(object): print("| %-16s | %-60s" % ("Type", "Description")) print_hbar(78) for rtype in types: - print "| %-16s | %-60s" % (rtype.__execution_type__, - rtype.__doc__.split("\n")[0]) + print("| %-16s | %-60s" % (rtype.__execution_type__, + rtype.__doc__.split("\n")[0])) print_hbar(78) def show(self, args): '''Show details of a specific runner type''' rtype = Runner.get_cls(args.type[0]) - print rtype.__doc__ + print(rtype.__doc__) diff --git a/yardstick/benchmark/core/scenario.py b/yardstick/benchmark/core/scenario.py index e228054ee..15335afd4 100644 --- a/yardstick/benchmark/core/scenario.py +++ b/yardstick/benchmark/core/scenario.py @@ -9,6 +9,8 @@ """ Handler for yardstick command 'scenario' """ +from __future__ import absolute_import +from __future__ import print_function from yardstick.benchmark.scenarios.base import Scenario from yardstick.benchmark.core import print_hbar @@ -33,4 +35,4 @@ class Scenarios(object): def show(self, args): '''Show details of a specific scenario type''' stype = Scenario.get_cls(args.type[0]) - print stype.__doc__ + print(stype.__doc__) diff --git a/yardstick/benchmark/core/task.py b/yardstick/benchmark/core/task.py index 8fb117771..d9a85764a 100644 --- a/yardstick/benchmark/core/task.py +++ b/yardstick/benchmark/core/task.py @@ -9,6 +9,8 @@ """ Handler for yardstick command 'task' """ +from __future__ import absolute_import +from __future__ import print_function import sys import os import yaml @@ -18,7 +20,7 @@ import time import logging import uuid import errno -from itertools import ifilter +from six.moves import filter from yardstick.benchmark.contexts.base import Context from yardstick.benchmark.runners import base as base_runner @@ -71,7 +73,7 @@ class Task(object): # pragma: no cover 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]) + self.task_id, task_args[i], task_args_fnames[i]) if not meet_precondition: LOG.info("meet_precondition is %s, please check envrionment", @@ -96,7 +98,7 @@ class Task(object): # pragma: no cover LOG.info("total finished in %d secs", total_end_time - total_start_time) - print "Done, exiting" + print("Done, exiting") def _run(self, scenarios, run_in_parallel, output_file): '''Deploys context and calls runners''' @@ -106,7 +108,7 @@ class Task(object): # pragma: no cover background_runners = [] # Start all background scenarios - for scenario in ifilter(_is_background_scenario, scenarios): + for scenario in filter(_is_background_scenario, scenarios): scenario["runner"] = dict(type="Duration", duration=1000000000) runner = run_one_scenario(scenario, output_file) background_runners.append(runner) @@ -121,14 +123,14 @@ class Task(object): # pragma: no cover # Wait for runners to finish for runner in runners: runner_join(runner) - print "Runner ended, output in", output_file + print("Runner ended, output in", output_file) else: # run serially for scenario in scenarios: if not _is_background_scenario(scenario): runner = run_one_scenario(scenario, output_file) runner_join(runner) - print "Runner ended, output in", output_file + print("Runner ended, output in", output_file) # Abort background runners for runner in background_runners: @@ -142,7 +144,7 @@ class Task(object): # pragma: no cover runner_join(runner) else: base_runner.Runner.release(runner) - print "Background task ended" + print("Background task ended") # TODO: Move stuff below into TaskCommands class !? @@ -150,6 +152,7 @@ class Task(object): # pragma: no cover class TaskParser(object): # pragma: no cover '''Parser for task config files in yaml format''' + def __init__(self, path): self.path = path @@ -224,7 +227,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 + print("Parsing task config:", self.path) try: kw = {} @@ -241,10 +244,10 @@ 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") + print("Failed to render template:\n%(task)s\n%(err)s\n" % {"task": input_task, "err": e}) raise e - print(("Input task is:\n%s\n") % rendered_task) + print("Input task is:\n%s\n" % rendered_task) cfg = yaml.load(rendered_task) except IOError as ioerror: @@ -343,7 +346,7 @@ def atexit_handler(): base_runner.Runner.terminate_all() if len(Context.list) > 0: - print "Undeploying all contexts" + print("Undeploying all contexts") for context in Context.list: context.undeploy() @@ -351,7 +354,7 @@ def atexit_handler(): def is_ip_addr(addr): '''check if string addr is an IP address''' try: - ipaddress.ip_address(unicode(addr)) + ipaddress.ip_address(addr.encode('utf-8')) return True except ValueError: return False @@ -434,7 +437,7 @@ def run_one_scenario(scenario_cfg, output_file): 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"] + print("Starting runner of type '%s'" % runner_cfg["type"]) runner.run(scenario_cfg, context_cfg) return runner @@ -460,7 +463,7 @@ def runner_join(runner): def print_invalid_header(source_name, args): - print(("Invalid %(source)s passed:\n\n %(args)s\n") + print("Invalid %(source)s passed:\n\n %(args)s\n" % {"source": source_name, "args": args}) @@ -470,13 +473,13 @@ def parse_task_args(src_name, args): kw = {} if kw is None else kw except yaml.parser.ParserError as e: print_invalid_header(src_name, args) - print(("%(source)s has to be YAML. Details:\n\n%(err)s\n") + print("%(source)s has to be YAML. Details:\n\n%(err)s\n" % {"source": src_name, "err": e}) raise TypeError() if not isinstance(kw, dict): print_invalid_header(src_name, args) - print(("%(src)s had to be dict, actually %(src_type)s\n") + print("%(src)s had to be dict, actually %(src_type)s\n" % {"src": src_name, "src_type": type(kw)}) raise TypeError() return kw diff --git a/yardstick/benchmark/core/testcase.py b/yardstick/benchmark/core/testcase.py index d292ad2d7..74304857f 100644 --- a/yardstick/benchmark/core/testcase.py +++ b/yardstick/benchmark/core/testcase.py @@ -8,6 +8,8 @@ ############################################################################## """ Handler for yardstick command 'testcase' """ +from __future__ import absolute_import +from __future__ import print_function import os import yaml import sys @@ -22,6 +24,7 @@ class Testcase(object): Set of commands to discover and display test cases. ''' + def __init__(self): self.test_case_path = YARDSTICK_ROOT_PATH + 'tests/opnfv/test_cases/' self.testcase_list = [] @@ -32,7 +35,7 @@ class Testcase(object): try: testcase_files = os.listdir(self.test_case_path) except Exception as e: - print(("Failed to list dir:\n%(path)s\n%(err)s\n") + print("Failed to list dir:\n%(path)s\n%(err)s\n" % {"path": self.test_case_path, "err": e}) raise e testcase_files.sort() @@ -52,11 +55,11 @@ class Testcase(object): with open(testcase_path) as f: try: testcase_info = f.read() - print testcase_info + print(testcase_info) except Exception as e: - print(("Failed to load test cases:" - "\n%(testcase_file)s\n%(err)s\n") + print("Failed to load test cases:" + "\n%(testcase_file)s\n%(err)s\n" % {"testcase_file": testcase_path, "err": e}) raise e except IOError as ioerror: @@ -70,8 +73,8 @@ class Testcase(object): try: testcase_info = f.read() except Exception as e: - print(("Failed to load test cases:" - "\n%(testcase_file)s\n%(err)s\n") + print("Failed to load test cases:" + "\n%(testcase_file)s\n%(err)s\n" % {"testcase_file": testcase_file, "err": e}) raise e description, installer, deploy_scenarios = \ @@ -107,6 +110,6 @@ class Testcase(object): print("| %-21s | %-60s" % ("Testcase Name", "Description")) print_hbar(88) for testcase_record in testcase_list: - print "| %-16s | %-60s" % (testcase_record['Name'], - testcase_record['Description']) + print("| %-16s | %-60s" % (testcase_record['Name'], + testcase_record['Description'])) print_hbar(88) diff --git a/yardstick/benchmark/runners/arithmetic.py b/yardstick/benchmark/runners/arithmetic.py index 69ea915a1..956c3ffd1 100755 --- a/yardstick/benchmark/runners/arithmetic.py +++ b/yardstick/benchmark/runners/arithmetic.py @@ -24,12 +24,17 @@ until the end of the shortest list is reached (optimally all lists should be defined with the same number of values when using such iter_type). ''' -import os -import multiprocessing +from __future__ import absolute_import + +import itertools import logging -import traceback +import multiprocessing +import os import time -import itertools +import traceback + +import six +from six.moves import range from yardstick.benchmark.runners import base @@ -71,8 +76,8 @@ def _worker_process(queue, cls, method_name, scenario_cfg, return -1 if start > stop else 1 param_iters = \ - [xrange(d['start'], d['stop'] + margin(d['start'], d['stop']), - d['step']) for d in runner_cfg['iterators']] + [range(d['start'], d['stop'] + margin(d['start'], d['stop']), + d['step']) for d in runner_cfg['iterators']] param_names = [d['name'] for d in runner_cfg['iterators']] iter_type = runner_cfg.get("iter_type", "nested_for_loops") @@ -82,10 +87,10 @@ def _worker_process(queue, cls, method_name, scenario_cfg, loop_iter = itertools.product(*param_iters) elif iter_type == 'tuple_loops': # Combine each i;th index of respective parameter list - loop_iter = itertools.izip(*param_iters) + loop_iter = six.moves.zip(*param_iters) else: LOG.warning("iter_type unrecognized: %s", iter_type) - raise + raise TypeError("iter_type unrecognized: %s", iter_type) # Populate options and run the requested method for each value combination for comb_values in loop_iter: diff --git a/yardstick/benchmark/runners/base.py b/yardstick/benchmark/runners/base.py index 8f3f75fa1..0e0292713 100755 --- a/yardstick/benchmark/runners/base.py +++ b/yardstick/benchmark/runners/base.py @@ -16,6 +16,7 @@ # 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 diff --git a/yardstick/benchmark/runners/duration.py b/yardstick/benchmark/runners/duration.py index 1412c0caa..89cac7db8 100644 --- a/yardstick/benchmark/runners/duration.py +++ b/yardstick/benchmark/runners/duration.py @@ -19,6 +19,7 @@ '''A runner that runs a specific time before it returns ''' +from __future__ import absolute_import import os import multiprocessing import logging diff --git a/yardstick/benchmark/runners/iteration.py b/yardstick/benchmark/runners/iteration.py index 3a839b65f..930f883e9 100644 --- a/yardstick/benchmark/runners/iteration.py +++ b/yardstick/benchmark/runners/iteration.py @@ -19,6 +19,7 @@ '''A runner that runs a configurable number of times before it returns ''' +from __future__ import absolute_import import os import multiprocessing import logging diff --git a/yardstick/benchmark/runners/sequence.py b/yardstick/benchmark/runners/sequence.py index 3b06e2a36..e6abeab3c 100644 --- a/yardstick/benchmark/runners/sequence.py +++ b/yardstick/benchmark/runners/sequence.py @@ -20,6 +20,7 @@ The input value in the sequence is specified in a list in the input file. ''' +from __future__ import absolute_import import os import multiprocessing import logging diff --git a/yardstick/benchmark/scenarios/availability/actionrollbackers.py b/yardstick/benchmark/scenarios/availability/actionrollbackers.py index 38f57d476..28c338d60 100644 --- a/yardstick/benchmark/scenarios/availability/actionrollbackers.py +++ b/yardstick/benchmark/scenarios/availability/actionrollbackers.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging LOG = logging.getLogger(__name__) diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py index e88fed636..7eb93a80f 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py +++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py @@ -6,11 +6,14 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -import traceback import subprocess +import traceback + import yardstick.ssh as ssh -from baseattacker import BaseAttacker +from yardstick.benchmark.scenarios.availability.attacker.baseattacker import \ + BaseAttacker LOG = logging.getLogger(__name__) diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py index 595067a95..38a966803 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py +++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py @@ -6,11 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -from baseattacker import BaseAttacker import yardstick.ssh as ssh from yardstick.benchmark.scenarios.availability import util +from yardstick.benchmark.scenarios.availability.attacker.baseattacker import \ + BaseAttacker LOG = logging.getLogger(__name__) @@ -40,7 +42,7 @@ class GeneralAttacker(BaseAttacker): str = util.buildshellparams(actionParameter) LOG.debug("inject parameter is: {0}".format(actionParameter)) LOG.debug("inject parameter values are: {0}" - .format(actionParameter.values())) + .format(list(actionParameter.values()))) l = list(item for item in actionParameter.values()) self.action_param = str.format(*l) @@ -49,7 +51,7 @@ class GeneralAttacker(BaseAttacker): str = util.buildshellparams(rollbackParameter) LOG.debug("recover parameter is: {0}".format(rollbackParameter)) LOG.debug("recover parameter values are: {0}". - format(rollbackParameter.values())) + format(list(rollbackParameter.values()))) l = list(item for item in rollbackParameter.values()) self.rollback_param = str.format(*l) diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py index 1d190a160..521c57931 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py +++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py @@ -6,10 +6,12 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -from baseattacker import BaseAttacker import yardstick.ssh as ssh +from yardstick.benchmark.scenarios.availability.attacker.baseattacker import \ + BaseAttacker LOG = logging.getLogger(__name__) diff --git a/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py b/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py index f96e57728..f5f74f291 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py +++ b/yardstick/benchmark/scenarios/availability/attacker/baseattacker.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import pkg_resources import yaml import logging diff --git a/yardstick/benchmark/scenarios/availability/director.py b/yardstick/benchmark/scenarios/availability/director.py index 104c68380..76fcc0e7f 100644 --- a/yardstick/benchmark/scenarios/availability/director.py +++ b/yardstick/benchmark/scenarios/availability/director.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging from yardstick.benchmark.scenarios.availability.monitor import basemonitor diff --git a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py index 38d1c4e5c..a11966a12 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py +++ b/yardstick/benchmark/scenarios/availability/monitor/basemonitor.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import pkg_resources import logging import multiprocessing @@ -23,6 +24,7 @@ monitor_conf_path = pkg_resources.resource_filename( class MonitorMgr(object): """docstring for MonitorMgr""" + def __init__(self): self._monitor_list = [] @@ -130,7 +132,7 @@ class BaseMonitor(multiprocessing.Process): total_time = end_time - begin_time self._queue.put({"total_time": total_time, - "outage_time": last_outage-first_outage, + "outage_time": last_outage - first_outage, "total_count": total_count, "outage_count": outage_count}) diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py index cd33e6188..6ddb73ea2 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py @@ -6,11 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import subprocess import traceback + import yardstick.ssh as ssh -import basemonitor as basemonitor +from yardstick.benchmark.scenarios.availability.monitor import basemonitor LOG = logging.getLogger(__name__) diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py index 461a2ded5..78a603193 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py @@ -6,10 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import yardstick.ssh as ssh -import basemonitor as basemonitor +from yardstick.benchmark.scenarios.availability.monitor import basemonitor from yardstick.benchmark.scenarios.availability.util import buildshellparams diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py index 5f492ad69..10b398e9b 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py @@ -6,10 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import yardstick.ssh as ssh -import basemonitor as basemonitor +from yardstick.benchmark.scenarios.availability.monitor import basemonitor LOG = logging.getLogger(__name__) diff --git a/yardstick/benchmark/scenarios/availability/operation/baseoperation.py b/yardstick/benchmark/scenarios/availability/operation/baseoperation.py index 80efd1b02..709884b6f 100644 --- a/yardstick/benchmark/scenarios/availability/operation/baseoperation.py +++ b/yardstick/benchmark/scenarios/availability/operation/baseoperation.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import pkg_resources import yaml import logging diff --git a/yardstick/benchmark/scenarios/availability/operation/operation_general.py b/yardstick/benchmark/scenarios/availability/operation/operation_general.py index c82df836d..42d70f4da 100644 --- a/yardstick/benchmark/scenarios/availability/operation/operation_general.py +++ b/yardstick/benchmark/scenarios/availability/operation/operation_general.py @@ -6,8 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -from baseoperation import BaseOperation + +from yardstick.benchmark.scenarios.availability.operation.baseoperation \ + import \ + BaseOperation + import yardstick.ssh as ssh from yardstick.benchmark.scenarios.availability.util import buildshellparams diff --git a/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py b/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py index a24f26e81..70e004012 100644 --- a/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py +++ b/yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import pkg_resources import yaml import logging @@ -46,7 +47,7 @@ class ResultCheckerMgr(object): def verify(self): result = True for obj in self._result_checker_list: - result &= obj.success + result &= obj.success return result diff --git a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py index 275aff076..75c433a0e 100644 --- a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py +++ b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -from baseresultchecker import BaseResultChecker + +from yardstick.benchmark.scenarios.availability.result_checker \ + .baseresultchecker import \ + BaseResultChecker from yardstick.benchmark.scenarios.availability import Condition import yardstick.ssh as ssh from yardstick.benchmark.scenarios.availability.util import buildshellparams diff --git a/yardstick/benchmark/scenarios/availability/scenario_general.py b/yardstick/benchmark/scenarios/availability/scenario_general.py index b064c6724..2d7ce664e 100644 --- a/yardstick/benchmark/scenarios/availability/scenario_general.py +++ b/yardstick/benchmark/scenarios/availability/scenario_general.py @@ -6,8 +6,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging -import traceback from yardstick.benchmark.scenarios import base from yardstick.benchmark.scenarios.availability.director import Director @@ -34,8 +34,8 @@ class ScenarioGeneral(base.Scenario): orderedSteps = sorted(steps, key=lambda x: x['index']) for step in orderedSteps: LOG.debug( - "\033[94m running step: {0} .... \033[0m" - .format(orderedSteps.index(step)+1)) + "\033[94m running step: %s .... \033[0m", + orderedSteps.index(step) + 1) try: actionPlayer = self.director.createActionPlayer( step['actionType'], step['actionKey']) @@ -44,9 +44,8 @@ class ScenarioGeneral(base.Scenario): step['actionType'], step['actionKey']) if actionRollbacker: self.director.executionSteps.append(actionRollbacker) - except Exception, e: - LOG.debug(e.message) - traceback.print_exc() + except Exception: + LOG.exception("Exception") LOG.debug( "\033[91m exception when running step: {0} .... \033[0m" .format(orderedSteps.index(step))) diff --git a/yardstick/benchmark/scenarios/availability/serviceha.py b/yardstick/benchmark/scenarios/availability/serviceha.py index 46a197c3b..b981c8cd8 100755 --- a/yardstick/benchmark/scenarios/availability/serviceha.py +++ b/yardstick/benchmark/scenarios/availability/serviceha.py @@ -6,6 +6,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import print_function +from __future__ import absolute_import import logging from yardstick.benchmark.scenarios import base from yardstick.benchmark.scenarios.availability.monitor import basemonitor @@ -109,15 +111,16 @@ def _test(): # pragma: no cover sla = {"outage_time": 5} args = {"options": options, "sla": sla} - print "create instance" + print("create instance") terstInstance = ServiceHA(args, ctx) terstInstance.setup() result = {} terstInstance.run(result) - print result + print(result) terstInstance.teardown() + if __name__ == '__main__': # pragma: no cover _test() diff --git a/yardstick/benchmark/scenarios/base.py b/yardstick/benchmark/scenarios/base.py index 33efbcbc4..5f5c07d3b 100644 --- a/yardstick/benchmark/scenarios/base.py +++ b/yardstick/benchmark/scenarios/base.py @@ -19,6 +19,7 @@ """ Scenario base class """ +from __future__ import absolute_import import yardstick.common.utils as utils diff --git a/yardstick/benchmark/scenarios/compute/cachestat.py b/yardstick/benchmark/scenarios/compute/cachestat.py index 20786ff61..0f60d466e 100644 --- a/yardstick/benchmark/scenarios/compute/cachestat.py +++ b/yardstick/benchmark/scenarios/compute/cachestat.py @@ -9,12 +9,14 @@ """cache hit/miss ratio and usage statistics""" +from __future__ import absolute_import import pkg_resources import logging import re import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base +from six.moves import zip LOG = logging.getLogger(__name__) @@ -120,7 +122,7 @@ class CACHEstat(base.Scenario): ite += 1 values = line[:] if values and len(values) == len(fields): - cachestat[cache] = dict(zip(fields, values)) + cachestat[cache] = dict(list(zip(fields, values))) for entry in cachestat: for item in average: diff --git a/yardstick/benchmark/scenarios/compute/computecapacity.py b/yardstick/benchmark/scenarios/compute/computecapacity.py index 7f0c58de1..9d518f7a0 100644 --- a/yardstick/benchmark/scenarios/compute/computecapacity.py +++ b/yardstick/benchmark/scenarios/compute/computecapacity.py @@ -6,9 +6,12 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -66,4 +69,4 @@ class ComputeCapacity(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) diff --git a/yardstick/benchmark/scenarios/compute/cpuload.py b/yardstick/benchmark/scenarios/compute/cpuload.py index 9d71038ef..121d5a75d 100644 --- a/yardstick/benchmark/scenarios/compute/cpuload.py +++ b/yardstick/benchmark/scenarios/compute/cpuload.py @@ -9,13 +9,16 @@ """Processor statistics and system load.""" +from __future__ import absolute_import + import logging -import time import re -import yardstick.ssh as ssh +import time -from yardstick.benchmark.scenarios import base +from six.moves import map, zip +import yardstick.ssh as ssh +from yardstick.benchmark.scenarios import base LOG = logging.getLogger(__name__) @@ -145,7 +148,7 @@ class CPULoad(base.Scenario): cpu = 'cpu' if line[0] == 'all' else 'cpu' + line[0] values = line[1:] if values and len(values) == len(fields): - temp_dict = dict(zip(fields, values)) + temp_dict = dict(list(zip(fields, values))) if cpu not in maximum: maximum[cpu] = temp_dict else: @@ -177,7 +180,7 @@ class CPULoad(base.Scenario): cpu = 'cpu' if line[0] == 'all' else 'cpu' + line[0] values = line[1:] if values and len(values) == len(fields): - average[cpu] = dict(zip(fields, values)) + average[cpu] = dict(list(zip(fields, values))) else: raise RuntimeError("mpstat average: parse error", fields, line) @@ -210,9 +213,9 @@ class CPULoad(base.Scenario): cpu = cur_list[0] - cur_stats = map(int, cur_list[1:]) + cur_stats = list(map(int, cur_list[1:])) if self.interval > 0: - prev_stats = map(int, prev_list[1:]) + prev_stats = list(map(int, prev_list[1:])) else: prev_stats = [0] * len(cur_stats) @@ -236,9 +239,9 @@ class CPULoad(base.Scenario): else: return "%.2f" % (100.0 * (x - y) / samples) - load = map(_percent, cur_stats, prev_stats) + load = list(map(_percent, cur_stats, prev_stats)) - mpstat[cpu] = dict(zip(fields, load)) + mpstat[cpu] = dict(list(zip(fields, load))) return {'mpstat': mpstat} @@ -278,7 +281,7 @@ class CPULoad(base.Scenario): # p = CPULoad(args, ctx) # p.run(result) # import json -# print json.dumps(result) +# print(oslo_serialization.jsonutils.dump_as_bytes(result)) # if __name__ == '__main__': # _test() diff --git a/yardstick/benchmark/scenarios/compute/cyclictest.py b/yardstick/benchmark/scenarios/compute/cyclictest.py index 568e6e7df..76bafff2b 100644 --- a/yardstick/benchmark/scenarios/compute/cyclictest.py +++ b/yardstick/benchmark/scenarios/compute/cyclictest.py @@ -6,12 +6,16 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json +import os import re import time -import os + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -183,7 +187,7 @@ class Cyclictest(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if "sla" in self.scenario_cfg: sla_error = "" @@ -236,7 +240,8 @@ def _test(): # pragma: no cover cyclictest = Cyclictest(args, ctx) cyclictest.run(result) - print result + print(result) + if __name__ == '__main__': # pragma: no cover _test() diff --git a/yardstick/benchmark/scenarios/compute/lmbench.py b/yardstick/benchmark/scenarios/compute/lmbench.py index 518840c09..6a17ae8a1 100644 --- a/yardstick/benchmark/scenarios/compute/lmbench.py +++ b/yardstick/benchmark/scenarios/compute/lmbench.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -130,9 +134,10 @@ class Lmbench(base.Scenario): raise RuntimeError(stderr) if test_type == 'latency': - result.update({"latencies": json.loads(stdout)}) + result.update( + {"latencies": jsonutils.loads(stdout)}) else: - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if "sla" in self.scenario_cfg: sla_error = "" @@ -185,7 +190,8 @@ def _test(): p = Lmbench(args, ctx) p.run(result) - print result + print(result) + if __name__ == '__main__': _test() diff --git a/yardstick/benchmark/scenarios/compute/memload.py b/yardstick/benchmark/scenarios/compute/memload.py index e1ba93d02..35528d4ef 100644 --- a/yardstick/benchmark/scenarios/compute/memload.py +++ b/yardstick/benchmark/scenarios/compute/memload.py @@ -9,10 +9,12 @@ """Memory load and statistics.""" +from __future__ import absolute_import import logging import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base +from six.moves import zip LOG = logging.getLogger(__name__) @@ -88,7 +90,7 @@ class MEMLoad(base.Scenario): ite += 1 values = line[1:] if values and len(values) == len(fields): - free[memory] = dict(zip(fields, values)) + free[memory] = dict(list(zip(fields, values))) for entry in free: for item in average: diff --git a/yardstick/benchmark/scenarios/compute/perf.py b/yardstick/benchmark/scenarios/compute/perf.py index 8f1a4d630..ae4990688 100644 --- a/yardstick/benchmark/scenarios/compute/perf.py +++ b/yardstick/benchmark/scenarios/compute/perf.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -100,7 +104,7 @@ class Perf(base.Scenario): if status: raise RuntimeError(stdout) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if "sla" in self.scenario_cfg: metric = self.scenario_cfg['sla']['metric'] @@ -140,7 +144,8 @@ def _test(): p = Perf(args, ctx) p.run(result) - print result + print(result) + if __name__ == '__main__': _test() diff --git a/yardstick/benchmark/scenarios/compute/plugintest.py b/yardstick/benchmark/scenarios/compute/plugintest.py index e7ec91c5c..c9d025964 100644 --- a/yardstick/benchmark/scenarios/compute/plugintest.py +++ b/yardstick/benchmark/scenarios/compute/plugintest.py @@ -6,8 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import + import logging -import json + +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -53,4 +56,4 @@ class PluginTest(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) diff --git a/yardstick/benchmark/scenarios/compute/ramspeed.py b/yardstick/benchmark/scenarios/compute/ramspeed.py index db70af90b..4330202de 100644 --- a/yardstick/benchmark/scenarios/compute/ramspeed.py +++ b/yardstick/benchmark/scenarios/compute/ramspeed.py @@ -6,9 +6,12 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -131,7 +134,7 @@ class Ramspeed(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if "sla" in self.scenario_cfg: sla_error = "" diff --git a/yardstick/benchmark/scenarios/compute/unixbench.py b/yardstick/benchmark/scenarios/compute/unixbench.py index b22be29c9..4a2eb9766 100644 --- a/yardstick/benchmark/scenarios/compute/unixbench.py +++ b/yardstick/benchmark/scenarios/compute/unixbench.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -115,7 +119,7 @@ class Unixbench(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if "sla" in self.scenario_cfg: sla_error = "" @@ -152,7 +156,7 @@ def _test(): # pragma: no cover p = Unixbench(args, ctx) p.run(result) - print result + print(result) if __name__ == '__main__': diff --git a/yardstick/benchmark/scenarios/dummy/dummy.py b/yardstick/benchmark/scenarios/dummy/dummy.py index de6742c40..95146e0c5 100644 --- a/yardstick/benchmark/scenarios/dummy/dummy.py +++ b/yardstick/benchmark/scenarios/dummy/dummy.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging from yardstick.benchmark.scenarios import base diff --git a/yardstick/benchmark/scenarios/networking/iperf3.py b/yardstick/benchmark/scenarios/networking/iperf3.py index 13fa0155b..b8ec9acdf 100644 --- a/yardstick/benchmark/scenarios/networking/iperf3.py +++ b/yardstick/benchmark/scenarios/networking/iperf3.py @@ -10,9 +10,13 @@ # iperf3 scenario # iperf3 homepage at: http://software.es.net/iperf/ +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -89,7 +93,7 @@ For more info see http://software.es.net/iperf self.host.close() status, stdout, stderr = self.target.execute("pkill iperf3") if status: - LOG.warn(stderr) + LOG.warning(stderr) self.target.close() def run(self, result): @@ -138,7 +142,8 @@ For more info see http://software.es.net/iperf # Note: convert all ints to floats in order to avoid # schema conflicts in influxdb. We probably should add # a format func in the future. - result.update(json.loads(stdout, parse_int=float)) + result.update( + jsonutils.loads(stdout, parse_int=float)) if "sla" in self.scenario_cfg: sla_iperf = self.scenario_cfg["sla"] @@ -188,7 +193,8 @@ def _test(): p = Iperf(args, ctx) p.run(result) - print result + print(result) + if __name__ == '__main__': _test() diff --git a/yardstick/benchmark/scenarios/networking/netperf.py b/yardstick/benchmark/scenarios/networking/netperf.py index 28f5bea56..80dbed334 100755 --- a/yardstick/benchmark/scenarios/networking/netperf.py +++ b/yardstick/benchmark/scenarios/networking/netperf.py @@ -7,9 +7,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## # bulk data test and req/rsp test are supported -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -129,7 +133,7 @@ class Netperf(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if result['mean_latency'] == '': raise RuntimeError(stdout) @@ -175,7 +179,7 @@ def _test(): netperf = Netperf(args, ctx) netperf.run(result) - print result + print(result) if __name__ == '__main__': diff --git a/yardstick/benchmark/scenarios/networking/netperf_node.py b/yardstick/benchmark/scenarios/networking/netperf_node.py index a76982b6f..0cf52b8dd 100755 --- a/yardstick/benchmark/scenarios/networking/netperf_node.py +++ b/yardstick/benchmark/scenarios/networking/netperf_node.py @@ -7,9 +7,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## # bulk data test and req/rsp test are supported -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -152,7 +156,7 @@ class NetperfNode(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if result['mean_latency'] == '': raise RuntimeError(stdout) @@ -200,7 +204,8 @@ def _test(): # pragma: no cover netperf = NetperfNode(args, ctx) netperf.run(result) - print result + print(result) + if __name__ == '__main__': _test() diff --git a/yardstick/benchmark/scenarios/networking/netutilization.py b/yardstick/benchmark/scenarios/networking/netutilization.py index 1ea92cca3..1ba6f1ec3 100644 --- a/yardstick/benchmark/scenarios/networking/netutilization.py +++ b/yardstick/benchmark/scenarios/networking/netutilization.py @@ -6,11 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import re import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base +from six.moves import zip LOG = logging.getLogger(__name__) @@ -121,7 +123,7 @@ class NetUtilization(base.Scenario): values = line[1:] if values and len(values) == len(fields): - temp_dict = dict(zip(fields, values)) + temp_dict = dict(list(zip(fields, values))) if net_interface not in maximum: maximum[net_interface] = temp_dict else: @@ -158,7 +160,8 @@ class NetUtilization(base.Scenario): net_interface = line[0] values = line[1:] if values and len(values) == len(fields): - average[net_interface] = dict(zip(fields, values)) + average[net_interface] = dict( + list(zip(fields, values))) else: raise RuntimeError("network_utilization average: \ parse error", fields, line) diff --git a/yardstick/benchmark/scenarios/networking/networkcapacity.py b/yardstick/benchmark/scenarios/networking/networkcapacity.py index 250f7eaf0..e7ce83570 100644 --- a/yardstick/benchmark/scenarios/networking/networkcapacity.py +++ b/yardstick/benchmark/scenarios/networking/networkcapacity.py @@ -6,9 +6,12 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -67,4 +70,4 @@ class NetworkCapacity(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) diff --git a/yardstick/benchmark/scenarios/networking/ping.py b/yardstick/benchmark/scenarios/networking/ping.py index 6e49a1437..eb173f1df 100644 --- a/yardstick/benchmark/scenarios/networking/ping.py +++ b/yardstick/benchmark/scenarios/networking/ping.py @@ -9,6 +9,8 @@ # ping scenario +from __future__ import print_function +from __future__ import absolute_import import pkg_resources import logging @@ -122,7 +124,8 @@ def _test(): # pragma: no cover p = Ping(args, ctx) p.run(result) - print result + print(result) + if __name__ == '__main__': # pragma: no cover _test() diff --git a/yardstick/benchmark/scenarios/networking/ping6.py b/yardstick/benchmark/scenarios/networking/ping6.py index f4d23ce7b..dd4272236 100644 --- a/yardstick/benchmark/scenarios/networking/ping6.py +++ b/yardstick/benchmark/scenarios/networking/ping6.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import pkg_resources import logging diff --git a/yardstick/benchmark/scenarios/networking/pktgen.py b/yardstick/benchmark/scenarios/networking/pktgen.py index e2df706a2..69663ec5f 100644 --- a/yardstick/benchmark/scenarios/networking/pktgen.py +++ b/yardstick/benchmark/scenarios/networking/pktgen.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -130,7 +134,7 @@ class Pktgen(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) result['packets_received'] = self._iptables_get_result() @@ -170,7 +174,7 @@ def _test(): p = Pktgen(args, ctx) p.run(result) - print result + print(result) if __name__ == '__main__': diff --git a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py index 503ea97e1..2bdb91abb 100644 --- a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py +++ b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import pkg_resources import logging import time diff --git a/yardstick/benchmark/scenarios/networking/sfc.py b/yardstick/benchmark/scenarios/networking/sfc.py index 1bd99b957..87fea4f95 100644 --- a/yardstick/benchmark/scenarios/networking/sfc.py +++ b/yardstick/benchmark/scenarios/networking/sfc.py @@ -1,9 +1,14 @@ -import pkg_resources +from __future__ import absolute_import + import logging import subprocess -import sfc_openstack + +import pkg_resources +from six.moves import range + import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base +from yardstick.benchmark.scenarios.networking import sfc_openstack LOG = logging.getLogger(__name__) @@ -199,7 +204,7 @@ class Sfc(base.Scenario): # pragma: no cover sfc = Sfc(scenario_cfg, context_cfg) sfc.setup() sfc.run(result) - print result + print(result) sfc.teardown() if __name__ == '__main__': # pragma: no cover diff --git a/yardstick/benchmark/scenarios/networking/sfc_openstack.py b/yardstick/benchmark/scenarios/networking/sfc_openstack.py index d1d45d8e4..caaf10060 100644 --- a/yardstick/benchmark/scenarios/networking/sfc_openstack.py +++ b/yardstick/benchmark/scenarios/networking/sfc_openstack.py @@ -1,3 +1,5 @@ +from __future__ import print_function +from __future__ import absolute_import import os from novaclient import client as novaclient from neutronclient.v2_0 import client as neutronclient @@ -40,8 +42,8 @@ def get_credentials(service): # pragma: no cover "ca_file": cacert}) creds.update({"insecure": "True", "https_insecure": "True"}) if not os.path.isfile(cacert): - print ("WARNING: The 'OS_CACERT' environment variable is " + - "set to %s but the file does not exist." % cacert) + print(("WARNING: The 'OS_CACERT' environment variable is " + + "set to %s but the file does not exist." % cacert)) return creds @@ -49,8 +51,8 @@ def get_instances(nova_client): # pragma: no cover try: instances = nova_client.servers.list(search_opts={'all_tenants': 1}) return instances - except Exception, e: - print "Error [get_instances(nova_client)]:", e + except Exception as e: + print("Error [get_instances(nova_client)]:", e) return None @@ -62,8 +64,8 @@ def get_SFs(nova_client): # pragma: no cover if "sfc_test" not in instance.name: SFs.append(instance) return SFs - except Exception, e: - print "Error [get_SFs(nova_client)]:", e + except Exception as e: + print("Error [get_SFs(nova_client)]:", e) return None @@ -83,8 +85,8 @@ def create_floating_ips(neutron_client): # pragma: no cover ip_json = neutron_client.create_floatingip({'floatingip': props}) fip_addr = ip_json['floatingip']['floating_ip_address'] ips.append(fip_addr) - except Exception, e: - print "Error [create_floating_ip(neutron_client)]:", e + except Exception as e: + print("Error [create_floating_ip(neutron_client)]:", e) return None return ips @@ -96,9 +98,9 @@ def floatIPtoSFs(SFs, floatips): # pragma: no cover SF.add_floating_ip(floatips[i]) i = i + 1 return True - except Exception, e: - print ("Error [add_floating_ip(nova_client, '%s', '%s')]:" % - (SF, floatips[i]), e) + except Exception as e: + print(("Error [add_floating_ip(nova_client, '%s', '%s')]:" % + (SF, floatips[i]), e)) return False @@ -113,5 +115,6 @@ def get_an_IP(): # pragma: no cover floatIPtoSFs(SFs, floatips) return floatips + if __name__ == '__main__': # pragma: no cover get_an_IP() diff --git a/yardstick/benchmark/scenarios/networking/vsperf.py b/yardstick/benchmark/scenarios/networking/vsperf.py index 4f4ef21eb..9d6db7c1d 100644 --- a/yardstick/benchmark/scenarios/networking/vsperf.py +++ b/yardstick/benchmark/scenarios/networking/vsperf.py @@ -13,6 +13,7 @@ # limitations under the License. """ Vsperf specific scenario definition """ +from __future__ import absolute_import import logging import os import subprocess @@ -211,7 +212,7 @@ class Vsperf(base.Scenario): # convert result.csv to JSON format reader = csv.DictReader(stdout.split('\r\n')) - result.update(reader.next()) + result.update(next(reader)) # sla check; go through all defined SLAs and check if values measured # by VSPERF are higher then those defined by SLAs diff --git a/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation.py b/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation.py index bec23fc52..bf42d9a9a 100644 --- a/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation.py +++ b/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import os @@ -81,7 +82,7 @@ class VtcInstantiationValidation(base.Scenario): heat_template_parameters, deployment_configuration, openstack_credentials) - except Exception as e: - LOG.info('Exception: {}'.format(e.message)) - LOG.info('Got output: {}'.format(res)) + except Exception: + LOG.exception('Exception') + LOG.info('Got output: %s', res) result.update(res) diff --git a/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation_noisy.py b/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation_noisy.py index 8d9bf0962..fb6e762d1 100644 --- a/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation_noisy.py +++ b/yardstick/benchmark/scenarios/networking/vtc_instantiation_validation_noisy.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import os @@ -92,7 +93,7 @@ class VtcInstantiationValidationNoisy(base.Scenario): heat_template_parameters, deployment_configuration, openstack_credentials) - except Exception as e: - LOG.info('Exception: {}'.format(e.message)) - LOG.info('Got output: {}'.format(res)) + except Exception: + LOG.exception('Exception') + LOG.info('Got output: %s', res) result.update(res) diff --git a/yardstick/benchmark/scenarios/networking/vtc_throughput.py b/yardstick/benchmark/scenarios/networking/vtc_throughput.py index ff20279ff..0754d3782 100644 --- a/yardstick/benchmark/scenarios/networking/vtc_throughput.py +++ b/yardstick/benchmark/scenarios/networking/vtc_throughput.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import os @@ -81,7 +82,7 @@ class VtcThroughput(base.Scenario): heat_template_parameters, deployment_configuration, openstack_credentials) - except Exception as e: - LOG.info('Exception: {}'.format(e.message)) - LOG.info('Got output: {}'.format(res)) + except Exception: + LOG.exception("Exception") + LOG.info('Got output: %s', res) result.update(res) diff --git a/yardstick/benchmark/scenarios/networking/vtc_throughput_noisy.py b/yardstick/benchmark/scenarios/networking/vtc_throughput_noisy.py index f03226732..552ef8090 100644 --- a/yardstick/benchmark/scenarios/networking/vtc_throughput_noisy.py +++ b/yardstick/benchmark/scenarios/networking/vtc_throughput_noisy.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import os @@ -91,7 +92,7 @@ class VtcThroughputNoisy(base.Scenario): heat_template_parameters, deployment_configuration, openstack_credentials) - except Exception as e: - LOG.info('Exception: {}'.format(e.message)) - LOG.info('Got output: {}'.format(res)) + except Exception: + LOG.exception('Exception') + LOG.info('Got output: %s', res) result.update(res) diff --git a/yardstick/benchmark/scenarios/parser/parser.py b/yardstick/benchmark/scenarios/parser/parser.py index bb16e7c89..6d39733c6 100644 --- a/yardstick/benchmark/scenarios/parser/parser.py +++ b/yardstick/benchmark/scenarios/parser/parser.py @@ -6,6 +6,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import print_function +from __future__ import absolute_import import pkg_resources import logging import subprocess @@ -61,7 +63,7 @@ class Parser(base.Scenario): p = subprocess.Popen(cmd1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.communicate() - print "yangtotosca finished" + print("yangtotosca finished") result['yangtotosca'] = "success" if p.returncode == 0 else "fail" @@ -78,5 +80,6 @@ def _test(): '''internal test function''' pass + if __name__ == '__main__': _test() diff --git a/yardstick/benchmark/scenarios/storage/fio.py b/yardstick/benchmark/scenarios/storage/fio.py index 4e004235d..2a8738e88 100644 --- a/yardstick/benchmark/scenarios/storage/fio.py +++ b/yardstick/benchmark/scenarios/storage/fio.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -114,7 +118,7 @@ class Fio(base.Scenario): if status: raise RuntimeError(stderr) - raw_data = json.loads(stdout) + raw_data = jsonutils.loads(stdout) # The bandwidth unit is KB/s, and latency unit is us if rw in ["read", "randread", "rw", "randrw"]: @@ -175,7 +179,8 @@ def _test(): fio = Fio(args, ctx) fio.run(result) - print result + print(result) + if __name__ == '__main__': _test() diff --git a/yardstick/benchmark/scenarios/storage/storagecapacity.py b/yardstick/benchmark/scenarios/storage/storagecapacity.py index bf5bc2810..c437f22c0 100644 --- a/yardstick/benchmark/scenarios/storage/storagecapacity.py +++ b/yardstick/benchmark/scenarios/storage/storagecapacity.py @@ -6,9 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import + import logging -import json + +import pkg_resources +from oslo_serialization import jsonutils +from six.moves import range import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -131,4 +135,4 @@ class StorageCapacity(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) diff --git a/yardstick/benchmark/scenarios/storage/storperf.py b/yardstick/benchmark/scenarios/storage/storperf.py index 72ceff7ce..6ea035133 100644 --- a/yardstick/benchmark/scenarios/storage/storperf.py +++ b/yardstick/benchmark/scenarios/storage/storperf.py @@ -6,11 +6,14 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import + import logging -import json -import requests import time +import requests +from oslo_serialization import jsonutils + from yardstick.benchmark.scenarios import base LOG = logging.getLogger(__name__) @@ -73,7 +76,8 @@ class StorPerf(base.Scenario): setup_query = requests.get('http://%s:5000/api/v1.0/configurations' % self.target) - setup_query_content = json.loads(setup_query.content) + setup_query_content = jsonutils.loads( + setup_query.content) if setup_query_content["stack_created"]: self.setup_done = True LOG.debug("stack_created: %s", @@ -96,7 +100,8 @@ class StorPerf(base.Scenario): setup_res = requests.post('http://%s:5000/api/v1.0/configurations' % self.target, json=env_args) - setup_res_content = json.loads(setup_res.content) + setup_res_content = jsonutils.loads( + setup_res.content) if setup_res.status_code != 200: raise RuntimeError("Failed to create a stack, error message:", @@ -114,7 +119,8 @@ class StorPerf(base.Scenario): report_res = requests.get('http://{}:5000/api/v1.0/jobs'.format (self.target), params={'id': job_id}) - report_res_content = json.loads(report_res.content) + report_res_content = jsonutils.loads( + report_res.content) if report_res.status_code != 200: raise RuntimeError("Failed to fetch report, error message:", @@ -154,7 +160,7 @@ class StorPerf(base.Scenario): job_res = requests.post('http://%s:5000/api/v1.0/jobs' % self.target, json=job_args) - job_res_content = json.loads(job_res.content) + job_res_content = jsonutils.loads(job_res.content) if job_res.status_code != 200: raise RuntimeError("Failed to start a job, error message:", @@ -171,7 +177,8 @@ class StorPerf(base.Scenario): self.target) if terminate_res.status_code != 200: - terminate_res_content = json.loads(terminate_res.content) + terminate_res_content = jsonutils.loads( + terminate_res.content) raise RuntimeError("Failed to start a job, error message:", terminate_res_content["message"]) @@ -190,7 +197,8 @@ class StorPerf(base.Scenario): result_res = requests.get('http://%s:5000/api/v1.0/jobs?id=%s' % (self.target, job_id)) - result_res_content = json.loads(result_res.content) + result_res_content = jsonutils.loads( + result_res.content) result.update(result_res_content) @@ -200,7 +208,8 @@ class StorPerf(base.Scenario): configurations' % self.target) if teardown_res.status_code == 400: - teardown_res_content = json.loads(teardown_res.content) + teardown_res_content = jsonutils.loads( + teardown_res.content) raise RuntimeError("Failed to reset environment, error message:", teardown_res_content['message']) diff --git a/yardstick/cmd/__init__.py b/yardstick/cmd/__init__.py index df891e304..6b7d65792 100644 --- a/yardstick/cmd/__init__.py +++ b/yardstick/cmd/__init__.py @@ -6,10 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import print_function def print_hbar(barlen): '''print to stdout a horizontal bar''' - print("+"), - print("-" * barlen), + print(("+"), end=' ') + print(("-" * barlen), end=' ') print("+") diff --git a/yardstick/cmd/cli.py b/yardstick/cmd/cli.py index beaa187aa..05bf8f06f 100644 --- a/yardstick/cmd/cli.py +++ b/yardstick/cmd/cli.py @@ -11,6 +11,7 @@ Command-line interface to yardstick ''' +from __future__ import absolute_import import logging import os import sys diff --git a/yardstick/cmd/commands/__init__.py b/yardstick/cmd/commands/__init__.py index ba229d481..5c5356736 100644 --- a/yardstick/cmd/commands/__init__.py +++ b/yardstick/cmd/commands/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import from yardstick.benchmark.core import Param diff --git a/yardstick/cmd/commands/env.py b/yardstick/cmd/commands/env.py index d0fc75dd3..dfcb63727 100644 --- a/yardstick/cmd/commands/env.py +++ b/yardstick/cmd/commands/env.py @@ -6,13 +6,17 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import from __future__ import print_function -import time + import os import sys +import time + +from six.moves import range -from yardstick.common.httpClient import HttpClient from yardstick.common import constants as consts +from yardstick.common.httpClient import HttpClient class EnvCommand(object): @@ -20,6 +24,7 @@ class EnvCommand(object): Set of commands to prepare environment ''' + def do_influxdb(self, args): data = {'action': 'createInfluxDBContainer'} task_id = self._start_async_task(data) @@ -52,7 +57,7 @@ class EnvCommand(object): CHECK_STATUS_RETRY = 20 CHECK_STATUS_DELAY = 5 - for retry in xrange(CHECK_STATUS_RETRY): + for retry in range(CHECK_STATUS_RETRY): response = HttpClient().get(url) status = response['status'] diff --git a/yardstick/cmd/commands/plugin.py b/yardstick/cmd/commands/plugin.py index 94095665a..c3e951e8c 100644 --- a/yardstick/cmd/commands/plugin.py +++ b/yardstick/cmd/commands/plugin.py @@ -9,6 +9,9 @@ """ Handler for yardstick command 'plugin' """ +from __future__ import print_function + +from __future__ import absolute_import from yardstick.benchmark.core.plugin import Plugin from yardstick.common.utils import cliargs from yardstick.cmd.commands import change_osloobj_to_paras diff --git a/yardstick/cmd/commands/runner.py b/yardstick/cmd/commands/runner.py index 62a2082c4..02176aba3 100644 --- a/yardstick/cmd/commands/runner.py +++ b/yardstick/cmd/commands/runner.py @@ -9,6 +9,9 @@ """ Handler for yardstick command 'runner' """ +from __future__ import print_function + +from __future__ import absolute_import from yardstick.benchmark.core.runner import Runners from yardstick.common.utils import cliargs from yardstick.cmd.commands import change_osloobj_to_paras diff --git a/yardstick/cmd/commands/scenario.py b/yardstick/cmd/commands/scenario.py index 6aa3a451a..5a6d04f55 100644 --- a/yardstick/cmd/commands/scenario.py +++ b/yardstick/cmd/commands/scenario.py @@ -9,6 +9,8 @@ """ Handler for yardstick command 'scenario' """ +from __future__ import print_function +from __future__ import absolute_import from yardstick.benchmark.core.scenario import Scenarios from yardstick.common.utils import cliargs from yardstick.cmd.commands import change_osloobj_to_paras diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py index bd018bcab..fa82f078f 100644 --- a/yardstick/cmd/commands/task.py +++ b/yardstick/cmd/commands/task.py @@ -8,11 +8,13 @@ ############################################################################## """ Handler for yardstick command 'task' """ +from __future__ import print_function + +from __future__ import absolute_import from yardstick.benchmark.core.task import Task from yardstick.common.utils import cliargs from yardstick.cmd.commands import change_osloobj_to_paras - output_file_default = "/tmp/yardstick.out" diff --git a/yardstick/cmd/commands/testcase.py b/yardstick/cmd/commands/testcase.py index 6ff796238..92831ad2f 100644 --- a/yardstick/cmd/commands/testcase.py +++ b/yardstick/cmd/commands/testcase.py @@ -8,6 +8,9 @@ ############################################################################## """ Handler for yardstick command 'testcase' """ +from __future__ import print_function + +from __future__ import absolute_import from yardstick.benchmark.core.testcase import Testcase from yardstick.common.utils import cliargs from yardstick.cmd.commands import change_osloobj_to_paras diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py index 174d39bfe..d99e216f4 100644 --- a/yardstick/common/constants.py +++ b/yardstick/common/constants.py @@ -6,6 +6,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import os DOCKER_URL = 'unix://var/run/docker.sock' diff --git a/yardstick/common/httpClient.py b/yardstick/common/httpClient.py index 6acd0303d..11c2d752d 100644 --- a/yardstick/common/httpClient.py +++ b/yardstick/common/httpClient.py @@ -6,9 +6,11 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json +from __future__ import absolute_import + import logging +from oslo_serialization import jsonutils import requests logger = logging.getLogger(__name__) @@ -17,7 +19,7 @@ logger = logging.getLogger(__name__) class HttpClient(object): def post(self, url, data): - data = json.dumps(data) + data = jsonutils.dump_as_bytes(data) headers = {'Content-Type': 'application/json'} try: response = requests.post(url, data=data, headers=headers) diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index d8dc61ef6..e351d16d3 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import os import logging diff --git a/yardstick/common/task_template.py b/yardstick/common/task_template.py index 2739323bd..bda8a1b13 100755 --- a/yardstick/common/task_template.py +++ b/yardstick/common/task_template.py @@ -7,12 +7,14 @@ # http://www.apache.org/licenses/LICENSE-2.0 # yardstick: this file is copied from rally and slightly modified ############################################################################## +from __future__ import absolute_import import re import jinja2 import jinja2.meta class TaskTemplate(object): + @classmethod def render(cls, task_template, **kwargs): """Render jinja2 task template to Yardstick input task. diff --git a/yardstick/common/template_format.py b/yardstick/common/template_format.py index 2deaf393c..2432c5dc6 100644 --- a/yardstick/common/template_format.py +++ b/yardstick/common/template_format.py @@ -12,8 +12,10 @@ # yardstick: this file is copied from python-heatclient and slightly modified -import json +from __future__ import absolute_import + import yaml +from oslo_serialization import jsonutils if hasattr(yaml, 'CSafeLoader'): yaml_loader = yaml.CSafeLoader @@ -46,7 +48,7 @@ def parse(tmpl_str): JSON or YAML format. ''' if tmpl_str.startswith('{'): - tpl = json.loads(tmpl_str) + tpl = jsonutils.loads(tmpl_str) else: try: tpl = yaml.load(tmpl_str, Loader=yaml_loader) diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index 3ecb0ae20..57ace14e6 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -15,17 +15,21 @@ # yardstick comment: this is a modified copy of rally/rally/common/utils.py -import os -import sys -import yaml +from __future__ import absolute_import +from __future__ import print_function + import errno -import subprocess import logging +import os +import subprocess +import sys +from functools import reduce -from oslo_utils import importutils +import yaml from keystoneauth1 import identity from keystoneauth1 import session from neutronclient.v2_0 import client +from oslo_utils import importutils import yardstick @@ -94,12 +98,12 @@ def get_para_from_yaml(file_path, args): value = reduce(func, args.split('.'), value) if value is None: - print 'parameter not found' + print('parameter not found') return None return value else: - print 'file not exist' + print('file not exist') return None diff --git a/yardstick/definitions.py b/yardstick/definitions.py index 300a78e58..d4afac65d 100644 --- a/yardstick/definitions.py +++ b/yardstick/definitions.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os dirname = os.path.dirname diff --git a/yardstick/dispatcher/__init__.py b/yardstick/dispatcher/__init__.py index b519efc7a..dfb130760 100644 --- a/yardstick/dispatcher/__init__.py +++ b/yardstick/dispatcher/__init__.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import from oslo_config import cfg import yardstick.common.utils as utils diff --git a/yardstick/dispatcher/base.py b/yardstick/dispatcher/base.py index ffdddb0ff..6e863cadc 100644 --- a/yardstick/dispatcher/base.py +++ b/yardstick/dispatcher/base.py @@ -16,6 +16,7 @@ # yardstick comment: this is a modified copy of # ceilometer/ceilometer/dispatcher/__init__.py +from __future__ import absolute_import import abc import six diff --git a/yardstick/dispatcher/file.py b/yardstick/dispatcher/file.py index c2cc265ba..9c728e983 100644 --- a/yardstick/dispatcher/file.py +++ b/yardstick/dispatcher/file.py @@ -16,10 +16,12 @@ # yardstick comment: this is a modified copy of # ceilometer/ceilometer/dispatcher/file.py +from __future__ import absolute_import + import logging import logging.handlers -import json +from oslo_serialization import jsonutils from oslo_config import cfg from yardstick.dispatcher.base import Base as DispatchBase @@ -70,7 +72,7 @@ class FileDispatcher(DispatchBase): def record_result_data(self, data): if self.log: - self.log.info(json.dumps(data)) + self.log.info(jsonutils.dump_as_bytes(data)) def flush_result_data(self): pass diff --git a/yardstick/dispatcher/http.py b/yardstick/dispatcher/http.py index 98e772dd8..790086155 100644 --- a/yardstick/dispatcher/http.py +++ b/yardstick/dispatcher/http.py @@ -16,11 +16,13 @@ # yardstick comment: this is a modified copy of # ceilometer/ceilometer/dispatcher/http.py -import os -import json +from __future__ import absolute_import + import logging -import requests +import os +from oslo_serialization import jsonutils +import requests from oslo_config import cfg from yardstick.dispatcher.base import Base as DispatchBase @@ -81,16 +83,18 @@ class HttpDispatcher(DispatchBase): case_name = v["scenario_cfg"]["tc"] break if case_name == "": - LOG.error('Test result : %s', json.dumps(self.result)) + LOG.error('Test result : %s', + jsonutils.dump_as_bytes(self.result)) LOG.error('The case_name cannot be found, no data will be posted.') return self.result["case_name"] = case_name try: - LOG.debug('Test result : %s', json.dumps(self.result)) + LOG.debug('Test result : %s', + jsonutils.dump_as_bytes(self.result)) res = requests.post(self.target, - data=json.dumps(self.result), + data=jsonutils.dump_as_bytes(self.result), headers=self.headers, timeout=self.timeout) LOG.debug('Test result posting finished with status code' diff --git a/yardstick/dispatcher/influxdb.py b/yardstick/dispatcher/influxdb.py index fc9f3e932..427e669a2 100644 --- a/yardstick/dispatcher/influxdb.py +++ b/yardstick/dispatcher/influxdb.py @@ -7,16 +7,19 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import os -import json +from __future__ import absolute_import + import logging -import requests +import os import time +import requests +import six from oslo_config import cfg +from oslo_serialization import jsonutils -from yardstick.dispatcher.base import Base as DispatchBase from third_party.influxdb.influxdb_line_protocol import make_lines +from yardstick.dispatcher.base import Base as DispatchBase LOG = logging.getLogger(__name__) @@ -80,9 +83,9 @@ class InfluxdbDispatcher(DispatchBase): if type(v) == dict or type(v) == list]: return data - for k, v in data.iteritems(): + for k, v in six.iteritems(data): if type(v) == dict: - for n_k, n_v in v.iteritems(): + for n_k, n_v in six.iteritems(v): next_data["%s.%s" % (k, n_k)] = n_v elif type(v) == list: for index, item in enumerate(v): @@ -127,7 +130,7 @@ class InfluxdbDispatcher(DispatchBase): return make_lines(msg).encode('utf-8') def record_result_data(self, data): - LOG.debug('Test result : %s', json.dumps(data)) + LOG.debug('Test result : %s', jsonutils.dump_as_bytes(data)) self.raw_result.append(data) if self.target == '': # if the target was not set, do not do anything @@ -148,7 +151,7 @@ class InfluxdbDispatcher(DispatchBase): return 0 if self.tc == "": - LOG.error('Test result : %s', json.dumps(data)) + LOG.error('Test result : %s', jsonutils.dump_as_bytes(data)) LOG.error('The case_name cannot be found, no data will be posted.') return -1 @@ -171,5 +174,6 @@ class InfluxdbDispatcher(DispatchBase): return 0 def flush_result_data(self): - LOG.debug('Test result all : %s', json.dumps(self.raw_result)) + LOG.debug('Test result all : %s', + jsonutils.dump_as_bytes(self.raw_result)) return 0 diff --git a/yardstick/main.py b/yardstick/main.py index 418e3daca..5d427beb8 100755 --- a/yardstick/main.py +++ b/yardstick/main.py @@ -38,6 +38,7 @@ NFV TST """ +from __future__ import absolute_import import sys from yardstick.cmd.cli import YardstickCLI diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py index e32d360e4..7e0f360c4 100644 --- a/yardstick/orchestrator/heat.py +++ b/yardstick/orchestrator/heat.py @@ -9,20 +9,23 @@ """Heat template and stack management""" -import time +from __future__ import absolute_import +from __future__ import print_function + +import collections import datetime import getpass -import socket import logging -import json +import socket +import time -from oslo_utils import encodeutils import heatclient import pkg_resources +from oslo_serialization import jsonutils +from oslo_utils import encodeutils -from yardstick.common import template_format import yardstick.common.openstack_utils as op_utils - +from yardstick.common import template_format log = logging.getLogger(__name__) @@ -36,6 +39,7 @@ def get_short_key_uuid(uuid): class HeatObject(object): ''' base class for template and stack''' + def __init__(self): self._heat_client = None self.uuid = None @@ -119,7 +123,7 @@ class HeatStack(HeatObject): self._delete() break except RuntimeError as err: - log.warn(err.args) + log.warning(err.args) time.sleep(2) i += 1 @@ -173,7 +177,7 @@ class HeatTemplate(HeatObject): if template_file: with open(template_file) as stream: - print "Parsing external template:", template_file + print("Parsing external template:", template_file) template_str = stream.read() self._template = template_format.parse(template_str) self._parameters = heat_parameters @@ -312,6 +316,7 @@ class HeatTemplate(HeatObject): 'type': 'OS::Nova::KeyPair', 'properties': { 'name': name, + # resource_string returns bytes, so we must decode to unicode 'public_key': encodeutils.safe_decode( pkg_resources.resource_string( 'yardstick.resources', @@ -402,7 +407,7 @@ class HeatTemplate(HeatObject): ) if networks: - for i in range(len(networks)): + for i, _ in enumerate(networks): server_properties['networks'].append({'network': networks[i]}) if scheduler_hints: @@ -412,11 +417,11 @@ class HeatTemplate(HeatObject): server_properties['user_data'] = user_data if metadata: - assert type(metadata) is dict + assert isinstance(metadata, collections.Mapping) server_properties['metadata'] = metadata if additional_properties: - assert type(additional_properties) is dict + assert isinstance(additional_properties, collections.Mapping) for prop in additional_properties: server_properties[prop] = additional_properties[prop] @@ -438,13 +443,15 @@ class HeatTemplate(HeatObject): stack = HeatStack(self.name) heat = self._get_heat_client() - json_template = json.dumps(self._template) + json_template = jsonutils.dump_as_bytes( + self._template) start_time = time.time() stack.uuid = self.uuid = heat.stacks.create( stack_name=self.name, template=json_template, parameters=self.heat_parameters)['stack']['id'] status = self.status() + outputs = [] if block: while status != u'CREATE_COMPLETE': @@ -458,13 +465,12 @@ class HeatTemplate(HeatObject): end_time = time.time() outputs = getattr(heat.stacks.get(self.uuid), 'outputs') + log.info("Created stack '%s' in %d secs", + self.name, end_time - start_time) - for output in outputs: - self.outputs[output["output_key"].encode("ascii")] = \ - output["output_value"].encode("ascii") - - log.info("Created stack '%s' in %d secs", - self.name, end_time - start_time) + # keep outputs as unicode + self.outputs = {output["output_key"]: output["output_value"] for output + in outputs} stack.outputs = self.outputs return stack diff --git a/yardstick/plot/plotter.py b/yardstick/plot/plotter.py index 4cbbdfe74..4e65303dc 100644 --- a/yardstick/plot/plotter.py +++ b/yardstick/plot/plotter.py @@ -16,13 +16,19 @@ $ yardstick-plot -i /tmp/yardstick.out -o /tmp/plots/ ''' +from __future__ import absolute_import +from __future__ import print_function + import argparse -import json import os import sys import time -import matplotlib.pyplot as plt + import matplotlib.lines as mlines +import matplotlib.pyplot as plt +from oslo_serialization import jsonutils +from six.moves import range +from six.moves import zip class Parser(object): @@ -44,7 +50,7 @@ class Parser(object): prog='yardstick-plot', description="A tool for visualizing results from yardstick. " "Currently supports plotting graphs for output files " - "from tests: " + str(self.data.keys()) + "from tests: " + str(list(self.data.keys())) ) parser.add_argument( '-i', '--input', @@ -65,7 +71,7 @@ class Parser(object): self.scenarios[record["runner_id"]] = obj_name return runner_object = self.scenarios[record["runner_id"]] - for test_type in self.data.keys(): + for test_type in self.data: if test_type in runner_object: self.data[test_type].append(record) @@ -80,17 +86,17 @@ class Parser(object): if self.args.input: input_file = self.args.input else: - print("No input file specified, reading from %s" - % self.default_input_loc) + print(("No input file specified, reading from %s" + % self.default_input_loc)) input_file = self.default_input_loc try: with open(input_file) as f: for line in f: - record = json.loads(line) + record = jsonutils.loads(line) self._add_record(record) except IOError as e: - print(os.strerror(e.errno)) + print((os.strerror(e.errno))) sys.exit(1) @@ -126,7 +132,7 @@ class Plotter(object): os.makedirs(self.output_folder) new_file = os.path.join(self.output_folder, file_name) plt.savefig(new_file) - print("Saved graph to " + new_file) + print(("Saved graph to " + new_file)) def _plot_ping(self, records): '''ping test result interpretation and visualization on the graph''' @@ -143,7 +149,7 @@ class Plotter(object): if len(rtts) == 1: plt.bar(1, rtts[0], 0.35, color=self.colors[0]) else: - plt.plot(seqs, rtts, self.colors[0]+'-') + plt.plot(seqs, rtts, self.colors[0] + '-') self._construct_legend(['rtt']) plt.xlabel("sequence number") @@ -164,13 +170,13 @@ class Plotter(object): received[i] = 0.0 plt.axvline(flows[i], color='r') - ppm = [1000000.0*(i - j)/i for i, j in zip(sent, received)] + ppm = [1000000.0 * (i - j) / i for i, j in zip(sent, received)] # If there is a single data-point then display a bar-chart if len(ppm) == 1: plt.bar(1, ppm[0], 0.35, color=self.colors[0]) else: - plt.plot(flows, ppm, self.colors[0]+'-') + plt.plot(flows, ppm, self.colors[0] + '-') self._construct_legend(['ppm']) plt.xlabel("number of flows") @@ -191,7 +197,7 @@ class Plotter(object): for i, val in enumerate(intervals): if val: for j, _ in enumerate(intervals): - kbps.append(val[j]['sum']['bits_per_second']/1000) + kbps.append(val[j]['sum']['bits_per_second'] / 1000) seconds.append(seconds[-1] + val[j]['sum']['seconds']) else: kbps.append(0.0) @@ -202,7 +208,7 @@ class Plotter(object): plt.axvline(seconds[-1], color='r') self._construct_legend(['bandwidth']) - plt.plot(seconds[1:], kbps[1:], self.colors[0]+'-') + plt.plot(seconds[1:], kbps[1:], self.colors[0] + '-') plt.xlabel("time in seconds") plt.ylabel("bandwidth in Kb/s") @@ -312,5 +318,6 @@ def main(): print("Plotting graph(s)") plotter.plot() + if __name__ == '__main__': main() diff --git a/yardstick/ssh.py b/yardstick/ssh.py index 927ca94db..1cad8eefa 100644 --- a/yardstick/ssh.py +++ b/yardstick/ssh.py @@ -25,7 +25,7 @@ Execute command and get output: status, stdout, stderr = ssh.execute("ps ax") if status: raise Exception("Command failed with non-zero status.") - print stdout.splitlines() + print(stdout.splitlines()) Execute command with huge output: @@ -62,6 +62,7 @@ Eventlet: sshclient = eventlet.import_patched("yardstick.ssh") """ +from __future__ import absolute_import import os import select import socket @@ -70,6 +71,7 @@ import re import logging import paramiko +from oslo_utils import encodeutils from scp import SCPClient import six @@ -199,7 +201,8 @@ class SSH(object): session.exec_command(cmd) start_time = time.time() - data_to_send = "" + # encode on transmit, decode on receive + data_to_send = encodeutils.safe_encode("") stderr_data = None # If we have data to be sent to stdin then `select' should also @@ -214,14 +217,15 @@ class SSH(object): r, w, e = select.select([session], writes, [session], 1) if session.recv_ready(): - data = session.recv(4096) + data = encodeutils.safe_decode(session.recv(4096), 'utf-8') self.log.debug("stdout: %r", data) if stdout is not None: stdout.write(data) continue if session.recv_stderr_ready(): - stderr_data = session.recv_stderr(4096) + stderr_data = encodeutils.safe_decode( + session.recv_stderr(4096), 'utf-8') self.log.debug("stderr: %r", stderr_data) if stderr is not None: stderr.write(stderr_data) @@ -230,7 +234,8 @@ class SSH(object): if session.send_ready(): if stdin is not None and not stdin.closed: if not data_to_send: - data_to_send = stdin.read(4096) + data_to_send = encodeutils.safe_encode( + stdin.read(4096), incoming='utf-8') if not data_to_send: # we may need to keep stdin open if not keep_stdin_open: diff --git a/yardstick/vTC/apexlake/experimental_framework/__init__.py b/yardstick/vTC/apexlake/experimental_framework/__init__.py index d4ab29e9d..9c4eef12d 100644 --- a/yardstick/vTC/apexlake/experimental_framework/__init__.py +++ b/yardstick/vTC/apexlake/experimental_framework/__init__.py @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -''' +""" Experimental Framework -''' +""" +from __future__ import absolute_import +import os + +APEX_LAKE_ROOT = os.path.realpath( + os.path.join(os.path.dirname(os.path.dirname(__file__)))) diff --git a/yardstick/vTC/apexlake/experimental_framework/api.py b/yardstick/vTC/apexlake/experimental_framework/api.py index e0209befd..24dd1f89a 100644 --- a/yardstick/vTC/apexlake/experimental_framework/api.py +++ b/yardstick/vTC/apexlake/experimental_framework/api.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import experimental_framework.benchmarking_unit as b_unit from experimental_framework import heat_template_generation, common diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py b/yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py index 1963696f8..d5de308c7 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py @@ -18,6 +18,7 @@ initialization, execution and finalization ''' +from __future__ import absolute_import import json import time import inspect @@ -27,6 +28,7 @@ from experimental_framework import common # from experimental_framework import data_manager as data from experimental_framework import heat_template_generation as heat from experimental_framework import deployment_unit as deploy +from six.moves import range class BenchmarkingUnit: @@ -116,10 +118,10 @@ class BenchmarkingUnit: """ common.LOG.info('Run Benchmarking Unit') - experiment = dict() - result = dict() - for iteration in range(0, self.iterations): - common.LOG.info('Iteration ' + str(iteration)) + experiment = {} + result = {} + for iteration in range(self.iterations): + common.LOG.info('Iteration %s', iteration) for template_file_name in self.template_files: experiment_name = BenchmarkingUnit.\ extract_experiment_name(template_file_name) @@ -238,7 +240,7 @@ class BenchmarkingUnit: :return: (str) Experiment Name """ strings = template_file_name.split('.') - return ".".join(strings[:(len(strings)-1)]) + return ".".join(strings[:(len(strings) - 1)]) @staticmethod def get_benchmark_class(complete_module_name): @@ -253,7 +255,7 @@ class BenchmarkingUnit: """ strings = complete_module_name.split('.') class_name = 'experimental_framework.benchmarks.{}'.format(strings[0]) - pkg = __import__(class_name, globals(), locals(), [], -1) + pkg = __import__(class_name, globals(), locals(), [], 0) module = getattr(getattr(pkg, 'benchmarks'), strings[0]) members = inspect.getmembers(module) for m in members: diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py index ac7fad88e..96cce2265 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py @@ -13,6 +13,7 @@ # limitations under the License. +from __future__ import absolute_import import abc @@ -30,7 +31,7 @@ class BenchmarkBaseClass(object): raise ValueError("Parameters need to be provided in a dict") for param in self.get_features()['parameters']: - if param not in params.keys(): + if param not in list(params.keys()): params[param] = self.get_features()['default_values'][param] for param in self.get_features()['parameters']: diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py index 320becae5..db9d449ef 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py @@ -12,16 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import os -import commands # import signal import time + +import subprocess from experimental_framework.benchmarks import benchmark_base_class as base from experimental_framework.constants import framework_parameters as fp from experimental_framework.constants import conf_file_sections as cfs from experimental_framework.packet_generators import dpdk_packet_generator \ as dpdk import experimental_framework.common as common +from six.moves import range THROUGHPUT = 'throughput' @@ -36,7 +39,7 @@ class InstantiationValidationBenchmark(base.BenchmarkBaseClass): def __init__(self, name, params): base.BenchmarkBaseClass.__init__(self, name, params) - self.base_dir = "{}{}{}".format( + self.base_dir = os.path.join( common.get_base_dir(), fp.EXPERIMENTAL_FRAMEWORK_DIR, fp.DPDK_PKTGEN_DIR) self.results_file = self.base_dir + PACKETS_FILE_NAME @@ -45,10 +48,11 @@ class InstantiationValidationBenchmark(base.BenchmarkBaseClass): self.interface_name = '' # Set the packet checker command - self.pkt_checker_command = common.get_base_dir() - self.pkt_checker_command += 'experimental_framework/libraries/' - self.pkt_checker_command += 'packet_checker/' - self.pkt_checker_command += PACKET_CHECKER_PROGRAM_NAME + ' ' + self.pkt_checker_command = os.path.join( + common.get_base_dir(), + 'experimental_framework/libraries/', + 'packet_checker/', + PACKET_CHECKER_PROGRAM_NAME + ' ') def init(self): """ @@ -69,9 +73,11 @@ class InstantiationValidationBenchmark(base.BenchmarkBaseClass): features['description'] = 'Instantiation Validation Benchmark' features['parameters'] = [THROUGHPUT, VLAN_SENDER, VLAN_RECEIVER] features['allowed_values'] = dict() - features['allowed_values'][THROUGHPUT] = map(str, range(0, 100)) - features['allowed_values'][VLAN_SENDER] = map(str, range(-1, 4096)) - features['allowed_values'][VLAN_RECEIVER] = map(str, range(-1, 4096)) + features['allowed_values'][THROUGHPUT] = [str(x) for x in range(100)] + features['allowed_values'][VLAN_SENDER] = [str(x) for x in + range(-1, 4096)] + features['allowed_values'][VLAN_RECEIVER] = [str(x) + for x in range(-1, 4096)] features['default_values'] = dict() features['default_values'][THROUGHPUT] = '1' features['default_values'][VLAN_SENDER] = '-1' @@ -203,7 +209,7 @@ class InstantiationValidationBenchmark(base.BenchmarkBaseClass): # Start the packet checker current_dir = os.path.dirname(os.path.realpath(__file__)) dir_list = self.pkt_checker_command.split('/') - directory = '/'.join(dir_list[0:len(dir_list)-1]) + directory = os.pathsep.join(dir_list[0:len(dir_list) - 1]) os.chdir(directory) command = "make" common.run_command(command) @@ -245,10 +251,10 @@ class InstantiationValidationBenchmark(base.BenchmarkBaseClass): processes currently running on the host :return: type: list of int """ - output = commands.getoutput("ps -ef |pgrep " + - PACKET_CHECKER_PROGRAM_NAME) + output = subprocess.check_output( + 'pgrep "{}"'.format(PACKET_CHECKER_PROGRAM_NAME)) if not output: pids = [] else: - pids = map(int, output.split('\n')) + pids = [int(x) for x in output.splitlines()] return pids diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_noisy_neighbors_benchmark.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_noisy_neighbors_benchmark.py index 1eab70c67..5569b6c12 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_noisy_neighbors_benchmark.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_noisy_neighbors_benchmark.py @@ -13,8 +13,11 @@ # limitations under the License. -import instantiation_validation_benchmark as base +from __future__ import absolute_import from experimental_framework import common +from experimental_framework.benchmarks import \ + instantiation_validation_benchmark as base +from six.moves import range NUM_OF_NEIGHBORS = 'num_of_neighbours' @@ -38,7 +41,7 @@ class InstantiationValidationNoisyNeighborsBenchmark( self.template_file = common.get_template_dir() + \ temp_name self.stack_name = 'neighbour' - self.neighbor_stack_names = list() + self.neighbor_stack_names = [] def get_features(self): features = super(InstantiationValidationNoisyNeighborsBenchmark, diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/multi_tenancy_throughput_benchmark.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/multi_tenancy_throughput_benchmark.py index f2a87b2b2..44c9f327a 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/multi_tenancy_throughput_benchmark.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/multi_tenancy_throughput_benchmark.py @@ -13,9 +13,11 @@ # limitations under the License. +from __future__ import absolute_import from experimental_framework.benchmarks import rfc2544_throughput_benchmark \ as base from experimental_framework import common +from six.moves import range NETWORK_NAME = 'network' diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/rfc2544_throughput_benchmark.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/rfc2544_throughput_benchmark.py index 9db62e639..5c7b55e42 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/rfc2544_throughput_benchmark.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/rfc2544_throughput_benchmark.py @@ -11,6 +11,8 @@ # 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. +from __future__ import absolute_import +from six.moves import range from experimental_framework.benchmarks import benchmark_base_class from experimental_framework.packet_generators \ @@ -60,8 +62,10 @@ class RFC2544ThroughputBenchmark(benchmark_base_class.BenchmarkBaseClass): features['allowed_values'] = dict() features['allowed_values'][PACKET_SIZE] = ['64', '128', '256', '512', '1024', '1280', '1514'] - features['allowed_values'][VLAN_SENDER] = map(str, range(-1, 4096)) - features['allowed_values'][VLAN_RECEIVER] = map(str, range(-1, 4096)) + features['allowed_values'][VLAN_SENDER] = [str(x) for x in + range(-1, 4096)] + features['allowed_values'][VLAN_RECEIVER] = [str(x) for x in + range(-1, 4096)] features['default_values'] = dict() features['default_values'][PACKET_SIZE] = '1280' features['default_values'][VLAN_SENDER] = '1007' @@ -99,7 +103,7 @@ class RFC2544ThroughputBenchmark(benchmark_base_class.BenchmarkBaseClass): :return: packet_sizes (list) """ packet_size = '1280' # default value - if PACKET_SIZE in self.params.keys() and \ + if PACKET_SIZE in list(self.params.keys()) and \ isinstance(self.params[PACKET_SIZE], str): packet_size = self.params[PACKET_SIZE] return packet_size diff --git a/yardstick/vTC/apexlake/experimental_framework/benchmarks/test_benchmark.py b/yardstick/vTC/apexlake/experimental_framework/benchmarks/test_benchmark.py index cbb930d21..5891832f2 100644 --- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/test_benchmark.py +++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/test_benchmark.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import time from experimental_framework.benchmarks import benchmark_base_class as base diff --git a/yardstick/vTC/apexlake/experimental_framework/common.py b/yardstick/vTC/apexlake/experimental_framework/common.py index 4bacd38a6..feea8bde6 100644 --- a/yardstick/vTC/apexlake/experimental_framework/common.py +++ b/yardstick/vTC/apexlake/experimental_framework/common.py @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function +from __future__ import absolute_import import os import re -import ConfigParser +import six.moves.configparser import logging import fileinput from experimental_framework.constants import conf_file_sections as cf @@ -70,7 +72,7 @@ def init(api=False): init_conf_file(api) init_log() init_general_vars(api) - if len(CONF_FILE.get_variable_list(cf.CFS_PKTGEN)) > 0: + if CONF_FILE.get_variable_list(cf.CFS_PKTGEN): init_pktgen() @@ -129,7 +131,7 @@ def init_general_vars(api=False): RESULT_DIR = "/tmp/apexlake/results/" if not os.path.isdir(RESULT_DIR): - os.mkdir(RESULT_DIR) + os.makedirs(RESULT_DIR) if cf.CFSO_RELEASE in CONF_FILE.get_variable_list(cf.CFS_OPENSTACK): RELEASE = CONF_FILE.get_variable(cf.CFS_OPENSTACK, cf.CFSO_RELEASE) @@ -311,7 +313,7 @@ class ConfigurationFile: # config_file = BASE_DIR + config_file InputValidation.validate_file_exist( config_file, 'The provided configuration file does not exist') - self.config = ConfigParser.ConfigParser() + self.config = six.moves.configparser.ConfigParser() self.config.read(config_file) for section in sections: setattr( @@ -457,7 +459,7 @@ def replace_in_file(file, text_to_search, text_to_replace): message = "The file does not exist" InputValidation.validate_file_exist(file, message) for line in fileinput.input(file, inplace=True): - print(line.replace(text_to_search, text_to_replace).rstrip()) + print((line.replace(text_to_search, text_to_replace).rstrip())) # ------------------------------------------------------ @@ -610,7 +612,7 @@ class InputValidation(object): missing = [ credential_key for credential_key in credential_keys - if credential_key not in credentials.keys() + if credential_key not in list(credentials.keys()) ] if len(missing) == 0: return True diff --git a/yardstick/vTC/apexlake/experimental_framework/constants/framework_parameters.py b/yardstick/vTC/apexlake/experimental_framework/constants/framework_parameters.py index 4ee3a8aa3..6e651bf19 100644 --- a/yardstick/vTC/apexlake/experimental_framework/constants/framework_parameters.py +++ b/yardstick/vTC/apexlake/experimental_framework/constants/framework_parameters.py @@ -13,6 +13,7 @@ # limitations under the License. +from __future__ import absolute_import from experimental_framework.constants import conf_file_sections as cfs # ------------------------------------------------------ diff --git a/yardstick/vTC/apexlake/experimental_framework/deployment_unit.py b/yardstick/vTC/apexlake/experimental_framework/deployment_unit.py index 22fec1392..0bb507c51 100644 --- a/yardstick/vTC/apexlake/experimental_framework/deployment_unit.py +++ b/yardstick/vTC/apexlake/experimental_framework/deployment_unit.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import os import time @@ -50,8 +51,8 @@ class DeploymentUnit: time.sleep(5) status = self.heat_manager.check_stack_status(stack_name) return True - except Exception as e: - common.LOG.debug(e.message) + except Exception: + common.LOG.debug("check_stack_status", exc_info=True) return False def destroy_all_deployed_stacks(self): @@ -81,17 +82,16 @@ class DeploymentUnit: self.heat_manager.create_stack(template_file, stack_name, parameters) deployed = True - except Exception as e: - common.LOG.debug(e.message) + except Exception: + common.LOG.debug("create_stack", exc_info=True) deployed = False if not deployed and 'COMPLETE' in \ self.heat_manager.check_stack_status(stack_name): try: self.destroy_heat_template(stack_name) - except Exception as e: - common.LOG.debug(e.message) - pass + except Exception: + common.LOG.debug("destroy_heat_template", exc_info=True) status = self.heat_manager.check_stack_status(stack_name) while status and 'CREATE_IN_PROGRESS' in status: @@ -102,16 +102,15 @@ class DeploymentUnit: attempt += 1 try: self.destroy_heat_template(stack_name) - except Exception as e: - common.LOG.debug(e.message) - pass + except Exception: + common.LOG.debug("destroy_heat_template", exc_info=True) return self.deploy_heat_template(template_file, stack_name, parameters, attempt) else: try: self.destroy_heat_template(stack_name) - except Exception as e: - common.LOG.debug(e.message) + except Exception: + common.LOG.debug("destroy_heat_template", exc_info=True) finally: return False if self.heat_manager.check_stack_status(stack_name) and \ diff --git a/yardstick/vTC/apexlake/experimental_framework/heat_manager.py b/yardstick/vTC/apexlake/experimental_framework/heat_manager.py index 7400ebd21..a3233349d 100644 --- a/yardstick/vTC/apexlake/experimental_framework/heat_manager.py +++ b/yardstick/vTC/apexlake/experimental_framework/heat_manager.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import from keystoneclient.v2_0 import client as keystoneClient from heatclient import client as heatClient from heatclient.common import template_utils @@ -97,7 +98,6 @@ class HeatManager: if stack.stack_name == stack_name: self.heat.stacks.delete(stack.id) return True - except Exception as e: - common.LOG.debug(e.message) - pass + except Exception: + common.LOG.debug("destroy_heat_template", exc_info=True) return False diff --git a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py index e0c1a667f..0f0af8b05 100644 --- a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py +++ b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py @@ -17,6 +17,7 @@ Generation of the heat templates from the base template ''' +from __future__ import absolute_import import json import os import shutil diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py b/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py index 4d2c6fe72..57f586463 100644 --- a/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py +++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import abc diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py b/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py index 6dc32b671..959003628 100644 --- a/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py +++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py @@ -12,12 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import os -import base_packet_generator -import experimental_framework.common as common import time + + +import experimental_framework.common as common from experimental_framework.constants import conf_file_sections as conf_file from experimental_framework.constants import framework_parameters as fp +from experimental_framework.packet_generators import base_packet_generator class DpdkPacketGenerator(base_packet_generator.BasePacketGenerator): @@ -186,8 +189,7 @@ class DpdkPacketGenerator(base_packet_generator.BasePacketGenerator): conf_file.CFSP_DPDK_PROGRAM_NAME, conf_file.CFSP_DPDK_COREMASK, conf_file.CFSP_DPDK_MEMORY_CHANNEL]: - if var not in variables.keys() or (var in variables.keys() and - variables[var] is ''): + if variables.get(var, '') == '': raise ValueError("The variable " + var + " does not exist") @staticmethod diff --git a/yardstick/vTC/apexlake/setup.py b/yardstick/vTC/apexlake/setup.py index 188a7f0c3..0211a57c1 100644 --- a/yardstick/vTC/apexlake/setup.py +++ b/yardstick/vTC/apexlake/setup.py @@ -16,6 +16,7 @@ Experimental Framework """ +from __future__ import absolute_import from distutils.core import setup diff --git a/yardstick/vTC/apexlake/tests/api_test.py b/yardstick/vTC/apexlake/tests/api_test.py index 4b70b9bd6..b6191ed8f 100644 --- a/yardstick/vTC/apexlake/tests/api_test.py +++ b/yardstick/vTC/apexlake/tests/api_test.py @@ -13,14 +13,18 @@ # limitations under the License. +from __future__ import absolute_import import unittest import mock import os import experimental_framework.common as common +from experimental_framework import APEX_LAKE_ROOT from experimental_framework.api import FrameworkApi from experimental_framework.benchmarking_unit import BenchmarkingUnit import experimental_framework.benchmarks.\ instantiation_validation_benchmark as iv +from six.moves import map +from six.moves import range class DummyBenchmarkingUnit(BenchmarkingUnit): @@ -61,6 +65,7 @@ class DummyBenchmarkingUnit2(BenchmarkingUnit): class TestGeneratesTemplate(unittest.TestCase): + def setUp(self): pass @@ -92,11 +97,11 @@ class TestGeneratesTemplate(unittest.TestCase): iv.VLAN_RECEIVER] expected['allowed_values'] = dict() expected['allowed_values'][iv.THROUGHPUT] = \ - map(str, range(0, 100)) + list(map(str, list(range(0, 100)))) expected['allowed_values'][iv.VLAN_SENDER] = \ - map(str, range(-1, 4096)) + list(map(str, list(range(-1, 4096)))) expected['allowed_values'][iv.VLAN_RECEIVER] = \ - map(str, range(-1, 4096)) + list(map(str, list(range(-1, 4096)))) expected['default_values'] = dict() expected['default_values'][iv.THROUGHPUT] = '1' expected['default_values'][iv.VLAN_SENDER] = '-1' @@ -121,9 +126,8 @@ class TestGeneratesTemplate(unittest.TestCase): def test_execute_framework_for_success(self, mock_b_unit, mock_heat, mock_credentials, mock_log, mock_common_init): - common.TEMPLATE_DIR = "{}/{}/".format( - os.getcwd(), 'tests/data/generated_templates' - ) + common.TEMPLATE_DIR = os.path.join(APEX_LAKE_ROOT, + 'tests/data/generated_templates/') test_cases = dict() iterations = 1 diff --git a/yardstick/vTC/apexlake/tests/base_packet_generator_test.py b/yardstick/vTC/apexlake/tests/base_packet_generator_test.py index b0e27d069..153de171d 100644 --- a/yardstick/vTC/apexlake/tests/base_packet_generator_test.py +++ b/yardstick/vTC/apexlake/tests/base_packet_generator_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest from experimental_framework.packet_generators import base_packet_generator diff --git a/yardstick/vTC/apexlake/tests/benchmark_base_class_test.py b/yardstick/vTC/apexlake/tests/benchmark_base_class_test.py index 405c0102f..4e5eb9fb0 100644 --- a/yardstick/vTC/apexlake/tests/benchmark_base_class_test.py +++ b/yardstick/vTC/apexlake/tests/benchmark_base_class_test.py @@ -13,6 +13,7 @@ # limitations under the License. +from __future__ import absolute_import import unittest from experimental_framework.benchmarks import benchmark_base_class as base @@ -45,8 +46,8 @@ class TestBenchmarkBaseClass(unittest.TestCase): params['C'] = 'c' bench_base = DummyBechmarkBaseClass(name, params) self.assertEqual(name, bench_base.name) - self.assertIn('A', bench_base.params.keys()) - self.assertIn('B', bench_base.params.keys()) + self.assertIn('A', list(bench_base.params.keys())) + self.assertIn('B', list(bench_base.params.keys())) self.assertEqual('a', bench_base.params['A']) self.assertEqual('b', bench_base.params['B']) diff --git a/yardstick/vTC/apexlake/tests/benchmarking_unit_test.py b/yardstick/vTC/apexlake/tests/benchmarking_unit_test.py index 652327aab..7b33ba693 100644 --- a/yardstick/vTC/apexlake/tests/benchmarking_unit_test.py +++ b/yardstick/vTC/apexlake/tests/benchmarking_unit_test.py @@ -11,9 +11,12 @@ # 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. - +from __future__ import absolute_import +import os import unittest import mock + +from experimental_framework import APEX_LAKE_ROOT from experimental_framework.benchmarking_unit import BenchmarkingUnit # from experimental_framework.data_manager import DataManager from experimental_framework.deployment_unit import DeploymentUnit @@ -275,7 +278,8 @@ class TestBenchmarkingUnit(unittest.TestCase): mock_rfc2544, mock_log, mock_influx): mock_heat.return_value = list() mock_time.return_value = '12345' - mock_temp_dir.return_value = 'tests/data/test_templates/' + mock_temp_dir.return_value = os.path.join(APEX_LAKE_ROOT, + 'tests/data/test_templates/') common.TEMPLATE_FILE_EXTENSION = '.yaml' common.RESULT_DIR = 'tests/data/results/' common.INFLUXDB_IP = 'InfluxIP' @@ -336,7 +340,8 @@ class TestBenchmarkingUnit(unittest.TestCase): mock_log): mock_heat.return_value = list() mock_time.return_value = '12345' - mock_temp_dir.return_value = 'tests/data/test_templates/' + mock_temp_dir.return_value = os.path.join(APEX_LAKE_ROOT, + 'tests/data/test_templates/') common.TEMPLATE_FILE_EXTENSION = '.yaml' common.RESULT_DIR = 'tests/data/results/' diff --git a/yardstick/vTC/apexlake/tests/common_test.py b/yardstick/vTC/apexlake/tests/common_test.py index 486ed6d25..b8dbfe6b8 100644 --- a/yardstick/vTC/apexlake/tests/common_test.py +++ b/yardstick/vTC/apexlake/tests/common_test.py @@ -12,13 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import mock import os import logging -import ConfigParser +import six.moves.configparser import experimental_framework.common as common import experimental_framework.constants.conf_file_sections as cf +from experimental_framework import APEX_LAKE_ROOT __author__ = 'vmricco' @@ -47,6 +49,7 @@ def reset_common(): class DummyConfigurationFile(common.ConfigurationFile): + def __init__(self, sections, conf_file=''): pass @@ -58,6 +61,7 @@ class DummyConfigurationFile(common.ConfigurationFile): class DummyConfigurationFile2(common.ConfigurationFile): + def __init__(self, sections): self.pktgen_counter = 0 @@ -74,7 +78,7 @@ class DummyConfigurationFile2(common.ConfigurationFile): self.pktgen_counter += 1 return 'dpdk_pktgen' if variable_name == cf.CFSP_DPDK_PKTGEN_DIRECTORY: - return os.getcwd() + return APEX_LAKE_ROOT if variable_name == cf.CFSP_DPDK_PROGRAM_NAME: return 'program' if variable_name == cf.CFSP_DPDK_COREMASK: @@ -86,7 +90,7 @@ class DummyConfigurationFile2(common.ConfigurationFile): if variable_name == cf.CFSP_DPDK_BUS_SLOT_NIC_2: return 'bus_slot_nic_2' if variable_name == cf.CFSP_DPDK_DPDK_DIRECTORY: - return os.getcwd() + return APEX_LAKE_ROOT def get_variable_list(self, section): if section == cf.CFS_PKTGEN: @@ -114,8 +118,7 @@ class TestCommonInit(unittest.TestCase): def setUp(self): common.CONF_FILE = DummyConfigurationFile('') - self.dir = '{}/{}'.format(os.getcwd(), - 'experimental_framework/') + self.dir = os.path.join(APEX_LAKE_ROOT, 'experimental_framework/') def tearDown(self): reset_common() @@ -131,7 +134,8 @@ class TestCommonInit(unittest.TestCase): init_general_vars, init_conf_file, mock_getcwd): mock_getcwd.return_value = self.dir common.init(True) - init_pkgen.assert_called_once() + if common.CONF_FILE.get_variable_list(cf.CFS_PKTGEN): + init_pkgen.assert_called_once() init_conf_file.assert_called_once() init_general_vars.assert_called_once() init_log.assert_called_once() @@ -144,7 +148,7 @@ class TestCommonInit(unittest.TestCase): @mock.patch('experimental_framework.common.LOG') def test_init_general_vars_for_success(self, mock_log, mock_makedirs, mock_path_exists, mock_val_file): - common.BASE_DIR = "{}/".format(os.getcwd()) + common.BASE_DIR = APEX_LAKE_ROOT mock_path_exists.return_value = False mock_val_file.return_value = True common.init_general_vars() @@ -160,15 +164,19 @@ class TestCommonInit2(unittest.TestCase): def setUp(self): common.CONF_FILE = DummyConfigurationFile2('') - self.dir = '{}/{}'.format(os.getcwd(), 'experimental_framework/') + self.dir = os.path.join(APEX_LAKE_ROOT, 'experimental_framework') def tearDown(self): reset_common() common.CONF_FILE = None + @mock.patch('experimental_framework.common.InputValidation') + @mock.patch('os.path.exists') + @mock.patch('os.makedirs') @mock.patch('experimental_framework.common.LOG') - def test_init_general_vars_2_for_success(self, mock_log): - common.BASE_DIR = "{}/".format(os.getcwd()) + def test_init_general_vars_2_for_success(self, mock_log, mock_makedirs, + mock_path_exists, mock_val_file): + common.BASE_DIR = APEX_LAKE_ROOT common.init_general_vars() self.assertEqual(common.TEMPLATE_FILE_EXTENSION, '.yaml') self.assertEqual(common.TEMPLATE_DIR, '/tmp/apexlake/heat_templates/') @@ -183,14 +191,16 @@ class TestCommonInit2(unittest.TestCase): def test_init_pktgen_for_success(self): common.init_pktgen() self.assertEqual(common.PKTGEN, 'dpdk_pktgen') - directory = self.dir.split('experimental_framework/')[0] + directory = self.dir.split('experimental_framework')[0] self.assertEqual(common.PKTGEN_DIR, directory) self.assertEqual(common.PKTGEN_PROGRAM, 'program') self.assertEqual(common.PKTGEN_COREMASK, 'coremask') self.assertEqual(common.PKTGEN_MEMCHANNEL, 'memchannel') self.assertEqual(common.PKTGEN_BUS_SLOT_NIC_1, 'bus_slot_nic_1') self.assertEqual(common.PKTGEN_BUS_SLOT_NIC_2, 'bus_slot_nic_2') - expected_dir = "{}/".format(os.getcwd()) + # we always add '/' to end of dirs for some reason + # probably because we aren't using os.path.join everywhere + expected_dir = APEX_LAKE_ROOT + '/' self.assertEqual(common.PKTGEN_DPDK_DIRECTORY, expected_dir) def test_init_pktgen_for_failure(self): @@ -260,8 +270,8 @@ class TestConfigFileClass(unittest.TestCase): 'Deployment-parameters', 'Testcase-parameters' ] - c_file = './tests/data/common/conf.cfg' - common.BASE_DIR = os.getcwd() + c_file = os.path.join(APEX_LAKE_ROOT, 'tests/data/common/conf.cfg') + common.BASE_DIR = APEX_LAKE_ROOT self.conf_file = common.ConfigurationFile(self.sections, c_file) def tearDown(self): @@ -275,7 +285,8 @@ class TestConfigFileClass(unittest.TestCase): sections = ['General', 'OpenStack', 'Experiment-VNF', 'PacketGen', 'Deployment-parameters', 'Testcase-parameters'] c = DummyConfigurationFile3( - sections, config_file='./tests/data/common/conf.cfg') + sections, config_file=os.path.join(APEX_LAKE_ROOT, + 'tests/data/common/conf.cfg')) self.assertEqual( DummyConfigurationFile3._config_section_map('', '', True), 6) @@ -285,8 +296,9 @@ class TestConfigFileClass(unittest.TestCase): def test__config_section_map_for_success(self): general_section = 'General' # openstack_section = 'OpenStack' - config_file = 'tests/data/common/conf.cfg' - config = ConfigParser.ConfigParser() + config_file = os.path.join(APEX_LAKE_ROOT, + 'tests/data/common/conf.cfg') + config = six.moves.configparser.ConfigParser() config.read(config_file) expected = { @@ -361,8 +373,9 @@ class TestCommonMethods(unittest.TestCase): 'Deployment-parameters', 'Testcase-parameters' ] - config_file = './tests/data/common/conf.cfg' - common.BASE_DIR = os.getcwd() + config_file = os.path.join(APEX_LAKE_ROOT, + 'tests/data/common/conf.cfg') + common.BASE_DIR = APEX_LAKE_ROOT common.CONF_FILE = DummyConfigurationFile4(self.sections, config_file) def tearDown(self): @@ -397,13 +410,14 @@ class TestCommonMethods(unittest.TestCase): self.assertEqual(expected, output) def test_get_file_first_line_for_success(self): - file = 'tests/data/common/conf.cfg' + file = os.path.join(APEX_LAKE_ROOT, 'tests/data/common/conf.cfg') expected = '[General]\n' output = common.get_file_first_line(file) self.assertEqual(expected, output) def test_replace_in_file_for_success(self): - filename = 'tests/data/common/file_replacement.txt' + filename = os.path.join(APEX_LAKE_ROOT, + 'tests/data/common/file_replacement.txt') text_to_search = 'replacement of' text_to_replace = '***' common.replace_in_file(filename, text_to_search, text_to_replace) @@ -542,27 +556,14 @@ class TestinputValidation(unittest.TestCase): list(), '' ) - def test_validate_file_exist_for_success(self): - filename = 'tests/data/common/file_replacement.txt' - output = common.InputValidation.validate_file_exist(filename, '') - self.assertTrue(output) - - def test_validate_file_exist_for_failure(self): - filename = 'tests/data/common/file_replacement' - self.assertRaises( - ValueError, - common.InputValidation.validate_file_exist, - filename, '' - ) - def test_validate_directory_exist_and_format_for_success(self): - directory = 'tests/data/common/' + directory = os.path.join(APEX_LAKE_ROOT, 'tests/data/common/') output = common.InputValidation.\ validate_directory_exist_and_format(directory, '') self.assertTrue(output) def test_validate_directory_exist_and_format_for_failure(self): - directory = 'tests/data/com/' + directory = os.path.join(APEX_LAKE_ROOT, 'tests/data/com/') self.assertRaises( ValueError, common.InputValidation.validate_directory_exist_and_format, diff --git a/yardstick/vTC/apexlake/tests/conf_file_sections_test.py b/yardstick/vTC/apexlake/tests/conf_file_sections_test.py index 2b03edb04..abf4134a5 100644 --- a/yardstick/vTC/apexlake/tests/conf_file_sections_test.py +++ b/yardstick/vTC/apexlake/tests/conf_file_sections_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest from experimental_framework.constants import conf_file_sections as cfs diff --git a/yardstick/vTC/apexlake/tests/deployment_unit_test.py b/yardstick/vTC/apexlake/tests/deployment_unit_test.py index cec834e56..5a9178f53 100644 --- a/yardstick/vTC/apexlake/tests/deployment_unit_test.py +++ b/yardstick/vTC/apexlake/tests/deployment_unit_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import logging import mock diff --git a/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py b/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py index bad250e7b..0b0df6c2b 100644 --- a/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py +++ b/yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import mock from experimental_framework.constants import conf_file_sections as conf_file diff --git a/yardstick/vTC/apexlake/tests/generates_template_test.py b/yardstick/vTC/apexlake/tests/generates_template_test.py index dad3177d6..cc3e1bf6e 100644 --- a/yardstick/vTC/apexlake/tests/generates_template_test.py +++ b/yardstick/vTC/apexlake/tests/generates_template_test.py @@ -12,11 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import experimental_framework.heat_template_generation as heat_gen import mock import os import experimental_framework.common as common +from experimental_framework import APEX_LAKE_ROOT __author__ = 'gpetralx' @@ -45,6 +47,7 @@ def reset_common(): class TestGeneratesTemplate(unittest.TestCase): + def setUp(self): self.deployment_configuration = { 'vnic_type': ['normal', 'direct'], @@ -61,9 +64,11 @@ class TestGeneratesTemplate(unittest.TestCase): @mock.patch('experimental_framework.common.get_template_dir') def test_generates_template_for_success(self, mock_template_dir, mock_log): - generated_templates_dir = 'tests/data/generated_templates/' + generated_templates_dir = os.path.join( + APEX_LAKE_ROOT, 'tests/data/generated_templates/') mock_template_dir.return_value = generated_templates_dir - test_templates = 'tests/data/test_templates/' + test_templates = os.path.join(APEX_LAKE_ROOT, + 'tests/data/test_templates/') heat_gen.generates_templates(self.template_name, self.deployment_configuration) for dirname, dirnames, filenames in os.walk(test_templates): @@ -73,8 +78,9 @@ class TestGeneratesTemplate(unittest.TestCase): self.assertListEqual(test.readlines(), generated.readlines()) - t_name = '/tests/data/generated_templates/VTC_base_single_vm_wait.tmp' - self.template_name = "{}{}".format(os.getcwd(), t_name) + self.template_name = os.path.join( + APEX_LAKE_ROOT, + 'tests/data/generated_templates/VTC_base_single_vm_wait.tmp') heat_gen.generates_templates(self.template_name, self.deployment_configuration) for dirname, dirnames, filenames in os.walk(test_templates): @@ -86,7 +92,8 @@ class TestGeneratesTemplate(unittest.TestCase): @mock.patch('experimental_framework.common.get_template_dir') def test_get_all_heat_templates_for_success(self, template_dir): - generated_templates = 'tests/data/generated_templates/' + generated_templates = os.path.join(APEX_LAKE_ROOT, + 'tests/data/generated_templates/') template_dir.return_value = generated_templates extension = '.yaml' expected = ['experiment_1.yaml', 'experiment_2.yaml'] diff --git a/yardstick/vTC/apexlake/tests/heat_manager_test.py b/yardstick/vTC/apexlake/tests/heat_manager_test.py index 0fe8554cd..58bd75560 100644 --- a/yardstick/vTC/apexlake/tests/heat_manager_test.py +++ b/yardstick/vTC/apexlake/tests/heat_manager_test.py @@ -12,11 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + +from __future__ import absolute_import +import os import unittest import logging import experimental_framework.common as common -from experimental_framework import heat_manager +from experimental_framework import heat_manager, APEX_LAKE_ROOT import mock __author__ = 'gpetralx' @@ -27,6 +31,7 @@ def get_mock_heat(version, *args, **kwargs): class MockStacks(object): + def __init__(self, stacks): self.stacks = stacks @@ -34,7 +39,7 @@ class MockStacks(object): list_name = list() for stack in self.stacks: list_name.append(stack.stack_name) - print list_name + print(list_name) return self.stacks def validate(self, template=None): @@ -47,11 +52,12 @@ class MockStacks(object): def create(self, stack_name=None, files=None, template=None, parameters=None): - print stack_name + print(stack_name) self.stacks.append(MockStack(stack_name)) class MockStacks_2(object): + def __init__(self, stacks): self.stacks = stacks @@ -60,6 +66,7 @@ class MockStacks_2(object): class MockStack(object): + def __init__(self, stack_name): self.name = stack_name @@ -80,6 +87,7 @@ class MockStack(object): class MockHeat(object): + def __init__(self): stacks = [MockStack('stack_1'), MockStack('stack_2')] self.stacks_list = MockStacks(stacks) @@ -90,18 +98,21 @@ class MockHeat(object): class MockHeat_2(MockHeat): + def __init__(self): stacks = [MockStack('stack_1'), MockStack('stack_2')] self.stacks_list = MockStacks_2(stacks) class HeatManagerMock(heat_manager.HeatManager): + def init_heat(self): if self.heat is None: self.heat = MockHeat() class HeatManagerMock_2(heat_manager.HeatManager): + def init_heat(self): if self.heat is None: self.heat = MockHeat_2() @@ -134,8 +145,9 @@ class TestHeatManager(unittest.TestCase): self.heat_manager.check_stack_status('stack_x')) def test_validate_template_for_success(self): - template_file = \ - 'tests/data/test_templates/VTC_base_single_vm_wait_1.yaml' + template_file = os.path.join( + APEX_LAKE_ROOT, + 'tests/data/test_templates/VTC_base_single_vm_wait_1.yaml') with self.assertRaises(ValueError): self.heat_manager.validate_heat_template(template_file) @@ -180,11 +192,13 @@ class TestHeatManager_2(unittest.TestCase): class ServiceCatalog(): + def url_for(self, service_type): return 'http://heat_url' class KeystoneMock(object): + @property def auth_token(self): return 'token' @@ -193,6 +207,7 @@ class KeystoneMock(object): class TestHeatInit(unittest.TestCase): + def setUp(self): credentials = dict() credentials['ip_controller'] = '1.1.1.1' @@ -216,5 +231,5 @@ class TestHeatInit(unittest.TestCase): tenant_name='project', password='password', auth_url='auth_uri') - heat_client.assert_called_once_with('1', endpoint='http://heat_url', + heat_client.assert_called_once_with('1', endpoint='http://heat_url', token='token') diff --git a/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py b/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py index 369129a00..2bd8b7b38 100644 --- a/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py +++ b/yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import mock import os @@ -21,6 +22,8 @@ import experimental_framework.benchmarks.\ instantiation_validation_benchmark as iv_module from experimental_framework.benchmarks.\ instantiation_validation_benchmark import InstantiationValidationBenchmark +from six.moves import map +from six.moves import range kill_counter = [0, 0] @@ -204,11 +207,11 @@ class InstantiationValidationInitTest(unittest.TestCase): ] expected['allowed_values'] = dict() expected['allowed_values'][iv_module.THROUGHPUT] = \ - map(str, range(0, 100)) + list(map(str, list(range(0, 100)))) expected['allowed_values'][iv_module.VLAN_SENDER] = \ - map(str, range(-1, 4096)) + list(map(str, list(range(-1, 4096)))) expected['allowed_values'][iv_module.VLAN_RECEIVER] = \ - map(str, range(-1, 4096)) + list(map(str, list(range(-1, 4096)))) expected['default_values'] = dict() expected['default_values'][iv_module.THROUGHPUT] = '1' expected['default_values'][iv_module.VLAN_SENDER] = '-1' @@ -216,7 +219,7 @@ class InstantiationValidationInitTest(unittest.TestCase): output = self.iv.get_features() self.assertEqual(expected, output) - @mock.patch('commands.getoutput') + @mock.patch('subprocess.check_output') def test__get_pids_for_success(self, mock_getoutput): expected = [1234] mock_getoutput.return_value = '1234' diff --git a/yardstick/vTC/apexlake/tests/instantiation_validation_noisy_bench_test.py b/yardstick/vTC/apexlake/tests/instantiation_validation_noisy_bench_test.py index f65600f6e..f9aa9473f 100644 --- a/yardstick/vTC/apexlake/tests/instantiation_validation_noisy_bench_test.py +++ b/yardstick/vTC/apexlake/tests/instantiation_validation_noisy_bench_test.py @@ -12,13 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import mock -import os + +from six.moves import range + import experimental_framework.common as common import experimental_framework.deployment_unit as deploy import experimental_framework.benchmarks.\ instantiation_validation_noisy_neighbors_benchmark as mut +from experimental_framework import APEX_LAKE_ROOT class InstantiationValidationInitTest(unittest.TestCase): @@ -34,7 +38,7 @@ class InstantiationValidationInitTest(unittest.TestCase): openstack_credentials['heat_url'] = '' openstack_credentials['password'] = '' common.DEPLOYMENT_UNIT = deploy.DeploymentUnit(openstack_credentials) - common.BASE_DIR = os.getcwd() + common.BASE_DIR = APEX_LAKE_ROOT common.TEMPLATE_DIR = 'tests/data/generated_templates' self.iv = mut.\ InstantiationValidationNoisyNeighborsBenchmark(name, params) @@ -72,9 +76,11 @@ class InstantiationValidationInitTest(unittest.TestCase): expected['parameters'].append(mut.NUM_OF_NEIGHBORS) expected['parameters'].append(mut.AMOUNT_OF_RAM) expected['parameters'].append(mut.NUMBER_OF_CORES) - expected['allowed_values']['throughput'] = map(str, range(0, 100)) - expected['allowed_values']['vlan_sender'] = map(str, range(-1, 4096)) - expected['allowed_values']['vlan_receiver'] = map(str, range(-1, 4096)) + expected['allowed_values']['throughput'] = [str(x) for x in range(100)] + expected['allowed_values']['vlan_sender'] = [str(x) for x in + range(-1, 4096)] + expected['allowed_values']['vlan_receiver'] = [str(x) for x in + range(-1, 4096)] expected['allowed_values'][mut.NUM_OF_NEIGHBORS] = \ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] expected['allowed_values'][mut.NUMBER_OF_CORES] = \ @@ -115,10 +121,10 @@ class InstantiationValidationInitTest(unittest.TestCase): 'num_of_neighbours': 1} self.iv.template_file = 'template.yaml' self.iv.init() - mock_replace.assert_called_once_wih('file', - 'local out_file = ""', - 'local out_file = "' + - 'res_file' + '"') + mock_replace.assert_called_once_with('file', + 'local out_file = ""', + 'local out_file = "' + + 'res_file' + '"') mock_deploy_heat.assert_called_once_with('template.yaml', 'neighbour0', {'cores': 1, @@ -131,12 +137,14 @@ class InstantiationValidationInitTest(unittest.TestCase): @mock.patch('experimental_framework.common.' 'DEPLOYMENT_UNIT.destroy_heat_template') def test_finalize_for_success(self, mock_heat_destroy, mock_replace): + self.iv.lua_file = 'file' + self.iv.results_file = 'res_file' self.iv.neighbor_stack_names = ['neighbor0'] stack_name = 'neighbor0' self.iv.finalize() mock_heat_destroy.assert_called_once_with(stack_name) - mock_replace.assert_called_once_wih('file', - 'local out_file = ""', - 'local out_file = "' + - 'res_file' + '"') + mock_replace.assert_called_once_with('file', + 'local out_file = "' + + 'res_file' + '"', + 'local out_file = ""') self.assertEqual(self.iv.neighbor_stack_names, list()) diff --git a/yardstick/vTC/apexlake/tests/multi_tenancy_throughput_benchmark_test.py b/yardstick/vTC/apexlake/tests/multi_tenancy_throughput_benchmark_test.py index fc5a7fddb..39b38d7d3 100644 --- a/yardstick/vTC/apexlake/tests/multi_tenancy_throughput_benchmark_test.py +++ b/yardstick/vTC/apexlake/tests/multi_tenancy_throughput_benchmark_test.py @@ -12,17 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import mock import os import experimental_framework.common as common from experimental_framework.benchmarks \ import multi_tenancy_throughput_benchmark as bench +from six.moves import range __author__ = 'gpetralx' class MockDeploymentUnit(object): + def deploy_heat_template(self, temp_file, stack_name, heat_param): pass @@ -35,6 +38,7 @@ def get_deployment_unit(): class TestMultiTenancyThroughputBenchmark(unittest.TestCase): + def setUp(self): name = 'benchmark' params = dict() @@ -47,9 +51,9 @@ class TestMultiTenancyThroughputBenchmark(unittest.TestCase): def test_get_features_for_sanity(self): output = self.benchmark.get_features() self.assertIsInstance(output, dict) - self.assertIn('parameters', output.keys()) - self.assertIn('allowed_values', output.keys()) - self.assertIn('default_values', output.keys()) + self.assertIn('parameters', list(output.keys())) + self.assertIn('allowed_values', list(output.keys())) + self.assertIn('default_values', list(output.keys())) self.assertIsInstance(output['parameters'], list) self.assertIsInstance(output['allowed_values'], dict) self.assertIsInstance(output['default_values'], dict) diff --git a/yardstick/vTC/apexlake/tests/rfc2544_throughput_benchmark_test.py b/yardstick/vTC/apexlake/tests/rfc2544_throughput_benchmark_test.py index ef3b0dabb..487de7775 100644 --- a/yardstick/vTC/apexlake/tests/rfc2544_throughput_benchmark_test.py +++ b/yardstick/vTC/apexlake/tests/rfc2544_throughput_benchmark_test.py @@ -13,6 +13,7 @@ # limitations under the License. +from __future__ import absolute_import import unittest import mock import os @@ -37,9 +38,9 @@ class RFC2544ThroughputBenchmarkRunTest(unittest.TestCase): def test_get_features_for_sanity(self): output = self.benchmark.get_features() self.assertIsInstance(output, dict) - self.assertIn('parameters', output.keys()) - self.assertIn('allowed_values', output.keys()) - self.assertIn('default_values', output.keys()) + self.assertIn('parameters', list(output.keys())) + self.assertIn('allowed_values', list(output.keys())) + self.assertIn('default_values', list(output.keys())) self.assertIsInstance(output['parameters'], list) self.assertIsInstance(output['allowed_values'], dict) self.assertIsInstance(output['default_values'], dict) @@ -74,7 +75,6 @@ class RFC2544ThroughputBenchmarkRunTest(unittest.TestCase): output = self.benchmark.run() self.assertEqual(expected, output) conf_lua_file_mock.assert_called_once() - reset_lua_file_mock.assert_called_once() dpdk_instance = mock_dpdk() dpdk_instance.init_dpdk_pktgen.assert_called_once_with( dpdk_interfaces=2, pcap_file_0='packet_1.pcap', diff --git a/yardstick/vTC/apexlake/tests/tree_node_test.py b/yardstick/vTC/apexlake/tests/tree_node_test.py index e51343f0e..fb38b69bd 100644 --- a/yardstick/vTC/apexlake/tests/tree_node_test.py +++ b/yardstick/vTC/apexlake/tests/tree_node_test.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import import unittest import experimental_framework.heat_template_generation as heat_gen @@ -19,6 +20,7 @@ __author__ = 'gpetralx' class TestTreeNode(unittest.TestCase): + def setUp(self): self.tree = heat_gen.TreeNode() |