aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/base.py1
-rw-r--r--api/conf.py3
-rw-r--r--api/database/__init__.py5
-rw-r--r--api/database/models.py1
-rw-r--r--api/resources/env_action.py24
-rw-r--r--api/resources/release_action.py1
-rw-r--r--api/resources/results.py1
-rw-r--r--api/resources/samples_action.py1
-rw-r--r--api/server.py15
-rw-r--r--api/swagger/models.py1
-rw-r--r--api/urls.py1
-rw-r--r--api/utils/common.py18
-rw-r--r--api/utils/daemonthread.py1
-rw-r--r--api/utils/influx.py6
-rw-r--r--api/views.py7
-rw-r--r--ez_setup.py44
-rw-r--r--requirements.txt10
-rwxr-xr-xsetup.py1
-rwxr-xr-xtests/functional/test_cli_runner.py2
-rwxr-xr-xtests/functional/test_cli_scenario.py2
-rwxr-xr-xtests/functional/utils.py20
-rw-r--r--tests/unit/apiserver/__init__.py35
-rw-r--r--tests/unit/apiserver/resources/__init__.py0
-rw-r--r--tests/unit/apiserver/resources/test_env_action.py32
-rw-r--r--tests/unit/apiserver/utils/test_common.py (renamed from tests/unit/api/utils/test_common.py)1
-rw-r--r--tests/unit/apiserver/utils/test_influx.py (renamed from tests/unit/api/utils/test_influx.py)38
-rw-r--r--tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml135
-rw-r--r--tests/unit/benchmark/contexts/standalone_sample.yaml112
-rw-r--r--tests/unit/benchmark/contexts/test_dummy.py1
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py25
-rw-r--r--tests/unit/benchmark/contexts/test_model.py5
-rw-r--r--tests/unit/benchmark/contexts/test_node.py6
-rw-r--r--tests/unit/benchmark/contexts/test_standalone.py131
-rw-r--r--tests/unit/benchmark/core/test_plugin.py17
-rw-r--r--tests/unit/benchmark/core/test_task.py34
-rw-r--r--tests/unit/benchmark/core/test_testcase.py2
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py57
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_attacker_general.py10
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_attacker_process.py8
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_basemonitor.py18
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_baseoperation.py19
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py17
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_director.py39
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_command.py28
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_general.py17
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_process.py9
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_operation_general.py11
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_result_checker_general.py30
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_scenario_general.py11
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_serviceha.py8
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_cachestat.py19
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_computecapacity.py13
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_cpuload.py3
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_cyclictest.py21
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_lmbench.py21
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_memload.py18
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_plugintest.py10
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_ramspeed.py27
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_unixbench.py16
-rw-r--r--tests/unit/benchmark/scenarios/dummy/test_dummy.py1
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_iperf3.py23
-rwxr-xr-xtests/unit/benchmark/scenarios/networking/test_netperf.py13
-rwxr-xr-xtests/unit/benchmark/scenarios/networking/test_netperf_node.py13
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_netutilization.py4
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_networkcapacity.py27
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_ping.py5
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_ping6.py52
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_pktgen.py11
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py13
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_sfc.py6
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vsperf.py26
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation.py8
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation_noisy.py9
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vtc_throughput.py1
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vtc_throughput_noisy_test.py1
-rw-r--r--tests/unit/benchmark/scenarios/parser/test_parser.py14
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_fio.py22
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_storagecapacity.py44
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_storperf.py48
-rw-r--r--tests/unit/cmd/commands/test_env.py1
-rw-r--r--tests/unit/common/test_httpClient.py10
-rw-r--r--tests/unit/common/test_openstack_utils.py1
-rw-r--r--tests/unit/common/test_template_format.py1
-rw-r--r--tests/unit/common/test_utils.py8
-rw-r--r--tests/unit/dispatcher/test_influxdb.py36
-rw-r--r--tests/unit/dispatcher/test_influxdb_line_protocol.py1
-rw-r--r--tests/unit/network_services/__init__.py0
-rw-r--r--tests/unit/network_services/collector/__init__.py0
-rw-r--r--tests/unit/network_services/collector/test_publisher.py41
-rw-r--r--tests/unit/network_services/collector/test_subscriber.py69
-rw-r--r--tests/unit/orchestrator/test_heat.py26
-rw-r--r--tests/unit/test_ssh.py13
-rw-r--r--third_party/influxdb/influxdb_line_protocol.py5
-rw-r--r--yardstick/__init__.py1
-rw-r--r--yardstick/benchmark/__init__.py1
-rw-r--r--yardstick/benchmark/contexts/base.py17
-rw-r--r--yardstick/benchmark/contexts/dummy.py7
-rw-r--r--yardstick/benchmark/contexts/heat.py61
-rw-r--r--yardstick/benchmark/contexts/model.py40
-rw-r--r--yardstick/benchmark/contexts/node.py75
-rw-r--r--yardstick/benchmark/contexts/standalone.py116
-rw-r--r--yardstick/benchmark/core/__init__.py2
-rw-r--r--yardstick/benchmark/core/plugin.py7
-rw-r--r--yardstick/benchmark/core/runner.py16
-rw-r--r--yardstick/benchmark/core/scenario.py12
-rw-r--r--yardstick/benchmark/core/task.py72
-rw-r--r--yardstick/benchmark/core/testcase.py29
-rwxr-xr-xyardstick/benchmark/runners/arithmetic.py29
-rwxr-xr-xyardstick/benchmark/runners/base.py27
-rw-r--r--yardstick/benchmark/runners/duration.py9
-rw-r--r--yardstick/benchmark/runners/iteration.py9
-rw-r--r--yardstick/benchmark/runners/sequence.py9
-rw-r--r--yardstick/benchmark/scenarios/availability/actionrollbackers.py1
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py9
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/attacker_general.py8
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/attacker_process.py4
-rw-r--r--yardstick/benchmark/scenarios/availability/attacker/baseattacker.py3
-rw-r--r--yardstick/benchmark/scenarios/availability/director.py1
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/basemonitor.py6
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/monitor_command.py6
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/monitor_general.py3
-rw-r--r--yardstick/benchmark/scenarios/availability/monitor/monitor_process.py3
-rw-r--r--yardstick/benchmark/scenarios/availability/operation/baseoperation.py3
-rw-r--r--yardstick/benchmark/scenarios/availability/operation/operation_general.py7
-rw-r--r--yardstick/benchmark/scenarios/availability/result_checker/baseresultchecker.py5
-rw-r--r--yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py6
-rw-r--r--yardstick/benchmark/scenarios/availability/scenario_general.py11
-rwxr-xr-xyardstick/benchmark/scenarios/availability/serviceha.py13
-rw-r--r--yardstick/benchmark/scenarios/base.py11
-rw-r--r--yardstick/benchmark/scenarios/compute/cachestat.py8
-rw-r--r--yardstick/benchmark/scenarios/compute/computecapacity.py9
-rw-r--r--yardstick/benchmark/scenarios/compute/cpuload.py23
-rw-r--r--yardstick/benchmark/scenarios/compute/cyclictest.py19
-rw-r--r--yardstick/benchmark/scenarios/compute/lmbench.py16
-rw-r--r--yardstick/benchmark/scenarios/compute/memload.py4
-rw-r--r--yardstick/benchmark/scenarios/compute/perf.py13
-rw-r--r--yardstick/benchmark/scenarios/compute/plugintest.py7
-rw-r--r--yardstick/benchmark/scenarios/compute/ramspeed.py9
-rw-r--r--yardstick/benchmark/scenarios/compute/unixbench.py12
-rw-r--r--yardstick/benchmark/scenarios/dummy/dummy.py3
-rw-r--r--yardstick/benchmark/scenarios/networking/iperf3.py16
-rwxr-xr-xyardstick/benchmark/scenarios/networking/netperf.py16
-rwxr-xr-xyardstick/benchmark/scenarios/networking/netperf_node.py19
-rw-r--r--yardstick/benchmark/scenarios/networking/netutilization.py7
-rw-r--r--yardstick/benchmark/scenarios/networking/networkcapacity.py9
-rw-r--r--yardstick/benchmark/scenarios/networking/ping.py7
-rw-r--r--yardstick/benchmark/scenarios/networking/ping6.py3
-rw-r--r--yardstick/benchmark/scenarios/networking/pktgen.py16
-rw-r--r--yardstick/benchmark/scenarios/networking/pktgen_dpdk.py3
-rw-r--r--yardstick/benchmark/scenarios/networking/sfc.py29
-rw-r--r--yardstick/benchmark/scenarios/networking/sfc_openstack.py25
-rw-r--r--yardstick/benchmark/scenarios/networking/vsperf.py5
-rw-r--r--yardstick/benchmark/scenarios/networking/vtc_instantiation_validation.py9
-rw-r--r--yardstick/benchmark/scenarios/networking/vtc_instantiation_validation_noisy.py9
-rw-r--r--yardstick/benchmark/scenarios/networking/vtc_throughput.py9
-rw-r--r--yardstick/benchmark/scenarios/networking/vtc_throughput_noisy.py9
-rw-r--r--yardstick/benchmark/scenarios/parser/parser.py9
-rw-r--r--yardstick/benchmark/scenarios/storage/fio.py17
-rw-r--r--yardstick/benchmark/scenarios/storage/storagecapacity.py10
-rw-r--r--yardstick/benchmark/scenarios/storage/storperf.py27
-rw-r--r--yardstick/cmd/__init__.py7
-rw-r--r--yardstick/cmd/cli.py15
-rw-r--r--yardstick/cmd/commands/__init__.py1
-rw-r--r--yardstick/cmd/commands/env.py15
-rw-r--r--yardstick/cmd/commands/plugin.py11
-rw-r--r--yardstick/cmd/commands/runner.py11
-rw-r--r--yardstick/cmd/commands/scenario.py10
-rw-r--r--yardstick/cmd/commands/task.py8
-rw-r--r--yardstick/cmd/commands/testcase.py11
-rw-r--r--yardstick/common/constants.py3
-rw-r--r--yardstick/common/httpClient.py6
-rw-r--r--yardstick/common/openstack_utils.py1
-rwxr-xr-xyardstick/common/task_template.py2
-rw-r--r--yardstick/common/template_format.py10
-rw-r--r--yardstick/common/utils.py18
-rw-r--r--yardstick/definitions.py1
-rw-r--r--yardstick/dispatcher/__init__.py1
-rw-r--r--yardstick/dispatcher/base.py3
-rw-r--r--yardstick/dispatcher/file.py6
-rw-r--r--yardstick/dispatcher/http.py16
-rw-r--r--yardstick/dispatcher/influxdb.py22
-rwxr-xr-xyardstick/main.py3
-rw-r--r--yardstick/network_services/__init__.py0
-rw-r--r--yardstick/network_services/collector/__init__.py0
-rw-r--r--yardstick/network_services/collector/publisher.py29
-rw-r--r--yardstick/network_services/collector/subscriber.py39
-rw-r--r--yardstick/orchestrator/heat.py109
-rw-r--r--yardstick/plot/plotter.py69
-rw-r--r--yardstick/ssh.py18
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/__init__.py9
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/api.py1
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py18
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py7
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_benchmark.py32
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/instantiation_validation_noisy_neighbors_benchmark.py7
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/multi_tenancy_throughput_benchmark.py2
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/rfc2544_throughput_benchmark.py10
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/benchmarks/test_benchmark.py1
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/common.py14
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/constants/framework_parameters.py1
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/deployment_unit.py23
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/heat_manager.py6
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py5
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py4
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py4
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/base_packet_generator.py1
-rw-r--r--yardstick/vTC/apexlake/experimental_framework/packet_generators/dpdk_packet_generator.py14
-rw-r--r--yardstick/vTC/apexlake/setup.py1
-rw-r--r--yardstick/vTC/apexlake/tests/api_test.py16
-rw-r--r--yardstick/vTC/apexlake/tests/base_packet_generator_test.py1
-rw-r--r--yardstick/vTC/apexlake/tests/benchmark_base_class_test.py5
-rw-r--r--yardstick/vTC/apexlake/tests/benchmarking_unit_test.py11
-rw-r--r--yardstick/vTC/apexlake/tests/common_test.py73
-rw-r--r--yardstick/vTC/apexlake/tests/conf_file_sections_test.py1
-rw-r--r--yardstick/vTC/apexlake/tests/deployment_unit_test.py1
-rw-r--r--yardstick/vTC/apexlake/tests/dpdk_packet_generator_test.py5
-rw-r--r--yardstick/vTC/apexlake/tests/generates_template_test.py17
-rw-r--r--yardstick/vTC/apexlake/tests/heat_manager_test.py27
-rw-r--r--yardstick/vTC/apexlake/tests/instantiation_validation_bench_test.py11
-rw-r--r--yardstick/vTC/apexlake/tests/instantiation_validation_noisy_bench_test.py34
-rw-r--r--yardstick/vTC/apexlake/tests/multi_tenancy_throughput_benchmark_test.py10
-rw-r--r--yardstick/vTC/apexlake/tests/rfc2544_throughput_benchmark_test.py8
-rw-r--r--yardstick/vTC/apexlake/tests/tree_node_test.py2
223 files changed, 2478 insertions, 1087 deletions
diff --git a/api/base.py b/api/base.py
index 7671527d4..527008588 100644
--- a/api/base.py
+++ b/api/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 re
import importlib
import logging
diff --git a/api/conf.py b/api/conf.py
index 3d9d190a0..a4f332533 100644
--- a/api/conf.py
+++ b/api/conf.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
from pyroute2 import IPDB
@@ -14,8 +15,6 @@ with IPDB() as ip:
GATEWAY_IP = ip.routes['default'].gateway
PORT = 8086
-TEST_ACTION = ['runTestCase']
-
TEST_CASE_PATH = '../tests/opnfv/test_cases/'
SAMPLE_PATH = '../samples/'
diff --git a/api/database/__init__.py b/api/database/__init__.py
index 5b0bb05a2..753b34684 100644
--- a/api/database/__init__.py
+++ b/api/database/__init__.py
@@ -6,16 +6,19 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
+from yardstick.common import constants as consts
+
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
-engine = create_engine('sqlite:////tmp/yardstick.db', convert_unicode=True)
+engine = create_engine(consts.SQLITE, convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
diff --git a/api/database/models.py b/api/database/models.py
index 2fc141c1f..2270de96b 100644
--- a/api/database/models.py
+++ b/api/database/models.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
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import String
diff --git a/api/resources/env_action.py b/api/resources/env_action.py
index 7e2487158..8955f3cb6 100644
--- a/api/resources/env_action.py
+++ b/api/resources/env_action.py
@@ -6,25 +6,27 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
+
+import errno
+import json
import logging
-import threading
+import os
import subprocess
+import threading
import time
import uuid
-import json
-import os
-import errno
-import ConfigParser
-from docker import Client
+from six.moves import configparser
-from yardstick.common import constants as config
-from yardstick.common import utils as yardstick_utils
-from yardstick.common.httpClient import HttpClient
from api import conf as api_conf
+from api.database.handler import AsyncTaskHandler
from api.utils import influx
from api.utils.common import result_handler
-from api.database.handler import AsyncTaskHandler
+from docker import Client
+from yardstick.common import constants as config
+from yardstick.common import utils as yardstick_utils
+from yardstick.common.httpClient import HttpClient
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@@ -167,7 +169,7 @@ def _config_influxdb():
def _change_output_to_influxdb():
yardstick_utils.makedirs(config.YARDSTICK_CONFIG_DIR)
- parser = ConfigParser.ConfigParser()
+ parser = configparser.ConfigParser()
parser.read(config.YARDSTICK_CONFIG_SAMPLE_FILE)
parser.set('DEFAULT', 'dispatcher', 'influxdb')
diff --git a/api/resources/release_action.py b/api/resources/release_action.py
index d4dc246ef..c5aa20afc 100644
--- a/api/resources/release_action.py
+++ b/api/resources/release_action.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 uuid
import os
import logging
diff --git a/api/resources/results.py b/api/resources/results.py
index fd518958c..86fc25193 100644
--- a/api/resources/results.py
+++ b/api/resources/results.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
import uuid
diff --git a/api/resources/samples_action.py b/api/resources/samples_action.py
index df6db17ee..490e48b25 100644
--- a/api/resources/samples_action.py
+++ b/api/resources/samples_action.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 uuid
import os
import logging
diff --git a/api/server.py b/api/server.py
index 8cce4de87..be7963481 100644
--- a/api/server.py
+++ b/api/server.py
@@ -6,17 +6,20 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import logging
-from itertools import ifilter
+from __future__ import absolute_import
+
import inspect
+import logging
+from functools import reduce
+from six.moves import filter
+from flasgger import Swagger
from flask import Flask
from flask_restful import Api
-from flasgger import Swagger
from api.database import Base
-from api.database import engine
from api.database import db_session
+from api.database import engine
from api.database import models
from api.urls import urlpatterns
from yardstick import _init_logging
@@ -44,12 +47,11 @@ def init_db():
pass
return False
- subclses = ifilter(func, inspect.getmembers(models, inspect.isclass))
+ subclses = filter(func, inspect.getmembers(models, inspect.isclass))
logger.debug('Import models: %s', [a[1] for a in subclses])
Base.metadata.create_all(bind=engine)
-init_db()
reduce(lambda a, b: a.add_resource(b.resource, b.url,
endpoint=b.endpoint) or a, urlpatterns, api)
@@ -57,4 +59,5 @@ if __name__ == '__main__':
_init_logging()
logger.setLevel(logging.DEBUG)
logger.info('Starting server')
+ init_db()
app.run(host='0.0.0.0')
diff --git a/api/swagger/models.py b/api/swagger/models.py
index 9a0157e0e..d3c7a9b75 100644
--- a/api/swagger/models.py
+++ b/api/swagger/models.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
from flask_restful import fields
from flask_restful_swagger import swagger
diff --git a/api/urls.py b/api/urls.py
index 58df29142..04b7485f1 100644
--- a/api/urls.py
+++ b/api/urls.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
from api import views
from api.utils.common import Url
diff --git a/api/utils/common.py b/api/utils/common.py
index 6971c6dfe..1c800ce49 100644
--- a/api/utils/common.py
+++ b/api/utils/common.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 collections
import logging
@@ -13,18 +14,19 @@ from flask import jsonify
from api.utils.daemonthread import DaemonThread
from yardstick.cmd.cli import YardstickCLI
+import six
logger = logging.getLogger(__name__)
-def translate_to_str(object):
- if isinstance(object, collections.Mapping):
- return {str(k): translate_to_str(v) for k, v in object.items()}
- elif isinstance(object, list):
- return [translate_to_str(ele) for ele in object]
- elif isinstance(object, unicode):
- return str(object)
- return object
+def translate_to_str(obj):
+ if isinstance(obj, collections.Mapping):
+ return {str(k): translate_to_str(v) for k, v in obj.items()}
+ elif isinstance(obj, list):
+ return [translate_to_str(ele) for ele in obj]
+ elif isinstance(obj, six.text_type):
+ return str(obj)
+ return obj
def get_command_list(command_list, opts, args):
diff --git a/api/utils/daemonthread.py b/api/utils/daemonthread.py
index 19182c429..0049834eb 100644
--- a/api/utils/daemonthread.py
+++ b/api/utils/daemonthread.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 threading
import os
import errno
diff --git a/api/utils/influx.py b/api/utils/influx.py
index d4b070fb4..275c63a24 100644
--- a/api/utils/influx.py
+++ b/api/utils/influx.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
-import ConfigParser
-from urlparse import urlsplit
+import six.moves.configparser as ConfigParser
+from six.moves.urllib.parse import urlsplit
from influxdb import InfluxDBClient
from api import conf
diff --git a/api/views.py b/api/views.py
index eb81145fc..0c39bfad0 100644
--- a/api/views.py
+++ b/api/views.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
import os
@@ -36,6 +37,7 @@ class ReleaseAction(ApiResource):
class SamplesAction(ApiResource):
+
def post(self):
return self._dispatch_post()
@@ -43,7 +45,8 @@ class SamplesAction(ApiResource):
TestSuiteActionModel = models.TestSuiteActionModel
TestSuiteActionArgsModel = models.TestSuiteActionArgsModel
TestSuiteActionArgsOptsModel = models.TestSuiteActionArgsOptsModel
-TestSuiteActionArgsOptsTaskArgModel = models.TestSuiteActionArgsOptsTaskArgModel
+TestSuiteActionArgsOptsTaskArgModel = \
+ models.TestSuiteActionArgsOptsTaskArgModel
class TestsuitesAction(ApiResource):
@@ -56,11 +59,13 @@ ResultModel = models.ResultModel
class Results(ApiResource):
+
@swag_from(os.getcwd() + '/swagger/docs/results.yaml')
def get(self):
return self._dispatch_get()
class EnvAction(ApiResource):
+
def post(self):
return self._dispatch_post()
diff --git a/ez_setup.py b/ez_setup.py
index a693849f9..6771f3619 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -13,6 +13,7 @@ the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools.
"""
+from __future__ import absolute_import
import os
import shutil
import sys
@@ -21,7 +22,6 @@ import zipfile
import optparse
import subprocess
import platform
-import textwrap
import contextlib
from distutils import log
@@ -29,7 +29,7 @@ from distutils import log
try:
from urllib.request import urlopen
except ImportError:
- from urllib2 import urlopen
+ from six.moves.urllib import urlopen
try:
from site import USER_SITE
@@ -39,6 +39,7 @@ except ImportError:
DEFAULT_VERSION = "6.1"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
+
def _python_cmd(*args):
"""
Return True if the command succeeded.
@@ -130,7 +131,7 @@ def _do_download(version, download_base, to_dir, download_delay):
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
- to_dir=os.curdir, download_delay=15):
+ to_dir=os.curdir, download_delay=15):
to_dir = os.path.abspath(to_dir)
rep_modules = 'pkg_resources', 'setuptools'
imported = set(sys.modules).intersection(rep_modules)
@@ -145,14 +146,14 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
return _do_download(version, download_base, to_dir, download_delay)
except pkg_resources.VersionConflict as VC_err:
if imported:
- msg = textwrap.dedent("""
- The required version of setuptools (>={version}) is not available,
- and can't be installed while this script is running. Please
- install a more recent version first, using
- 'easy_install -U setuptools'.
-
- (Currently using {VC_err.args[0]!r})
- """).format(VC_err=VC_err, version=version)
+ msg = """\
+The required version of setuptools (>={version}) is not available,
+and can't be installed while this script is running. Please
+install a more recent version first, using
+'easy_install -U setuptools'.
+
+(Currently using {VC_err.args[0]!r})
+""".format(VC_err=VC_err, version=version)
sys.stderr.write(msg)
sys.exit(2)
@@ -160,6 +161,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
del pkg_resources, sys.modules['pkg_resources']
return _do_download(version, download_base, to_dir, download_delay)
+
def _clean_check(cmd, target):
"""
Run the command to download target. If the command fails, clean up before
@@ -172,6 +174,7 @@ def _clean_check(cmd, target):
os.unlink(target)
raise
+
def download_file_powershell(url, target):
"""
Download the file at url to target using Powershell (which will validate
@@ -191,6 +194,7 @@ def download_file_powershell(url, target):
]
_clean_check(cmd, target)
+
def has_powershell():
if platform.system() != 'Windows':
return False
@@ -202,12 +206,15 @@ def has_powershell():
return False
return True
+
download_file_powershell.viable = has_powershell
+
def download_file_curl(url, target):
cmd = ['curl', url, '--silent', '--output', target]
_clean_check(cmd, target)
+
def has_curl():
cmd = ['curl', '--version']
with open(os.path.devnull, 'wb') as devnull:
@@ -217,12 +224,15 @@ def has_curl():
return False
return True
+
download_file_curl.viable = has_curl
+
def download_file_wget(url, target):
cmd = ['wget', url, '--quiet', '--output-document', target]
_clean_check(cmd, target)
+
def has_wget():
cmd = ['wget', '--version']
with open(os.path.devnull, 'wb') as devnull:
@@ -232,8 +242,10 @@ def has_wget():
return False
return True
+
download_file_wget.viable = has_wget
+
def download_file_insecure(url, target):
"""
Use Python to download the file, even though it cannot authenticate the
@@ -250,8 +262,10 @@ def download_file_insecure(url, target):
with open(target, "wb") as dst:
dst.write(data)
+
download_file_insecure.viable = lambda: True
+
def get_best_downloader():
downloaders = (
download_file_powershell,
@@ -262,8 +276,10 @@ def get_best_downloader():
viable_downloaders = (dl for dl in downloaders if dl.viable())
return next(viable_downloaders, None)
+
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
- to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader):
+ to_dir=os.curdir, delay=15,
+ downloader_factory=get_best_downloader):
"""
Download setuptools from a specified location and return its filename
@@ -287,12 +303,14 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
downloader(url, saveto)
return os.path.realpath(saveto)
+
def _build_install_args(options):
"""
Build the arguments to 'python setup.py install' on the setuptools package
"""
return ['--user'] if options.user_install else []
+
def _parse_args():
"""
Parse the command line for options
@@ -318,6 +336,7 @@ def _parse_args():
# positional arguments are ignored
return options
+
def main():
"""Install or upgrade setuptools and EasyInstall"""
options = _parse_args()
@@ -328,5 +347,6 @@ def main():
)
return _install(archive, _build_install_args(options))
+
if __name__ == '__main__':
sys.exit(main())
diff --git a/requirements.txt b/requirements.txt
index 9c037ed79..107e8dee4 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -19,7 +19,7 @@ extras==0.0.3
fixtures==1.4.0
flake8==2.5.4
funcsigs==0.4
-functools32==3.2.3.post2
+functools32==3.2.3.post2; python_version <= '2.7'
futures==3.0.5
iso8601==0.1.11
Jinja2==2.8
@@ -31,7 +31,8 @@ linecache2==1.0.0
lxml==3.5.0
MarkupSafe==0.23
mccabe==0.4.0
-mock==1.3.0
+# upgrade to version 2.0.0 to match python3 unittest.mock features
+mock==2.0.0
monotonic==1.0
msgpack-python==0.4.7
netaddr==0.7.18
@@ -52,6 +53,7 @@ pycrypto==2.6.1
pyflakes==1.0.0
pyparsing==2.1.0
pyrsistent==0.11.12
+osc-lib==1.2.0
python-cinderclient==1.9.0
python-glanceclient==2.5.0
python-heatclient==1.5.0
@@ -59,7 +61,7 @@ python-keystoneclient==3.6.0
python-mimeparse==1.5.1
python-neutronclient==6.0.0
python-novaclient==6.0.0
-python-openstackclient==3.3.0
+python-openstackclient==3.7.0
python-subunit==1.2.0
python-swiftclient==3.0.0
pytz==2015.7
@@ -85,3 +87,5 @@ docker-py==1.10.6
flasgger==0.5.13
flask-restful-swagger==0.19
SQLAlchemy==1.1.4
+zmq==0.0.0
+pika==0.10.0
diff --git a/setup.py b/setup.py
index 0100b4635..315ab6793 100755
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
from setuptools import setup, find_packages
diff --git a/tests/functional/test_cli_runner.py b/tests/functional/test_cli_runner.py
index 195b572c7..620edc396 100755
--- a/tests/functional/test_cli_runner.py
+++ b/tests/functional/test_cli_runner.py
@@ -8,6 +8,7 @@
##############################################################################
+from __future__ import absolute_import
import unittest
from tests.functional import utils
@@ -46,4 +47,3 @@ class RunnerTestCase(unittest.TestCase):
res = self.yardstick("runner show Sequence")
sequence = "sequence - list of values which are executed" in res
self.assertTrue(sequence)
-
diff --git a/tests/functional/test_cli_scenario.py b/tests/functional/test_cli_scenario.py
index 877973783..4741e8244 100755
--- a/tests/functional/test_cli_scenario.py
+++ b/tests/functional/test_cli_scenario.py
@@ -8,6 +8,7 @@
##############################################################################
+from __future__ import absolute_import
import unittest
from tests.functional import utils
@@ -59,4 +60,3 @@ class ScenarioTestCase(unittest.TestCase):
res = self.yardstick("scenario show Pktgen")
pktgen = "Execute pktgen between two hosts" in res
self.assertTrue(pktgen)
-
diff --git a/tests/functional/utils.py b/tests/functional/utils.py
index aaaaaac22..b96d2dd50 100755
--- a/tests/functional/utils.py
+++ b/tests/functional/utils.py
@@ -7,13 +7,13 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
+
import copy
-import json
import os
-import shutil
import subprocess
-
+from oslo_serialization import jsonutils
from oslo_utils import encodeutils
@@ -40,11 +40,11 @@ class Yardstick(object):
"""Call yardstick in the shell
:param cmd: yardstick command
- :param getjson: in cases, when yardstick prints JSON, you can catch output
- deserialized
+ :param getjson: in cases, when yardstick prints JSON, you can catch
+ output deserialized
TO DO:
- :param report_path: if present, yardstick command and its output will be
- written to file with passed file name
+ :param report_path: if present, yardstick command and its output will
+ be written to file with passed file name
:param raw: don't write command itself to report file. Only output
will be written
"""
@@ -53,11 +53,11 @@ class Yardstick(object):
cmd = cmd.split(" ")
try:
output = encodeutils.safe_decode(subprocess.check_output(
- self.args + cmd, stderr=subprocess.STDOUT, env=self.env))
+ self.args + cmd, stderr=subprocess.STDOUT, env=self.env),
+ 'utf-8')
if getjson:
- return json.loads(output)
+ return jsonutils.loads(output)
return output
except subprocess.CalledProcessError as e:
raise e
-
diff --git a/tests/unit/apiserver/__init__.py b/tests/unit/apiserver/__init__.py
new file mode 100644
index 000000000..021415296
--- /dev/null
+++ b/tests/unit/apiserver/__init__.py
@@ -0,0 +1,35 @@
+from __future__ import absolute_import
+
+import os
+import unittest
+import tempfile
+
+from oslo_serialization import jsonutils
+
+from yardstick.common import constants as consts
+
+
+class APITestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.db_fd, self.db_path = tempfile.mkstemp()
+ consts.SQLITE = 'sqlite:///{}'.format(self.db_path)
+ from api import server
+
+ server.app.config['TESTING'] = True
+ self.app = server.app.test_client()
+
+ server.init_db()
+
+ def tearDown(self):
+ os.close(self.db_fd)
+ os.unlink(self.db_path)
+
+ def _post(self, url, data):
+ headers = {'Content-Type': 'application/json'}
+ resp = self.app.post(url, data=jsonutils.dumps(data), headers=headers)
+ return jsonutils.loads(resp.data)
+
+ def _get(self, url):
+ resp = self.app.get(url)
+ return jsonutils.loads(resp.data)
diff --git a/tests/unit/apiserver/resources/__init__.py b/tests/unit/apiserver/resources/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/apiserver/resources/__init__.py
diff --git a/tests/unit/apiserver/resources/test_env_action.py b/tests/unit/apiserver/resources/test_env_action.py
new file mode 100644
index 000000000..e8f99b706
--- /dev/null
+++ b/tests/unit/apiserver/resources/test_env_action.py
@@ -0,0 +1,32 @@
+from __future__ import absolute_import
+
+import time
+import unittest
+
+from tests.unit.apiserver import APITestCase
+
+
+class EnvTestCase(APITestCase):
+
+ def test_create_grafana(self):
+ url = 'yardstick/env/action'
+ data = dict(action='createGrafanaContainer')
+ resp = self._post(url, data)
+
+ time.sleep(1)
+
+ task_id = resp['result']['task_id']
+ url = '/yardstick/asynctask?task_id={}'.format(task_id)
+ resp = self._get(url)
+
+ time.sleep(2)
+
+ self.assertTrue(u'status' in resp)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/api/utils/test_common.py b/tests/unit/apiserver/utils/test_common.py
index 5d177409e..acf6e41b1 100644
--- a/tests/unit/api/utils/test_common.py
+++ b/tests/unit/apiserver/utils/test_common.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 unittest
from api.utils import common
diff --git a/tests/unit/api/utils/test_influx.py b/tests/unit/apiserver/utils/test_influx.py
index 0852da2dd..aff0cab5c 100644
--- a/tests/unit/api/utils/test_influx.py
+++ b/tests/unit/apiserver/utils/test_influx.py
@@ -6,19 +6,23 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import unittest
import mock
-import uuid
-import datetime
from api.utils import influx
+import six.moves.configparser as ConfigParser
+
class GetDataDbClientTestCase(unittest.TestCase):
@mock.patch('api.utils.influx.ConfigParser')
def test_get_data_db_client_dispatcher_not_influxdb(self, mock_parser):
mock_parser.ConfigParser().get.return_value = 'file'
+ # reset exception to avoid
+ # TypeError: catching classes that do not inherit from BaseException
+ mock_parser.NoOptionError = ConfigParser.NoOptionError
try:
influx.get_data_db_client()
except Exception as e:
@@ -35,38 +39,14 @@ class GetIpTestCase(unittest.TestCase):
self.assertEqual(result, output)
-class WriteDataTestCase(unittest.TestCase):
-
- @mock.patch('api.utils.influx.get_data_db_client')
- def test_write_data(self, mock_get_client):
- measurement = 'tasklist'
- field = {'status': 1}
- timestamp = datetime.datetime.now()
- tags = {'task_id': str(uuid.uuid4())}
-
- influx._write_data(measurement, field, timestamp, tags)
- mock_get_client.assert_called_with()
-
-
-class WriteDataTasklistTestCase(unittest.TestCase):
-
- @mock.patch('api.utils.influx._write_data')
- def test_write_data_tasklist(self, mock_write_data):
- task_id = str(uuid.uuid4())
- timestamp = datetime.datetime.now()
- status = 1
- influx.write_data_tasklist(task_id, timestamp, status)
-
- field = {'status': status, 'error': ''}
- tags = {'task_id': task_id}
- mock_write_data.assert_called_with('tasklist', field, timestamp, tags)
-
-
class QueryTestCase(unittest.TestCase):
@mock.patch('api.utils.influx.ConfigParser')
def test_query_dispatcher_not_influxdb(self, mock_parser):
mock_parser.ConfigParser().get.return_value = 'file'
+ # reset exception to avoid
+ # TypeError: catching classes that do not inherit from BaseException
+ mock_parser.NoOptionError = ConfigParser.NoOptionError
try:
sql = 'select * form tasklist'
influx.query(sql)
diff --git a/tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml b/tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml
new file mode 100644
index 000000000..e468d0465
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone_duplicate_sample.yaml
@@ -0,0 +1,135 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+---
+# Sample config file about the POD information, including the
+# name/IP/user/ssh key of Bare Metal and Controllers/Computes
+#
+# The options of this config file include:
+# name: the name of this node
+# role: node's role, support role: Master/Controller/Comupte/BareMetal
+# ip: the node's IP address
+# user: the username for login
+# key_filename:the path of the private key file for login
+
+nodes:
+-
+ name: node1
+ role: TrafficGen
+ ip: 1.1.1.1
+ user: root
+ password: r00t
+ interfaces:
+ xe0: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:05:00.0"
+ driver: i40e
+ dpdk_port_num: 0
+ local_ip: "152.16.100.20"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:01"
+ xe1: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:05:00.1"
+ driver: i40e
+ dpdk_port_num: 1
+ local_ip: "152.16.100.21"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:02"
+-
+ name: node2
+ role: nfvi_node
+ class: OvsDpdk
+ ip: 1.1.1.2
+ user: root
+ password: r00t
+ vports:
+ - dpdkvhostuser0
+ - dpdkvhostuser1
+ vports_mac:
+ - "00:00:00:00:00:03"
+ - "00:00:00:00:00:04"
+ phy_ports: # Physical ports to configure sriov
+ - "0000:05:00.0"
+ - "0000:05:00.1"
+ flow:
+ - ovs-ofctl add-flow br0 in_port=1,action=output:3
+ - ovs-ofctl add-flow br0 in_port=3,action=output:1
+ - ovs-ofctl add-flow br0 in_port=4,action=output:2
+ - ovs-ofctl add-flow br0 in_port=2,action=output:4
+ phy_driver: i40e # kernel driver
+ images: "/var/lib/libvirt/images/ubuntu.qcow2"
+-
+ name: node2
+ role: nfvi_node
+ class: OvsDpdk
+ ip: 1.1.1.5
+ user: root
+ password: r00t
+ vports:
+ - dpdkvhostuser0
+ - dpdkvhostuser1
+ vports_mac:
+ - "00:00:00:00:00:03"
+ - "00:00:00:00:00:04"
+ phy_ports: # Physical ports to configure sriov
+ - "0000:05:00.0"
+ - "0000:05:00.1"
+ flow:
+ - ovs-ofctl add-flow br0 in_port=1,action=output:3
+ - ovs-ofctl add-flow br0 in_port=3,action=output:1
+ - ovs-ofctl add-flow br0 in_port=4,action=output:2
+ - ovs-ofctl add-flow br0 in_port=2,action=output:4
+ phy_driver: i40e # kernel driver
+ images: "/var/lib/libvirt/images/ubuntu.qcow2"
+
+-
+ name: node3
+ role: vnf
+ ip: 1.1.1.3
+ user: root
+ password: r00t
+ host: 1.1.1.1
+ interfaces:
+ xe0: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:00:04.0"
+ driver: virtio-pci
+ dpdk_port_num: 0
+ local_ip: "152.16.100.19"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:05"
+
+ xe1: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:00:05.0"
+ driver: virtio-pci
+ dpdk_port_num: 1
+ local_ip: "152.16.40.19"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:06"
+ routing_table:
+ - network: "152.16.100.20"
+ netmask: "255.255.255.0"
+ gateway: "152.16.100.20"
+ if: "xe0"
+ - network: "152.16.40.20"
+ netmask: "255.255.255.0"
+ gateway: "152.16.40.20"
+ if: "xe1"
+ nd_route_tbl:
+ - network: "0064:ff9b:0:0:0:0:9810:6414"
+ netmask: "112"
+ gateway: "0064:ff9b:0:0:0:0:9810:6414"
+ if: "xe0"
+ - network: "0064:ff9b:0:0:0:0:9810:2814"
+ netmask: "112"
+ gateway: "0064:ff9b:0:0:0:0:9810:2814"
+ if: "xe1"
diff --git a/tests/unit/benchmark/contexts/standalone_sample.yaml b/tests/unit/benchmark/contexts/standalone_sample.yaml
new file mode 100644
index 000000000..95e12d62f
--- /dev/null
+++ b/tests/unit/benchmark/contexts/standalone_sample.yaml
@@ -0,0 +1,112 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+---
+# Sample config file about the POD information, including the
+# name/IP/user/ssh key of Bare Metal and Controllers/Computes
+#
+# The options of this config file include:
+# name: the name of this node
+# role: node's role, support role: Master/Controller/Comupte/BareMetal
+# ip: the node's IP address
+# user: the username for login
+# key_filename:the path of the private key file for login
+
+nodes:
+-
+ name: node1
+ role: TrafficGen
+ ip: 1.1.1.1
+ user: root
+ password: r00t
+ interfaces:
+ xe0: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:05:00.0"
+ driver: i40e
+ dpdk_port_num: 0
+ local_ip: "152.16.100.20"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:01"
+ xe1: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:05:00.1"
+ driver: i40e
+ dpdk_port_num: 1
+ local_ip: "152.16.100.21"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:02"
+-
+ name: node2
+ role: nfvi_node
+ class: OvsDpdk
+ ip: 1.1.1.2
+ user: root
+ password: r00t
+ vports:
+ - dpdkvhostuser0
+ - dpdkvhostuser1
+ vports_mac:
+ - "00:00:00:00:00:03"
+ - "00:00:00:00:00:04"
+ phy_ports: # Physical ports to configure sriov
+ - "0000:05:00.0"
+ - "0000:05:00.1"
+ flow:
+ - ovs-ofctl add-flow br0 in_port=1,action=output:3
+ - ovs-ofctl add-flow br0 in_port=3,action=output:1
+ - ovs-ofctl add-flow br0 in_port=4,action=output:2
+ - ovs-ofctl add-flow br0 in_port=2,action=output:4
+ phy_driver: i40e # kernel driver
+ images: "/var/lib/libvirt/images/ubuntu.qcow2"
+
+-
+ name: node3
+ role: vnf
+ ip: 1.1.1.3
+ user: root
+ password: r00t
+ host: 1.1.1.1
+ interfaces:
+ xe0: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:00:04.0"
+ driver: virtio-pci
+ dpdk_port_num: 0
+ local_ip: "152.16.100.19"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:05"
+
+ xe1: # logical name from topology.yaml and vnfd.yaml
+ vpci: "0000:00:05.0"
+ driver: virtio-pci
+ dpdk_port_num: 1
+ local_ip: "152.16.40.19"
+ netmask: "255.255.255.0"
+ local_mac: "00:00:00:00:00:06"
+ routing_table:
+ - network: "152.16.100.20"
+ netmask: "255.255.255.0"
+ gateway: "152.16.100.20"
+ if: "xe0"
+ - network: "152.16.40.20"
+ netmask: "255.255.255.0"
+ gateway: "152.16.40.20"
+ if: "xe1"
+ nd_route_tbl:
+ - network: "0064:ff9b:0:0:0:0:9810:6414"
+ netmask: "112"
+ gateway: "0064:ff9b:0:0:0:0:9810:6414"
+ if: "xe0"
+ - network: "0064:ff9b:0:0:0:0:9810:2814"
+ netmask: "112"
+ gateway: "0064:ff9b:0:0:0:0:9810:2814"
+ if: "xe1"
diff --git a/tests/unit/benchmark/contexts/test_dummy.py b/tests/unit/benchmark/contexts/test_dummy.py
index 5214e6630..1a54035df 100644
--- a/tests/unit/benchmark/contexts/test_dummy.py
+++ b/tests/unit/benchmark/contexts/test_dummy.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.contexts.dummy
+from __future__ import absolute_import
import unittest
from yardstick.benchmark.contexts import dummy
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
index dd830a485..f8f349205 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -11,14 +11,21 @@
# Unittest for yardstick.benchmark.contexts.heat
+from __future__ import absolute_import
+
+import logging
import os
-import mock
import unittest
+import uuid
+
+import mock
-from yardstick.benchmark.contexts import model
from yardstick.benchmark.contexts import heat
+LOG = logging.getLogger(__name__)
+
+
class HeatContextTestCase(unittest.TestCase):
def setUp(self):
@@ -70,7 +77,8 @@ class HeatContextTestCase(unittest.TestCase):
'bar', self.test_context, networks['bar'])
self.assertTrue(len(self.test_context.networks) == 1)
- mock_server.assert_called_with('baz', self.test_context, servers['baz'])
+ mock_server.assert_called_with('baz', self.test_context,
+ servers['baz'])
self.assertTrue(len(self.test_context.servers) == 1)
if os.path.exists(self.test_context.key_filename):
@@ -78,7 +86,8 @@ class HeatContextTestCase(unittest.TestCase):
os.remove(self.test_context.key_filename)
os.remove(self.test_context.key_filename + ".pub")
except OSError:
- LOG.exception("key_filename: %s", e.key_filename)
+ LOG.exception("key_filename: %s",
+ self.test_context.key_filename)
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_resources_to_template_no_servers(self, mock_template):
@@ -88,8 +97,9 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b"
self.test_context._add_resources_to_template(mock_template)
- mock_template.add_keypair.assert_called_with("foo-key",
- "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
+ mock_template.add_keypair.assert_called_with(
+ "foo-key",
+ "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
mock_template.add_security_group.assert_called_with("foo-secgroup")
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
@@ -113,12 +123,13 @@ class HeatContextTestCase(unittest.TestCase):
self.assertTrue(mock_template.delete.called)
-
def test__get_server(self):
self.mock_context.name = 'bar'
self.mock_context.stack.outputs = {'public_ip': '127.0.0.1',
'private_ip': '10.0.0.1'}
+ self.mock_context.key_uuid = uuid.uuid4()
+
attr_name = {'name': 'foo.bar',
'public_ip_attr': 'public_ip',
'private_ip_attr': 'private_ip'}
diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index a1978e320..537a8c008 100644
--- a/tests/unit/benchmark/contexts/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.contexts.model
+from __future__ import absolute_import
import mock
import unittest
@@ -119,7 +120,8 @@ class NetworkTestCase(unittest.TestCase):
attrs = {'external_network': 'ext_net'}
test_network = model.Network('foo', self.mock_context, attrs)
- exp_router = model.Router('router', 'foo', self.mock_context, 'ext_net')
+ exp_router = model.Router('router', 'foo', self.mock_context,
+ 'ext_net')
self.assertEqual(test_network.router.stack_name, exp_router.stack_name)
self.assertEqual(test_network.router.stack_if_name,
@@ -219,4 +221,3 @@ class ServerTestCase(unittest.TestCase):
user=self.mock_context.user,
key_name=self.mock_context.keypair_name,
scheduler_hints='hints')
-
diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py
index 6939b8551..64fe4a566 100644
--- a/tests/unit/benchmark/contexts/test_node.py
+++ b/tests/unit/benchmark/contexts/test_node.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.contexts.node
+from __future__ import absolute_import
import os
import unittest
@@ -21,6 +22,7 @@ class NodeContextTestCase(unittest.TestCase):
NODES_SAMPLE = "nodes_sample.yaml"
NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml"
+
def setUp(self):
self.test_context = node.NodeContext()
@@ -40,7 +42,7 @@ class NodeContextTestCase(unittest.TestCase):
'file': self._get_file_abspath("error_file")
}
- self.assertRaises(SystemExit, self.test_context.init, attrs)
+ self.assertRaises(IOError, self.test_context.init, attrs)
def test_successful_init(self):
@@ -98,7 +100,7 @@ class NodeContextTestCase(unittest.TestCase):
attr_name = 'node1.foo'
- self.assertRaises(SystemExit, self.test_context._get_server, attr_name)
+ self.assertRaises(ValueError, self.test_context._get_server, attr_name)
def test__get_server_found(self):
diff --git a/tests/unit/benchmark/contexts/test_standalone.py b/tests/unit/benchmark/contexts/test_standalone.py
new file mode 100644
index 000000000..687ef7305
--- /dev/null
+++ b/tests/unit/benchmark/contexts/test_standalone.py
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Unittest for yardstick.benchmark.contexts.standalone
+
+from __future__ import absolute_import
+import os
+import unittest
+
+from yardstick.benchmark.contexts import standalone
+
+
+class StandaloneContextTestCase(unittest.TestCase):
+
+ NODES_SAMPLE = "standalone_sample.yaml"
+ NODES_DUPLICATE_SAMPLE = "standalone_duplicate_sample.yaml"
+
+ def setUp(self):
+ self.test_context = standalone.StandaloneContext()
+
+ def test_construct(self):
+
+ self.assertIsNone(self.test_context.name)
+ self.assertIsNone(self.test_context.file_path)
+ self.assertEqual(self.test_context.nodes, [])
+ self.assertEqual(self.test_context.nfvi_node, [])
+
+ def test_unsuccessful_init(self):
+
+ attrs = {
+ 'name': 'foo',
+ 'file': self._get_file_abspath("error_file")
+ }
+
+ self.assertRaises(IOError, self.test_context.init, attrs)
+
+ def test_successful_init(self):
+
+ attrs = {
+ 'name': 'foo',
+ 'file': self._get_file_abspath(self.NODES_SAMPLE)
+ }
+
+ self.test_context.init(attrs)
+
+ self.assertEqual(self.test_context.name, "foo")
+ self.assertEqual(len(self.test_context.nodes), 3)
+ self.assertEqual(len(self.test_context.nfvi_node), 1)
+ self.assertEqual(self.test_context.nfvi_node[0]["name"], "node2")
+
+ def test__get_server_with_dic_attr_name(self):
+
+ attrs = {
+ 'name': 'foo',
+ 'file': self._get_file_abspath(self.NODES_SAMPLE)
+ }
+
+ self.test_context.init(attrs)
+
+ attr_name = {'name': 'foo.bar'}
+ result = self.test_context._get_server(attr_name)
+
+ self.assertEqual(result, None)
+
+ def test__get_server_not_found(self):
+
+ attrs = {
+ 'name': 'foo',
+ 'file': self._get_file_abspath(self.NODES_SAMPLE)
+ }
+
+ self.test_context.init(attrs)
+
+ attr_name = 'bar.foo'
+ result = self.test_context._get_server(attr_name)
+
+ self.assertEqual(result, None)
+
+ def test__get_server_duplicate(self):
+
+ attrs = {
+ 'name': 'foo',
+ 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
+ }
+
+ self.test_context.init(attrs)
+
+ attr_name = 'node2.foo'
+
+ self.assertRaises(ValueError, self.test_context._get_server, attr_name)
+
+ def test__get_server_found(self):
+
+ attrs = {
+ 'name': 'foo',
+ 'file': self._get_file_abspath(self.NODES_SAMPLE)
+ }
+
+ self.test_context.init(attrs)
+
+ attr_name = 'node1.foo'
+ result = self.test_context._get_server(attr_name)
+
+ self.assertEqual(result['ip'], '1.1.1.1')
+ self.assertEqual(result['name'], 'node1.foo')
+ self.assertEqual(result['user'], 'root')
+
+ def test_deploy(self):
+ self.assertIsNone(self.test_context.deploy())
+
+ def test_undeploy(self):
+ self.assertIsNone(self.test_context.undeploy())
+
+ def _get_file_abspath(self, filename):
+ curr_path = os.path.dirname(os.path.abspath(__file__))
+ file_path = os.path.join(curr_path, filename)
+ return file_path
diff --git a/tests/unit/benchmark/core/test_plugin.py b/tests/unit/benchmark/core/test_plugin.py
index 441116a25..edc103415 100644
--- a/tests/unit/benchmark/core/test_plugin.py
+++ b/tests/unit/benchmark/core/test_plugin.py
@@ -10,16 +10,27 @@
##############################################################################
# Unittest for yardstick.benchmark.core.plugin
-
-import mock
+from __future__ import absolute_import
+import os
+from os.path import dirname as dirname
+
+try:
+ from unittest import mock
+except ImportError:
+ import mock
import unittest
from yardstick.benchmark.core import plugin
class Arg(object):
+
def __init__(self):
- self.input_file = ('plugin/sample_config.yaml',)
+ # self.input_file = ('plugin/sample_config.yaml',)
+ self.input_file = [
+ os.path.join(os.path.abspath(
+ dirname(dirname(dirname(dirname(dirname(__file__)))))),
+ 'plugin/sample_config.yaml')]
@mock.patch('yardstick.benchmark.core.plugin.ssh')
diff --git a/tests/unit/benchmark/core/test_task.py b/tests/unit/benchmark/core/test_task.py
index 463c43e1f..5dd32ea17 100644
--- a/tests/unit/benchmark/core/test_task.py
+++ b/tests/unit/benchmark/core/test_task.py
@@ -11,10 +11,18 @@
# Unittest for yardstick.benchmark.core.task
+from __future__ import print_function
+
+from __future__ import absolute_import
import os
-import mock
import unittest
+try:
+ from unittest import mock
+except ImportError:
+ import mock
+
+
from yardstick.benchmark.core import task
@@ -28,9 +36,9 @@ class TaskTestCase(unittest.TestCase):
}
scenario_cfg = {"nodes": nodes}
server_info = {
- "ip": "10.20.0.3",
- "user": "root",
- "key_filename": "/root/.ssh/id_rsa"
+ "ip": "10.20.0.3",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
}
mock_context.get_server.return_value = server_info
context_cfg = task.parse_nodes_with_context(scenario_cfg)
@@ -48,7 +56,7 @@ class TaskTestCase(unittest.TestCase):
'duration': 60,
'interval': 1,
'type': 'Duration'
- },
+ },
'type': 'Ping'
}
@@ -82,8 +90,8 @@ class TaskTestCase(unittest.TestCase):
t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
mock_environ.get.side_effect = ['huawei-pod1', 'compass']
task_files, task_args, task_args_fnames = t.parse_suite()
- print ("files=%s, args=%s, fnames=%s" % (task_files, task_args,
- task_args_fnames))
+ print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
+ task_args_fnames))
self.assertEqual(task_files[0],
'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
@@ -99,8 +107,8 @@ class TaskTestCase(unittest.TestCase):
t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
mock_environ.get.side_effect = ['huawei-pod1', 'compass']
task_files, task_args, task_args_fnames = t.parse_suite()
- print ("files=%s, args=%s, fnames=%s" % (task_files, task_args,
- task_args_fnames))
+ print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
+ task_args_fnames))
self.assertEqual(task_files[0],
'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
@@ -117,8 +125,8 @@ class TaskTestCase(unittest.TestCase):
t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
mock_environ.get.side_effect = ['huawei-pod1', 'compass']
task_files, task_args, task_args_fnames = t.parse_suite()
- print ("files=%s, args=%s, fnames=%s" % (task_files, task_args,
- task_args_fnames))
+ print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
+ task_args_fnames))
self.assertEqual(task_files[0],
'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
@@ -134,8 +142,8 @@ class TaskTestCase(unittest.TestCase):
t = task.TaskParser(self._get_file_abspath(SAMPLE_SCENARIO_PATH))
mock_environ.get.side_effect = ['huawei-pod1', 'compass']
task_files, task_args, task_args_fnames = t.parse_suite()
- print ("files=%s, args=%s, fnames=%s" % (task_files, task_args,
- task_args_fnames))
+ print("files=%s, args=%s, fnames=%s" % (task_files, task_args,
+ task_args_fnames))
self.assertEqual(task_files[0],
'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
diff --git a/tests/unit/benchmark/core/test_testcase.py b/tests/unit/benchmark/core/test_testcase.py
index 6e0473cc1..c7da2de7c 100644
--- a/tests/unit/benchmark/core/test_testcase.py
+++ b/tests/unit/benchmark/core/test_testcase.py
@@ -11,12 +11,14 @@
# Unittest for yardstick.cmd.commands.testcase
+from __future__ import absolute_import
import unittest
from yardstick.benchmark.core import testcase
class Arg(object):
+
def __init__(self):
self.casename = ('opnfv_yardstick_tc001',)
diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
index 340f94cb0..9e2e8b172 100644
--- a/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
+++ b/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
@@ -9,15 +9,20 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal
+# Unittest for
+# yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal
+from __future__ import absolute_import
import mock
import unittest
-from yardstick.benchmark.scenarios.availability.attacker import baseattacker
-from yardstick.benchmark.scenarios.availability.attacker import attacker_baremetal
+from yardstick.benchmark.scenarios.availability.attacker import \
+ attacker_baremetal
-@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.subprocess')
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal'
+ '.subprocess')
class ExecuteShellTestCase(unittest.TestCase):
def test__fun_execute_shell_command_successful(self, mock_subprocess):
@@ -26,34 +31,37 @@ class ExecuteShellTestCase(unittest.TestCase):
exitcode, output = attacker_baremetal._execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
- def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
+ def test__fun_execute_shell_command_fail_cmd_exception(self,
+ mock_subprocess):
cmd = "env"
mock_subprocess.check_output.side_effect = RuntimeError
exitcode, output = attacker_baremetal._execute_shell_command(cmd)
self.assertEqual(exitcode, -1)
-@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal.ssh')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.attacker.attacker_baremetal'
+ '.ssh')
class AttackerBaremetalTestCase(unittest.TestCase):
def setUp(self):
- host = {
- "ipmi_ip": "10.20.0.5",
- "ipmi_user": "root",
- "ipmi_pwd": "123456",
- "ip": "10.20.0.5",
- "user": "root",
- "key_filename": "/root/.ssh/id_rsa"
- }
- self.context = {"node1": host}
- self.attacker_cfg = {
- 'fault_type': 'bear-metal-down',
- 'host': 'node1',
- }
+ host = {
+ "ipmi_ip": "10.20.0.5",
+ "ipmi_user": "root",
+ "ipmi_pwd": "123456",
+ "ip": "10.20.0.5",
+ "user": "root",
+ "key_filename": "/root/.ssh/id_rsa"
+ }
+ self.context = {"node1": host}
+ self.attacker_cfg = {
+ 'fault_type': 'bear-metal-down',
+ 'host': 'node1',
+ }
def test__attacker_baremetal_all_successful(self, mock_ssh):
-
- ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context)
+ ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "running", '')
ins.setup()
@@ -61,8 +69,8 @@ class AttackerBaremetalTestCase(unittest.TestCase):
ins.recover()
def test__attacker_baremetal_check_failuer(self, mock_ssh):
-
- ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context)
+ ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "error check", '')
ins.setup()
@@ -70,7 +78,8 @@ class AttackerBaremetalTestCase(unittest.TestCase):
self.attacker_cfg["jump_host"] = 'node1'
self.context["node1"]["pwd"] = "123456"
- ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg, self.context)
+ ins = attacker_baremetal.BaremetalAttacker(self.attacker_cfg,
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "running", '')
ins.setup()
diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
index aa2e0cc4d..322b58391 100644
--- a/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
@@ -12,11 +12,13 @@
# Unittest for yardstick.benchmark.scenarios.availability.attacker
# .attacker_general
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.attacker import baseattacker
+
@mock.patch('yardstick.benchmark.scenarios.availability.attacker.'
'attacker_general.ssh')
class GeneralAttackerServiceTestCase(unittest.TestCase):
@@ -30,10 +32,10 @@ class GeneralAttackerServiceTestCase(unittest.TestCase):
self.context = {"node1": host}
self.attacker_cfg = {
'fault_type': 'general-attacker',
- 'action_parameter':{'process_name':'nova_api'},
- 'rollback_parameter':{'process_name':'nova_api'},
- 'key':'stop-service',
- 'attack_key':'stop-service',
+ 'action_parameter': {'process_name': 'nova_api'},
+ 'rollback_parameter': {'process_name': 'nova_api'},
+ 'key': 'stop-service',
+ 'attack_key': 'stop-service',
'host': 'node1',
}
diff --git a/tests/unit/benchmark/scenarios/availability/test_attacker_process.py b/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
index eb0cce70d..d7771bd33 100644
--- a/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
+++ b/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
@@ -9,14 +9,18 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.availability.attacker.attacker_process
+# Unittest for
+# yardstick.benchmark.scenarios.availability.attacker.attacker_process
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.attacker import baseattacker
-@mock.patch('yardstick.benchmark.scenarios.availability.attacker.attacker_process.ssh')
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.attacker.attacker_process.ssh')
class AttackerServiceTestCase(unittest.TestCase):
def setUp(self):
diff --git a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
index a20cf8187..7030c7849 100644
--- a/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
+++ b/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
@@ -9,21 +9,25 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_command
+# Unittest for
+# yardstick.benchmark.scenarios.availability.monitor.monitor_command
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.monitor import basemonitor
-@mock.patch('yardstick.benchmark.scenarios.availability.monitor.basemonitor.BaseMonitor')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.basemonitor'
+ '.BaseMonitor')
class MonitorMgrTestCase(unittest.TestCase):
def setUp(self):
config = {
'monitor_type': 'openstack-api',
- 'key' : 'service-status'
+ 'key': 'service-status'
}
self.monitor_configs = []
@@ -42,10 +46,12 @@ class MonitorMgrTestCase(unittest.TestCase):
monitorMgr.init_monitors(self.monitor_configs, None)
monitorIns = monitorMgr['service-status']
+
class BaseMonitorTestCase(unittest.TestCase):
class MonitorSimple(basemonitor.BaseMonitor):
__monitor_type__ = "MonitorForTest"
+
def setup(self):
self.monitor_result = False
@@ -65,14 +71,15 @@ class BaseMonitorTestCase(unittest.TestCase):
ins.start_monitor()
ins.wait_monitor()
-
def test__basemonitor_all_successful(self):
ins = self.MonitorSimple(self.monitor_cfg, None)
ins.setup()
ins.run()
ins.verify_SLA()
- @mock.patch('yardstick.benchmark.scenarios.availability.monitor.basemonitor.multiprocessing')
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.basemonitor'
+ '.multiprocessing')
def test__basemonitor_func_false(self, mock_multiprocess):
ins = self.MonitorSimple(self.monitor_cfg, None)
ins.setup()
@@ -87,4 +94,3 @@ class BaseMonitorTestCase(unittest.TestCase):
except Exception:
pass
self.assertIsNone(cls)
-
diff --git a/tests/unit/benchmark/scenarios/availability/test_baseoperation.py b/tests/unit/benchmark/scenarios/availability/test_baseoperation.py
index d85f1e19f..03ec1492b 100644
--- a/tests/unit/benchmark/scenarios/availability/test_baseoperation.py
+++ b/tests/unit/benchmark/scenarios/availability/test_baseoperation.py
@@ -9,26 +9,31 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.availability.operation.baseoperation
+# Unittest for
+# yardstick.benchmark.scenarios.availability.operation.baseoperation
+from __future__ import absolute_import
import mock
import unittest
-from yardstick.benchmark.scenarios.availability.operation import baseoperation
+from yardstick.benchmark.scenarios.availability.operation import baseoperation
-@mock.patch('yardstick.benchmark.scenarios.availability.operation.baseoperation.BaseOperation')
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.operation.baseoperation'
+ '.BaseOperation')
class OperationMgrTestCase(unittest.TestCase):
def setUp(self):
config = {
'operation_type': 'general-operation',
- 'key' : 'service-status'
+ 'key': 'service-status'
}
self.operation_configs = []
self.operation_configs.append(config)
- def test_all_successful(self, mock_operation):
+ def test_all_successful(self, mock_operation):
mgr_ins = baseoperation.OperationMgr()
mgr_ins.init_operations(self.operation_configs, None)
operation_ins = mgr_ins["service-status"]
@@ -59,7 +64,7 @@ class BaseOperationTestCase(unittest.TestCase):
def setUp(self):
self.config = {
'operation_type': 'general-operation',
- 'key' : 'service-status'
+ 'key': 'service-status'
}
def test_all_successful(self):
@@ -70,7 +75,7 @@ class BaseOperationTestCase(unittest.TestCase):
def test_get_script_fullpath(self):
base_ins = baseoperation.BaseOperation(self.config, None)
- base_ins.get_script_fullpath("ha_tools/test.bash");
+ base_ins.get_script_fullpath("ha_tools/test.bash")
def test_get_operation_cls_successful(self):
base_ins = baseoperation.BaseOperation(self.config, None)
diff --git a/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py b/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
index 9972d6b1b..36ce900fb 100644
--- a/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
+++ b/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
@@ -12,20 +12,22 @@
# Unittest for yardstick.benchmark.scenarios.availability.result_checker
# .baseresultchecker
+from __future__ import absolute_import
import mock
import unittest
-from yardstick.benchmark.scenarios.availability.result_checker import baseresultchecker
+from yardstick.benchmark.scenarios.availability.result_checker import \
+ baseresultchecker
@mock.patch('yardstick.benchmark.scenarios.availability.result_checker'
- '.baseresultchecker.BaseResultChecker')
+ '.baseresultchecker.BaseResultChecker')
class ResultCheckerMgrTestCase(unittest.TestCase):
def setUp(self):
config = {
'checker_type': 'general-result-checker',
- 'key' : 'process-checker'
+ 'key': 'process-checker'
}
self.checker_configs = []
@@ -52,6 +54,7 @@ class BaseResultCheckerTestCase(unittest.TestCase):
class ResultCheckeSimple(baseresultchecker.BaseResultChecker):
__result_checker__type__ = "ResultCheckeForTest"
+
def setup(self):
self.success = False
@@ -61,7 +64,7 @@ class BaseResultCheckerTestCase(unittest.TestCase):
def setUp(self):
self.checker_cfg = {
'checker_type': 'general-result-checker',
- 'key' : 'process-checker'
+ 'key': 'process-checker'
}
def test_baseresultchecker_setup_verify_successful(self):
@@ -81,8 +84,10 @@ class BaseResultCheckerTestCase(unittest.TestCase):
path = ins.get_script_fullpath("test.bash")
def test_get_resultchecker_cls_successful(self):
- baseresultchecker.BaseResultChecker.get_resultchecker_cls("ResultCheckeForTest")
+ baseresultchecker.BaseResultChecker.get_resultchecker_cls(
+ "ResultCheckeForTest")
def test_get_resultchecker_cls_fail(self):
with self.assertRaises(RuntimeError):
- baseresultchecker.BaseResultChecker.get_resultchecker_cls("ResultCheckeNotExist")
+ baseresultchecker.BaseResultChecker.get_resultchecker_cls(
+ "ResultCheckeNotExist")
diff --git a/tests/unit/benchmark/scenarios/availability/test_director.py b/tests/unit/benchmark/scenarios/availability/test_director.py
index 06116725d..d01a60e2d 100644
--- a/tests/unit/benchmark/scenarios/availability/test_director.py
+++ b/tests/unit/benchmark/scenarios/availability/test_director.py
@@ -11,24 +11,26 @@
# Unittest for yardstick.benchmark.scenarios.availability.director
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.director import Director
-from yardstick.benchmark.scenarios.availability import actionplayers
@mock.patch('yardstick.benchmark.scenarios.availability.director.basemonitor')
@mock.patch('yardstick.benchmark.scenarios.availability.director.baseattacker')
-@mock.patch('yardstick.benchmark.scenarios.availability.director.baseoperation')
-@mock.patch('yardstick.benchmark.scenarios.availability.director.baseresultchecker')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.director.baseoperation')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.director.baseresultchecker')
class DirectorTestCase(unittest.TestCase):
def setUp(self):
self.scenario_cfg = {
'type': "general_scenario",
'options': {
- 'attackers':[{
+ 'attackers': [{
'fault_type': "general-attacker",
'key': "kill-process"}],
'monitors': [{
@@ -36,11 +38,11 @@ class DirectorTestCase(unittest.TestCase):
'key': "service-status"}],
'operations': [{
'operation_type': 'general-operation',
- 'key' : 'service-status'}],
+ 'key': 'service-status'}],
'resultCheckers': [{
'checker_type': 'general-result-checker',
- 'key' : 'process-checker',}],
- 'steps':[
+ 'key': 'process-checker', }],
+ 'steps': [
{
'actionKey': "service-status",
'actionType': "operation",
@@ -57,7 +59,7 @@ class DirectorTestCase(unittest.TestCase):
'actionKey': "service-status",
'actionType': "monitor",
'index': 4},
- ]
+ ]
}
}
host = {
@@ -67,15 +69,19 @@ class DirectorTestCase(unittest.TestCase):
}
self.ctx = {"nodes": {"node1": host}}
- def test_director_all_successful(self, mock_checer, mock_opertion, mock_attacker, mock_monitor):
+ def test_director_all_successful(self, mock_checer, mock_opertion,
+ mock_attacker, mock_monitor):
ins = Director(self.scenario_cfg, self.ctx)
opertion_action = ins.createActionPlayer("operation", "service-status")
attacker_action = ins.createActionPlayer("attacker", "kill-process")
- checker_action = ins.createActionPlayer("resultchecker", "process-checker")
+ checker_action = ins.createActionPlayer("resultchecker",
+ "process-checker")
monitor_action = ins.createActionPlayer("monitor", "service-status")
- opertion_rollback = ins.createActionRollbacker("operation", "service-status")
- attacker_rollback = ins.createActionRollbacker("attacker", "kill-process")
+ opertion_rollback = ins.createActionRollbacker("operation",
+ "service-status")
+ attacker_rollback = ins.createActionRollbacker("attacker",
+ "kill-process")
ins.executionSteps.append(opertion_rollback)
ins.executionSteps.append(attacker_rollback)
@@ -91,13 +97,8 @@ class DirectorTestCase(unittest.TestCase):
ins.verify()
ins.knockoff()
- def test_director_get_wrong_item(self, mock_checer, mock_opertion, mock_attacker, mock_monitor):
+ def test_director_get_wrong_item(self, mock_checer, mock_opertion,
+ mock_attacker, mock_monitor):
ins = Director(self.scenario_cfg, self.ctx)
ins.createActionPlayer("wrong_type", "wrong_key")
ins.createActionRollbacker("wrong_type", "wrong_key")
-
-
-
-
-
-
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
index c8cda7dc7..a84bfd2c5 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
@@ -9,14 +9,19 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_command
+# Unittest for
+# yardstick.benchmark.scenarios.availability.monitor.monitor_command
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.monitor import monitor_command
-@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.subprocess')
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
+ '.subprocess')
class ExecuteShellTestCase(unittest.TestCase):
def test__fun_execute_shell_command_successful(self, mock_subprocess):
@@ -25,13 +30,17 @@ class ExecuteShellTestCase(unittest.TestCase):
exitcode, output = monitor_command._execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
- def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
+ def test__fun_execute_shell_command_fail_cmd_exception(self,
+ mock_subprocess):
cmd = "env"
mock_subprocess.check_output.side_effect = RuntimeError
exitcode, output = monitor_command._execute_shell_command(cmd)
self.assertEqual(exitcode, -1)
-@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.subprocess')
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
+ '.subprocess')
class MonitorOpenstackCmdTestCase(unittest.TestCase):
def setUp(self):
@@ -48,7 +57,6 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase):
'sla': {'max_outage_time': 5}
}
-
def test__monitor_command_monitor_func_successful(self, mock_subprocess):
instance = monitor_command.MonitorOpenstackCmd(self.config, None)
@@ -69,11 +77,15 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase):
instance._result = {"outage_time": 10}
instance.verify_SLA()
- @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.ssh')
- def test__monitor_command_ssh_monitor_successful(self, mock_ssh, mock_subprocess):
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
+ '.ssh')
+ def test__monitor_command_ssh_monitor_successful(self, mock_ssh,
+ mock_subprocess):
self.config["host"] = "node1"
- instance = monitor_command.MonitorOpenstackCmd(self.config, self.context)
+ instance = monitor_command.MonitorOpenstackCmd(
+ self.config, self.context)
instance.setup()
mock_ssh.SSH().execute.return_value = (0, "0", '')
ret = instance.monitor_func()
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
index de7d26cbf..369f6f4f7 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
@@ -12,6 +12,7 @@
# Unittest for yardstick.benchmark.scenarios.availability.monitor
# .monitor_general
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.monitor import monitor_general
@@ -22,6 +23,7 @@ from yardstick.benchmark.scenarios.availability.monitor import monitor_general
@mock.patch('yardstick.benchmark.scenarios.availability.monitor.'
'monitor_general.open')
class GeneralMonitorServiceTestCase(unittest.TestCase):
+
def setUp(self):
host = {
"ip": "10.20.0.5",
@@ -53,23 +55,26 @@ class GeneralMonitorServiceTestCase(unittest.TestCase):
ins.setup()
mock_ssh.SSH().execute.return_value = (0, "running", '')
ins.monitor_func()
- ins._result = {'outage_time' : 0}
+ ins._result = {'outage_time': 0}
ins.verify_SLA()
- def test__monitor_general_all_successful_noparam(self, mock_open, mock_ssh):
- ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
+ def test__monitor_general_all_successful_noparam(self, mock_open,
+ mock_ssh):
+ ins = monitor_general.GeneralMonitor(
+ self.monitor_cfg_noparam, self.context)
ins.setup()
mock_ssh.SSH().execute.return_value = (0, "running", '')
ins.monitor_func()
- ins._result = {'outage_time' : 0}
+ ins._result = {'outage_time': 0}
ins.verify_SLA()
def test__monitor_general_failure(self, mock_open, mock_ssh):
- ins = monitor_general.GeneralMonitor(self.monitor_cfg_noparam, self.context)
+ ins = monitor_general.GeneralMonitor(
+ self.monitor_cfg_noparam, self.context)
ins.setup()
mock_ssh.SSH().execute.return_value = (1, "error", 'error')
ins.monitor_func()
- ins._result = {'outage_time' : 2}
+ ins._result = {'outage_time': 2}
ins.verify_SLA()
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_process.py b/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
index dda104b4e..8270405cd 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
@@ -9,14 +9,18 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.availability.monitor.monitor_process
+# Unittest for
+# yardstick.benchmark.scenarios.availability.monitor.monitor_process
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability.monitor import monitor_process
-@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh')
+
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.monitor.monitor_process.ssh')
class MonitorProcessTestCase(unittest.TestCase):
def setUp(self):
@@ -53,4 +57,3 @@ class MonitorProcessTestCase(unittest.TestCase):
ins.monitor_func()
ins._result = {"outage_time": 10}
ins.verify_SLA()
-
diff --git a/tests/unit/benchmark/scenarios/availability/test_operation_general.py b/tests/unit/benchmark/scenarios/availability/test_operation_general.py
index 26cd3f7c4..2c6dc1617 100644
--- a/tests/unit/benchmark/scenarios/availability/test_operation_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_operation_general.py
@@ -12,9 +12,12 @@
# Unittest for yardstick.benchmark.scenarios.availability.operation
# .operation_general
+from __future__ import absolute_import
import mock
import unittest
-from yardstick.benchmark.scenarios.availability.operation import operation_general
+from yardstick.benchmark.scenarios.availability.operation import \
+ operation_general
+
@mock.patch('yardstick.benchmark.scenarios.availability.operation.'
'operation_general.ssh')
@@ -46,7 +49,7 @@ class GeneralOperaionTestCase(unittest.TestCase):
def test__operation_successful(self, mock_open, mock_ssh):
ins = operation_general.GeneralOperaion(self.operation_cfg,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "success", '')
ins.setup()
ins.run()
@@ -54,7 +57,7 @@ class GeneralOperaionTestCase(unittest.TestCase):
def test__operation_successful_noparam(self, mock_open, mock_ssh):
ins = operation_general.GeneralOperaion(self.operation_cfg_noparam,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "success", '')
ins.setup()
ins.run()
@@ -62,7 +65,7 @@ class GeneralOperaionTestCase(unittest.TestCase):
def test__operation_fail(self, mock_open, mock_ssh):
ins = operation_general.GeneralOperaion(self.operation_cfg,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (1, "failed", '')
ins.setup()
ins.run()
diff --git a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
index bbadf0ac3..c5451fabd 100644
--- a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
@@ -12,11 +12,13 @@
# Unittest for yardstick.benchmark.scenarios.availability.result_checker
# .result_checker_general
+from __future__ import absolute_import
import mock
import unittest
import copy
-from yardstick.benchmark.scenarios.availability.result_checker import result_checker_general
+from yardstick.benchmark.scenarios.availability.result_checker import \
+ result_checker_general
@mock.patch('yardstick.benchmark.scenarios.availability.result_checker.'
@@ -35,16 +37,16 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
self.checker_cfg = {
'parameter': {'processname': 'process'},
'checker_type': 'general-result-checker',
- 'condition' : 'eq',
- 'expectedValue' : 1,
- 'key' : 'process-checker',
- 'checker_key' : 'process-checker',
+ 'condition': 'eq',
+ 'expectedValue': 1,
+ 'key': 'process-checker',
+ 'checker_key': 'process-checker',
'host': 'node1'
}
def test__result_checker_eq(self, mock_open, mock_ssh):
ins = result_checker_general.GeneralResultChecker(self.checker_cfg,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "1", '')
ins.setup()
self.assertTrue(ins.verify())
@@ -53,7 +55,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config = copy.deepcopy(self.checker_cfg)
config['condition'] = 'gt'
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "2", '')
ins.setup()
self.assertTrue(ins.verify())
@@ -62,7 +64,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config = copy.deepcopy(self.checker_cfg)
config['condition'] = 'gt_eq'
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "1", '')
ins.setup()
self.assertTrue(ins.verify())
@@ -71,7 +73,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config = copy.deepcopy(self.checker_cfg)
config['condition'] = 'lt'
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "0", '')
ins.setup()
self.assertTrue(ins.verify())
@@ -80,7 +82,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config = copy.deepcopy(self.checker_cfg)
config['condition'] = 'lt_eq'
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "1", '')
ins.setup()
self.assertTrue(ins.verify())
@@ -90,7 +92,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config['condition'] = 'in'
config['expectedValue'] = "value"
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "value return", '')
ins.setup()
self.assertTrue(ins.verify())
@@ -99,7 +101,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config = copy.deepcopy(self.checker_cfg)
config['condition'] = 'wrong'
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (0, "1", '')
ins.setup()
self.assertFalse(ins.verify())
@@ -108,7 +110,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase):
config = copy.deepcopy(self.checker_cfg)
config.pop('parameter')
ins = result_checker_general.GeneralResultChecker(config,
- self.context);
+ self.context)
mock_ssh.SSH().execute.return_value = (1, "fail", '')
ins.setup()
- ins.verify() \ No newline at end of file
+ ins.verify()
diff --git a/tests/unit/benchmark/scenarios/availability/test_scenario_general.py b/tests/unit/benchmark/scenarios/availability/test_scenario_general.py
index bab9d62f1..593fc77b3 100644
--- a/tests/unit/benchmark/scenarios/availability/test_scenario_general.py
+++ b/tests/unit/benchmark/scenarios/availability/test_scenario_general.py
@@ -11,26 +11,29 @@
# Unittest for yardstick.benchmark.scenarios.availability.scenario_general
+from __future__ import absolute_import
import mock
import unittest
-from yardstick.benchmark.scenarios.availability.scenario_general import ScenarioGeneral
+from yardstick.benchmark.scenarios.availability.scenario_general import \
+ ScenarioGeneral
-@mock.patch('yardstick.benchmark.scenarios.availability.scenario_general.Director')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.scenario_general.Director')
class ScenarioGeneralTestCase(unittest.TestCase):
def setUp(self):
self.scenario_cfg = {
'type': "general_scenario",
'options': {
- 'attackers':[{
+ 'attackers': [{
'fault_type': "general-attacker",
'key': "kill-process"}],
'monitors': [{
'monitor_type': "general-monitor",
'key': "service-status"}],
- 'steps':[
+ 'steps': [
{
'actionKey': "kill-process",
'actionType': "attacker",
diff --git a/tests/unit/benchmark/scenarios/availability/test_serviceha.py b/tests/unit/benchmark/scenarios/availability/test_serviceha.py
index 6e58b6e7a..4ae508958 100644
--- a/tests/unit/benchmark/scenarios/availability/test_serviceha.py
+++ b/tests/unit/benchmark/scenarios/availability/test_serviceha.py
@@ -11,13 +11,16 @@
# Unittest for yardstick.benchmark.scenarios.availability.serviceha
+from __future__ import absolute_import
import mock
import unittest
from yardstick.benchmark.scenarios.availability import serviceha
+
@mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor')
-@mock.patch('yardstick.benchmark.scenarios.availability.serviceha.baseattacker')
+@mock.patch(
+ 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker')
class ServicehaTestCase(unittest.TestCase):
def setUp(self):
@@ -48,7 +51,8 @@ class ServicehaTestCase(unittest.TestCase):
sla = {"outage_time": 5}
self.args = {"options": options, "sla": sla}
- def test__serviceha_setup_run_successful(self, mock_attacker, mock_monitor):
+ def test__serviceha_setup_run_successful(self, mock_attacker,
+ mock_monitor):
p = serviceha.ServiceHA(self.args, self.ctx)
p.setup()
diff --git a/tests/unit/benchmark/scenarios/compute/test_cachestat.py b/tests/unit/benchmark/scenarios/compute/test_cachestat.py
index f5a6b5ff9..8a06c754b 100644
--- a/tests/unit/benchmark/scenarios/compute/test_cachestat.py
+++ b/tests/unit/benchmark/scenarios/compute/test_cachestat.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.compute.cachestat.CACHEstat
+from __future__ import absolute_import
import mock
import unittest
import os
@@ -72,11 +73,19 @@ class CACHEstatTestCase(unittest.TestCase):
output = self._read_file("cachestat_sample_output.txt")
mock_ssh.SSH().execute.return_value = (0, output, '')
result = c._get_cache_usage()
- expected_result = {"cachestat": {"cache0": {"HITS": "6462",\
- "DIRTIES": "29", "RATIO": "100.0%", "MISSES": "0", "BUFFERS_MB": "1157",\
- "CACHE_MB": "66782"}}, "average": {"HITS": 6462, "DIRTIES": 29, "RATIO": "100.0%",\
- "MISSES": 0, "BUFFERS_MB":1157, "CACHE_MB": 66782}, "max": {"HITS": 6462,\
- "DIRTIES": 29, "RATIO": 100.0, "MISSES": 0, "BUFFERS_MB": 1157, "CACHE_MB": 66782}}
+ expected_result = {"cachestat": {"cache0": {"HITS": "6462",
+ "DIRTIES": "29",
+ "RATIO": "100.0%",
+ "MISSES": "0",
+ "BUFFERS_MB": "1157",
+ "CACHE_MB": "66782"}},
+ "average": {"HITS": 6462, "DIRTIES": 29,
+ "RATIO": "100.0%",
+ "MISSES": 0, "BUFFERS_MB": 1157,
+ "CACHE_MB": 66782},
+ "max": {"HITS": 6462,
+ "DIRTIES": 29, "RATIO": 100.0, "MISSES": 0,
+ "BUFFERS_MB": 1157, "CACHE_MB": 66782}}
self.assertEqual(result, expected_result)
diff --git a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
index da06b5dbb..4efa66932 100644
--- a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
+++ b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
@@ -9,12 +9,15 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
+# Unittest for
+# yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
+
+from __future__ import absolute_import
-import mock
import unittest
-import os
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import computecapacity
@@ -53,7 +56,7 @@ class ComputeCapacityTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
c.run(self.result)
- expected_result = json.loads(SAMPLE_OUTPUT)
+ expected_result = jsonutils.loads(SAMPLE_OUTPUT)
self.assertEqual(self.result, expected_result)
def test_capacity_unsuccessful_script_error(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/compute/test_cpuload.py b/tests/unit/benchmark/scenarios/compute/test_cpuload.py
index 77f2a02d8..ffa781215 100644
--- a/tests/unit/benchmark/scenarios/compute/test_cpuload.py
+++ b/tests/unit/benchmark/scenarios/compute/test_cpuload.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.compute.lmbench.Lmbench
+from __future__ import absolute_import
import mock
import unittest
import os
@@ -208,7 +209,7 @@ class CPULoadTestCase(unittest.TestCase):
'%nice': '0.03'}}}
self.assertDictEqual(result, expected_result)
-
+
def test_run_proc_stat(self, mock_ssh):
options = {
"interval": 1,
diff --git a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
index 807429025..04ca2abf9 100644
--- a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
+++ b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
@@ -11,9 +11,12 @@
# Unittest for yardstick.benchmark.scenarios.compute.cyclictest.Cyclictest
-import mock
+from __future__ import absolute_import
+
import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import cyclictest
@@ -85,17 +88,17 @@ class CyclictestTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
c.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
def test_cyclictest_successful_sla(self, mock_ssh):
result = {}
self.scenario_cfg.update({"sla": {
- "action": "monitor",
- "max_min_latency": 100,
- "max_avg_latency": 500,
- "max_max_latency": 1000
- }
+ "action": "monitor",
+ "max_min_latency": 100,
+ "max_avg_latency": 500,
+ "max_max_latency": 1000
+ }
})
c = cyclictest.Cyclictest(self.scenario_cfg, self.context_cfg)
mock_ssh.SSH().execute.return_value = (0, '', '')
@@ -106,7 +109,7 @@ class CyclictestTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
c.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/compute/test_lmbench.py b/tests/unit/benchmark/scenarios/compute/test_lmbench.py
index 6be116371..5b72ef75d 100644
--- a/tests/unit/benchmark/scenarios/compute/test_lmbench.py
+++ b/tests/unit/benchmark/scenarios/compute/test_lmbench.py
@@ -11,9 +11,12 @@
# Unittest for yardstick.benchmark.scenarios.compute.lmbench.Lmbench
-import mock
+from __future__ import absolute_import
+
import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import lmbench
@@ -65,7 +68,8 @@ class LmbenchTestCase(unittest.TestCase):
sample_output = '[{"latency": 4.944, "size": 0.00049}]'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
l.run(self.result)
- expected_result = json.loads('{"latencies": ' + sample_output + "}")
+ expected_result = jsonutils.loads(
+ '{"latencies": ' + sample_output + "}")
self.assertEqual(self.result, expected_result)
def test_successful_bandwidth_run_no_sla(self, mock_ssh):
@@ -82,7 +86,7 @@ class LmbenchTestCase(unittest.TestCase):
sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
l.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_successful_latency_run_sla(self, mock_ssh):
@@ -101,7 +105,8 @@ class LmbenchTestCase(unittest.TestCase):
sample_output = '[{"latency": 4.944, "size": 0.00049}]'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
l.run(self.result)
- expected_result = json.loads('{"latencies": ' + sample_output + "}")
+ expected_result = jsonutils.loads(
+ '{"latencies": ' + sample_output + "}")
self.assertEqual(self.result, expected_result)
def test_successful_bandwidth_run_sla(self, mock_ssh):
@@ -121,7 +126,7 @@ class LmbenchTestCase(unittest.TestCase):
sample_output = '{"size(MB)": 0.262144, "bandwidth(MBps)": 11025.5}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
l.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_unsuccessful_latency_run_sla(self, mock_ssh):
@@ -163,7 +168,7 @@ class LmbenchTestCase(unittest.TestCase):
options = {
"test_type": "latency_for_cache",
- "repetition":1,
+ "repetition": 1,
"warmup": 0
}
args = {
@@ -175,7 +180,7 @@ class LmbenchTestCase(unittest.TestCase):
sample_output = "{\"L1cache\": 1.6}"
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
l.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_unsuccessful_script_error(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/compute/test_memload.py b/tests/unit/benchmark/scenarios/compute/test_memload.py
index cdf518d82..76625ef11 100644
--- a/tests/unit/benchmark/scenarios/compute/test_memload.py
+++ b/tests/unit/benchmark/scenarios/compute/test_memload.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.compute.memload.MEMLoad
+from __future__ import absolute_import
import mock
import unittest
import os
@@ -74,15 +75,17 @@ class MEMLoadTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, output, '')
result = m._get_mem_usage()
expected_result = {"max": {"used": 76737332, "cached": 67252400,
- "free": 187016644, "shared": 2844,
- "total": 263753976, "buffers": 853528},
+ "free": 187016644, "shared": 2844,
+ "total": 263753976, "buffers": 853528},
"average": {"used": 76737332, "cached": 67252400,
- "free": 187016644, "shared": 2844,
- "total": 263753976, "buffers": 853528},
+ "free": 187016644, "shared": 2844,
+ "total": 263753976, "buffers": 853528},
"free": {"memory0": {"used": "76737332",
- "cached": "67252400", "free": "187016644",
- "shared": "2844", "total": "263753976",
- "buffers": "853528"}}}
+ "cached": "67252400",
+ "free": "187016644",
+ "shared": "2844",
+ "total": "263753976",
+ "buffers": "853528"}}}
self.assertEqual(result, expected_result)
def _read_file(self, filename):
@@ -91,4 +94,3 @@ class MEMLoadTestCase(unittest.TestCase):
with open(output) as f:
sample_output = f.read()
return sample_output
-
diff --git a/tests/unit/benchmark/scenarios/compute/test_plugintest.py b/tests/unit/benchmark/scenarios/compute/test_plugintest.py
index 94f52738c..a5331caf7 100644
--- a/tests/unit/benchmark/scenarios/compute/test_plugintest.py
+++ b/tests/unit/benchmark/scenarios/compute/test_plugintest.py
@@ -11,10 +11,12 @@
# Unittest for yardstick.benchmark.scenarios.compute.plugintest.PluginTest
-import mock
-import json
+from __future__ import absolute_import
+
import unittest
-import os
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import plugintest
@@ -50,7 +52,7 @@ class PluginTestTestCase(unittest.TestCase):
sample_output = '{"Test Output": "Hello world!"}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
s.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_sample_unsuccessful_script_error(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
index 100102d19..82cc93870 100644
--- a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
+++ b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
@@ -11,9 +11,12 @@
# Unittest for yardstick.benchmark.scenarios.compute.ramspeed.Ramspeed
-import mock
+from __future__ import absolute_import
+
import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import ramspeed
@@ -69,12 +72,12 @@ class RamspeedTestCase(unittest.TestCase):
"Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
"Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
"INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
- {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
- 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
- "Bandwidth(MBps)": 8340.85}]}'
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
+ "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
r.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_ramspeed_successful_run_sla(self, mock_ssh):
@@ -105,12 +108,12 @@ class RamspeedTestCase(unittest.TestCase):
"Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
"Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
"INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
- {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
- 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
- "Bandwidth(MBps)": 8340.85}]}'
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384,\
+ "Bandwidth(MBps)": 14128.94}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
r.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
@@ -176,7 +179,7 @@ class RamspeedTestCase(unittest.TestCase):
"Bandwidth(MBps)": 9401.58}]}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
r.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
@@ -197,7 +200,7 @@ class RamspeedTestCase(unittest.TestCase):
"Bandwidth(MBps)": 9401.58}]}'
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
r.run(self.result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(self.result, expected_result)
def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/compute/test_unixbench.py b/tests/unit/benchmark/scenarios/compute/test_unixbench.py
index 0935bcad2..747bda1ed 100644
--- a/tests/unit/benchmark/scenarios/compute/test_unixbench.py
+++ b/tests/unit/benchmark/scenarios/compute/test_unixbench.py
@@ -11,9 +11,12 @@
# Unittest for yardstick.benchmark.scenarios.compute.unixbench.Unixbench
-import mock
+from __future__ import absolute_import
+
import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.compute import unixbench
@@ -57,7 +60,7 @@ class UnixbenchTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
u.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
def test_unixbench_successful_in_quiet_mode(self, mock_ssh):
@@ -65,7 +68,7 @@ class UnixbenchTestCase(unittest.TestCase):
options = {
"test_type": 'dhry2reg',
"run_mode": 'quiet',
- "copies":1
+ "copies": 1
}
args = {
"options": options,
@@ -79,10 +82,9 @@ class UnixbenchTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
u.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
-
def test_unixbench_successful_sla(self, mock_ssh):
options = {
@@ -106,7 +108,7 @@ class UnixbenchTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
u.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
self.assertEqual(result, expected_result)
def test_unixbench_unsuccessful_sla_single_score(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/dummy/test_dummy.py b/tests/unit/benchmark/scenarios/dummy/test_dummy.py
index 1f9b729a9..560675d09 100644
--- a/tests/unit/benchmark/scenarios/dummy/test_dummy.py
+++ b/tests/unit/benchmark/scenarios/dummy/test_dummy.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.dummy.dummy
+from __future__ import absolute_import
import unittest
from yardstick.benchmark.scenarios.dummy import dummy
diff --git a/tests/unit/benchmark/scenarios/networking/test_iperf3.py b/tests/unit/benchmark/scenarios/networking/test_iperf3.py
index 91f800b60..ea53cb9ab 100644
--- a/tests/unit/benchmark/scenarios/networking/test_iperf3.py
+++ b/tests/unit/benchmark/scenarios/networking/test_iperf3.py
@@ -11,10 +11,13 @@
# Unittest for yardstick.benchmark.scenarios.networking.iperf3.Iperf
-import mock
-import unittest
+from __future__ import absolute_import
+
import os
-import json
+import unittest
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.networking import iperf3
@@ -78,7 +81,7 @@ class IperfTestCase(unittest.TestCase):
sample_output = self._read_sample_output(self.output_name_tcp)
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
@@ -97,7 +100,7 @@ class IperfTestCase(unittest.TestCase):
sample_output = self._read_sample_output(self.output_name_tcp)
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
@@ -119,8 +122,7 @@ class IperfTestCase(unittest.TestCase):
self.assertRaises(AssertionError, p.run, result)
def test_iperf_successful_sla_jitter(self, mock_ssh):
-
- options = {"udp":"udp","bandwidth":"20m"}
+ options = {"udp": "udp", "bandwidth": "20m"}
args = {
'options': options,
'sla': {'jitter': 10}
@@ -133,13 +135,12 @@ class IperfTestCase(unittest.TestCase):
sample_output = self._read_sample_output(self.output_name_udp)
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
def test_iperf_unsuccessful_sla_jitter(self, mock_ssh):
-
- options = {"udp":"udp","bandwidth":"20m"}
+ options = {"udp": "udp", "bandwidth": "20m"}
args = {
'options': options,
'sla': {'jitter': 0.0001}
@@ -167,7 +168,7 @@ class IperfTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, p.run, result)
- def _read_sample_output(self,filename):
+ def _read_sample_output(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
output = os.path.join(curr_path, filename)
with open(output) as f:
diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf.py b/tests/unit/benchmark/scenarios/networking/test_netperf.py
index 3f224733c..1b5dd6472 100755
--- a/tests/unit/benchmark/scenarios/networking/test_netperf.py
+++ b/tests/unit/benchmark/scenarios/networking/test_netperf.py
@@ -11,10 +11,13 @@
# Unittest for yardstick.benchmark.scenarios.networking.netperf.Netperf
-import mock
-import unittest
+from __future__ import absolute_import
+
import os
-import json
+import unittest
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.networking import netperf
@@ -59,7 +62,7 @@ class NetperfTestCase(unittest.TestCase):
sample_output = self._read_sample_output()
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
@@ -78,7 +81,7 @@ class NetperfTestCase(unittest.TestCase):
sample_output = self._read_sample_output()
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
index 1c39b292b..29a7edf67 100755
--- a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
+++ b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
@@ -12,10 +12,13 @@
# Unittest for
# yardstick.benchmark.scenarios.networking.netperf_node.NetperfNode
-import mock
-import unittest
+from __future__ import absolute_import
+
import os
-import json
+import unittest
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.networking import netperf_node
@@ -59,7 +62,7 @@ class NetperfNodeTestCase(unittest.TestCase):
sample_output = self._read_sample_output()
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
@@ -78,7 +81,7 @@ class NetperfNodeTestCase(unittest.TestCase):
sample_output = self._read_sample_output()
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
p.run(result)
self.assertEqual(result, expected_result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_netutilization.py b/tests/unit/benchmark/scenarios/networking/test_netutilization.py
index eb6626fea..7c04f5e9a 100644
--- a/tests/unit/benchmark/scenarios/networking/test_netutilization.py
+++ b/tests/unit/benchmark/scenarios/networking/test_netutilization.py
@@ -9,8 +9,10 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.networking.netutilization.NetUtilization
+# Unittest for
+# yardstick.benchmark.scenarios.networking.netutilization.NetUtilization
+from __future__ import absolute_import
import mock
import unittest
import os
diff --git a/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
index e42832f1b..3f8d84e54 100644
--- a/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
+++ b/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
@@ -9,27 +9,32 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.networking.networkcapacity.NetworkCapacity
+# Unittest for
+# yardstick.benchmark.scenarios.networking.networkcapacity.NetworkCapacity
+
+from __future__ import absolute_import
-import mock
import unittest
-import os
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.networking import networkcapacity
-SAMPLE_OUTPUT = '{"Number of connections":"308","Number of frames received": "166503"}'
+SAMPLE_OUTPUT = \
+ '{"Number of connections":"308","Number of frames received": "166503"}'
+
@mock.patch('yardstick.benchmark.scenarios.networking.networkcapacity.ssh')
class NetworkCapacityTestCase(unittest.TestCase):
def setUp(self):
self.ctx = {
- 'host': {
- 'ip': '172.16.0.137',
- 'user': 'cirros',
- 'password': "root"
- },
+ 'host': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'password': "root"
+ },
}
self.result = {}
@@ -46,7 +51,7 @@ class NetworkCapacityTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
c.run(self.result)
- expected_result = json.loads(SAMPLE_OUTPUT)
+ expected_result = jsonutils.loads(SAMPLE_OUTPUT)
self.assertEqual(self.result, expected_result)
def test_capacity_unsuccessful_script_error(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping.py b/tests/unit/benchmark/scenarios/networking/test_ping.py
index 8d35b8490..5535a79a9 100644
--- a/tests/unit/benchmark/scenarios/networking/test_ping.py
+++ b/tests/unit/benchmark/scenarios/networking/test_ping.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.networking.ping.Ping
+from __future__ import absolute_import
import mock
import unittest
@@ -37,7 +38,7 @@ class PingTestCase(unittest.TestCase):
args = {
'options': {'packetsize': 200},
'target': 'ares.demo'
- }
+ }
result = {}
p = ping.Ping(args, self.ctx)
@@ -53,7 +54,7 @@ class PingTestCase(unittest.TestCase):
'options': {'packetsize': 200},
'sla': {'max_rtt': 150},
'target': 'ares.demo'
- }
+ }
result = {}
p = ping.Ping(args, self.ctx)
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping6.py b/tests/unit/benchmark/scenarios/networking/test_ping6.py
index 0b8fba268..e22cacb36 100644
--- a/tests/unit/benchmark/scenarios/networking/test_ping6.py
+++ b/tests/unit/benchmark/scenarios/networking/test_ping6.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.networking.ping.Ping
+from __future__ import absolute_import
import mock
import unittest
@@ -21,37 +22,37 @@ class PingTestCase(unittest.TestCase):
def setUp(self):
self.ctx = {
- 'nodes':{
- 'host1': {
- 'ip': '172.16.0.137',
- 'user': 'cirros',
- 'role': "Controller",
- 'key_filename': "mykey.key",
- 'password': "root"
+ 'nodes': {
+ 'host1': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'role': "Controller",
+ 'key_filename': "mykey.key",
+ 'password': "root"
},
- 'host2': {
- "ip": "172.16.0.138",
- "key_filename": "/root/.ssh/id_rsa",
- "role": "Compute",
- "name": "node3.IPV6",
- "user": "root"
+ 'host2': {
+ "ip": "172.16.0.138",
+ "key_filename": "/root/.ssh/id_rsa",
+ "role": "Compute",
+ "name": "node3.IPV6",
+ "user": "root"
},
}
}
def test_get_controller_node(self):
args = {
- 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
'sla': {'max_rtt': 50}
}
p = ping6.Ping6(args, self.ctx)
- controller_node = p._get_controller_node(['host1','host2'])
+ controller_node = p._get_controller_node(['host1', 'host2'])
self.assertEqual(controller_node, 'host1')
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_successful_setup(self, mock_ssh):
args = {
- 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
'sla': {'max_rtt': 50}
}
p = ping6.Ping6(args, self.ctx)
@@ -63,58 +64,57 @@ class PingTestCase(unittest.TestCase):
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_successful_no_sla(self, mock_ssh):
args = {
- 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
}
result = {}
p = ping6.Ping6(args, self.ctx)
p.client = mock_ssh.SSH()
- mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
+ mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
p.run(result)
self.assertEqual(result, {'rtt': 100.0})
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_successful_sla(self, mock_ssh):
-
args = {
- 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
'sla': {'max_rtt': 150}
}
result = {}
p = ping6.Ping6(args, self.ctx)
p.client = mock_ssh.SSH()
- mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
+ mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
p.run(result)
self.assertEqual(result, {'rtt': 100.0})
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_unsuccessful_sla(self, mock_ssh):
-
args = {
- 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
'sla': {'max_rtt': 50}
}
result = {}
p = ping6.Ping6(args, self.ctx)
p.client = mock_ssh.SSH()
- mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
+ mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
self.assertRaises(AssertionError, p.run, result)
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_unsuccessful_script_error(self, mock_ssh):
args = {
- 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
+ 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
'sla': {'max_rtt': 150}
}
result = {}
p = ping6.Ping6(args, self.ctx)
p.client = mock_ssh.SSH()
- mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(1, '', 'FOOBAR')]
+ mock_ssh.SSH().execute.side_effect = [
+ (0, 'host1', ''), (1, '', 'FOOBAR')]
self.assertRaises(RuntimeError, p.run, result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/tests/unit/benchmark/scenarios/networking/test_pktgen.py
index 13a4c1bd4..f50fa108c 100644
--- a/tests/unit/benchmark/scenarios/networking/test_pktgen.py
+++ b/tests/unit/benchmark/scenarios/networking/test_pktgen.py
@@ -11,9 +11,12 @@
# Unittest for yardstick.benchmark.scenarios.networking.pktgen.Pktgen
-import mock
+from __future__ import absolute_import
+
import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.networking import pktgen
@@ -133,7 +136,7 @@ class PktgenTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
p.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
expected_result["packets_received"] = 149300
self.assertEqual(result, expected_result)
@@ -159,7 +162,7 @@ class PktgenTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
p.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
expected_result["packets_received"] = 149300
self.assertEqual(result, expected_result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
index afc87abfb..7ba4db9d9 100644
--- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
+++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
@@ -11,12 +11,14 @@
# Unittest for yardstick.benchmark.scenarios.networking.pktgen.Pktgen
-import mock
+from __future__ import absolute_import
import unittest
-import json
+
+import mock
from yardstick.benchmark.scenarios.networking import pktgen_dpdk
+
@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
class PktgenDPDKLatencyTestCase(unittest.TestCase):
@@ -116,7 +118,11 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
p.run(result)
- self.assertEqual(result, {"avg_latency": 132})
+ # with python 3 we get float, might be due python division changes
+ # AssertionError: {'avg_latency': 132.33333333333334} != {
+ # 'avg_latency': 132}
+ delta = result['avg_latency'] - 132
+ self.assertLessEqual(delta, 1)
def test_pktgen_dpdk_successful_sla(self, mock_ssh):
@@ -169,5 +175,6 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_sfc.py b/tests/unit/benchmark/scenarios/networking/test_sfc.py
index 618efc32e..224a43bd8 100644
--- a/tests/unit/benchmark/scenarios/networking/test_sfc.py
+++ b/tests/unit/benchmark/scenarios/networking/test_sfc.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.networking.sfc
+from __future__ import absolute_import
import mock
import unittest
@@ -27,7 +28,7 @@ class SfcTestCase(unittest.TestCase):
context_cfg['target'] = dict()
context_cfg['target']['user'] = 'root'
context_cfg['target']['password'] = 'opnfv'
- context_cfg['target']['ip'] = '127.0.0.1'
+ context_cfg['target']['ip'] = '127.0.0.1'
# Used in Sfc.run()
context_cfg['host'] = dict()
@@ -58,7 +59,8 @@ class SfcTestCase(unittest.TestCase):
@mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess')
def test2_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh):
# Mock a successfull SSH in Sfc.setup() and Sfc.run()
- mock_ssh.SSH().execute.return_value = (0, 'vxlan_tool.py', 'succeeded timed out')
+ mock_ssh.SSH().execute.return_value = (
+ 0, 'vxlan_tool.py', 'succeeded timed out')
mock_openstack.get_an_IP.return_value = "127.0.0.1"
mock_subprocess.call.return_value = 'mocked!'
diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/tests/unit/benchmark/scenarios/networking/test_vsperf.py
index 25d52212b..76d2afdc0 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vsperf.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vsperf.py
@@ -16,17 +16,20 @@
# Unittest for yardstick.benchmark.scenarios.networking.vsperf.Vsperf
-import mock
+from __future__ import absolute_import
+try:
+ from unittest import mock
+except ImportError:
+ import mock
import unittest
-import os
-import subprocess
from yardstick.benchmark.scenarios.networking import vsperf
@mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess')
@mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh')
-@mock.patch("__builtin__.open", return_value=None)
+@mock.patch("yardstick.benchmark.scenarios.networking.vsperf.open",
+ mock.mock_open())
class VsperfTestCase(unittest.TestCase):
def setUp(self):
@@ -58,7 +61,7 @@ class VsperfTestCase(unittest.TestCase):
}
}
- def test_vsperf_setup(self, mock_open, mock_ssh, mock_subprocess):
+ def test_vsperf_setup(self, mock_ssh, mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
mock_ssh.SSH().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
@@ -67,7 +70,7 @@ class VsperfTestCase(unittest.TestCase):
self.assertIsNotNone(p.client)
self.assertEqual(p.setup_done, True)
- def test_vsperf_teardown(self, mock_open, mock_ssh, mock_subprocess):
+ def test_vsperf_teardown(self, mock_ssh, mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
# setup() specific mocks
@@ -81,7 +84,7 @@ class VsperfTestCase(unittest.TestCase):
p.teardown()
self.assertEqual(p.setup_done, False)
- def test_vsperf_run_ok(self, mock_open, mock_ssh, mock_subprocess):
+ def test_vsperf_run_ok(self, mock_ssh, mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
# setup() specific mocks
@@ -90,14 +93,16 @@ class VsperfTestCase(unittest.TestCase):
# run() specific mocks
mock_ssh.SSH().execute.return_value = (0, '', '')
- mock_ssh.SSH().execute.return_value = (0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
+ mock_ssh.SSH().execute.return_value = (
+ 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
result = {}
p.run(result)
self.assertEqual(result['throughput_rx_fps'], '14797660.000')
- def test_vsperf_run_falied_vsperf_execution(self, mock_open, mock_ssh, mock_subprocess):
+ def test_vsperf_run_falied_vsperf_execution(self, mock_ssh,
+ mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
# setup() specific mocks
@@ -110,7 +115,7 @@ class VsperfTestCase(unittest.TestCase):
result = {}
self.assertRaises(RuntimeError, p.run, result)
- def test_vsperf_run_falied_csv_report(self, mock_open, mock_ssh, mock_subprocess):
+ def test_vsperf_run_falied_csv_report(self, mock_ssh, mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
# setup() specific mocks
@@ -128,5 +133,6 @@ class VsperfTestCase(unittest.TestCase):
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation.py b/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation.py
index 418dd39e6..07b3da992 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation.py
@@ -11,10 +11,11 @@
# Unittest for yardstick.benchmark.scenarios.networking.iperf3.Iperf
-import mock
+from __future__ import absolute_import
import unittest
-from yardstick.benchmark.scenarios.networking import vtc_instantiation_validation
+from yardstick.benchmark.scenarios.networking import \
+ vtc_instantiation_validation
class VtcInstantiationValidationTestCase(unittest.TestCase):
@@ -34,7 +35,8 @@ class VtcInstantiationValidationTestCase(unittest.TestCase):
scenario['options']['vlan_sender'] = ''
scenario['options']['vlan_receiver'] = ''
- self.vt = vtc_instantiation_validation.VtcInstantiationValidation(scenario, '')
+ self.vt = vtc_instantiation_validation.VtcInstantiationValidation(
+ scenario, '')
def test_run_for_success(self):
result = {}
diff --git a/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation_noisy.py b/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation_noisy.py
index e0a46241c..34f3610b1 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation_noisy.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vtc_instantiation_validation_noisy.py
@@ -11,10 +11,11 @@
# Unittest for yardstick.benchmark.scenarios.networking.iperf3.Iperf
-import mock
+from __future__ import absolute_import
import unittest
-from yardstick.benchmark.scenarios.networking import vtc_instantiation_validation_noisy
+from yardstick.benchmark.scenarios.networking import \
+ vtc_instantiation_validation_noisy
class VtcInstantiationValidationiNoisyTestCase(unittest.TestCase):
@@ -37,7 +38,9 @@ class VtcInstantiationValidationiNoisyTestCase(unittest.TestCase):
scenario['options']['amount_of_ram'] = '1G'
scenario['options']['number_of_cores'] = '1'
- self.vt = vtc_instantiation_validation_noisy.VtcInstantiationValidationNoisy(scenario, '')
+ self.vt = \
+ vtc_instantiation_validation_noisy.VtcInstantiationValidationNoisy(
+ scenario, '')
def test_run_for_success(self):
result = {}
diff --git a/tests/unit/benchmark/scenarios/networking/test_vtc_throughput.py b/tests/unit/benchmark/scenarios/networking/test_vtc_throughput.py
index ecdf555d2..a73fad5a8 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vtc_throughput.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vtc_throughput.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.networking.iperf3.Iperf
+from __future__ import absolute_import
import mock
import unittest
diff --git a/tests/unit/benchmark/scenarios/networking/test_vtc_throughput_noisy_test.py b/tests/unit/benchmark/scenarios/networking/test_vtc_throughput_noisy_test.py
index 98957b1de..e1b162c79 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vtc_throughput_noisy_test.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vtc_throughput_noisy_test.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.scenarios.networking.iperf3.Iperf
+from __future__ import absolute_import
import mock
import unittest
diff --git a/tests/unit/benchmark/scenarios/parser/test_parser.py b/tests/unit/benchmark/scenarios/parser/test_parser.py
index d11a6d5c8..59b98a092 100644
--- a/tests/unit/benchmark/scenarios/parser/test_parser.py
+++ b/tests/unit/benchmark/scenarios/parser/test_parser.py
@@ -11,12 +11,16 @@
# Unittest for yardstick.benchmark.scenarios.parser.Parser
-import mock
+from __future__ import absolute_import
+
import unittest
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.parser import parser
+
@mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess')
class ParserTestCase(unittest.TestCase):
@@ -32,8 +36,8 @@ class ParserTestCase(unittest.TestCase):
def test_parser_successful(self, mock_subprocess):
args = {
- 'options': {'yangfile':'/root/yardstick/samples/yang.yaml',
- 'toscafile':'/root/yardstick/samples/tosca.yaml'},
+ 'options': {'yangfile': '/root/yardstick/samples/yang.yaml',
+ 'toscafile': '/root/yardstick/samples/tosca.yaml'},
}
p = parser.Parser(args, {})
result = {}
@@ -41,7 +45,7 @@ class ParserTestCase(unittest.TestCase):
sample_output = '{"yangtotosca": "success"}'
p.run(result)
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
def test_parser_teardown_successful(self, mock_subprocess):
diff --git a/tests/unit/benchmark/scenarios/storage/test_fio.py b/tests/unit/benchmark/scenarios/storage/test_fio.py
index 153d15052..603ff389e 100644
--- a/tests/unit/benchmark/scenarios/storage/test_fio.py
+++ b/tests/unit/benchmark/scenarios/storage/test_fio.py
@@ -11,10 +11,13 @@
# Unittest for yardstick.benchmark.scenarios.storage.fio.Fio
-import mock
-import unittest
-import json
+from __future__ import absolute_import
+
import os
+import unittest
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.storage import fio
@@ -74,7 +77,7 @@ class FioTestCase(unittest.TestCase):
expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
'"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
'"write_lat": 233.55}'
- expected_result = json.loads(expected_result)
+ expected_result = jsonutils.loads(expected_result)
self.assertEqual(result, expected_result)
def test_fio_successful_read_no_sla(self, mock_ssh):
@@ -98,7 +101,7 @@ class FioTestCase(unittest.TestCase):
expected_result = '{"read_bw": 36113, "read_iops": 9028,' \
'"read_lat": 108.7}'
- expected_result = json.loads(expected_result)
+ expected_result = jsonutils.loads(expected_result)
self.assertEqual(result, expected_result)
def test_fio_successful_write_no_sla(self, mock_ssh):
@@ -122,7 +125,7 @@ class FioTestCase(unittest.TestCase):
expected_result = '{"write_bw": 35107, "write_iops": 8776,'\
'"write_lat": 111.74}'
- expected_result = json.loads(expected_result)
+ expected_result = jsonutils.loads(expected_result)
self.assertEqual(result, expected_result)
def test_fio_successful_lat_sla(self, mock_ssh):
@@ -150,10 +153,9 @@ class FioTestCase(unittest.TestCase):
expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
'"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
'"write_lat": 233.55}'
- expected_result = json.loads(expected_result)
+ expected_result = jsonutils.loads(expected_result)
self.assertEqual(result, expected_result)
-
def test_fio_unsuccessful_lat_sla(self, mock_ssh):
options = {
@@ -200,7 +202,7 @@ class FioTestCase(unittest.TestCase):
expected_result = '{"read_bw": 83888, "read_iops": 20972,' \
'"read_lat": 236.8, "write_bw": 84182, "write_iops": 21045,'\
'"write_lat": 233.55}'
- expected_result = json.loads(expected_result)
+ expected_result = jsonutils.loads(expected_result)
self.assertEqual(result, expected_result)
def test_fio_unsuccessful_bw_iops_sla(self, mock_ssh):
@@ -248,8 +250,10 @@ class FioTestCase(unittest.TestCase):
sample_output = f.read()
return sample_output
+
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
index ace0ca374..6fb5f5686 100644
--- a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
+++ b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
@@ -9,35 +9,41 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.storage.storagecapacity.StorageCapacity
+# Unittest for
+# yardstick.benchmark.scenarios.storage.storagecapacity.StorageCapacity
+
+from __future__ import absolute_import
-import mock
import unittest
-import os
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.storage import storagecapacity
-DISK_SIZE_SAMPLE_OUTPUT = '{"Numberf of devides": "2", "Total disk size in bytes": "1024000000"}'
+DISK_SIZE_SAMPLE_OUTPUT = \
+ '{"Numberf of devides": "2", "Total disk size in bytes": "1024000000"}'
BLOCK_SIZE_SAMPLE_OUTPUT = '{"/dev/sda": 1024, "/dev/sdb": 4096}'
DISK_UTIL_RAW_OUTPUT = "vda 10.00\nvda 0.00"
-DISK_UTIL_SAMPLE_OUTPUT = '{"vda": {"avg_util": 5.0, "max_util": 10.0, "min_util": 0.0}}'
+DISK_UTIL_SAMPLE_OUTPUT = \
+ '{"vda": {"avg_util": 5.0, "max_util": 10.0, "min_util": 0.0}}'
+
@mock.patch('yardstick.benchmark.scenarios.storage.storagecapacity.ssh')
class StorageCapacityTestCase(unittest.TestCase):
def setUp(self):
self.scn = {
- "options": {
- 'test_type': 'disk_size'
- }
+ "options": {
+ 'test_type': 'disk_size'
+ }
}
self.ctx = {
- "host": {
- 'ip': '172.16.0.137',
- 'user': 'cirros',
- 'password': "root"
- }
+ "host": {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'password': "root"
+ }
}
self.result = {}
@@ -54,7 +60,8 @@ class StorageCapacityTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, DISK_SIZE_SAMPLE_OUTPUT, '')
c.run(self.result)
- expected_result = json.loads(DISK_SIZE_SAMPLE_OUTPUT)
+ expected_result = jsonutils.loads(
+ DISK_SIZE_SAMPLE_OUTPUT)
self.assertEqual(self.result, expected_result)
def test_capacity_block_size_successful(self, mock_ssh):
@@ -67,7 +74,8 @@ class StorageCapacityTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, BLOCK_SIZE_SAMPLE_OUTPUT, '')
c.run(self.result)
- expected_result = json.loads(BLOCK_SIZE_SAMPLE_OUTPUT)
+ expected_result = jsonutils.loads(
+ BLOCK_SIZE_SAMPLE_OUTPUT)
self.assertEqual(self.result, expected_result)
def test_capacity_disk_utilization_successful(self, mock_ssh):
@@ -82,7 +90,8 @@ class StorageCapacityTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, DISK_UTIL_RAW_OUTPUT, '')
c.run(self.result)
- expected_result = json.loads(DISK_UTIL_SAMPLE_OUTPUT)
+ expected_result = jsonutils.loads(
+ DISK_UTIL_SAMPLE_OUTPUT)
self.assertEqual(self.result, expected_result)
def test_capacity_unsuccessful_script_error(self, mock_ssh):
@@ -91,6 +100,7 @@ class StorageCapacityTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, c.run, self.result)
+
def main():
unittest.main()
diff --git a/tests/unit/benchmark/scenarios/storage/test_storperf.py b/tests/unit/benchmark/scenarios/storage/test_storperf.py
index 8fc97d2ed..adc9d47c6 100644
--- a/tests/unit/benchmark/scenarios/storage/test_storperf.py
+++ b/tests/unit/benchmark/scenarios/storage/test_storperf.py
@@ -11,43 +11,58 @@
# Unittest for yardstick.benchmark.scenarios.storage.storperf.StorPerf
-import mock
+from __future__ import absolute_import
+
import unittest
-import requests
-import json
+
+import mock
+from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.storage import storperf
def mocked_requests_config_post(*args, **kwargs):
class MockResponseConfigPost:
+
def __init__(self, json_data, status_code):
self.content = json_data
self.status_code = status_code
- return MockResponseConfigPost('{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622","stack_created": "false"}', 200)
+ return MockResponseConfigPost(
+ '{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622",'
+ '"stack_created": "false"}',
+ 200)
def mocked_requests_config_get(*args, **kwargs):
class MockResponseConfigGet:
+
def __init__(self, json_data, status_code):
self.content = json_data
self.status_code = status_code
- return MockResponseConfigGet('{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622","stack_created": "true"}', 200)
+ return MockResponseConfigGet(
+ '{"stack_id": "dac27db1-3502-4300-b301-91c64e6a1622",'
+ '"stack_created": "true"}',
+ 200)
def mocked_requests_job_get(*args, **kwargs):
class MockResponseJobGet:
+
def __init__(self, json_data, status_code):
self.content = json_data
self.status_code = status_code
- return MockResponseJobGet('{"status": "completed", "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}', 200)
+ return MockResponseJobGet(
+ '{"status": "completed",\
+ "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}',
+ 200)
def mocked_requests_job_post(*args, **kwargs):
class MockResponseJobPost:
+
def __init__(self, json_data, status_code):
self.content = json_data
self.status_code = status_code
@@ -58,6 +73,7 @@ def mocked_requests_job_post(*args, **kwargs):
def mocked_requests_job_delete(*args, **kwargs):
class MockResponseJobDelete:
+
def __init__(self, json_data, status_code):
self.content = json_data
self.status_code = status_code
@@ -67,6 +83,7 @@ def mocked_requests_job_delete(*args, **kwargs):
def mocked_requests_delete(*args, **kwargs):
class MockResponseDelete:
+
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
@@ -76,6 +93,7 @@ def mocked_requests_delete(*args, **kwargs):
def mocked_requests_delete_failed(*args, **kwargs):
class MockResponseDeleteFailed:
+
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
@@ -130,8 +148,9 @@ class StorPerfTestCase(unittest.TestCase):
side_effect=mocked_requests_job_post)
@mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.get',
side_effect=mocked_requests_job_get)
- @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.delete',
- side_effect=mocked_requests_job_delete)
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.storage.storperf.requests.delete',
+ side_effect=mocked_requests_job_delete)
def test_successful_run(self, mock_post, mock_get, mock_delete):
options = {
"agent_count": 8,
@@ -152,15 +171,18 @@ class StorPerfTestCase(unittest.TestCase):
s = storperf.StorPerf(args, self.ctx)
s.setup_done = True
- sample_output = '{"status": "completed", "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}'
+ sample_output = '{"status": "completed",\
+ "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}'
- expected_result = json.loads(sample_output)
+ expected_result = jsonutils.loads(sample_output)
s.run(self.result)
self.assertEqual(self.result, expected_result)
- @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.delete', side_effect=mocked_requests_delete)
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.storage.storperf.requests.delete',
+ side_effect=mocked_requests_delete)
def test_successful_teardown(self, mock_delete):
options = {
"agent_count": 8,
@@ -184,7 +206,9 @@ class StorPerfTestCase(unittest.TestCase):
self.assertFalse(s.setup_done)
- @mock.patch('yardstick.benchmark.scenarios.storage.storperf.requests.delete', side_effect=mocked_requests_delete_failed)
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.storage.storperf.requests.delete',
+ side_effect=mocked_requests_delete_failed)
def test_failed_teardown(self, mock_delete):
options = {
"agent_count": 8,
diff --git a/tests/unit/cmd/commands/test_env.py b/tests/unit/cmd/commands/test_env.py
index e85c36755..c6e0e1d20 100644
--- a/tests/unit/cmd/commands/test_env.py
+++ b/tests/unit/cmd/commands/test_env.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 unittest
import mock
import uuid
diff --git a/tests/unit/common/test_httpClient.py b/tests/unit/common/test_httpClient.py
index 94ac1c891..eb09d1a52 100644
--- a/tests/unit/common/test_httpClient.py
+++ b/tests/unit/common/test_httpClient.py
@@ -6,9 +6,12 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
+
import unittest
+
import mock
-import json
+from oslo_serialization import jsonutils
from yardstick.common import httpClient
@@ -21,8 +24,9 @@ class HttpClientTestCase(unittest.TestCase):
data = {'hello': 'world'}
headers = {'Content-Type': 'application/json'}
httpClient.HttpClient().post(url, data)
- mock_requests.post.assert_called_with(url, data=json.dumps(data),
- headers=headers)
+ mock_requests.post.assert_called_with(
+ url, data=jsonutils.dump_as_bytes(data),
+ headers=headers)
@mock.patch('yardstick.common.httpClient.requests')
def test_get(self, mock_requests):
diff --git a/tests/unit/common/test_openstack_utils.py b/tests/unit/common/test_openstack_utils.py
index ef619aace..d610e181c 100644
--- a/tests/unit/common/test_openstack_utils.py
+++ b/tests/unit/common/test_openstack_utils.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.common.openstack_utils
+from __future__ import absolute_import
import unittest
import mock
diff --git a/tests/unit/common/test_template_format.py b/tests/unit/common/test_template_format.py
index 0e1a1a57d..2a7d80b4d 100644
--- a/tests/unit/common/test_template_format.py
+++ b/tests/unit/common/test_template_format.py
@@ -12,6 +12,7 @@
# yardstick: this file is copied from python-heatclient and slightly modified
+from __future__ import absolute_import
import mock
import unittest
import yaml
diff --git a/tests/unit/common/test_utils.py b/tests/unit/common/test_utils.py
index a64c1f1ab..267c71312 100644
--- a/tests/unit/common/test_utils.py
+++ b/tests/unit/common/test_utils.py
@@ -9,6 +9,7 @@
# Unittest for yardstick.common.utils
+from __future__ import absolute_import
import os
import mock
import unittest
@@ -17,9 +18,10 @@ from yardstick.common import utils
class IterSubclassesTestCase(unittest.TestCase):
-# Disclaimer: this class is a modified copy from
-# rally/tests/unit/common/plugin/test_discover.py
-# Copyright 2015: Mirantis Inc.
+ # Disclaimer: this class is a modified copy from
+ # rally/tests/unit/common/plugin/test_discover.py
+ # Copyright 2015: Mirantis Inc.
+
def test_itersubclasses(self):
class A(object):
pass
diff --git a/tests/unit/dispatcher/test_influxdb.py b/tests/unit/dispatcher/test_influxdb.py
index 5553c86a9..b84389e7e 100644
--- a/tests/unit/dispatcher/test_influxdb.py
+++ b/tests/unit/dispatcher/test_influxdb.py
@@ -11,11 +11,17 @@
# Unittest for yardstick.dispatcher.influxdb
-import mock
+from __future__ import absolute_import
import unittest
+try:
+ from unittest import mock
+except ImportError:
+ import mock
+
from yardstick.dispatcher.influxdb import InfluxdbDispatcher
+
class InfluxdbDispatcherTestCase(unittest.TestCase):
def setUp(self):
@@ -24,7 +30,9 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
"context_cfg": {
"host": {
"ip": "10.229.43.154",
- "key_filename": "/root/yardstick/yardstick/resources/files/yardstick_key",
+ "key_filename":
+ "/root/yardstick/yardstick/resources/files"
+ "/yardstick_key",
"name": "kvm.LF",
"user": "root"
},
@@ -35,7 +43,8 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
"scenario_cfg": {
"runner": {
"interval": 1,
- "object": "yardstick.benchmark.scenarios.networking.ping.Ping",
+ "object": "yardstick.benchmark.scenarios.networking.ping"
+ ".Ping",
"output_filename": "/tmp/yardstick.out",
"runner_id": 8921,
"duration": 10,
@@ -63,7 +72,7 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
},
"runner_id": 8921
}
- self.data3 ={
+ self.data3 = {
"benchmark": {
"data": {
"mpstat": {
@@ -99,26 +108,35 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
self.assertEqual(influxdb.flush_result_data(), 0)
def test__dict_key_flatten(self):
- line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
+ line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \
+ 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
+ # need to sort for assert to work
+ line = ",".join(sorted(line.split(',')))
influxdb = InfluxdbDispatcher(None)
- flattened_data = influxdb._dict_key_flatten(self.data3['benchmark']['data'])
- result = ",".join([k+"="+v for k, v in flattened_data.items()])
+ flattened_data = influxdb._dict_key_flatten(
+ self.data3['benchmark']['data'])
+ result = ",".join(
+ [k + "=" + v for k, v in sorted(flattened_data.items())])
self.assertEqual(result, line)
def test__get_nano_timestamp(self):
influxdb = InfluxdbDispatcher(None)
results = {'benchmark': {'timestamp': '1451461248.925574'}}
- self.assertEqual(influxdb._get_nano_timestamp(results), '1451461248925574144')
+ self.assertEqual(influxdb._get_nano_timestamp(results),
+ '1451461248925574144')
@mock.patch('yardstick.dispatcher.influxdb.time')
def test__get_nano_timestamp_except(self, mock_time):
results = {}
influxdb = InfluxdbDispatcher(None)
mock_time.time.return_value = 1451461248.925574
- self.assertEqual(influxdb._get_nano_timestamp(results), '1451461248925574144')
+ self.assertEqual(influxdb._get_nano_timestamp(results),
+ '1451461248925574144')
+
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/tests/unit/dispatcher/test_influxdb_line_protocol.py b/tests/unit/dispatcher/test_influxdb_line_protocol.py
index 42553c498..debb1994a 100644
--- a/tests/unit/dispatcher/test_influxdb_line_protocol.py
+++ b/tests/unit/dispatcher/test_influxdb_line_protocol.py
@@ -3,6 +3,7 @@
# yardstick comment: this file is a modified copy of
# influxdb-python/influxdb/tests/test_line_protocol.py
+from __future__ import absolute_import
import unittest
from third_party.influxdb.influxdb_line_protocol import make_lines
diff --git a/tests/unit/network_services/__init__.py b/tests/unit/network_services/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/network_services/__init__.py
diff --git a/tests/unit/network_services/collector/__init__.py b/tests/unit/network_services/collector/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/network_services/collector/__init__.py
diff --git a/tests/unit/network_services/collector/test_publisher.py b/tests/unit/network_services/collector/test_publisher.py
new file mode 100644
index 000000000..d1e56e114
--- /dev/null
+++ b/tests/unit/network_services/collector/test_publisher.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Unittest for yardstick.network_services.collector.publisher
+
+from __future__ import absolute_import
+import unittest
+
+from yardstick.network_services.collector import publisher
+
+
+class PublisherTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.test_publisher = publisher.Publisher()
+
+ def test_successful_init(self):
+ pass
+
+ def test_unsuccessful_init(self):
+ pass
+
+ def test_start(self):
+ self.assertIsNone(self.test_publisher.start())
+
+ def test_stop(self):
+ self.assertIsNone(self.test_publisher.stop())
diff --git a/tests/unit/network_services/collector/test_subscriber.py b/tests/unit/network_services/collector/test_subscriber.py
new file mode 100644
index 000000000..373f5dccf
--- /dev/null
+++ b/tests/unit/network_services/collector/test_subscriber.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Unittest for yardstick.network_services.collector.subscriber
+
+from __future__ import absolute_import
+import unittest
+
+from yardstick.network_services.collector import subscriber
+
+
+class CollectorTestCase(unittest.TestCase):
+
+ TRAFFIC_PROFILE = {}
+ VNFS = {}
+
+ def setUp(self):
+ self.test_subscriber = subscriber.Collector(self.TRAFFIC_PROFILE,
+ self.VNFS)
+
+ def test_successful_init(self):
+
+ self.assertEqual(self.test_subscriber.traffic_profile, {})
+ self.assertEqual(self.test_subscriber.service, {})
+
+ def test_unsuccessful_init(self):
+ pass
+
+ def test_start(self):
+ self.assertIsNone(self.test_subscriber.start())
+
+ def test_stop(self):
+ self.assertIsNone(self.test_subscriber.stop())
+
+ def test_get_kpi(self):
+
+ class VnfAprrox(object):
+ def __init__(self):
+ self.result = {}
+ self.name = "vnf__1"
+
+ def collect_kpi(self):
+ self.result = {'pkt_in_up_stream': 100,
+ 'pkt_drop_up_stream': 5,
+ 'pkt_in_down_stream': 50,
+ 'pkt_drop_down_stream': 40}
+ return self.result
+
+ vnf = VnfAprrox()
+ result = self.test_subscriber.get_kpi(vnf)
+
+ self.assertEqual(result["vnf__1"]["pkt_in_up_stream"], 100)
+ self.assertEqual(result["vnf__1"]["pkt_drop_up_stream"], 5)
+ self.assertEqual(result["vnf__1"]["pkt_in_down_stream"], 50)
+ self.assertEqual(result["vnf__1"]["pkt_drop_down_stream"], 40)
diff --git a/tests/unit/orchestrator/test_heat.py b/tests/unit/orchestrator/test_heat.py
new file mode 100644
index 000000000..97314c275
--- /dev/null
+++ b/tests/unit/orchestrator/test_heat.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2017 Intel Corporation
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.orchestrator.heat
+
+import unittest
+import uuid
+
+from yardstick.orchestrator import heat
+
+
+class HeatContextTestCase(unittest.TestCase):
+
+ def test_get_short_key_uuid(self):
+ u = uuid.uuid4()
+ k = heat.get_short_key_uuid(u)
+ self.assertEqual(heat.HEAT_KEY_UUID_LENGTH, len(k))
+ self.assertIn(k, str(u))
diff --git a/tests/unit/test_ssh.py b/tests/unit/test_ssh.py
index 045ac0f1b..1c63c00a3 100644
--- a/tests/unit/test_ssh.py
+++ b/tests/unit/test_ssh.py
@@ -16,12 +16,14 @@
# yardstick comment: this file is a modified copy of
# rally/tests/unit/common/test_sshutils.py
+from __future__ import absolute_import
import os
import socket
import unittest
-from cStringIO import StringIO
+from io import StringIO
import mock
+from oslo_utils import encodeutils
from yardstick import ssh
@@ -274,7 +276,9 @@ class SSHRunTestCase(unittest.TestCase):
fake_stdin.close = mock.Mock(side_effect=close)
self.test_client.run("cmd", stdin=fake_stdin)
call = mock.call
- send_calls = [call("line1"), call("line2"), call("e2")]
+ send_calls = [call(encodeutils.safe_encode("line1", "utf-8")),
+ call(encodeutils.safe_encode("line2", "utf-8")),
+ call(encodeutils.safe_encode("e2", "utf-8"))]
self.assertEqual(send_calls, self.fake_session.send.mock_calls)
@mock.patch("yardstick.ssh.select")
@@ -288,10 +292,10 @@ class SSHRunTestCase(unittest.TestCase):
self.fake_session.exit_status_ready.side_effect = [0, 0, 0, True]
self.fake_session.send_ready.return_value = True
self.fake_session.send.side_effect = len
- fake_stdin = StringIO("line1\nline2\n")
+ fake_stdin = StringIO(u"line1\nline2\n")
self.test_client.run("cmd", stdin=fake_stdin, keep_stdin_open=True)
call = mock.call
- send_calls = [call("line1\nline2\n")]
+ send_calls = [call(encodeutils.safe_encode("line1\nline2\n", "utf-8"))]
self.assertEqual(send_calls, self.fake_session.send.mock_calls)
@mock.patch("yardstick.ssh.select")
@@ -393,5 +397,6 @@ class SSHRunTestCase(unittest.TestCase):
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/third_party/influxdb/influxdb_line_protocol.py b/third_party/influxdb/influxdb_line_protocol.py
index eee982163..12b010c6b 100644
--- a/third_party/influxdb/influxdb_line_protocol.py
+++ b/third_party/influxdb/influxdb_line_protocol.py
@@ -24,9 +24,12 @@
# yardstick comment: this file is a modified copy of
# influxdb-python/influxdb/line_protocol.py
+from __future__ import absolute_import
from __future__ import unicode_literals
+
from copy import copy
+from oslo_utils import encodeutils
from six import binary_type, text_type, integer_types
@@ -64,7 +67,7 @@ def _get_unicode(data, force=False):
Try to return a text aka unicode object from the given data.
"""
if isinstance(data, binary_type):
- return data.decode('utf-8')
+ return encodeutils.safe_decode(data, 'utf-8')
elif data is None:
return ''
elif force:
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..9f2b21537 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
@@ -14,7 +15,7 @@ import yardstick.common.utils as utils
@six.add_metaclass(abc.ABCMeta)
class Context(object):
- '''Class that represents a context in the logical model'''
+ """Class that represents a context in the logical model"""
list = []
def __init__(self):
@@ -26,7 +27,7 @@ class Context(object):
@staticmethod
def get_cls(context_type):
- '''Return class of specified type.'''
+ """Return class of specified type."""
for context in utils.itersubclasses(Context):
if context_type == context.__context_type__:
return context
@@ -40,23 +41,23 @@ class Context(object):
@abc.abstractmethod
def deploy(self):
- '''Deploy context.'''
+ """Deploy context."""
@abc.abstractmethod
def undeploy(self):
- '''Undeploy context.'''
+ """Undeploy context."""
@abc.abstractmethod
def _get_server(self, attr_name):
- '''get server info by name from context
- '''
+ """get server info by name from context
+ """
@staticmethod
def get_server(attr_name):
- '''lookup server info by name from context
+ """lookup server info by name from context
attr_name: either a name for a server created by yardstick or a dict
with attribute name mapping when using external heat templates
- '''
+ """
server = None
for context in Context.list:
server = context._get_server(attr_name)
diff --git a/yardstick/benchmark/contexts/dummy.py b/yardstick/benchmark/contexts/dummy.py
index 6901b2617..f7530035c 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
@@ -16,7 +17,7 @@ LOG = logging.getLogger(__name__)
class DummyContext(Context):
- '''Class that handle dummy info'''
+ """Class that handle dummy info"""
__context_type__ = "Dummy"
@@ -27,11 +28,11 @@ class DummyContext(Context):
pass
def deploy(self):
- '''don't need to deploy'''
+ """don't need to deploy"""
pass
def undeploy(self):
- '''don't need to undeploy'''
+ """don't need to undeploy"""
pass
def _get_server(self, attr_name):
diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py
index 166ca40c8..0346efcf4 100644
--- a/yardstick/benchmark/contexts/heat.py
+++ b/yardstick/benchmark/contexts/heat.py
@@ -7,23 +7,31 @@
# 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
+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'''
+ """Class that represents a context in the logical model"""
__context_type__ = "Heat"
@@ -44,12 +52,13 @@ class HeatContext(Context):
# generate an uuid to identify yardstick_key
# the first 8 digits of the uuid will be used
self.key_uuid = uuid.uuid4()
- self.key_filename = YARDSTICK_ROOT_PATH + \
- 'yardstick/resources/files/yardstick_key-' + str(self.key_uuid)[:8]
+ self.key_filename = ''.join(
+ [YARDSTICK_ROOT_PATH, 'yardstick/resources/files/yardstick_key-',
+ get_short_key_uuid(self.key_uuid)])
super(self.__class__, self).__init__()
def init(self, attrs):
- '''initializes itself from the supplied arguments'''
+ """initializes itself from the supplied arguments"""
self.name = attrs["name"]
if "user" in attrs:
@@ -92,21 +101,21 @@ class HeatContext(Context):
@property
def image(self):
- '''returns application's default image name'''
+ """returns application's default image name"""
return self._image
@property
def flavor(self):
- '''returns application's default flavor name'''
+ """returns application's default flavor name"""
return self._flavor
@property
def user(self):
- '''return login user name corresponding to image'''
+ """return login user name corresponding to image"""
return self._user
def _add_resources_to_template(self, template):
- '''add to the template the resources represented by this context'''
+ """add to the template the resources represented by this context"""
template.add_keypair(self.keypair_name, self.key_uuid)
template.add_security_group(self.secgroup_name)
@@ -191,8 +200,8 @@ class HeatContext(Context):
server.add_to_template(template, self.networks, {})
def deploy(self):
- '''deploys template into a stack using cloud'''
- print "Deploying context '%s'" % self.name
+ """deploys template into a stack using cloud"""
+ print("Deploying context '%s'" % self.name)
heat_template = HeatTemplate(self.name, self.template_file,
self.heat_parameters)
@@ -213,40 +222,40 @@ 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'''
+ """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
+ """lookup server info by name from context
attr_name: either a name for a server created by yardstick or a dict
with attribute name mapping when using external heat templates
- '''
+ """
key_filename = pkg_resources.resource_filename(
- 'yardstick.resources', 'files/yardstick_key-{:.{width}}'.format(
- self.key_uuid, width=8))
+ '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..636abfa35 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
+ """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
@@ -27,15 +30,15 @@ class Object(object):
@property
def dn(self):
- '''returns distinguished name for object'''
+ """returns distinguished name for object"""
return self.name + "." + self._context.name
class PlacementGroup(Object):
- '''Class that represents a placement group in the logical model
+ """Class that represents a placement group in the logical model
Concept comes from the OVF specification. Policy should be one of
"availability" or "affinity (there are more but they are not supported)"
- '''
+ """
map = {}
def __init__(self, name, context, policy):
@@ -60,7 +63,8 @@ class PlacementGroup(Object):
class Router(Object):
- '''Class that represents a router in the logical model'''
+ """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)
@@ -70,7 +74,7 @@ class Router(Object):
class Network(Object):
- '''Class that represents a network in the logical model'''
+ """Class that represents a network in the logical model"""
list = []
def __init__(self, name, context, attrs):
@@ -87,22 +91,22 @@ class Network(Object):
Network.list.append(self)
def has_route_to(self, network_name):
- '''determines if this network has a route to the named network'''
+ """determines if this network has a route to the named network"""
if self.router and self.router.external_gateway_info == network_name:
return True
return False
@staticmethod
def find_by_route_to(external_network):
- '''finds a network that has a route to the specified network'''
+ """finds a network that has a route to the specified network"""
for network in Network.list:
if network.has_route_to(external_network):
return network
@staticmethod
def find_external_network():
- '''return the name of an external network some network in this
- context has a route to'''
+ """return the name of an external network some network in this
+ context has a route to"""
for network in Network.list:
if network.router:
return network.router.external_gateway_info
@@ -110,7 +114,7 @@ class Network(Object):
class Server(Object):
- '''Class that represents a server in the logical model'''
+ """Class that represents a server in the logical model"""
list = []
def __init__(self, name, context, attrs):
@@ -167,7 +171,7 @@ class Server(Object):
@property
def image(self):
- '''returns a server's image name'''
+ """returns a server's image name"""
if self._image:
return self._image
else:
@@ -175,14 +179,14 @@ class Server(Object):
@property
def flavor(self):
- '''returns a server's flavor name'''
+ """returns a server's flavor name"""
if self._flavor:
return self._flavor
else:
return self._context.flavor
def _add_instance(self, template, server_name, networks, scheduler_hints):
- '''adds to the template one server and corresponding resources'''
+ """adds to the template one server and corresponding resources"""
port_name_list = []
for network in networks:
port_name = server_name + "-" + network.name + "-port"
@@ -215,7 +219,7 @@ class Server(Object):
scheduler_hints=scheduler_hints)
def add_to_template(self, template, networks, scheduler_hints=None):
- '''adds to the template one or more servers (instances)'''
+ """adds to the template one or more servers (instances)"""
if self.instances == 1:
server_name = self.stack_name
self._add_instance(template, server_name, networks,
@@ -229,9 +233,9 @@ class Server(Object):
def update_scheduler_hints(scheduler_hints, added_servers, placement_group):
- ''' update scheduler hints from server's placement configuration
+ """ update scheduler hints from server's placement configuration
TODO: this code is openstack specific and should move somewhere else
- '''
+ """
if placement_group.policy == "affinity":
if "same_host" in scheduler_hints:
host_list = scheduler_hints["same_host"]
diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py
index 78bce8259..9242e2727 100644
--- a/yardstick/benchmark/contexts/node.py
+++ b/yardstick/benchmark/contexts/node.py
@@ -7,10 +7,12 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import sys
+from __future__ import absolute_import
+import logging
+import errno
import os
+import collections
import yaml
-import logging
from yardstick.benchmark.contexts.base import Context
from yardstick.definitions import YARDSTICK_ROOT_PATH
@@ -19,7 +21,7 @@ LOG = logging.getLogger(__name__)
class NodeContext(Context):
- '''Class that handle nodes info'''
+ """Class that handle nodes info"""
__context_type__ = "Node"
@@ -32,62 +34,75 @@ class NodeContext(Context):
self.baremetals = []
super(self.__class__, self).__init__()
+ def read_config_file(self):
+ """Read from config file"""
+
+ with open(self.file_path) as stream:
+ LOG.info("Parsing pod file: %s", self.file_path)
+ cfg = yaml.load(stream)
+ return cfg
+
def init(self, attrs):
- '''initializes itself from the supplied arguments'''
+ """initializes itself from the supplied arguments"""
self.name = attrs["name"]
self.file_path = attrs.get("file", "pod.yaml")
- if not os.path.exists(self.file_path):
- self.file_path = os.path.join(YARDSTICK_ROOT_PATH, self.file_path)
-
- LOG.info("Parsing pod file: %s", self.file_path)
try:
- with open(self.file_path) as stream:
- cfg = yaml.load(stream)
+ cfg = self.read_config_file()
except IOError as ioerror:
- sys.exit(ioerror)
+ if ioerror.errno == errno.ENOENT:
+ self.file_path = \
+ os.path.join(YARDSTICK_ROOT_PATH, self.file_path)
+ cfg = self.read_config_file()
+ else:
+ raise
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)
LOG.debug("BareMetals: %r", self.baremetals)
def deploy(self):
- '''don't need to deploy'''
+ """don't need to deploy"""
pass
def undeploy(self):
- '''don't need to undeploy'''
+ """don't need to undeploy"""
pass
def _get_server(self, attr_name):
- '''lookup server info by name from context
+ """lookup server info by name from context
attr_name: a name for a server listed in nodes config file
- '''
- if type(attr_name) is dict:
+ """
+ if isinstance(attr_name, collections.Mapping):
return None
if self.name != attr_name.split(".")[1]:
return None
node_name = attr_name.split(".")[0]
- nodes = [n for n in self.nodes
- if n["name"] == node_name]
- if len(nodes) == 0:
+ matching_nodes = (n for n in self.nodes if n["name"] == node_name)
+
+ try:
+ # A clone is created in order to avoid affecting the
+ # original one.
+ node = dict(next(matching_nodes))
+ except StopIteration:
return None
- elif len(nodes) > 1:
- LOG.error("Duplicate nodes!!!")
- LOG.error("Nodes: %r", nodes)
- sys.exit(-1)
-
- # A clone is created in order to avoid affecting the
- # original one.
- node = dict(nodes[0])
+
+ try:
+ duplicate = next(matching_nodes)
+ except StopIteration:
+ pass
+ else:
+ raise ValueError("Duplicate nodes!!! Nodes: %s %s",
+ (matching_nodes, duplicate))
+
node["name"] = attr_name
return node
diff --git a/yardstick/benchmark/contexts/standalone.py b/yardstick/benchmark/contexts/standalone.py
new file mode 100644
index 000000000..c1d963f50
--- /dev/null
+++ b/yardstick/benchmark/contexts/standalone.py
@@ -0,0 +1,116 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""This module handle non managed standalone virtualization node."""
+
+from __future__ import absolute_import
+import logging
+import errno
+import collections
+import yaml
+
+from yardstick.benchmark.contexts.base import Context
+from yardstick.definitions import YARDSTICK_ROOT_PATH
+
+LOG = logging.getLogger(__name__)
+
+
+class StandaloneContext(Context):
+ """ This class handles standalone nodes - VM running on Non-Managed NFVi
+ Configuration: vswitch, ovs, ovs-dpdk, sr-iov, linuxbridge
+ """
+
+ __context_type__ = "Standalone"
+
+ def __init__(self):
+ self.name = None
+ self.file_path = None
+ self.nodes = []
+ self.nfvi_node = []
+ super(self.__class__, self).__init__()
+
+ def read_config_file(self):
+ """Read from config file"""
+
+ with open(self.file_path) as stream:
+ LOG.info("Parsing pod file: %s", self.file_path)
+ cfg = yaml.load(stream)
+ return cfg
+
+ def init(self, attrs):
+ """initializes itself from the supplied arguments"""
+
+ self.name = attrs["name"]
+ self.file_path = attrs.get("file", "pod.yaml")
+ LOG.info("Parsing pod file: %s", self.file_path)
+
+ try:
+ cfg = self.read_config_file()
+ except IOError as ioerror:
+ if ioerror.errno == errno.ENOENT:
+ self.file_path = YARDSTICK_ROOT_PATH + self.file_path
+ cfg = self.read_config_file()
+ else:
+ raise
+
+ self.nodes.extend(cfg["nodes"])
+ self.nfvi_node.extend([node for node in cfg["nodes"]
+ if node["role"] == "nfvi_node"])
+ LOG.debug("Nodes: %r", self.nodes)
+ LOG.debug("NFVi Node: %r", self.nfvi_node)
+
+ def deploy(self):
+ """don't need to deploy"""
+
+ # Todo: NFVi deploy (sriov, vswitch, ovs etc) based on the config.
+ pass
+
+ def undeploy(self):
+ """don't need to undeploy"""
+
+ # Todo: NFVi undeploy (sriov, vswitch, ovs etc) based on the config.
+ pass
+
+ def _get_server(self, attr_name):
+ """lookup server info by name from context
+
+ Keyword arguments:
+ attr_name -- A name for a server listed in nodes config file
+ """
+
+ if isinstance(attr_name, collections.Mapping):
+ return None
+
+ if self.name.split("-")[0] != attr_name.split(".")[1]:
+ return None
+
+ node_name = attr_name.split(".")[0]
+ matching_nodes = (n for n in self.nodes if n["name"] == node_name)
+
+ try:
+ # A clone is created in order to avoid affecting the
+ # original one.
+ node = dict(next(matching_nodes))
+ except StopIteration:
+ return None
+
+ try:
+ duplicate = next(matching_nodes)
+ except StopIteration:
+ pass
+ else:
+ raise ValueError("Duplicate nodes!!! Nodes: %s %s",
+ (matching_nodes, duplicate))
+
+ node["name"] = attr_name
+ return node
diff --git a/yardstick/benchmark/core/__init__.py b/yardstick/benchmark/core/__init__.py
index 12c83f87e..161e448cc 100644
--- a/yardstick/benchmark/core/__init__.py
+++ b/yardstick/benchmark/core/__init__.py
@@ -32,7 +32,7 @@ class Param(object):
def print_hbar(barlen):
- '''print to stdout a horizontal bar'''
+ """print to stdout a horizontal bar"""
print("+"),
print("-" * barlen),
print("+")
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..b9c22cbc9 100644
--- a/yardstick/benchmark/core/runner.py
+++ b/yardstick/benchmark/core/runner.py
@@ -9,28 +9,30 @@
""" 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
class Runners(object):
- '''Runner commands.
+ """Runner commands.
Set of commands to discover and display runner types.
- '''
+ """
def list_all(self, args):
- '''List existing runner types'''
+ """List existing runner types"""
types = Runner.get_types()
print_hbar(78)
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'''
+ """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..a9d933faf 100644
--- a/yardstick/benchmark/core/scenario.py
+++ b/yardstick/benchmark/core/scenario.py
@@ -9,18 +9,20 @@
""" 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
class Scenarios(object):
- '''Scenario commands.
+ """Scenario commands.
Set of commands to discover and display scenario types.
- '''
+ """
def list_all(self, args):
- '''List existing scenario types'''
+ """List existing scenario types"""
types = Scenario.get_types()
print_hbar(78)
print("| %-16s | %-60s" % ("Type", "Description"))
@@ -31,6 +33,6 @@ class Scenarios(object):
print_hbar(78)
def show(self, args):
- '''Show details of a specific scenario type'''
+ """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..6cfec7b13 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
@@ -32,13 +34,13 @@ LOG = logging.getLogger(__name__)
class Task(object): # pragma: no cover
- '''Task commands.
+ """Task commands.
Set of commands to manage benchmark tasks.
- '''
+ """
def start(self, args, **kwargs):
- '''Start a benchmark scenario.'''
+ """Start a benchmark scenario."""
atexit.register(atexit_handler)
@@ -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,17 +98,17 @@ 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'''
+ """Deploys context and calls runners"""
for context in Context.list:
context.deploy()
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,14 +144,15 @@ 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 !?
class TaskParser(object): # pragma: no cover
- '''Parser for task config files in yaml format'''
+ """Parser for task config files in yaml format"""
+
def __init__(self, path):
self.path = path
@@ -178,8 +181,8 @@ class TaskParser(object): # pragma: no cover
return task_args, task_args_fnames
def parse_suite(self):
- '''parse the suite file and return a list of task config file paths
- and lists of optional parameters if present'''
+ """parse the suite file and return a list of task config file paths
+ and lists of optional parameters if present"""
LOG.info("\nParsing suite file:%s", self.path)
try:
@@ -223,8 +226,8 @@ class TaskParser(object): # pragma: no cover
return valid_task_files, valid_task_args, valid_task_args_fnames
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
+ """parses the task file and return an context and scenario instances"""
+ 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:
@@ -291,7 +294,8 @@ class TaskParser(object): # pragma: no cover
change_server_name(scenario, name_suffix)
try:
- change_server_name(scenario['nodes'], name_suffix)
+ for node in scenario['nodes']:
+ scenario['nodes'][node] += name_suffix
except KeyError:
pass
@@ -299,14 +303,14 @@ class TaskParser(object): # pragma: no cover
return cfg["scenarios"], run_in_parallel, meet_precondition
def _check_schema(self, cfg_schema, schema_type):
- '''Check if config file is using the correct schema type'''
+ """Check if config file is using the correct schema type"""
if cfg_schema != "yardstick:" + schema_type + ":0.1":
sys.exit("error: file %s has unknown schema %s" % (self.path,
cfg_schema))
def _check_precondition(self, cfg):
- '''Check if the envrionment meet the preconditon'''
+ """Check if the envrionment meet the preconditon"""
if "precondition" in cfg:
precondition = cfg["precondition"]
@@ -339,31 +343,31 @@ class TaskParser(object): # pragma: no cover
def atexit_handler():
- '''handler for process termination'''
+ """handler for process termination"""
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()
def is_ip_addr(addr):
- '''check if string addr is an IP address'''
+ """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
def _is_same_heat_context(host_attr, target_attr):
- '''check if two servers are in the same heat context
+ """check if two servers are in the same heat context
host_attr: either a name for a server created by yardstick or a dict
with attribute name mapping when using external heat templates
target_attr: either a name for a server created by yardstick or a dict
with attribute name mapping when using external heat templates
- '''
+ """
host = None
target = None
for context in Context.list:
@@ -393,7 +397,7 @@ def _is_background_scenario(scenario):
def run_one_scenario(scenario_cfg, output_file):
- '''run one scenario using context'''
+ """run one scenario using context"""
runner_cfg = scenario_cfg["runner"]
runner_cfg['output_filename'] = output_file
@@ -434,14 +438,14 @@ 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
def parse_nodes_with_context(scenario_cfg):
- '''paras the 'nodes' fields in scenario '''
+ """paras the 'nodes' fields in scenario """
nodes = scenario_cfg["nodes"]
nodes_cfg = {}
@@ -452,7 +456,7 @@ def parse_nodes_with_context(scenario_cfg):
def runner_join(runner):
- '''join (wait for) a runner, exit process at runner failure'''
+ """join (wait for) a runner, exit process at runner failure"""
status = runner.join()
base_runner.Runner.release(runner)
if status != 0:
@@ -460,7 +464,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 +474,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..92198bd91 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
@@ -18,21 +20,22 @@ from yardstick.definitions import YARDSTICK_ROOT_PATH
class Testcase(object):
- '''Testcase commands.
+ """Testcase commands.
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 = []
def list_all(self, args):
- '''List existing test cases'''
+ """List existing test cases"""
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()
@@ -45,18 +48,18 @@ class Testcase(object):
return True
def show(self, args):
- '''Show details of a specific test case'''
+ """Show details of a specific test case"""
testcase_name = args.casename[0]
testcase_path = self.test_case_path + testcase_name + ".yaml"
try:
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 = \
@@ -101,12 +104,12 @@ class Testcase(object):
return description, installer_type, deploy_scenarios
def _format_print(self, testcase_list):
- '''format output'''
+ """format output"""
print_hbar(88)
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..d5605f755 100755
--- a/yardstick/benchmark/runners/arithmetic.py
+++ b/yardstick/benchmark/runners/arithmetic.py
@@ -16,20 +16,25 @@
# yardstick comment: this is a modified copy of
# rally/rally/benchmark/runners/constant.py
-'''A runner that every run arithmetically steps specified input value(s) to
+"""A runner that every run arithmetically steps specified input value(s) to
the scenario. This just means step value(s) is added to the previous value(s).
It is possible to combine several named input values and run with those either
as nested for loops or combine each i:th index of each "input value list"
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:
@@ -142,7 +147,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
class ArithmeticRunner(base.Runner):
- '''Run a scenario arithmetically stepping input value(s)
+ """Run a scenario arithmetically stepping input value(s)
Parameters
interval - time to wait between each scenario invocation
@@ -175,7 +180,7 @@ class ArithmeticRunner(base.Runner):
default: none
-
name - and so on......
- '''
+ """
__execution_type__ = 'Arithmetic'
diff --git a/yardstick/benchmark/runners/base.py b/yardstick/benchmark/runners/base.py
index 8f3f75fa1..bf1a71cab 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
@@ -35,10 +36,10 @@ CONF = cfg.CONF
def _output_serializer_main(filename, queue):
- '''entrypoint for the singleton subprocess writing to outfile
+ """entrypoint for the singleton subprocess writing to outfile
Use of this process enables multiple instances of a scenario without
messing up the output file.
- '''
+ """
config = {}
config["type"] = CONF.dispatcher.capitalize()
config["file_path"] = filename
@@ -55,7 +56,7 @@ def _output_serializer_main(filename, queue):
def _execute_shell_command(command):
- '''execute shell script with error handling'''
+ """execute shell script with error handling"""
exitcode = 0
output = []
try:
@@ -70,7 +71,7 @@ def _execute_shell_command(command):
def _single_action(seconds, command, queue):
- '''entrypoint for the single action process'''
+ """entrypoint for the single action process"""
log.debug("single action, fires after %d seconds (from now)", seconds)
time.sleep(seconds)
log.debug("single action: executing command: '%s'", command)
@@ -84,7 +85,7 @@ def _single_action(seconds, command, queue):
def _periodic_action(interval, command, queue):
- '''entrypoint for the periodic action process'''
+ """entrypoint for the periodic action process"""
log.debug("periodic action, fires every: %d seconds", interval)
time_spent = 0
while True:
@@ -107,7 +108,7 @@ class Runner(object):
@staticmethod
def get_cls(runner_type):
- '''return class of specified type'''
+ """return class of specified type"""
for runner in utils.itersubclasses(Runner):
if runner_type == runner.__execution_type__:
return runner
@@ -115,7 +116,7 @@ class Runner(object):
@staticmethod
def get_types():
- '''return a list of known runner type (class) names'''
+ """return a list of known runner type (class) names"""
types = []
for runner in utils.itersubclasses(Runner):
types.append(runner)
@@ -140,7 +141,7 @@ class Runner(object):
@staticmethod
def release_dump_process():
- '''Release the dumper process'''
+ """Release the dumper process"""
log.debug("Stopping dump process")
if Runner.dump_process:
Runner.queue.put('_TERMINATE_')
@@ -149,7 +150,7 @@ class Runner(object):
@staticmethod
def release(runner):
- '''Release the runner'''
+ """Release the runner"""
if runner in Runner.runners:
Runner.runners.remove(runner)
@@ -159,13 +160,13 @@ class Runner(object):
@staticmethod
def terminate(runner):
- '''Terminate the runner'''
+ """Terminate the runner"""
if runner.process and runner.process.is_alive():
runner.process.terminate()
@staticmethod
def terminate_all():
- '''Terminate all runners (subprocesses)'''
+ """Terminate all runners (subprocesses)"""
log.debug("Terminating all runners")
# release dumper process as some errors before any runner is created
@@ -193,7 +194,7 @@ class Runner(object):
Runner.runners.append(self)
def run_post_stop_action(self):
- '''run a potentially configured post-stop action'''
+ """run a potentially configured post-stop action"""
if "post-stop-action" in self.config:
command = self.config["post-stop-action"]["command"]
log.debug("post stop action: command: '%s'", command)
@@ -249,7 +250,7 @@ class Runner(object):
self._run_benchmark(cls, "run", scenario_cfg, context_cfg)
def abort(self):
- '''Abort the execution of a scenario'''
+ """Abort the execution of a scenario"""
self.aborted.set()
def join(self, timeout=None):
diff --git a/yardstick/benchmark/runners/duration.py b/yardstick/benchmark/runners/duration.py
index 1412c0caa..772983cfd 100644
--- a/yardstick/benchmark/runners/duration.py
+++ b/yardstick/benchmark/runners/duration.py
@@ -16,9 +16,10 @@
# yardstick comment: this is a modified copy of
# rally/rally/benchmark/runners/constant.py
-'''A runner that runs a specific time before it returns
-'''
+"""A runner that runs a specific time before it returns
+"""
+from __future__ import absolute_import
import os
import multiprocessing
import logging
@@ -105,7 +106,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
class DurationRunner(base.Runner):
- '''Run a scenario for a certain amount of time
+ """Run a scenario for a certain amount of time
If the scenario ends before the time has elapsed, it will be started again.
@@ -118,7 +119,7 @@ If the scenario ends before the time has elapsed, it will be started again.
type: int
unit: seconds
default: 1 sec
- '''
+ """
__execution_type__ = 'Duration'
def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
diff --git a/yardstick/benchmark/runners/iteration.py b/yardstick/benchmark/runners/iteration.py
index 3a839b65f..c2376af48 100644
--- a/yardstick/benchmark/runners/iteration.py
+++ b/yardstick/benchmark/runners/iteration.py
@@ -16,9 +16,10 @@
# yardstick comment: this is a modified copy of
# rally/rally/benchmark/runners/constant.py
-'''A runner that runs a configurable number of times before it returns
-'''
+"""A runner that runs a configurable number of times before it returns
+"""
+from __future__ import absolute_import
import os
import multiprocessing
import logging
@@ -109,7 +110,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
class IterationRunner(base.Runner):
- '''Run a scenario for a configurable number of times
+ """Run a scenario for a configurable number of times
If the scenario ends before the time has elapsed, it will be started again.
@@ -122,7 +123,7 @@ If the scenario ends before the time has elapsed, it will be started again.
type: int
unit: seconds
default: 1 sec
- '''
+ """
__execution_type__ = 'Iteration'
def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
diff --git a/yardstick/benchmark/runners/sequence.py b/yardstick/benchmark/runners/sequence.py
index 3b06e2a36..af87c006e 100644
--- a/yardstick/benchmark/runners/sequence.py
+++ b/yardstick/benchmark/runners/sequence.py
@@ -16,10 +16,11 @@
# yardstick comment: this is a modified copy of
# rally/rally/benchmark/runners/constant.py
-'''A runner that every run changes a specified input value to the scenario.
+"""A runner that every run changes a specified input value to the scenario.
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
@@ -113,7 +114,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
class SequenceRunner(base.Runner):
- '''Run a scenario by changing an input value defined in a list
+ """Run a scenario by changing an input value defined in a list
Parameters
interval - time to wait between each scenario invocation
@@ -128,7 +129,7 @@ class SequenceRunner(base.Runner):
type: [int]
unit: na
default: none
- '''
+ """
__execution_type__ = 'Sequence'
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..1d632799d 100644
--- a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
+++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
@@ -6,17 +6,20 @@
# 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__)
def _execute_shell_command(command, stdin=None):
- '''execute shell script with error handling'''
+ """execute shell script with error handling"""
exitcode = 0
output = []
try:
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..ca2324055 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
@@ -60,7 +61,7 @@ class BaseAttacker(object):
@staticmethod
def get_attacker_cls(attacker_cfg):
- '''return attacker instance of specified type'''
+ """return attacker instance of specified type"""
attacker_type = attacker_cfg['fault_type']
for attacker_cls in utils.itersubclasses(BaseAttacker):
if attacker_type == attacker_cls.__attacker_type__:
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..3062037ee 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 = []
@@ -75,7 +77,7 @@ class BaseMonitor(multiprocessing.Process):
@staticmethod
def get_monitor_cls(monitor_type):
- '''return monitor class of specified type'''
+ """return monitor class of specified type"""
for monitor in utils.itersubclasses(BaseMonitor):
if monitor_type == monitor.__monitor_type__:
@@ -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..aae2daa86 100644
--- a/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py
+++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py
@@ -6,17 +6,19 @@
# 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__)
def _execute_shell_command(command):
- '''execute shell script with error handling'''
+ """execute shell script with error handling"""
exitcode = 0
output = []
try:
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..be286b8fd 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
@@ -60,7 +61,7 @@ class BaseOperation(object):
@staticmethod
def get_operation_cls(type):
- '''return operation instance of specified type'''
+ """return operation instance of specified type"""
operation_type = type
for operation_cls in utils.itersubclasses(BaseOperation):
if operation_type == operation_cls.__operation__type__:
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..1ccd05844 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
@@ -68,7 +69,7 @@ class BaseResultChecker(object):
@staticmethod
def get_resultchecker_cls(type):
- '''return resultchecker instance of specified type'''
+ """return resultchecker instance of specified type"""
resultchecker_type = type
for checker_cls in utils.itersubclasses(BaseResultChecker):
if resultchecker_type == checker_cls.__result_checker__type__:
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..e82e69b7d 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
@@ -28,7 +30,7 @@ class ServiceHA(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
nodes = self.context_cfg.get("nodes", None)
if nodes is None:
LOG.error("the nodes info is none")
@@ -75,13 +77,13 @@ class ServiceHA(base.Scenario):
return
def teardown(self):
- '''scenario teardown'''
+ """scenario teardown"""
for attacker in self.attackers:
attacker.recover()
def _test(): # pragma: no cover
- '''internal test function'''
+ """internal test function"""
host = {
"ip": "10.20.0.5",
"user": "root",
@@ -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..5d3c36c38 100644
--- a/yardstick/benchmark/scenarios/base.py
+++ b/yardstick/benchmark/scenarios/base.py
@@ -19,26 +19,27 @@
""" Scenario base class
"""
+from __future__ import absolute_import
import yardstick.common.utils as utils
class Scenario(object):
def setup(self):
- ''' default impl for scenario setup '''
+ """ default impl for scenario setup """
pass
def run(self, args):
- ''' catcher for not implemented run methods in subclasses '''
+ """ catcher for not implemented run methods in subclasses """
raise RuntimeError("run method not implemented")
def teardown(self):
- ''' default impl for scenario teardown '''
+ """ default impl for scenario teardown """
pass
@staticmethod
def get_types():
- '''return a list of known runner type (class) names'''
+ """return a list of known runner type (class) names"""
scenarios = []
for scenario in utils.itersubclasses(Scenario):
scenarios.append(scenario)
@@ -46,7 +47,7 @@ class Scenario(object):
@staticmethod
def get_cls(scenario_type):
- '''return class of specified type'''
+ """return class of specified type"""
for scenario in utils.itersubclasses(Scenario):
if scenario_type == scenario.__scenario_type__:
return scenario
diff --git a/yardstick/benchmark/scenarios/compute/cachestat.py b/yardstick/benchmark/scenarios/compute/cachestat.py
index 20786ff61..b4c3463e5 100644
--- a/yardstick/benchmark/scenarios/compute/cachestat.py
+++ b/yardstick/benchmark/scenarios/compute/cachestat.py
@@ -9,18 +9,20 @@
"""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__)
class CACHEstat(base.Scenario):
- '''Collect cache statistics.
+ """Collect cache statistics.
This scenario reads system cache hit/miss ratio and other statistics on
a Linux host.
@@ -56,7 +58,7 @@ class CACHEstat(base.Scenario):
some error margin depending on unusual workload types.
REQUIREMENTS: CONFIG_FUNCTION_PROFILER, awk.
- '''
+ """
__scenario_type__ = "CACHEstat"
TARGET_SCRIPT = "cache_stat.bash"
@@ -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..ae1d37324 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
@@ -137,7 +141,7 @@ class Cyclictest(base.Scenario):
self._connect_guest()
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
setup_options = self.scenario_cfg["setup_options"]
host_setup_seqs = setup_options["host_setup_seqs"]
guest_setup_seqs = setup_options["guest_setup_seqs"]
@@ -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 = ""
@@ -201,7 +205,7 @@ class Cyclictest(base.Scenario):
def _test(): # pragma: no cover
- '''internal test function'''
+ """internal test function"""
key_filename = pkg_resources.resource_filename("yardstick.resources",
"files/yardstick_key")
ctx = {
@@ -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..59d177586 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
@@ -24,7 +25,7 @@ class Dummy(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.setup_done = True
def run(self, result):
diff --git a/yardstick/benchmark/scenarios/networking/iperf3.py b/yardstick/benchmark/scenarios/networking/iperf3.py
index 13fa0155b..4d4c7e7ee 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"]
@@ -162,7 +167,7 @@ For more info see http://software.es.net/iperf
def _test():
- '''internal test function'''
+ """internal test function"""
key_filename = pkg_resources.resource_filename('yardstick.resources',
'files/yardstick_key')
ctx = {
@@ -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..d0528826f 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
@@ -56,7 +60,7 @@ class Netperf(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.target_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Netperf.TARGET_SCRIPT)
@@ -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)
@@ -146,7 +150,7 @@ class Netperf(base.Scenario):
def _test():
- '''internal test function'''
+ """internal test function"""
key_filename = pkg_resources.resource_filename("yardstick.resources",
"files/yardstick_key")
ctx = {
@@ -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..fd9fa0a50 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
@@ -57,7 +61,7 @@ class NetperfNode(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.target_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
NetperfNode.TARGET_SCRIPT)
@@ -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)
@@ -168,13 +172,13 @@ class NetperfNode(base.Scenario):
(mean_latency, sla_max_mean_latency)
def teardown(self):
- '''remove netperf from nodes after test'''
+ """remove netperf from nodes after test"""
self.server.execute("sudo bash netperf_remove.sh")
self.client.execute("sudo bash netperf_remove.sh")
def _test(): # pragma: no cover
- '''internal test function'''
+ """internal test function"""
ctx = {
"host": {
"ip": "192.168.10.10",
@@ -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..d20814697 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
@@ -100,7 +102,7 @@ class Ping(base.Scenario):
def _test(): # pragma: no cover
- '''internal test function'''
+ """internal test function"""
key_filename = pkg_resources.resource_filename("yardstick.resources",
"files/yardstick_key")
ctx = {
@@ -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..142a35664 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
@@ -83,7 +84,7 @@ class Ping6(base.Scenario): # pragma: no cover
return None
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.setup_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.SETUP_SCRIPT)
diff --git a/yardstick/benchmark/scenarios/networking/pktgen.py b/yardstick/benchmark/scenarios/networking/pktgen.py
index e2df706a2..b61337a70 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
@@ -43,7 +47,7 @@ class Pktgen(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.target_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Pktgen.TARGET_SCRIPT)
@@ -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()
@@ -144,7 +148,7 @@ class Pktgen(base.Scenario):
def _test():
- '''internal test function'''
+ """internal test function"""
key_filename = pkg_resources.resource_filename('yardstick.resources',
'files/yardstick_key')
ctx = {
@@ -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..0b70629f8 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
@@ -36,7 +37,7 @@ class PktgenDPDKLatency(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.pktgen_dpdk_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
PktgenDPDKLatency.PKTGEN_DPDK_SCRIPT)
diff --git a/yardstick/benchmark/scenarios/networking/sfc.py b/yardstick/benchmark/scenarios/networking/sfc.py
index 1bd99b957..c558e3512 100644
--- a/yardstick/benchmark/scenarios/networking/sfc.py
+++ b/yardstick/benchmark/scenarios/networking/sfc.py
@@ -1,15 +1,20 @@
-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__)
class Sfc(base.Scenario): # pragma: no cover
- ''' SFC scenario class '''
+ """ SFC scenario class """
__scenario_type__ = "sfc"
@@ -26,7 +31,7 @@ class Sfc(base.Scenario): # pragma: no cover
self.teardown_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.tacker_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Sfc.TACKER_SCRIPT)
@@ -35,7 +40,7 @@ class Sfc(base.Scenario): # pragma: no cover
'yardstick.benchmark.scenarios.networking',
Sfc.SERVER_SCRIPT)
- ''' calling Tacker to instantiate VNFs and Service Chains '''
+ """ calling Tacker to instantiate VNFs and Service Chains """
cmd_tacker = "%s" % (self.tacker_script)
subprocess.call(cmd_tacker, shell=True)
@@ -45,7 +50,7 @@ class Sfc(base.Scenario): # pragma: no cover
target_pwd = target.get('password', 'opnfv')
target_ip = target.get('ip', None)
- ''' webserver start automatically during the vm boot '''
+ """ webserver start automatically during the vm boot """
LOG.info("user:%s, target:%s", target_user, target_ip)
self.server = ssh.SSH(target_user, target_ip, password=target_pwd,
port=target_ssh_port)
@@ -97,7 +102,7 @@ class Sfc(base.Scenario): # pragma: no cover
self.setup_done = True
def run(self, result):
- ''' Creating client and server VMs to perform the test'''
+ """ Creating client and server VMs to perform the test"""
host = self.context_cfg['host']
host_user = host.get('user', 'root')
ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
@@ -144,7 +149,7 @@ class Sfc(base.Scenario): # pragma: no cover
'yardstick.benchmark.scenarios.networking',
Sfc.TACKER_CHANGECLASSI)
- ''' calling Tacker to change the classifier '''
+ """ calling Tacker to change the classifier """
cmd_tacker = "%s" % (self.tacker_classi)
subprocess.call(cmd_tacker, shell=True)
@@ -180,7 +185,7 @@ class Sfc(base.Scenario): # pragma: no cover
" :) \n" + '\033[0m')
def teardown(self):
- ''' for scenario teardown remove tacker VNFs, chains and classifiers'''
+ """ for scenario teardown remove tacker VNFs, chains and classifiers"""
self.teardown_script = pkg_resources.resource_filename(
"yardstick.benchmark.scenarios.networking",
Sfc.TEARDOWN_SCRIPT)
@@ -188,7 +193,7 @@ class Sfc(base.Scenario): # pragma: no cover
self.teardown_done = True
-'''def _test(): # pragma: no cover
+"""def _test(): # pragma: no cover
internal test function
logger = logging.getLogger("Sfc Yardstick")
@@ -199,8 +204,8 @@ 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
- _test()'''
+ _test()"""
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..f2c2ea9b8 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
@@ -111,7 +112,7 @@ class Vsperf(base.Scenario):
None)
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
vsperf = self.context_cfg['host']
vsperf_user = vsperf.get('user', 'ubuntu')
vsperf_ssh_port = vsperf.get('ssh_port', ssh.DEFAULT_PORT)
@@ -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..ac57c929c 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
@@ -28,7 +29,7 @@ class VtcInstantiationValidation(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.options = self.scenario_cfg['options']
self.setup_done = True
@@ -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..d3a9a9a02 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
@@ -28,7 +29,7 @@ class VtcInstantiationValidationNoisy(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.options = self.scenario_cfg['options']
self.setup_done = True
@@ -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..b9cb0b1e7 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
@@ -28,7 +29,7 @@ class VtcThroughput(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.options = self.scenario_cfg['options']
self.setup_done = True
@@ -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..38ebc4c42 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
@@ -28,7 +29,7 @@ class VtcThroughputNoisy(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.options = self.scenario_cfg['options']
self.setup_done = True
@@ -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..eb16833e5 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,12 +63,12 @@ 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"
def teardown(self):
- ''' for scenario teardown remove parser and pyang '''
+ """ for scenario teardown remove parser and pyang """
self.teardown_script = pkg_resources.resource_filename(
"yardstick.benchmark.scenarios.parser",
Parser.TEARDOWN_SCRIPT)
@@ -75,8 +77,9 @@ class Parser(base.Scenario):
def _test():
- '''internal test function'''
+ """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..e28bd7bcc 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
@@ -54,7 +58,7 @@ class Fio(base.Scenario):
self.setup_done = False
def setup(self):
- '''scenario setup'''
+ """scenario setup"""
self.target_script = pkg_resources.resource_filename(
"yardstick.benchmark.scenarios.storage",
Fio.TARGET_SCRIPT)
@@ -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"]:
@@ -148,7 +152,7 @@ class Fio(base.Scenario):
def _test():
- '''internal test function'''
+ """internal test function"""
key_filename = pkg_resources.resource_filename("yardstick.resources",
"files/yardstick_key")
ctx = {
@@ -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..3756d9ebb 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 to stdout a horizontal bar"""
+ print(("+"), end=' ')
+ print(("-" * barlen), end=' ')
print("+")
diff --git a/yardstick/cmd/cli.py b/yardstick/cmd/cli.py
index beaa187aa..6281bb813 100644
--- a/yardstick/cmd/cli.py
+++ b/yardstick/cmd/cli.py
@@ -7,10 +7,11 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-'''
+"""
Command-line interface to yardstick
-'''
+"""
+from __future__ import absolute_import
import logging
import os
import sys
@@ -56,7 +57,7 @@ def find_config_files(path_list):
class YardstickCLI():
- '''Command-line interface to yardstick'''
+ """Command-line interface to yardstick"""
# Command categories
categories = {
@@ -74,7 +75,7 @@ class YardstickCLI():
get_distribution('yardstick').version
def _find_actions(self, subparsers, actions_module):
- '''find action methods'''
+ """find action methods"""
# Find action methods inside actions_module and
# add them to the command parser.
# The 'actions_module' argument may be a class
@@ -93,7 +94,7 @@ class YardstickCLI():
subparser.set_defaults(func=callback)
def _add_command_parsers(self, categories, subparsers):
- '''add commands to command-line parser'''
+ """add commands to command-line parser"""
for category in categories:
command_object = categories[category]()
desc = command_object.__doc__ or ''
@@ -155,7 +156,7 @@ class YardstickCLI():
CONF.unregister_opts(self.opts)
def main(self, argv): # pragma: no cover
- '''run the command line interface'''
+ """run the command line interface"""
try:
self._register_cli_opt()
@@ -168,7 +169,7 @@ class YardstickCLI():
self._clear_config_opts()
def api(self, argv, task_id): # pragma: no cover
- '''run the api interface'''
+ """run the api interface"""
try:
self._register_cli_opt()
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..d5aef7faf 100644
--- a/yardstick/cmd/commands/env.py
+++ b/yardstick/cmd/commands/env.py
@@ -6,20 +6,25 @@
# 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):
- '''
+ """
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..f97c490b7 100644
--- a/yardstick/cmd/commands/plugin.py
+++ b/yardstick/cmd/commands/plugin.py
@@ -9,27 +9,30 @@
""" 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
class PluginCommands(object):
- '''Plugin commands.
+ """Plugin commands.
Set of commands to manage plugins.
- '''
+ """
@cliargs("input_file", type=str, help="path to plugin configuration file",
nargs=1)
def do_install(self, args):
- '''Install a plugin.'''
+ """Install a plugin."""
param = change_osloobj_to_paras(args)
Plugin().install(param)
@cliargs("input_file", type=str, help="path to plugin configuration file",
nargs=1)
def do_remove(self, args):
- '''Remove a plugin.'''
+ """Remove a plugin."""
param = change_osloobj_to_paras(args)
Plugin().remove(param)
diff --git a/yardstick/cmd/commands/runner.py b/yardstick/cmd/commands/runner.py
index 62a2082c4..b99ae789b 100644
--- a/yardstick/cmd/commands/runner.py
+++ b/yardstick/cmd/commands/runner.py
@@ -9,24 +9,27 @@
""" 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
class RunnerCommands(object):
- '''Runner commands.
+ """Runner commands.
Set of commands to discover and display runner types.
- '''
+ """
def do_list(self, args):
- '''List existing runner types'''
+ """List existing runner types"""
param = change_osloobj_to_paras(args)
Runners().list_all(param)
@cliargs("type", type=str, help="runner type", nargs=1)
def do_show(self, args):
- '''Show details of a specific runner type'''
+ """Show details of a specific runner type"""
param = change_osloobj_to_paras(args)
Runners().show(param)
diff --git a/yardstick/cmd/commands/scenario.py b/yardstick/cmd/commands/scenario.py
index 6aa3a451a..618ed2915 100644
--- a/yardstick/cmd/commands/scenario.py
+++ b/yardstick/cmd/commands/scenario.py
@@ -9,24 +9,26 @@
""" 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
class ScenarioCommands(object):
- '''Scenario commands.
+ """Scenario commands.
Set of commands to discover and display scenario types.
- '''
+ """
def do_list(self, args):
- '''List existing scenario types'''
+ """List existing scenario types"""
param = change_osloobj_to_paras(args)
Scenarios().list_all(param)
@cliargs("type", type=str, help="runner type", nargs=1)
def do_show(self, args):
- '''Show details of a specific scenario type'''
+ """Show details of a specific scenario type"""
param = change_osloobj_to_paras(args)
Scenarios().show(param)
diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py
index b7f74c2e6..d7c0a01fb 100644
--- a/yardstick/cmd/commands/task.py
+++ b/yardstick/cmd/commands/task.py
@@ -8,19 +8,21 @@
##############################################################################
""" 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"
class TaskCommands(object):
- '''Task commands.
+ """Task commands.
Set of commands to manage benchmark tasks.
- '''
+ """
@cliargs("inputfile", type=str, help="path to task or suite file", nargs=1)
@cliargs("--task-args", dest="task_args",
diff --git a/yardstick/cmd/commands/testcase.py b/yardstick/cmd/commands/testcase.py
index 6ff796238..bd17b1aa5 100644
--- a/yardstick/cmd/commands/testcase.py
+++ b/yardstick/cmd/commands/testcase.py
@@ -8,24 +8,27 @@
##############################################################################
""" 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
class TestcaseCommands(object):
- '''Testcase commands.
+ """Testcase commands.
Set of commands to discover and display test cases.
- '''
+ """
def do_list(self, args):
- '''List existing test cases'''
+ """List existing test cases"""
param = change_osloobj_to_paras(args)
Testcase().list_all(param)
@cliargs("casename", type=str, help="test case name", nargs=1)
def do_show(self, args):
- '''Show details of a specific test case'''
+ """Show details of a specific test case"""
param = change_osloobj_to_paras(args)
Testcase().show(param)
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py
index 174d39bfe..ffca4b3e9 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'
@@ -54,3 +55,5 @@ OPENSTACK_RC_FILE = join(YARDSTICK_CONFIG_DIR, 'openstack.creds')
BASE_URL = 'http://localhost:5000'
ENV_ACTION_API = BASE_URL + '/yardstick/env/action'
ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask'
+
+SQLITE = 'sqlite:////tmp/yardstick.db'
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..e1662ced1 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
@@ -40,13 +42,13 @@ yaml_loader.add_constructor(u'tag:yaml.org,2002:timestamp',
def parse(tmpl_str):
- '''Takes a string and returns a dict containing the parsed structure.
+ """Takes a string and returns a dict containing the parsed structure.
This includes determination of whether the string is using the
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..09ce8d1e8 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
@@ -30,7 +31,7 @@ class Base(object):
@staticmethod
def get_cls(dispatcher_type):
- '''Return class of specified type.'''
+ """Return class of specified type."""
for dispatcher in utils.itersubclasses(Base):
if dispatcher_type == dispatcher.__dispatcher_type__:
return dispatcher
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..5fc0c2e17 100755
--- a/yardstick/main.py
+++ b/yardstick/main.py
@@ -38,13 +38,14 @@
NFV TST
"""
+from __future__ import absolute_import
import sys
from yardstick.cmd.cli import YardstickCLI
def main():
- '''yardstick main'''
+ """yardstick main"""
YardstickCLI().main(sys.argv[1:])
if __name__ == '__main__':
diff --git a/yardstick/network_services/__init__.py b/yardstick/network_services/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/network_services/__init__.py
diff --git a/yardstick/network_services/collector/__init__.py b/yardstick/network_services/collector/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/network_services/collector/__init__.py
diff --git a/yardstick/network_services/collector/publisher.py b/yardstick/network_services/collector/publisher.py
new file mode 100644
index 000000000..004d4774b
--- /dev/null
+++ b/yardstick/network_services/collector/publisher.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""This module implements stub for publishing results in yardstick format."""
+
+
+class Publisher(object):
+ """Class that handles publishing test results in yardstick format."""
+
+ def __init__(self):
+ super(Publisher, self).__init__()
+
+ def start(self):
+ """Nothing to do, yet"""
+ pass
+
+ def stop(self):
+ """Nothing to do, yet"""
+ pass
diff --git a/yardstick/network_services/collector/subscriber.py b/yardstick/network_services/collector/subscriber.py
new file mode 100644
index 000000000..3bcb20876
--- /dev/null
+++ b/yardstick/network_services/collector/subscriber.py
@@ -0,0 +1,39 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""This module implements stub for publishing results in yardstick format."""
+
+
+class Collector(object):
+ """Class that handles dictionary of results in yardstick-plot format."""
+
+ def __init__(self, traffic_profile, vnfs):
+ super(Collector, self).__init__()
+ self.traffic_profile = traffic_profile
+ self.service = vnfs
+
+ def start(self):
+ """Nothing to do, yet"""
+ pass
+
+ def stop(self):
+ """Nothing to do, yet"""
+ pass
+
+ @classmethod
+ def get_kpi(cls, vnf):
+ """Returns dictionary of results in yardstick-plot format
+
+ :return:
+ """
+ return {vnf.name: vnf.collect_kpi()}
diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py
index f1104d625..c098de9e3 100644
--- a/yardstick/orchestrator/heat.py
+++ b/yardstick/orchestrator/heat.py
@@ -9,32 +9,43 @@
"""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 pkg_resources
-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__)
+HEAT_KEY_UUID_LENGTH = 8
+
+
+def get_short_key_uuid(uuid):
+ return str(uuid)[:HEAT_KEY_UUID_LENGTH]
+
+
class HeatObject(object):
- ''' base class for template and stack'''
+ """ base class for template and stack"""
+
def __init__(self):
self._heat_client = None
self.uuid = None
def _get_heat_client(self):
- '''returns a heat client instance'''
+ """returns a heat client instance"""
if self._heat_client is None:
sess = op_utils.get_session()
@@ -46,14 +57,14 @@ class HeatObject(object):
return self._heat_client
def status(self):
- '''returns stack state as a string'''
+ """returns stack state as a string"""
heat = self._get_heat_client()
stack = heat.stacks.get(self.uuid)
return getattr(stack, 'stack_status')
class HeatStack(HeatObject):
- ''' Represents a Heat stack (deployed template) '''
+ """ Represents a Heat stack (deployed template) """
stacks = []
def __init__(self, name):
@@ -65,11 +76,11 @@ class HeatStack(HeatObject):
@staticmethod
def stacks_exist():
- '''check if any stack has been deployed'''
+ """check if any stack has been deployed"""
return len(HeatStack.stacks) > 0
def _delete(self):
- '''deletes a stack from the target cloud using heat'''
+ """deletes a stack from the target cloud using heat"""
if self.uuid is None:
return
@@ -95,10 +106,10 @@ class HeatStack(HeatObject):
self.uuid = None
def delete(self, block=True, retries=3):
- '''deletes a stack in the target cloud using heat (with retry)
+ """deletes a stack in the target cloud using heat (with retry)
Sometimes delete fail with "InternalServerError" and the next attempt
succeeds. So it is worthwhile to test a couple of times.
- '''
+ """
if self.uuid is None:
return
@@ -112,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
@@ -128,12 +139,12 @@ class HeatStack(HeatObject):
stack.delete()
def update(self):
- '''update a stack'''
+ """update a stack"""
raise RuntimeError("not implemented")
class HeatTemplate(HeatObject):
- '''Describes a Heat template and a method to deploy template to a stack'''
+ """Describes a Heat template and a method to deploy template to a stack"""
def _init_template(self):
self._template = {}
@@ -141,9 +152,9 @@ class HeatTemplate(HeatObject):
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self._template['description'] = \
- '''Stack built by the yardstick framework for %s on host %s %s.
+ """Stack built by the yardstick framework for %s on host %s %s.
All referred generated resources are prefixed with the template
- name (i.e. %s).''' % (getpass.getuser(), socket.gethostname(),
+ name (i.e. %s).""" % (getpass.getuser(), socket.gethostname(),
timestamp, self.name)
# short hand for resources part of template
@@ -166,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
@@ -179,7 +190,7 @@ class HeatTemplate(HeatObject):
log.debug("template object '%s' created", name)
def add_network(self, name):
- '''add to the template a Neutron Net'''
+ """add to the template a Neutron Net"""
log.debug("adding Neutron::Net '%s'", name)
self.resources[name] = {
'type': 'OS::Neutron::Net',
@@ -187,7 +198,7 @@ class HeatTemplate(HeatObject):
}
def add_subnet(self, name, network, cidr):
- '''add to the template a Neutron Subnet'''
+ """add to the template a Neutron Subnet"""
log.debug("adding Neutron::Subnet '%s' in network '%s', cidr '%s'",
name, network, cidr)
self.resources[name] = {
@@ -206,7 +217,7 @@ class HeatTemplate(HeatObject):
}
def add_router(self, name, ext_gw_net, subnet_name):
- '''add to the template a Neutron Router and interface'''
+ """add to the template a Neutron Router and interface"""
log.debug("adding Neutron::Router:'%s', gw-net:'%s'", name, ext_gw_net)
self.resources[name] = {
@@ -221,7 +232,7 @@ class HeatTemplate(HeatObject):
}
def add_router_interface(self, name, router_name, subnet_name):
- '''add to the template a Neutron RouterInterface and interface'''
+ """add to the template a Neutron RouterInterface and interface"""
log.debug("adding Neutron::RouterInterface '%s' router:'%s', "
"subnet:'%s'", name, router_name, subnet_name)
@@ -235,7 +246,7 @@ class HeatTemplate(HeatObject):
}
def add_port(self, name, network_name, subnet_name, sec_group_id=None):
- '''add to the template a named Neutron Port'''
+ """add to the template a named Neutron Port"""
log.debug("adding Neutron::Port '%s', network:'%s', subnet:'%s', "
"secgroup:%s", name, network_name, subnet_name, sec_group_id)
self.resources[name] = {
@@ -261,9 +272,9 @@ class HeatTemplate(HeatObject):
def add_floating_ip(self, name, network_name, port_name, router_if_name,
secgroup_name=None):
- '''add to the template a Nova FloatingIP resource
+ """add to the template a Nova FloatingIP resource
see: https://bugs.launchpad.net/heat/+bug/1299259
- '''
+ """
log.debug("adding Nova::FloatingIP '%s', network '%s', port '%s', "
"rif '%s'", name, network_name, port_name, router_if_name)
@@ -284,8 +295,8 @@ class HeatTemplate(HeatObject):
}
def add_floating_ip_association(self, name, floating_ip_name, port_name):
- '''add to the template a Nova FloatingIP Association resource
- '''
+ """add to the template a Nova FloatingIP Association resource
+ """
log.debug("adding Nova::FloatingIPAssociation '%s', server '%s', "
"floating_ip '%s'", name, port_name, floating_ip_name)
@@ -299,23 +310,24 @@ class HeatTemplate(HeatObject):
}
def add_keypair(self, name, key_uuid):
- '''add to the template a Nova KeyPair'''
+ """add to the template a Nova KeyPair"""
log.debug("adding Nova::KeyPair '%s'", name)
self.resources[name] = {
'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',
- 'files/yardstick_key-{:.{width}}.pub'.format(
- key_uuid, width=8)),
+ 'files/yardstick_key-' +
+ get_short_key_uuid(key_uuid) + '.pub'),
'utf-8')
}
}
def add_servergroup(self, name, policy):
- '''add to the template a Nova ServerGroup'''
+ """add to the template a Nova ServerGroup"""
log.debug("adding Nova::ServerGroup '%s', policy '%s'", name, policy)
if policy not in ["anti-affinity", "affinity"]:
raise ValueError(policy)
@@ -334,7 +346,7 @@ class HeatTemplate(HeatObject):
}
def add_security_group(self, name):
- '''add to the template a Neutron SecurityGroup'''
+ """add to the template a Neutron SecurityGroup"""
log.debug("adding Neutron::SecurityGroup '%s'", name)
self.resources[name] = {
'type': 'OS::Neutron::SecurityGroup',
@@ -364,7 +376,7 @@ class HeatTemplate(HeatObject):
def add_server(self, name, image, flavor, ports=None, networks=None,
scheduler_hints=None, user=None, key_name=None,
user_data=None, metadata=None, additional_properties=None):
- '''add to the template a Nova Server'''
+ """add to the template a Nova Server"""
log.debug("adding Nova::Server '%s', image '%s', flavor '%s', "
"ports %s", name, image, flavor, ports)
@@ -395,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:
@@ -405,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]
@@ -423,21 +435,23 @@ class HeatTemplate(HeatObject):
}
def create(self, block=True):
- '''creates a template in the target cloud using heat
- returns a dict with the requested output values from the template'''
+ """creates a template in the target cloud using heat
+ returns a dict with the requested output values from the template"""
log.info("Creating stack '%s'", self.name)
# create stack early to support cleanup, e.g. ctrl-c while waiting
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':
@@ -451,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..2f1f25228 100644
--- a/yardstick/plot/plotter.py
+++ b/yardstick/plot/plotter.py
@@ -9,24 +9,30 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-''' yardstick-plot - a command line tool for visualizing results from the
+""" yardstick-plot - a command line tool for visualizing results from the
output file of yardstick framework.
Example invocation:
$ 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):
- ''' Command-line argument and input file parser for yardstick-plot tool'''
+ """ Command-line argument and input file parser for yardstick-plot tool"""
def __init__(self):
self.data = {
@@ -39,12 +45,12 @@ class Parser(object):
self.scenarios = {}
def _get_parser(self):
- '''get a command-line parser'''
+ """get a command-line parser"""
parser = argparse.ArgumentParser(
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',
@@ -59,43 +65,43 @@ class Parser(object):
return parser
def _add_record(self, record):
- '''add record to the relevant scenario'''
+ """add record to the relevant scenario"""
if "runner_id" in record and "benchmark" not in record:
obj_name = record["scenario_cfg"]["runner"]["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)
def parse_args(self):
- '''parse command-line arguments'''
+ """parse command-line arguments"""
parser = self._get_parser()
self.args = parser.parse_args()
return self.args
def parse_input_file(self):
- '''parse the input test results file'''
+ """parse the input test results file"""
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)
class Plotter(object):
- '''Graph plotter for scenario-specific results from yardstick framework'''
+ """Graph plotter for scenario-specific results from yardstick framework"""
def __init__(self, data, output_folder):
self.data = data
@@ -104,7 +110,7 @@ class Plotter(object):
self.colors = ['g', 'b', 'c', 'm', 'y']
def plot(self):
- '''plot the graph(s)'''
+ """plot the graph(s)"""
for test_type in self.data.keys():
if self.data[test_type]:
plt.figure(self.fig_counter)
@@ -116,7 +122,7 @@ class Plotter(object):
self._save_plot(test_type)
def _save_plot(self, test_type):
- '''save the graph to output folder'''
+ """save the graph to output folder"""
timestr = time.strftime("%Y%m%d-%H%M%S")
file_name = test_type + "_" + timestr + ".png"
if not self.output_folder:
@@ -126,10 +132,10 @@ 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'''
+ """ping test result interpretation and visualization on the graph"""
rtts = [r['benchmark']['data']['rtt'] for r in records]
seqs = [r['benchmark']['sequence'] for r in records]
@@ -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")
@@ -151,7 +157,7 @@ class Plotter(object):
plt.ylabel("round trip time in milliseconds (rtt)")
def _plot_pktgen(self, records):
- '''pktgen test result interpretation and visualization on the graph'''
+ """pktgen test result interpretation and visualization on the graph"""
flows = [r['benchmark']['data']['flows'] for r in records]
sent = [r['benchmark']['data']['packets_sent'] for r in records]
received = [int(r['benchmark']['data']['packets_received'])
@@ -164,20 +170,20 @@ 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")
plt.ylabel("lost packets per million packets (ppm)")
def _plot_iperf3(self, records):
- '''iperf3 test result interpretation and visualization on the graph'''
+ """iperf3 test result interpretation and visualization on the graph"""
intervals = []
for r in records:
# If did not fail the SLA
@@ -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,12 +208,12 @@ 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")
def _plot_fio(self, records):
- '''fio test result interpretation and visualization on the graph'''
+ """fio test result interpretation and visualization on the graph"""
rw_types = [r['sargs']['options']['rw'] for r in records]
seqs = [x for x in range(1, len(records) + 1)]
data = {}
@@ -271,8 +277,8 @@ class Plotter(object):
plt.xticks(seqs, seqs)
def _plot_fio_helper(self, data, seqs, key, bar_color, axl):
- '''check if measurements exist for a key and then plot the
- data to a given subplot'''
+ """check if measurements exist for a key and then plot the
+ data to a given subplot"""
if key in data:
if len(data[key]) == 1:
axl.bar(0.1, data[key], 0.35, color=bar_color)
@@ -281,7 +287,7 @@ class Plotter(object):
axl.plot(seqs, data[key], line_style)
def _construct_legend(self, legend_texts, obj=plt):
- '''construct legend for the plot or subplot'''
+ """construct legend for the plot or subplot"""
ci = 0
lines = []
@@ -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..cfbc3ca96 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("", incoming='utf-8')
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,11 @@ 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)
+ stdin_txt = stdin.read(4096)
+ if stdin_txt is None:
+ stdin_txt = ''
+ data_to_send = encodeutils.safe_encode(
+ stdin_txt, 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..56ea6d2f0 100644
--- a/yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py
+++ b/yardstick/vTC/apexlake/experimental_framework/benchmarking_unit.py
@@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-'''
+"""
The Benchmarking Unit manages the Benchmarking of VNFs orchestrating the
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..38c91ee3a 100644
--- a/yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py
+++ b/yardstick/vTC/apexlake/experimental_framework/benchmarks/benchmark_base_class.py
@@ -13,15 +13,16 @@
# limitations under the License.
+from __future__ import absolute_import
import abc
class BenchmarkBaseClass(object):
- '''
+ """
This class represents a Benchmark that we want to run on the platform.
One of them will be the calculation of the throughput changing the
configuration parameters
- '''
+ """
def __init__(self, name, params):
if not params:
@@ -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..1904af20b 100644
--- a/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py
+++ b/yardstick/vTC/apexlake/experimental_framework/heat_template_generation.py
@@ -13,10 +13,11 @@
# limitations under the License.
-'''
+"""
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/libraries/__init__.py b/yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py
index dcc18a45b..876e3ca31 100644
--- a/yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py
+++ b/yardstick/vTC/apexlake/experimental_framework/libraries/__init__.py
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-'''
+"""
Libraries to be used by the framework.
-'''
+"""
__author__ = 'vmriccox'
diff --git a/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py b/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py
index a7c96a842..935f144f4 100644
--- a/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py
+++ b/yardstick/vTC/apexlake/experimental_framework/packet_generators/__init__.py
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-'''
+"""
Packet generators
-'''
+"""
__author__ = 'vmriccox'
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..bd81527a2 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):
@@ -31,10 +34,10 @@ class DpdkPacketGenerator(base_packet_generator.BasePacketGenerator):
self.dpdk_interfaces = -1
def send_traffic(self):
- '''
+ """
Calls the packet generator and starts to send traffic
Blocking call
- '''
+ """
current_dir = os.path.dirname(os.path.realpath(__file__))
DpdkPacketGenerator._chdir(self.directory)
dpdk_vars = common.get_dpdk_pktgen_vars()
@@ -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..96ead5ef7 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
@@ -287,10 +288,10 @@ class TestDpdkPacketGenSendTraffic(unittest.TestCase):
mock_dir_name,
mock_os_path,
mock_os_system):
- '''
+ """
Calls the packet generator and starts to send traffic
Blocking call
- '''
+ """
mock_get_core_nics.return_value = "{corenics}"
mock_os_path.realpath.return_value = 'pktgen_dir_test'
mock_os_path.dirname.return_value = 'current_directory'
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()