summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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/api/utils/test_common.py1
-rw-r--r--tests/unit/api/utils/test_influx.py38
-rw-r--r--tests/unit/benchmark/contexts/test_dummy.py1
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py33
-rw-r--r--tests/unit/benchmark/contexts/test_model.py5
-rw-r--r--tests/unit/benchmark/contexts/test_node.py2
-rw-r--r--tests/unit/benchmark/core/__init__.py0
-rw-r--r--tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml (renamed from tests/unit/cmd/commands/no_constraint_no_args_scenario_sample.yaml)0
-rw-r--r--tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml (renamed from tests/unit/cmd/commands/no_constraint_with_args_scenario_sample.yaml)0
-rw-r--r--tests/unit/benchmark/core/test_plugin.py (renamed from tests/unit/cmd/commands/test_plugin.py)47
-rw-r--r--tests/unit/benchmark/core/test_task.py (renamed from tests/unit/cmd/commands/test_task.py)120
-rw-r--r--tests/unit/benchmark/core/test_testcase.py (renamed from tests/unit/cmd/commands/test_testcase.py)31
-rw-r--r--tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml (renamed from tests/unit/cmd/commands/with_constraint_no_args_scenario_sample.yaml)0
-rw-r--r--tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml (renamed from tests/unit/cmd/commands/with_constraint_with_args_scenario_sample.yaml)0
-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.py46
-rw-r--r--tests/unit/common/test_httpClient.py16
-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/orchestrator/test_heat.py26
-rw-r--r--tests/unit/test_ssh.py13
69 files changed, 779 insertions, 442 deletions
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/api/utils/test_common.py b/tests/unit/api/utils/test_common.py
index 5d177409e..acf6e41b1 100644
--- a/tests/unit/api/utils/test_common.py
+++ b/tests/unit/api/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/api/utils/test_influx.py
index 0852da2dd..aff0cab5c 100644
--- a/tests/unit/api/utils/test_influx.py
+++ b/tests/unit/api/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/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 f891b0a5f..f8f349205 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -11,13 +11,21 @@
# Unittest for yardstick.benchmark.contexts.heat
-import mock
+from __future__ import absolute_import
+
+import logging
+import os
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):
@@ -39,6 +47,8 @@ class HeatContextTestCase(unittest.TestCase):
self.assertIsNone(self.test_context._user)
self.assertIsNone(self.test_context.template_file)
self.assertIsNone(self.test_context.heat_parameters)
+ self.assertIsNotNone(self.test_context.key_uuid)
+ self.assertIsNotNone(self.test_context.key_filename)
@mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup')
@mock.patch('yardstick.benchmark.contexts.heat.Network')
@@ -55,6 +65,7 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context.init(attrs)
+ self.assertEqual(self.test_context.name, "foo")
self.assertEqual(self.test_context.keypair_name, "foo-key")
self.assertEqual(self.test_context.secgroup_name, "foo-secgroup")
@@ -66,17 +77,29 @@ 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):
+ try:
+ os.remove(self.test_context.key_filename)
+ os.remove(self.test_context.key_filename + ".pub")
+ except OSError:
+ 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):
self.test_context.keypair_name = "foo-key"
self.test_context.secgroup_name = "foo-secgroup"
+ 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")
+ 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')
@@ -105,6 +128,8 @@ class HeatContextTestCase(unittest.TestCase):
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..de5ba7066 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()
diff --git a/tests/unit/benchmark/core/__init__.py b/tests/unit/benchmark/core/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/unit/benchmark/core/__init__.py
diff --git a/tests/unit/cmd/commands/no_constraint_no_args_scenario_sample.yaml b/tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml
index 4933b93ae..4933b93ae 100644
--- a/tests/unit/cmd/commands/no_constraint_no_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/no_constraint_no_args_scenario_sample.yaml
diff --git a/tests/unit/cmd/commands/no_constraint_with_args_scenario_sample.yaml b/tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml
index f39df7346..f39df7346 100644
--- a/tests/unit/cmd/commands/no_constraint_with_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/no_constraint_with_args_scenario_sample.yaml
diff --git a/tests/unit/cmd/commands/test_plugin.py b/tests/unit/benchmark/core/test_plugin.py
index 2e823fdae..edc103415 100644
--- a/tests/unit/cmd/commands/test_plugin.py
+++ b/tests/unit/benchmark/core/test_plugin.py
@@ -9,43 +9,54 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.cmd.commands.plugin
+# Unittest for yardstick.benchmark.core.plugin
+from __future__ import absolute_import
+import os
+from os.path import dirname as dirname
-import mock
+try:
+ from unittest import mock
+except ImportError:
+ import mock
import unittest
-from yardstick.cmd.commands import plugin
+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.cmd.commands.plugin.ssh')
-class pluginCommandsTestCase(unittest.TestCase):
+@mock.patch('yardstick.benchmark.core.plugin.ssh')
+class pluginTestCase(unittest.TestCase):
def setUp(self):
self.result = {}
- def test_do_install(self, mock_ssh):
- p = plugin.PluginCommands()
+ def test_install(self, mock_ssh):
+ p = plugin.Plugin()
mock_ssh.SSH().execute.return_value = (0, '', '')
input_file = Arg()
- p.do_install(input_file)
+ p.install(input_file)
expected_result = {}
self.assertEqual(self.result, expected_result)
- def test_do_remove(self, mock_ssh):
- p = plugin.PluginCommands()
+ def test_remove(self, mock_ssh):
+ p = plugin.Plugin()
mock_ssh.SSH().execute.return_value = (0, '', '')
input_file = Arg()
- p.do_remove(input_file)
+ p.remove(input_file)
expected_result = {}
self.assertEqual(self.result, expected_result)
def test_install_setup_run(self, mock_ssh):
- p = plugin.PluginCommands()
+ p = plugin.Plugin()
mock_ssh.SSH().execute.return_value = (0, '', '')
plugins = {
"name": "sample"
@@ -64,7 +75,7 @@ class pluginCommandsTestCase(unittest.TestCase):
self.assertEqual(self.result, expected_result)
def test_remove_setup_run(self, mock_ssh):
- p = plugin.PluginCommands()
+ p = plugin.Plugin()
mock_ssh.SSH().execute.return_value = (0, '', '')
plugins = {
"name": "sample"
@@ -81,3 +92,11 @@ class pluginCommandsTestCase(unittest.TestCase):
p._run(plugin_name)
expected_result = {}
self.assertEqual(self.result, expected_result)
+
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/cmd/commands/test_task.py b/tests/unit/benchmark/core/test_task.py
index 0177fd08a..5dd32ea17 100644
--- a/tests/unit/cmd/commands/test_task.py
+++ b/tests/unit/benchmark/core/test_task.py
@@ -9,18 +9,26 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.cmd.commands.task
+# Unittest for yardstick.benchmark.core.task
+from __future__ import print_function
+
+from __future__ import absolute_import
import os
-import mock
import unittest
-from yardstick.cmd.commands import task
+try:
+ from unittest import mock
+except ImportError:
+ import mock
+
+
+from yardstick.benchmark.core import task
-class TaskCommandsTestCase(unittest.TestCase):
+class TaskTestCase(unittest.TestCase):
- @mock.patch('yardstick.cmd.commands.task.Context')
+ @mock.patch('yardstick.benchmark.core.task.Context')
def test_parse_nodes_host_target_same_context(self, mock_context):
nodes = {
"host": "node1.LF",
@@ -28,9 +36,9 @@ class TaskCommandsTestCase(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)
@@ -38,108 +46,111 @@ class TaskCommandsTestCase(unittest.TestCase):
self.assertEqual(context_cfg["host"], server_info)
self.assertEqual(context_cfg["target"], server_info)
- @mock.patch('yardstick.cmd.commands.task.Context')
- @mock.patch('yardstick.cmd.commands.task.base_runner')
+ @mock.patch('yardstick.benchmark.core.task.Context')
+ @mock.patch('yardstick.benchmark.core.task.base_runner')
def test_run(self, mock_base_runner, mock_ctx):
- scenario = \
- {'host': 'athena.demo',
- 'target': 'ares.demo',
- 'runner':
- {'duration': 60,
- 'interval': 1,
- 'type': 'Duration'
- },
- 'type': 'Ping'}
-
- t = task.TaskCommands()
+ scenario = {
+ 'host': 'athena.demo',
+ 'target': 'ares.demo',
+ 'runner': {
+ 'duration': 60,
+ 'interval': 1,
+ 'type': 'Duration'
+ },
+ 'type': 'Ping'
+ }
+
+ t = task.Task()
runner = mock.Mock()
runner.join.return_value = 0
mock_base_runner.Runner.get.return_value = runner
t._run([scenario], False, "yardstick.out")
self.assertTrue(runner.run.called)
- @mock.patch('yardstick.cmd.commands.task.os')
+ @mock.patch('yardstick.benchmark.core.task.os')
def test_check_precondition(self, mock_os):
- cfg = \
- {'precondition':
- {'installer_type': 'compass',
- 'deploy_scenarios': 'os-nosdn',
- 'pod_name': 'huawei-pod1'
- }
+ cfg = {
+ 'precondition': {
+ 'installer_type': 'compass',
+ 'deploy_scenarios': 'os-nosdn',
+ 'pod_name': 'huawei-pod1'
}
+ }
t = task.TaskParser('/opt')
- mock_os.environ.get.side_effect = ['compass', 'os-nosdn', 'huawei-pod1']
+ mock_os.environ.get.side_effect = ['compass',
+ 'os-nosdn',
+ 'huawei-pod1']
result = t._check_precondition(cfg)
self.assertTrue(result)
- @mock.patch('yardstick.cmd.commands.task.os.environ')
+ @mock.patch('yardstick.benchmark.core.task.os.environ')
def test_parse_suite_no_constraint_no_args(self, mock_environ):
SAMPLE_SCENARIO_PATH = "no_constraint_no_args_scenario_sample.yaml"
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')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1], None)
self.assertEqual(task_args_fnames[0], None)
self.assertEqual(task_args_fnames[1], None)
- @mock.patch('yardstick.cmd.commands.task.os.environ')
+ @mock.patch('yardstick.benchmark.core.task.os.environ')
def test_parse_suite_no_constraint_with_args(self, mock_environ):
SAMPLE_SCENARIO_PATH = "no_constraint_with_args_scenario_sample.yaml"
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')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1],
- '{"host": "node1.LF","target": "node2.LF"}')
+ '{"host": "node1.LF","target": "node2.LF"}')
self.assertEqual(task_args_fnames[0], None)
self.assertEqual(task_args_fnames[1], None)
- @mock.patch('yardstick.cmd.commands.task.os.environ')
+ @mock.patch('yardstick.benchmark.core.task.os.environ')
def test_parse_suite_with_constraint_no_args(self, mock_environ):
SAMPLE_SCENARIO_PATH = "with_constraint_no_args_scenario_sample.yaml"
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')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1], None)
self.assertEqual(task_args_fnames[0], None)
self.assertEqual(task_args_fnames[1], None)
- @mock.patch('yardstick.cmd.commands.task.os.environ')
+ @mock.patch('yardstick.benchmark.core.task.os.environ')
def test_parse_suite_with_constraint_with_args(self, mock_environ):
SAMPLE_SCENARIO_PATH = "with_constraint_with_args_scenario_sample.yaml"
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')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml')
self.assertEqual(task_files[1],
- 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
+ 'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml')
self.assertEqual(task_args[0], None)
self.assertEqual(task_args[1],
- '{"host": "node1.LF","target": "node2.LF"}')
+ '{"host": "node1.LF","target": "node2.LF"}')
self.assertEqual(task_args_fnames[0], None)
self.assertEqual(task_args_fnames[1], None)
@@ -148,3 +159,10 @@ class TaskCommandsTestCase(unittest.TestCase):
file_path = os.path.join(curr_path, filename)
return file_path
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/cmd/commands/test_testcase.py b/tests/unit/benchmark/core/test_testcase.py
index c55c367d0..c7da2de7c 100644
--- a/tests/unit/cmd/commands/test_testcase.py
+++ b/tests/unit/benchmark/core/test_testcase.py
@@ -11,26 +11,35 @@
# Unittest for yardstick.cmd.commands.testcase
-import mock
+from __future__ import absolute_import
import unittest
-from yardstick.cmd.commands import testcase
-from yardstick.cmd.commands.testcase import TestcaseCommands
+from yardstick.benchmark.core import testcase
+
class Arg(object):
+
def __init__(self):
- self.casename=('opnfv_yardstick_tc001',)
+ self.casename = ('opnfv_yardstick_tc001',)
+
-class TestcaseCommandsUT(unittest.TestCase):
+class TestcaseUT(unittest.TestCase):
- def test_do_list(self):
- t = testcase.TestcaseCommands()
- result = t.do_list("")
+ def test_list_all(self):
+ t = testcase.Testcase()
+ result = t.list_all("")
self.assertEqual(result, True)
- def test_do_show(self):
- t = testcase.TestcaseCommands()
+ def test_show(self):
+ t = testcase.Testcase()
casename = Arg()
- result = t.do_show(casename)
+ result = t.show(casename)
self.assertEqual(result, True)
+
+def main():
+ unittest.main()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/unit/cmd/commands/with_constraint_no_args_scenario_sample.yaml b/tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml
index 8194a2361..8194a2361 100644
--- a/tests/unit/cmd/commands/with_constraint_no_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/with_constraint_no_args_scenario_sample.yaml
diff --git a/tests/unit/cmd/commands/with_constraint_with_args_scenario_sample.yaml b/tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml
index 86c9b2800..86c9b2800 100644
--- a/tests/unit/cmd/commands/with_constraint_with_args_scenario_sample.yaml
+++ b/tests/unit/benchmark/core/with_constraint_with_args_scenario_sample.yaml
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 af1ab8030..c6e0e1d20 100644
--- a/tests/unit/cmd/commands/test_env.py
+++ b/tests/unit/cmd/commands/test_env.py
@@ -6,19 +6,59 @@
# 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
from yardstick.cmd.commands.env import EnvCommand
class EnvCommandTestCase(unittest.TestCase):
- @mock.patch('yardstick.cmd.commands.env.HttpClient')
- def test_do_influxdb(self, mock_http_client):
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
+ def test_do_influxdb(self, check_status_mock, start_async_task_mock):
env = EnvCommand()
env.do_influxdb({})
- self.assertTrue(mock_http_client().post.called)
+ self.assertTrue(start_async_task_mock.called)
+ self.assertTrue(check_status_mock.called)
+
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
+ def test_do_grafana(self, check_status_mock, start_async_task_mock):
+ env = EnvCommand()
+ env.do_grafana({})
+ self.assertTrue(start_async_task_mock.called)
+ self.assertTrue(check_status_mock.called)
+
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
+ def test_do_prepare(self, check_status_mock, start_async_task_mock):
+ env = EnvCommand()
+ env.do_prepare({})
+ self.assertTrue(start_async_task_mock.called)
+ self.assertTrue(check_status_mock.called)
+
+ @mock.patch('yardstick.cmd.commands.env.HttpClient.post')
+ def test_start_async_task(self, post_mock):
+ data = {'action': 'createGrafanaContainer'}
+ EnvCommand()._start_async_task(data)
+ self.assertTrue(post_mock.called)
+
+ @mock.patch('yardstick.cmd.commands.env.HttpClient.get')
+ @mock.patch('yardstick.cmd.commands.env.EnvCommand._print_status')
+ def test_check_status(self, print_mock, get_mock):
+ task_id = str(uuid.uuid4())
+ get_mock.return_value = {'status': 2, 'result': 'error'}
+ status = EnvCommand()._check_status(task_id, 'hello world')
+ self.assertEqual(status, 2)
+
+ def test_print_status(self):
+ try:
+ EnvCommand()._print_status('hello', 'word')
+ except Exception as e:
+ self.assertIsInstance(e, IndexError)
def main():
diff --git a/tests/unit/common/test_httpClient.py b/tests/unit/common/test_httpClient.py
index b39dc2332..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,15 @@ 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):
+ url = 'http://localhost:5000/hello'
+ httpClient.HttpClient().get(url)
+ mock_requests.get.assert_called_with(url)
def main():
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/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()