From f036e9898a69f5041f9cde02e3652c29e2de1643 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Mon, 5 Dec 2016 16:11:54 -0500 Subject: Add support for Python 3 Porting to Python3 using Openstack guidelines: https://wiki.openstack.org/wiki/Python3 This passes unittests on Python 3.5 and passes opnfv_smoke suite Updates: use six for urlparse and urlopen fix exception.message attribute removal run unittests on python3 use unitest.mock on python 3 fix open mock for vsperf fix float division by using delta/eplison comparison use unicode in StringIO use plugin/sample_config.yaml relative path from test case fixed apexlake unittests upgraded to mock 2.0.0 to match python3 unittest.mock features fixed flake8 issues implement safe JSON decode with oslo_serialization.jsonutils.dump_as_bytes() implement safe unicode encode/decode with oslo_utils.encodeutils heat: convert pub key file from bytes to unicode pkg_resources returns raw bytes, in python3 we have to decode this to utf-8 unicode so JSON can encode it for heat template JIRA: YARDSTICK-452 Change-Id: Ib80dd1d0c0eb0592acd832b82f6a7f8f7c20bfda Signed-off-by: Ross Brattain --- yardstick/benchmark/__init__.py | 1 + yardstick/benchmark/contexts/base.py | 1 + yardstick/benchmark/contexts/dummy.py | 1 + yardstick/benchmark/contexts/heat.py | 30 ++++++++++++------- yardstick/benchmark/contexts/model.py | 4 +++ yardstick/benchmark/contexts/node.py | 7 +++-- yardstick/benchmark/core/plugin.py | 7 +++-- yardstick/benchmark/core/runner.py | 8 +++-- yardstick/benchmark/core/scenario.py | 4 ++- yardstick/benchmark/core/task.py | 35 ++++++++++++---------- yardstick/benchmark/core/testcase.py | 19 +++++++----- yardstick/benchmark/runners/arithmetic.py | 21 ++++++++----- yardstick/benchmark/runners/base.py | 1 + yardstick/benchmark/runners/duration.py | 1 + yardstick/benchmark/runners/iteration.py | 1 + yardstick/benchmark/runners/sequence.py | 1 + .../scenarios/availability/actionrollbackers.py | 1 + .../availability/attacker/attacker_baremetal.py | 7 +++-- .../availability/attacker/attacker_general.py | 8 +++-- .../availability/attacker/attacker_process.py | 4 ++- .../availability/attacker/baseattacker.py | 1 + .../benchmark/scenarios/availability/director.py | 1 + .../scenarios/availability/monitor/basemonitor.py | 4 ++- .../availability/monitor/monitor_command.py | 4 ++- .../availability/monitor/monitor_general.py | 3 +- .../availability/monitor/monitor_process.py | 3 +- .../availability/operation/baseoperation.py | 1 + .../availability/operation/operation_general.py | 7 ++++- .../result_checker/baseresultchecker.py | 3 +- .../result_checker/result_checker_general.py | 6 +++- .../scenarios/availability/scenario_general.py | 11 ++++--- .../benchmark/scenarios/availability/serviceha.py | 7 +++-- yardstick/benchmark/scenarios/base.py | 1 + yardstick/benchmark/scenarios/compute/cachestat.py | 4 ++- .../benchmark/scenarios/compute/computecapacity.py | 9 ++++-- yardstick/benchmark/scenarios/compute/cpuload.py | 23 +++++++------- .../benchmark/scenarios/compute/cyclictest.py | 15 ++++++---- yardstick/benchmark/scenarios/compute/lmbench.py | 16 ++++++---- yardstick/benchmark/scenarios/compute/memload.py | 4 ++- yardstick/benchmark/scenarios/compute/perf.py | 13 +++++--- .../benchmark/scenarios/compute/plugintest.py | 7 +++-- yardstick/benchmark/scenarios/compute/ramspeed.py | 9 ++++-- yardstick/benchmark/scenarios/compute/unixbench.py | 12 +++++--- yardstick/benchmark/scenarios/dummy/dummy.py | 1 + yardstick/benchmark/scenarios/networking/iperf3.py | 14 ++++++--- .../benchmark/scenarios/networking/netperf.py | 12 +++++--- .../benchmark/scenarios/networking/netperf_node.py | 13 +++++--- .../scenarios/networking/netutilization.py | 7 +++-- .../scenarios/networking/networkcapacity.py | 9 ++++-- yardstick/benchmark/scenarios/networking/ping.py | 5 +++- yardstick/benchmark/scenarios/networking/ping6.py | 1 + yardstick/benchmark/scenarios/networking/pktgen.py | 12 +++++--- .../benchmark/scenarios/networking/pktgen_dpdk.py | 1 + yardstick/benchmark/scenarios/networking/sfc.py | 11 +++++-- .../scenarios/networking/sfc_openstack.py | 25 +++++++++------- yardstick/benchmark/scenarios/networking/vsperf.py | 3 +- .../networking/vtc_instantiation_validation.py | 7 +++-- .../vtc_instantiation_validation_noisy.py | 7 +++-- .../scenarios/networking/vtc_throughput.py | 7 +++-- .../scenarios/networking/vtc_throughput_noisy.py | 7 +++-- yardstick/benchmark/scenarios/parser/parser.py | 5 +++- yardstick/benchmark/scenarios/storage/fio.py | 13 +++++--- .../benchmark/scenarios/storage/storagecapacity.py | 10 +++++-- yardstick/benchmark/scenarios/storage/storperf.py | 27 +++++++++++------ 64 files changed, 345 insertions(+), 178 deletions(-) (limited to 'yardstick/benchmark') 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']) -- cgit 1.2.3-korg