summaryrefslogtreecommitdiffstats
path: root/yardstick/tests
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/tests')
-rw-r--r--yardstick/tests/__init__.py75
-rw-r--r--yardstick/tests/functional/base.py46
-rw-r--r--yardstick/tests/functional/benchmark/__init__.py0
-rw-r--r--yardstick/tests/functional/benchmark/scenarios/__init__.py0
-rw-r--r--yardstick/tests/functional/benchmark/scenarios/networking/__init__.py0
-rw-r--r--yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py195
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/README.md2
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/setup.py29
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/__init__.py0
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/__init__.py0
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/__init__.py0
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/__init__.py0
-rw-r--r--yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/dummy2.py40
-rw-r--r--yardstick/tests/functional/common/fake_pip_package/yardstick_new_plugin-1.0.0.tar.gzbin0 -> 1650 bytes
-rw-r--r--yardstick/tests/functional/common/test_packages.py94
-rw-r--r--yardstick/tests/unit/__init__.py65
-rw-r--r--yardstick/tests/unit/apiserver/resources/test_env_action.py8
-rw-r--r--yardstick/tests/unit/apiserver/utils/test_influx.py8
-rw-r--r--yardstick/tests/unit/base.py23
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py70
-rw-r--r--yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py58
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_base.py43
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_dummy.py52
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_heat.py331
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_kubernetes.py17
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_model.py2
-rw-r--r--yardstick/tests/unit/benchmark/contexts/test_node.py193
-rw-r--r--yardstick/tests/unit/benchmark/core/test_report.py2
-rw-r--r--yardstick/tests/unit/benchmark/core/test_task.py290
-rw-r--r--yardstick/tests/unit/benchmark/core/test_testcase.py10
-rw-r--r--yardstick/tests/unit/benchmark/runner/test_base.py25
-rw-r--r--yardstick/tests/unit/benchmark/runner/test_search.py11
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py4
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_director.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/availability/test_util.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_cachestat.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_computecapacity.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_cpuload.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_cyclictest.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_lmbench.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_memload.py10
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_plugintest.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py10
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_ramspeed.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu.py10
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/compute/test_unixbench.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/dummy/test_dummy.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py7
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py9
-rwxr-xr-xyardstick/tests/unit/benchmark/scenarios/networking/test_netperf.py9
-rwxr-xr-xyardstick/tests/unit/benchmark/scenarios/networking/test_netperf_node.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_netutilization.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py2
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_nstat.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_ping6.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_sfc.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py316
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf.py10
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py8
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/parser/test_parser.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/storage/test_bonnie.py12
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/storage/test_fio.py26
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/storage/test_storperf.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/test_base.py7
-rw-r--r--yardstick/tests/unit/common/banned_modules/__init__.py0
-rw-r--r--yardstick/tests/unit/common/banned_modules/banned_module.py17
-rw-r--r--yardstick/tests/unit/common/banned_modules/importing_module.py21
-rw-r--r--yardstick/tests/unit/common/test_ansible_common.py4
-rw-r--r--yardstick/tests/unit/common/test_httpClient.py8
-rw-r--r--yardstick/tests/unit/common/test_import_tools.py46
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py2
-rw-r--r--yardstick/tests/unit/common/test_packages.py88
-rw-r--r--yardstick/tests/unit/common/test_template_format.py7
-rw-r--r--yardstick/tests/unit/common/test_utils.py92
-rw-r--r--yardstick/tests/unit/common/test_yaml_loader.py8
-rw-r--r--yardstick/tests/unit/dispatcher/test_influxdb.py10
-rw-r--r--yardstick/tests/unit/orchestrator/test_heat.py90
-rw-r--r--yardstick/tests/unit/orchestrator/test_kubernetes.py10
-rw-r--r--yardstick/tests/unit/test_cmd/commands/test_env.py8
-rw-r--r--yardstick/tests/unit/test_cmd/commands/test_testcase.py8
-rw-r--r--yardstick/tests/unit/test_cmd/test_NSBperf.py10
-rw-r--r--yardstick/tests/unit/test_ssh.py62
127 files changed, 1807 insertions, 1227 deletions
diff --git a/yardstick/tests/__init__.py b/yardstick/tests/__init__.py
index e69de29bb..56e3106b8 100644
--- a/yardstick/tests/__init__.py
+++ b/yardstick/tests/__init__.py
@@ -0,0 +1,75 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import mock
+
+
+STL_MOCKS = {
+ 'trex_stl_lib': mock.MagicMock(),
+ 'trex_stl_lib.base64': mock.MagicMock(),
+ 'trex_stl_lib.binascii': mock.MagicMock(),
+ 'trex_stl_lib.collections': mock.MagicMock(),
+ 'trex_stl_lib.copy': mock.MagicMock(),
+ 'trex_stl_lib.datetime': mock.MagicMock(),
+ 'trex_stl_lib.functools': mock.MagicMock(),
+ 'trex_stl_lib.imp': mock.MagicMock(),
+ 'trex_stl_lib.inspect': mock.MagicMock(),
+ 'trex_stl_lib.json': mock.MagicMock(),
+ 'trex_stl_lib.linecache': mock.MagicMock(),
+ 'trex_stl_lib.math': mock.MagicMock(),
+ 'trex_stl_lib.os': mock.MagicMock(),
+ 'trex_stl_lib.platform': mock.MagicMock(),
+ 'trex_stl_lib.pprint': mock.MagicMock(),
+ 'trex_stl_lib.random': mock.MagicMock(),
+ 'trex_stl_lib.re': mock.MagicMock(),
+ 'trex_stl_lib.scapy': mock.MagicMock(),
+ 'trex_stl_lib.socket': mock.MagicMock(),
+ 'trex_stl_lib.string': mock.MagicMock(),
+ 'trex_stl_lib.struct': mock.MagicMock(),
+ 'trex_stl_lib.sys': mock.MagicMock(),
+ 'trex_stl_lib.threading': mock.MagicMock(),
+ 'trex_stl_lib.time': mock.MagicMock(),
+ 'trex_stl_lib.traceback': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_client': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_ext': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_port': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_stats': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_streams': mock.MagicMock(),
+ 'trex_stl_lib.trex_stl_types': mock.MagicMock(),
+ 'trex_stl_lib.types': mock.MagicMock(),
+ 'trex_stl_lib.utils': mock.MagicMock(),
+ 'trex_stl_lib.utils.argparse': mock.MagicMock(),
+ 'trex_stl_lib.utils.collections': mock.MagicMock(),
+ 'trex_stl_lib.utils.common': mock.MagicMock(),
+ 'trex_stl_lib.utils.json': mock.MagicMock(),
+ 'trex_stl_lib.utils.os': mock.MagicMock(),
+ 'trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
+ 'trex_stl_lib.utils.pwd': mock.MagicMock(),
+ 'trex_stl_lib.utils.random': mock.MagicMock(),
+ 'trex_stl_lib.utils.re': mock.MagicMock(),
+ 'trex_stl_lib.utils.string': mock.MagicMock(),
+ 'trex_stl_lib.utils.sys': mock.MagicMock(),
+ 'trex_stl_lib.utils.text_opts': mock.MagicMock(),
+ 'trex_stl_lib.utils.text_tables': mock.MagicMock(),
+ 'trex_stl_lib.utils.texttable': mock.MagicMock(),
+ 'trex_stl_lib.warnings': mock.MagicMock(),
+ 'trex_stl_lib.yaml': mock.MagicMock(),
+ 'trex_stl_lib.zlib': mock.MagicMock(),
+ 'trex_stl_lib.zmq': mock.MagicMock(),
+}
diff --git a/yardstick/tests/functional/base.py b/yardstick/tests/functional/base.py
new file mode 100644
index 000000000..51be013a1
--- /dev/null
+++ b/yardstick/tests/functional/base.py
@@ -0,0 +1,46 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import abc
+import six
+
+from oslo_config import cfg
+from oslotest import base
+
+
+CONF = cfg.CONF
+
+
+@six.add_metaclass(abc.ABCMeta)
+class BaseFunctionalTestCase(base.BaseTestCase):
+ """Base class for functional tests."""
+
+ def setUp(self):
+ super(BaseFunctionalTestCase, self).setUp()
+
+ def config(self, **kw):
+ """Override some configuration values.
+
+ The keyword arguments are the names of configuration options to
+ override and their values.
+
+ If a group argument is supplied, the overrides are applied to
+ the specified configuration option group.
+
+ All overrides are automatically cleared at the end of the current
+ test by the fixtures cleanup process.
+ """
+ group = kw.pop('group', None)
+ for k, v in kw.items():
+ CONF.set_override(k, v, group)
diff --git a/yardstick/tests/functional/benchmark/__init__.py b/yardstick/tests/functional/benchmark/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/benchmark/__init__.py
diff --git a/yardstick/tests/functional/benchmark/scenarios/__init__.py b/yardstick/tests/functional/benchmark/scenarios/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/benchmark/scenarios/__init__.py
diff --git a/yardstick/tests/functional/benchmark/scenarios/networking/__init__.py b/yardstick/tests/functional/benchmark/scenarios/networking/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/benchmark/scenarios/networking/__init__.py
diff --git a/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py
new file mode 100644
index 000000000..38f1a978d
--- /dev/null
+++ b/yardstick/tests/functional/benchmark/scenarios/networking/test_vnf_generic.py
@@ -0,0 +1,195 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import copy
+import sys
+
+import mock
+import unittest
+
+from yardstick import tests as y_tests
+from yardstick.common import utils
+
+
+with mock.patch.dict(sys.modules, y_tests.STL_MOCKS):
+ from yardstick.benchmark.scenarios.networking import vnf_generic
+
+
+TRAFFIC_PROFILE_1 = """
+schema: nsb:traffic_profile:0.1
+name: rfc2544
+description: Traffic profile to run RFC2544 latency
+traffic_profile:
+ traffic_type : RFC2544Profile
+ frame_rate : 100
+uplink_0:
+ ipv4:
+ id: 1
+ outer_l2:
+ framesize:
+ 64B: "{{get(imix, 'imix.uplink.64B', '0') }}"
+ 128B: "{{get(imix, 'imix.uplink.128B', '0') }}"
+"""
+
+TRAFFIC_PROFILE_2 = """
+{% set vports = get(extra_args, 'vports', 1) %}
+traffic_profile:
+ traffic_type : RFC2544Profile
+{% for vport in range(vports|int) %}
+uplink_{{vport}}:
+ ipv4: 192.168.0.{{vport}}
+{% endfor %}
+"""
+
+TOPOLOGY_PROFILE = """
+{% set vports = get(extra_args, 'vports', 2) %}
+nsd:nsd-catalog:
+ nsd:
+ - id: 3tg-topology
+ vld:
+{% for vport in range(0,vports,2|int) %}
+ - id: uplink_{{loop.index0}}
+ name: tg__0 to vnf__0 link {{vport + 1}}
+ vnfd-connection-point-ref:
+ - vnfd-connection-point-ref: xe{{vport}}
+ - id: downlink_{{loop.index0}}
+ name: vnf__0 to tg__0 link {{vport + 2}}
+ vnfd-connection-point-ref:
+ - vnfd-connection-point-ref: xe{{vport+1}}
+{% endfor %}
+"""
+
+class VnfGenericTestCase(unittest.TestCase):
+
+ def setUp(self):
+ scenario_cfg = {'topology': 'fake_topology',
+ 'task_path': 'fake_path',
+ 'traffic_profile': 'fake_fprofile_path'}
+ context_cfg = {}
+ topology_yaml = {'nsd:nsd-catalog': {'nsd': [mock.Mock()]}}
+
+ with mock.patch.object(utils, 'open_relative_file') as mock_open_path:
+ mock_open_path.side_effect = mock.mock_open(read_data=str(topology_yaml))
+ self.ns_testcase = vnf_generic.NetworkServiceTestCase(scenario_cfg,
+ context_cfg)
+ self.ns_testcase._get_traffic_profile = mock.Mock()
+ self.ns_testcase._get_topology = mock.Mock()
+
+ def test__fill_traffic_profile_no_args(self):
+ traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_1)
+ self.ns_testcase._get_traffic_profile.return_value = traffic_profile
+
+ self.ns_testcase._fill_traffic_profile()
+ config = self.ns_testcase.traffic_profile.params
+ self.assertEqual('nsb:traffic_profile:0.1', config['schema'])
+ self.assertEqual('rfc2544', config['name'])
+ self.assertEqual('Traffic profile to run RFC2544 latency',
+ config['description'])
+ t_profile = {'traffic_type': 'RFC2544Profile',
+ 'frame_rate': 100}
+ self.assertEqual(t_profile, config['traffic_profile'])
+ uplink_0 = {
+ 'ipv4': {'id': 1,
+ 'outer_l2': {'framesize': {'128B': '0', '64B': '0'}}
+ }
+ }
+ self.assertEqual(uplink_0, config['uplink_0'])
+
+ def test__fill_traffic_profile_with_args(self):
+ traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_2)
+ self.ns_testcase._get_traffic_profile.return_value = traffic_profile
+ self.ns_testcase.scenario_cfg['extra_args'] = {'vports': 3}
+
+ self.ns_testcase._fill_traffic_profile()
+ config = self.ns_testcase.traffic_profile.params
+ self.assertEqual({'ipv4': '192.168.0.0'}, config['uplink_0'])
+ self.assertEqual({'ipv4': '192.168.0.1'}, config['uplink_1'])
+ self.assertEqual({'ipv4': '192.168.0.2'}, config['uplink_2'])
+ self.assertNotIn('uplink_3', config)
+
+ def test__fill_traffic_profile_incorrect_args(self):
+ traffic_profile = copy.deepcopy(TRAFFIC_PROFILE_2)
+ self.ns_testcase._get_traffic_profile.return_value = traffic_profile
+ self.ns_testcase.scenario_cfg['extra_args'] = {'incorrect_vports': 3}
+
+ self.ns_testcase._fill_traffic_profile()
+ config = self.ns_testcase.traffic_profile.params
+ self.assertEqual({'ipv4': '192.168.0.0'}, config['uplink_0'])
+ self.assertNotIn('uplink_1', config)
+
+ def test__render_topology_with_args(self):
+ topology_profile = copy.deepcopy(TOPOLOGY_PROFILE)
+ self.ns_testcase._get_topology.return_value = topology_profile
+ self.ns_testcase.scenario_cfg['extra_args'] = {'vports': 6}
+
+ self.ns_testcase._render_topology()
+ topology = self.ns_testcase.topology
+ self.assertEqual("3tg-topology", topology['id'])
+ vld = self.ns_testcase.topology['vld']
+ self.assertEqual(len(vld), 6)
+ for index, vport in enumerate(range(0, 6, 2)):
+ self.assertEqual('uplink_{}'.format(index), vld[vport]['id'])
+ self.assertEqual('tg__0 to vnf__0 link {}'.format(vport + 1), vld[vport]['name'])
+ self.assertEqual('xe{}'.format(vport),
+ vld[vport]['vnfd-connection-point-ref'][0]
+ ['vnfd-connection-point-ref'])
+
+ self.assertEqual('downlink_{}'.format(index), vld[vport + 1]['id'])
+ self.assertEqual('vnf__0 to tg__0 link {}'.format(vport + 2), vld[vport + 1]['name'])
+ self.assertEqual('xe{}'.format(vport + 1),
+ vld[vport + 1]['vnfd-connection-point-ref'][0]
+ ['vnfd-connection-point-ref'])
+
+ def test__render_topology_incorrect_args(self):
+ topology_profile = copy.deepcopy(TOPOLOGY_PROFILE)
+ self.ns_testcase._get_topology.return_value = topology_profile
+ self.ns_testcase.scenario_cfg['extra_args'] = {'fake_vports': 5}
+
+ self.ns_testcase._render_topology()
+
+ topology = self.ns_testcase.topology
+ self.assertEqual("3tg-topology", topology['id'])
+ vld = self.ns_testcase.topology['vld']
+ self.assertEqual(len(vld), 2)
+
+ self.assertEqual('uplink_0', vld[0]['id'])
+ self.assertEqual('tg__0 to vnf__0 link 1', vld[0]['name'])
+ self.assertEqual('xe0',
+ vld[0]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])
+
+ self.assertEqual('downlink_0', vld[1]['id'])
+ self.assertEqual('vnf__0 to tg__0 link 2', vld[1]['name'])
+ self.assertEqual('xe1',
+ vld[1]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])
+
+ def test__render_topology_no_args(self):
+ topology_profile = copy.deepcopy(TOPOLOGY_PROFILE)
+ self.ns_testcase._get_topology.return_value = topology_profile
+
+ self.ns_testcase._render_topology()
+
+ topology = self.ns_testcase.topology
+ self.assertEqual("3tg-topology", topology['id'])
+ vld = self.ns_testcase.topology['vld']
+ self.assertEqual(len(vld), 2)
+
+ self.assertEqual('uplink_0', vld[0]['id'])
+ self.assertEqual('tg__0 to vnf__0 link 1', vld[0]['name'])
+ self.assertEqual('xe0',
+ vld[0]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])
+
+ self.assertEqual('downlink_0', vld[1]['id'])
+ self.assertEqual('vnf__0 to tg__0 link 2', vld[1]['name'])
+ self.assertEqual('xe1',
+ vld[1]['vnfd-connection-point-ref'][0]['vnfd-connection-point-ref'])
diff --git a/yardstick/tests/functional/common/fake_directory_package/README.md b/yardstick/tests/functional/common/fake_directory_package/README.md
new file mode 100644
index 000000000..689e47039
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/README.md
@@ -0,0 +1,2 @@
+# yardstick_new_plugin
+Yardstick plugin
diff --git a/yardstick/tests/functional/common/fake_directory_package/setup.py b/yardstick/tests/functional/common/fake_directory_package/setup.py
new file mode 100644
index 000000000..cf938ef4f
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/setup.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from setuptools import setup, find_packages
+
+setup(
+ name='yardstick_new_plugin_2',
+ version='1.0.0',
+ packages=find_packages(),
+ include_package_data=True,
+ url='https://www.opnfv.org',
+ entry_points={
+ 'yardstick.scenarios': [
+ 'Dummy2 = yardstick_new_plugin.benchmark.scenarios.dummy2.dummy2:'
+ 'Dummy2',
+ ]
+ },
+)
diff --git a/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/__init__.py b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/__init__.py
diff --git a/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/__init__.py b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/__init__.py
diff --git a/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/__init__.py b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/__init__.py
diff --git a/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/__init__.py b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/__init__.py
diff --git a/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/dummy2.py b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/dummy2.py
new file mode 100644
index 000000000..a2211ec51
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_directory_package/yardstick_new_plugin_2/benchmark/scenarios/dummy2/dummy2.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import logging
+
+from yardstick.benchmark.scenarios import base
+
+
+LOG = logging.getLogger(__name__)
+
+
+class Dummy2(base.Scenario):
+ """Execute Dummy (v2!) echo"""
+ __scenario_type__ = "Dummy2"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.setup_done = False
+
+ def setup(self):
+ self.setup_done = True
+
+ def run(self, result):
+ if not self.setup_done:
+ self.setup()
+
+ result["hello"] = "yardstick"
+ LOG.info("Dummy (v2!) echo hello yardstick!")
diff --git a/yardstick/tests/functional/common/fake_pip_package/yardstick_new_plugin-1.0.0.tar.gz b/yardstick/tests/functional/common/fake_pip_package/yardstick_new_plugin-1.0.0.tar.gz
new file mode 100644
index 000000000..e5379a78a
--- /dev/null
+++ b/yardstick/tests/functional/common/fake_pip_package/yardstick_new_plugin-1.0.0.tar.gz
Binary files differ
diff --git a/yardstick/tests/functional/common/test_packages.py b/yardstick/tests/functional/common/test_packages.py
new file mode 100644
index 000000000..5dead4e55
--- /dev/null
+++ b/yardstick/tests/functional/common/test_packages.py
@@ -0,0 +1,94 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+from os import path
+import re
+
+from yardstick.common import packages
+from yardstick.common import utils
+from yardstick.tests.functional import base
+
+
+class PipPackagesTestCase(base.BaseFunctionalTestCase):
+
+ TMP_FOLDER = '/tmp/pip_packages/'
+ PYTHONPATH = 'PYTHONPATH=%s' % TMP_FOLDER
+
+ def setUp(self):
+ super(PipPackagesTestCase, self).setUp()
+ privsep_helper = os.path.join(
+ os.getenv('VIRTUAL_ENV'), 'bin', 'privsep-helper')
+ self.config(
+ helper_command=' '.join(['sudo', '-EH', privsep_helper]),
+ group='yardstick_privileged')
+ self.addCleanup(self._cleanup)
+
+ def _cleanup(self):
+ utils.execute_command('sudo rm -rf %s' % self.TMP_FOLDER)
+
+ def _remove_package(self, package):
+ os.system('%s pip uninstall %s -y' % (self.PYTHONPATH, package))
+
+ def _list_packages(self):
+ pip_list_regex = re.compile(
+ r"(?P<name>[\w\.-]+) \((?P<version>[\w\d_\.\-]+),*.*\)")
+ pkg_dict = {}
+ pkgs = utils.execute_command('pip list',
+ env={'PYTHONPATH': self.TMP_FOLDER})
+ for line in pkgs:
+ match = pip_list_regex.match(line)
+ if match and match.group('name'):
+ pkg_dict[match.group('name')] = match.group('version')
+ return pkg_dict
+
+ def test_install_from_folder(self):
+ dirname = path.dirname(__file__)
+ package_dir = dirname + '/fake_directory_package'
+ package_name = 'yardstick-new-plugin-2'
+ self.addCleanup(self._remove_package, package_name)
+ self._remove_package(package_name)
+ self.assertFalse(package_name in self._list_packages())
+
+ self.assertEqual(0, packages.pip_install(package_dir, self.TMP_FOLDER))
+ self.assertTrue(package_name in self._list_packages())
+
+ def test_install_from_pip_package(self):
+ dirname = path.dirname(__file__)
+ package_path = (dirname +
+ '/fake_pip_package/yardstick_new_plugin-1.0.0.tar.gz')
+ package_name = 'yardstick-new-plugin'
+ self.addCleanup(self._remove_package, package_name)
+ self._remove_package(package_name)
+ self.assertFalse(package_name in self._list_packages())
+
+ self.assertEqual(0, packages.pip_install(package_path, self.TMP_FOLDER))
+ self.assertTrue(package_name in self._list_packages())
+
+ # NOTE(ralonsoh): an stable test plugin project is needed in OPNFV git
+ # server to execute this test.
+ # def test_install_from_url(self):
+
+ def test_pip_freeze(self):
+ # NOTE (ralonsoh): from requirements.txt file. The best way to test
+ # this function is to parse requirements.txt and test-requirements.txt
+ # and check all packages.
+ pkgs_ref = {'Babel': '2.3.4',
+ 'SQLAlchemy': '1.1.12',
+ 'influxdb': '4.1.1',
+ 'netifaces': '0.10.6',
+ 'unicodecsv': '0.14.1'}
+ pkgs = packages.pip_list()
+ for name, version in (pkgs_ref.items()):
+ self.assertEqual(version, pkgs[name])
diff --git a/yardstick/tests/unit/__init__.py b/yardstick/tests/unit/__init__.py
index a468b272b..c05f91c81 100644
--- a/yardstick/tests/unit/__init__.py
+++ b/yardstick/tests/unit/__init__.py
@@ -12,65 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import absolute_import
+import sys
+
import mock
+from yardstick import tests
+
-STL_MOCKS = {
- 'trex_stl_lib': mock.MagicMock(),
- 'trex_stl_lib.base64': mock.MagicMock(),
- 'trex_stl_lib.binascii': mock.MagicMock(),
- 'trex_stl_lib.collections': mock.MagicMock(),
- 'trex_stl_lib.copy': mock.MagicMock(),
- 'trex_stl_lib.datetime': mock.MagicMock(),
- 'trex_stl_lib.functools': mock.MagicMock(),
- 'trex_stl_lib.imp': mock.MagicMock(),
- 'trex_stl_lib.inspect': mock.MagicMock(),
- 'trex_stl_lib.json': mock.MagicMock(),
- 'trex_stl_lib.linecache': mock.MagicMock(),
- 'trex_stl_lib.math': mock.MagicMock(),
- 'trex_stl_lib.os': mock.MagicMock(),
- 'trex_stl_lib.platform': mock.MagicMock(),
- 'trex_stl_lib.pprint': mock.MagicMock(),
- 'trex_stl_lib.random': mock.MagicMock(),
- 'trex_stl_lib.re': mock.MagicMock(),
- 'trex_stl_lib.scapy': mock.MagicMock(),
- 'trex_stl_lib.socket': mock.MagicMock(),
- 'trex_stl_lib.string': mock.MagicMock(),
- 'trex_stl_lib.struct': mock.MagicMock(),
- 'trex_stl_lib.sys': mock.MagicMock(),
- 'trex_stl_lib.threading': mock.MagicMock(),
- 'trex_stl_lib.time': mock.MagicMock(),
- 'trex_stl_lib.traceback': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_client': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_ext': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_port': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_stats': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_streams': mock.MagicMock(),
- 'trex_stl_lib.trex_stl_types': mock.MagicMock(),
- 'trex_stl_lib.types': mock.MagicMock(),
- 'trex_stl_lib.utils': mock.MagicMock(),
- 'trex_stl_lib.utils.argparse': mock.MagicMock(),
- 'trex_stl_lib.utils.collections': mock.MagicMock(),
- 'trex_stl_lib.utils.common': mock.MagicMock(),
- 'trex_stl_lib.utils.json': mock.MagicMock(),
- 'trex_stl_lib.utils.os': mock.MagicMock(),
- 'trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
- 'trex_stl_lib.utils.pwd': mock.MagicMock(),
- 'trex_stl_lib.utils.random': mock.MagicMock(),
- 'trex_stl_lib.utils.re': mock.MagicMock(),
- 'trex_stl_lib.utils.string': mock.MagicMock(),
- 'trex_stl_lib.utils.sys': mock.MagicMock(),
- 'trex_stl_lib.utils.text_opts': mock.MagicMock(),
- 'trex_stl_lib.utils.text_tables': mock.MagicMock(),
- 'trex_stl_lib.utils.texttable': mock.MagicMock(),
- 'trex_stl_lib.warnings': mock.MagicMock(),
- 'trex_stl_lib.yaml': mock.MagicMock(),
- 'trex_stl_lib.zlib': mock.MagicMock(),
- 'trex_stl_lib.zmq': mock.MagicMock(),
-}
+mock_stl = mock.patch.dict(sys.modules, tests.STL_MOCKS)
+mock_stl.start()
diff --git a/yardstick/tests/unit/apiserver/resources/test_env_action.py b/yardstick/tests/unit/apiserver/resources/test_env_action.py
index cf646a29c..657841669 100644
--- a/yardstick/tests/unit/apiserver/resources/test_env_action.py
+++ b/yardstick/tests/unit/apiserver/resources/test_env_action.py
@@ -33,11 +33,3 @@ class EnvTestCase(APITestCase):
time.sleep(0)
self.assertIn(u'status', resp)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/apiserver/utils/test_influx.py b/yardstick/tests/unit/apiserver/utils/test_influx.py
index 883608bb2..dce6c1cec 100644
--- a/yardstick/tests/unit/apiserver/utils/test_influx.py
+++ b/yardstick/tests/unit/apiserver/utils/test_influx.py
@@ -50,11 +50,3 @@ class QueryTestCase(unittest.TestCase):
influx.query(sql)
except Exception as e: # pylint: disable=broad-except
self.assertIsInstance(e, RuntimeError)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/base.py b/yardstick/tests/unit/base.py
new file mode 100644
index 000000000..b943efc2b
--- /dev/null
+++ b/yardstick/tests/unit/base.py
@@ -0,0 +1,23 @@
+# Copyright 2018 Intel Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import abc
+
+import six
+import unittest
+
+
+@six.add_metaclass(abc.ABCMeta)
+class BaseUnitTestCase(unittest.TestCase):
+ """Base class for unit tests"""
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
index 02a85525a..0223fd3ff 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -26,14 +26,6 @@ class OvsDpdkContextTestCase(unittest.TestCase):
NODES_ovs_dpdk_SAMPLE = "nodes_ovs_dpdk_sample.yaml"
NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml"
- ATTRS = {
- 'name': 'StandaloneOvsDpdk',
- 'file': 'pod',
- 'flavor': {},
- 'servers': {},
- 'networks': {},
- }
-
NETWORKS = {
'mgmt': {'cidr': '152.16.100.10/24'},
'private_0': {
@@ -55,7 +47,17 @@ class OvsDpdkContextTestCase(unittest.TestCase):
}
def setUp(self):
+ self.attrs = {
+ 'name': 'foo',
+ 'task_id': '1234567890',
+ 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
+ }
self.ovs_dpdk = ovs_dpdk.OvsDpdkContext()
+ self.addCleanup(self._remove_contexts)
+
+ def _remove_contexts(self):
+ if self.ovs_dpdk in self.ovs_dpdk.list:
+ self.ovs_dpdk._delete_context()
@mock.patch('yardstick.benchmark.contexts.standalone.model.Server')
@mock.patch('yardstick.benchmark.contexts.standalone.model.StandaloneContextHelper')
@@ -66,9 +68,18 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.assertTrue(self.ovs_dpdk.first_run)
def test_init(self):
+ ATTRS = {
+ 'name': 'StandaloneOvsDpdk',
+ 'task_id': '1234567890',
+ 'file': 'pod',
+ 'flavor': {},
+ 'servers': {},
+ 'networks': {},
+ }
+
self.ovs_dpdk.helper.parse_pod_file = mock.Mock(
return_value=[{}, {}, {}])
- self.assertIsNone(self.ovs_dpdk.init(self.ATTRS))
+ self.assertIsNone(self.ovs_dpdk.init(ATTRS))
def test_setup_ovs(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
@@ -186,12 +197,7 @@ class OvsDpdkContextTestCase(unittest.TestCase):
def test__get_server_with_dic_attr_name(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
- }
-
- self.ovs_dpdk.init(attrs)
+ self.ovs_dpdk.init(self.attrs)
attr_name = {'name': 'foo.bar'}
result = self.ovs_dpdk._get_server(attr_name)
@@ -200,14 +206,9 @@ class OvsDpdkContextTestCase(unittest.TestCase):
def test__get_server_not_found(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
- }
-
self.ovs_dpdk.helper.parse_pod_file = mock.Mock(
return_value=[{}, {}, {}])
- self.ovs_dpdk.init(attrs)
+ self.ovs_dpdk.init(self.attrs)
attr_name = 'bar.foo'
result = self.ovs_dpdk._get_server(attr_name)
@@ -216,12 +217,7 @@ class OvsDpdkContextTestCase(unittest.TestCase):
def test__get_server_mismatch(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
- }
-
- self.ovs_dpdk.init(attrs)
+ self.ovs_dpdk.init(self.attrs)
attr_name = 'bar.foo1'
result = self.ovs_dpdk._get_server(attr_name)
@@ -230,31 +226,23 @@ class OvsDpdkContextTestCase(unittest.TestCase):
def test__get_server_duplicate(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
- }
+ self.attrs['file'] = self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
- self.ovs_dpdk.init(attrs)
+ self.ovs_dpdk.init(self.attrs)
- attr_name = 'node1.foo'
+ attr_name = 'node1.foo-12345678'
with self.assertRaises(ValueError):
self.ovs_dpdk._get_server(attr_name)
def test__get_server_found(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
- }
-
- self.ovs_dpdk.init(attrs)
+ self.ovs_dpdk.init(self.attrs)
- attr_name = 'node1.foo'
+ attr_name = 'node1.foo-12345678'
result = self.ovs_dpdk._get_server(attr_name)
self.assertEqual(result['ip'], '10.229.47.137')
- self.assertEqual(result['name'], 'node1.foo')
+ self.assertEqual(result['name'], 'node1.foo-12345678')
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
index f323fcd3c..f0953ef55 100644
--- a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
+++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py
@@ -29,6 +29,7 @@ class SriovContextTestCase(unittest.TestCase):
ATTRS = {
'name': 'StandaloneSriov',
+ 'task_id': '1234567890',
'file': 'pod',
'flavor': {},
'servers': {},
@@ -56,7 +57,17 @@ class SriovContextTestCase(unittest.TestCase):
}
def setUp(self):
+ self.attrs = {
+ 'name': 'foo',
+ 'task_id': '1234567890',
+ 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE)
+ }
self.sriov = sriov.SriovContext()
+ self.addCleanup(self._remove_contexts)
+
+ def _remove_contexts(self):
+ if self.sriov in self.sriov.list:
+ self.sriov._delete_context()
@mock.patch('yardstick.benchmark.contexts.standalone.sriov.Libvirt')
@mock.patch('yardstick.benchmark.contexts.standalone.model.StandaloneContextHelper')
@@ -105,12 +116,7 @@ class SriovContextTestCase(unittest.TestCase):
def test__get_server_with_dic_attr_name(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE)
- }
-
- self.sriov.init(attrs)
+ self.sriov.init(self.attrs)
attr_name = {'name': 'foo.bar'}
result = self.sriov._get_server(attr_name)
@@ -119,13 +125,8 @@ class SriovContextTestCase(unittest.TestCase):
def test__get_server_not_found(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE)
- }
-
self.sriov.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}])
- self.sriov.init(attrs)
+ self.sriov.init(self.attrs)
attr_name = 'bar.foo'
result = self.sriov._get_server(attr_name)
@@ -134,12 +135,7 @@ class SriovContextTestCase(unittest.TestCase):
def test__get_server_mismatch(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE)
- }
-
- self.sriov.init(attrs)
+ self.sriov.init(self.attrs)
attr_name = 'bar.foo1'
result = self.sriov._get_server(attr_name)
@@ -148,25 +144,29 @@ class SriovContextTestCase(unittest.TestCase):
def test__get_server_duplicate(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
- }
+ self.attrs['file'] = self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
- self.sriov.init(attrs)
+ self.sriov.init(self.attrs)
- attr_name = 'node1.foo'
+ attr_name = 'node1.foo-12345678'
with self.assertRaises(ValueError):
self.sriov._get_server(attr_name)
def test__get_server_found(self):
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SRIOV_SAMPLE)
- }
+ self.sriov.init(self.attrs)
+
+ attr_name = 'node1.foo-12345678'
+ result = self.sriov._get_server(attr_name)
+
+ self.assertEqual(result['ip'], '10.229.47.137')
+ self.assertEqual(result['name'], 'node1.foo-12345678')
+ self.assertEqual(result['user'], 'root')
+ self.assertEqual(result['key_filename'], '/root/.yardstick_key')
- self.sriov.init(attrs)
+ def test__get_server_no_task_id(self):
+ self.attrs['flags'] = {'no_setup': True}
+ self.sriov.init(self.attrs)
attr_name = 'node1.foo'
result = self.sriov._get_server(attr_name)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_base.py b/yardstick/tests/unit/benchmark/contexts/test_base.py
new file mode 100644
index 000000000..153c6a527
--- /dev/null
+++ b/yardstick/tests/unit/benchmark/contexts/test_base.py
@@ -0,0 +1,43 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+
+from yardstick.benchmark.contexts import base
+
+
+class FlagsTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.flags = base.Flags()
+
+ def test___init__(self):
+ self.assertFalse(self.flags.no_setup)
+ self.assertFalse(self.flags.no_teardown)
+
+ def test___init__with_flags(self):
+ flags = base.Flags(no_setup=True)
+ self.assertTrue(flags.no_setup)
+ self.assertFalse(flags.no_teardown)
+
+ def test_parse(self):
+ self.flags.parse(no_setup=True, no_teardown="False")
+
+ self.assertTrue(self.flags.no_setup)
+ self.assertEqual(self.flags.no_teardown, "False")
+
+ def test_parse_forbidden_flags(self):
+ self.flags.parse(foo=42)
+ with self.assertRaises(AttributeError):
+ _ = self.flags.foo
diff --git a/yardstick/tests/unit/benchmark/contexts/test_dummy.py b/yardstick/tests/unit/benchmark/contexts/test_dummy.py
index 1a54035df..e393001a1 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_dummy.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_dummy.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
@@ -9,9 +7,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.contexts.dummy
-
-from __future__ import absolute_import
import unittest
from yardstick.benchmark.contexts import dummy
@@ -20,10 +15,55 @@ from yardstick.benchmark.contexts import dummy
class DummyContextTestCase(unittest.TestCase):
def setUp(self):
+ self.attrs = {
+ 'name': 'foo',
+ 'task_id': '1234567890',
+ }
self.test_context = dummy.DummyContext()
+ self.addCleanup(self.test_context._delete_context)
+
+ def test___init__(self):
+ self.assertFalse(self.test_context._flags.no_setup)
+ self.assertFalse(self.test_context._flags.no_teardown)
+ self.assertIsNone(self.test_context._name)
+ self.assertIsNone(self.test_context._task_id)
+
+ def test_init(self):
+ self.test_context.init(self.attrs)
+ self.assertEqual(self.test_context._name, 'foo')
+ self.assertEqual(self.test_context._task_id, '1234567890')
+ self.assertFalse(self.test_context._flags.no_setup)
+ self.assertFalse(self.test_context._flags.no_teardown)
+
+ self.assertEqual(self.test_context.name, 'foo-12345678')
+ self.assertEqual(self.test_context.assigned_name, 'foo')
+
+ def test_init_flags_no_setup(self):
+ self.attrs['flags'] = {'no_setup': True, 'no_teardown': False}
+
+ self.test_context.init(self.attrs)
+
+ self.assertEqual(self.test_context._name, 'foo')
+ self.assertEqual(self.test_context._task_id, '1234567890')
+ self.assertTrue(self.test_context._flags.no_setup)
+ self.assertFalse(self.test_context._flags.no_teardown)
+
+ self.assertEqual(self.test_context.name, 'foo')
+ self.assertEqual(self.test_context.assigned_name, 'foo')
+
+ def test_init_flags_no_teardown(self):
+ self.attrs['flags'] = {'no_setup': False, 'no_teardown': True}
+
+ self.test_context.init(self.attrs)
+
+ self.assertFalse(self.test_context._flags.no_setup)
+ self.assertTrue(self.test_context._flags.no_teardown)
+
+ self.assertEqual(self.test_context.name, 'foo')
+ self.assertEqual(self.test_context.assigned_name, 'foo')
def test__get_server(self):
- self.test_context.init(None)
+ self.test_context.init(self.attrs)
self.test_context.deploy()
result = self.test_context._get_server(None)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_heat.py b/yardstick/tests/unit/benchmark/contexts/test_heat.py
index a87cf8120..c54a7ab12 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_heat.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_heat.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -13,13 +11,16 @@ from collections import OrderedDict
from itertools import count
import logging
import os
-import uuid
import mock
import unittest
+from yardstick.benchmark.contexts import base
from yardstick.benchmark.contexts import heat
from yardstick.benchmark.contexts import model
+from yardstick.common import constants as consts
+from yardstick.common import exceptions as y_exc
+from yardstick import ssh
LOG = logging.getLogger(__name__)
@@ -33,10 +34,18 @@ class HeatContextTestCase(unittest.TestCase):
def setUp(self):
self.test_context = heat.HeatContext()
+ self.addCleanup(self._remove_contexts)
self.mock_context = mock.Mock(spec=heat.HeatContext())
+ def _remove_contexts(self):
+ if self.test_context in self.test_context.list:
+ self.test_context._delete_context()
+
def test___init__(self):
- self.assertIsNone(self.test_context.name)
+ self.assertIsNone(self.test_context._name)
+ self.assertIsNone(self.test_context._task_id)
+ self.assertFalse(self.test_context._flags.no_setup)
+ self.assertFalse(self.test_context._flags.no_teardown)
self.assertIsNone(self.test_context.stack)
self.assertEqual(self.test_context.networks, OrderedDict())
self.assertEqual(self.test_context.servers, [])
@@ -50,8 +59,7 @@ 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)
+ self.assertIsNone(self.test_context.key_filename)
@mock.patch('yardstick.benchmark.contexts.heat.PlacementGroup')
@mock.patch('yardstick.benchmark.contexts.heat.ServerGroup')
@@ -64,6 +72,7 @@ class HeatContextTestCase(unittest.TestCase):
networks = {'bar': {'cidr': '10.0.1.0/24'}}
servers = {'baz': {'floating_ip': True, 'placement': 'pgrp1'}}
attrs = {'name': 'foo',
+ 'task_id': '1234567890',
'placement_groups': pgs,
'server_groups': sgs,
'networks': networks,
@@ -71,9 +80,13 @@ 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")
+ self.assertFalse(self.test_context._flags.no_setup)
+ self.assertFalse(self.test_context._flags.no_teardown)
+ self.assertEqual(self.test_context._name, "foo")
+ self.assertEqual(self.test_context._task_id, '1234567890')
+ self.assertEqual(self.test_context.name, "foo-12345678")
+ self.assertEqual(self.test_context.keypair_name, "foo-12345678-key")
+ self.assertEqual(self.test_context.secgroup_name, "foo-12345678-secgroup")
mock_pg.assert_called_with('pgrp1', self.test_context,
pgs['pgrp1']['policy'])
@@ -90,40 +103,76 @@ class HeatContextTestCase(unittest.TestCase):
servers['baz'])
self.assertEqual(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)
+ def test_init_no_name_or_task_id(self):
+ attrs = {}
+ self.assertRaises(KeyError, self.test_context.init, attrs)
+
+ def test_name(self):
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
+ self.assertEqual(self.test_context.name, 'foo-12345678')
+ self.assertEqual(self.test_context.assigned_name, 'foo')
+
+ def test_name_flags(self):
+ self.test_context._flags = base.Flags(
+ **{"no_setup": True, "no_teardown": True})
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+
+ self.assertEqual(self.test_context.name, 'foo')
+ self.assertEqual(self.test_context.assigned_name, 'foo')
+
+ def test_init_no_setup_no_teardown(self):
+
+ attrs = {'name': 'foo',
+ 'task_id': '1234567890',
+ 'placement_groups': {},
+ 'server_groups': {},
+ 'networks': {},
+ 'servers': {},
+ 'flags': {
+ 'no_setup': True,
+ 'no_teardown': True,
+ },
+ }
+
+ self.test_context.init(attrs)
+ self.assertTrue(self.test_context._flags.no_setup)
+ self.assertTrue(self.test_context._flags.no_teardown)
@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._name = 'ctx'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
+ self.test_context.keypair_name = "ctx-key"
+ self.test_context.secgroup_name = "ctx-secgroup"
self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b"
- netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'}
- self.mock_context.name = 'bar'
+ netattrs = {'cidr': '10.0.0.0/24', 'provider': None,
+ 'external_network': 'ext_net'}
+
self.test_context.networks = OrderedDict(
- {"fool-network": model.Network("fool-network", self.mock_context,
+ {"mynet": model.Network("mynet", self.test_context,
netattrs)})
self.test_context._add_resources_to_template(mock_template)
mock_template.add_keypair.assert_called_with(
- "foo-key",
- "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
- mock_template.add_security_group.assert_called_with("foo-secgroup")
-# mock_template.add_network.assert_called_with("bar-fool-network", 'physnet1', None)
+ "ctx-key",
+ "ctx-12345678")
+ mock_template.add_security_group.assert_called_with("ctx-secgroup")
+ mock_template.add_network.assert_called_with(
+ "ctx-12345678-mynet", 'physnet1', None, None, None, None)
mock_template.add_router.assert_called_with(
- "bar-fool-network-router",
+ "ctx-12345678-mynet-router",
netattrs["external_network"],
- "bar-fool-network-subnet")
+ "ctx-12345678-mynet-subnet")
mock_template.add_router_interface.assert_called_with(
- "bar-fool-network-router-if0",
- "bar-fool-network-router",
- "bar-fool-network-subnet")
+ "ctx-12345678-mynet-router-if0",
+ "ctx-12345678-mynet-router",
+ "ctx-12345678-mynet-subnet")
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test_attrs_get(self, *args):
@@ -148,23 +197,162 @@ class HeatContextTestCase(unittest.TestCase):
with self.assertRaises(AttributeError):
self.test_context.user = 'foo'
+ def test__create_new_stack(self):
+ template = mock.Mock()
+ self.test_context._create_new_stack(template)
+ template.create.assert_called_once()
+
+ def test__create_new_stack_stack_create_failed(self):
+ template = mock.Mock()
+ template.create.side_effect = y_exc.HeatTemplateError
+
+ self.assertRaises(y_exc.HeatTemplateError,
+ self.test_context._create_new_stack,
+ template)
+
+ def test__create_new_stack_keyboard_interrupt(self):
+ template = mock.Mock()
+ template.create.side_effect = KeyboardInterrupt
+ self.assertRaises(y_exc.StackCreationInterrupt,
+ self.test_context._create_new_stack,
+ template)
+
+ @mock.patch.object(os.path, 'exists', return_value=True)
+ @mock.patch.object(heat.HeatContext, '_add_resources_to_template')
+ @mock.patch.object(heat.HeatContext, '_create_new_stack')
+ def test_deploy_stack_creation_failed(self, mock_create,
+ mock_resources_template, mock_path_exists):
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = 'foo-12345678'
+ mock_create.side_effect = y_exc.HeatTemplateError
+ self.assertRaises(y_exc.HeatTemplateError,
+ self.test_context.deploy)
+
+ mock_path_exists.assert_called_once()
+ mock_resources_template.assert_called_once()
+
+ @mock.patch.object(os.path, 'exists', return_value=False)
+ @mock.patch.object(ssh.SSH, 'gen_keys')
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
- def test_deploy(self, mock_template):
- self.test_context.name = 'foo'
+ def test_deploy(self, mock_template, mock_genkeys, mock_path_exists):
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
self.test_context.template_file = '/bar/baz/some-heat-file'
self.test_context.heat_parameters = {'image': 'cirros'}
self.test_context.get_neutron_info = mock.MagicMock()
self.test_context.deploy()
- mock_template.assert_called_with('foo',
+ mock_template.assert_called_with('foo-12345678',
'/bar/baz/some-heat-file',
{'image': 'cirros'})
self.assertIsNotNone(self.test_context.stack)
+ key_filename = ''.join(
+ [consts.YARDSTICK_ROOT_PATH,
+ 'yardstick/resources/files/yardstick_key-',
+ self.test_context._name_task_id])
+ mock_genkeys.assert_called_once_with(key_filename)
+ mock_path_exists.assert_called_once_with(key_filename)
+
+ @mock.patch.object(heat, 'HeatTemplate')
+ @mock.patch.object(os.path, 'exists', return_value=False)
+ @mock.patch.object(ssh.SSH, 'gen_keys')
+ @mock.patch.object(heat.HeatContext, '_retrieve_existing_stack')
+ @mock.patch.object(heat.HeatContext, '_create_new_stack')
+ def test_deploy_no_setup(self, mock_create_new_stack,
+ mock_retrieve_existing_stack, mock_genkeys, mock_path_exists,
+ *args):
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context.template_file = '/bar/baz/some-heat-file'
+ self.test_context.heat_parameters = {'image': 'cirros'}
+ self.test_context.get_neutron_info = mock.MagicMock()
+ self.test_context._flags.no_setup = True
+ self.test_context.deploy()
+
+ mock_create_new_stack.assert_not_called()
+ mock_retrieve_existing_stack.assert_called_with(self.test_context.name)
+ self.assertIsNotNone(self.test_context.stack)
+ key_filename = ''.join(
+ [consts.YARDSTICK_ROOT_PATH,
+ 'yardstick/resources/files/yardstick_key-',
+ self.test_context._name])
+ mock_genkeys.assert_called_once_with(key_filename)
+ mock_path_exists.assert_called_once_with(key_filename)
+
+ @mock.patch.object(heat, 'HeatTemplate')
+ @mock.patch.object(os.path, 'exists', return_value=False)
+ @mock.patch.object(ssh.SSH, 'gen_keys')
+ @mock.patch.object(heat.HeatContext, '_create_new_stack')
+ @mock.patch.object(heat.HeatContext, '_retrieve_existing_stack',
+ return_value=None)
+ def test_deploy_try_retrieve_context_does_not_exist(self,
+ mock_retrieve_stack, mock_create_new_stack, mock_genkeys,
+ mock_path_exists, *args):
+ self.test_context._name = 'demo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._flags.no_setup = True
+ self.test_context.template_file = '/bar/baz/some-heat-file'
+ self.test_context.get_neutron_info = mock.MagicMock()
+
+ self.test_context.deploy()
+
+ mock_retrieve_stack.assert_called_once_with(self.test_context._name)
+ mock_create_new_stack.assert_called()
+ key_filename = ''.join(
+ [consts.YARDSTICK_ROOT_PATH,
+ 'yardstick/resources/files/yardstick_key-',
+ self.test_context._name])
+ mock_genkeys.assert_called_once_with(key_filename)
+ mock_path_exists.assert_called_once_with(key_filename)
+
+ @mock.patch.object(heat, 'HeatTemplate', return_value='heat_template')
+ @mock.patch.object(heat.HeatContext, '_add_resources_to_template')
+ @mock.patch.object(os.path, 'exists', return_value=False)
+ @mock.patch.object(ssh.SSH, 'gen_keys')
+ def test_deploy_ssh_key_before_adding_resources(self, mock_genkeys,
+ mock_path_exists, mock_add_resources, *args):
+ mock_manager = mock.Mock()
+ mock_manager.attach_mock(mock_add_resources,
+ '_add_resources_to_template')
+ mock_manager.attach_mock(mock_genkeys, 'gen_keys')
+ mock_manager.reset_mock()
+ self.test_context._name_task_id = 'demo-12345678'
+ self.test_context.get_neutron_info = mock.Mock()
+ with mock.patch.object(self.test_context, '_create_new_stack') as \
+ mock_create_stack, \
+ mock.patch.object(self.test_context, 'get_neutron_info') as \
+ mock_neutron_info:
+ self.test_context.deploy()
+
+ mock_neutron_info.assert_called_once()
+ mock_create_stack.assert_called_once()
+ key_filename = ''.join(
+ [consts.YARDSTICK_ROOT_PATH,
+ 'yardstick/resources/files/yardstick_key-',
+ self.test_context._name_task_id])
+ mock_genkeys.assert_called_once_with(key_filename)
+ mock_path_exists.assert_called_with(key_filename)
+
+ mock_call_gen_keys = mock.call.gen_keys(key_filename)
+ mock_call_add_resources = (
+ mock.call._add_resources_to_template('heat_template'))
+ self.assertTrue(mock_manager.mock_calls.index(mock_call_gen_keys) <
+ mock_manager.mock_calls.index(mock_call_add_resources))
+
+ def test_check_for_context(self):
+ pass
+ # check that the context exists
def test_add_server_port(self):
network1 = mock.MagicMock()
network2 = mock.MagicMock()
- self.test_context.name = 'foo'
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
self.test_context.stack = mock.MagicMock()
self.test_context.networks = {
'a': network1,
@@ -173,15 +361,15 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context.stack.outputs = {
u'b': u'10.20.30.45',
u'b-subnet_id': 1,
- u'foo-a-subnet-cidr': u'10.20.0.0/15',
- u'foo-a-subnet-gateway_ip': u'10.20.30.1',
+ u'foo-12345678-a-subnet-cidr': u'10.20.0.0/15',
+ u'foo-12345678-a-subnet-gateway_ip': u'10.20.30.1',
u'b-mac_address': u'00:01',
u'b-device_id': u'dev21',
u'b-network_id': u'net789',
u'd': u'40.30.20.15',
u'd-subnet_id': 2,
- u'foo-c-subnet-cidr': u'40.30.0.0/18',
- u'foo-c-subnet-gateway_ip': u'40.30.20.254',
+ u'foo-12345678-c-subnet-cidr': u'40.30.0.0/18',
+ u'foo-12345678-c-subnet-gateway_ip': u'40.30.20.254',
u'd-mac_address': u'00:10',
u'd-device_id': u'dev43',
u'd-network_id': u'net987',
@@ -219,17 +407,41 @@ class HeatContextTestCase(unittest.TestCase):
self.assertEqual(len(server.interfaces), 3)
self.assertDictEqual(server.interfaces['port_a'], expected)
+ @mock.patch('yardstick.benchmark.contexts.heat.os')
+ @mock.patch.object(heat.HeatContext, '_delete_key_file')
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
- def test_undeploy(self, mock_template):
+ def test_undeploy(self, mock_template, mock_delete_key, *args):
self.test_context.stack = mock_template
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
+ # mock_os.path.exists.return_value = True
+ self.test_context.key_filename = 'foo/bar/foobar'
self.test_context.undeploy()
+ mock_delete_key.assert_called()
self.assertTrue(mock_template.delete.called)
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
+ def test_undeploy_no_teardown(self, mock_template):
+ self.test_context.stack = mock_template
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._flags.no_teardown = True
+ self.test_context.undeploy()
+
+ mock_template.delete.assert_not_called()
+
+ @mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
@mock.patch('yardstick.benchmark.contexts.heat.os')
def test_undeploy_key_filename(self, mock_os, mock_template):
self.test_context.stack = mock_template
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id)
mock_os.path.exists.return_value = True
+ self.test_context.key_filename = 'foo/bar/foobar'
self.assertIsNone(self.test_context.undeploy())
@mock.patch("yardstick.benchmark.contexts.heat.pkg_resources")
@@ -250,24 +462,27 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.public_ip = '127.0.0.3'
baz3_server.context.user = 'zab'
- self.test_context.name = 'bar'
+ self.test_context._name = 'bar'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
self.test_context._user = 'bot'
self.test_context.stack = mock.Mock()
self.test_context.stack.outputs = {
'private_ip': '10.0.0.1',
'public_ip': '127.0.0.1',
}
- self.test_context.key_uuid = uuid.uuid4()
self.test_context._server_map = {
'baz3': baz3_server,
'foo2': foo2_server,
}
attr_name = {
- 'name': 'foo.bar',
+ 'name': 'foo.bar-12345678',
'private_ip_attr': 'private_ip',
'public_ip_attr': 'public_ip',
}
+ self.test_context.key_uuid = 'foo-42'
result = self.test_context._get_server(attr_name)
self.assertEqual(result['user'], 'bot')
self.assertEqual(result['ip'], '127.0.0.1')
@@ -289,22 +504,26 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.public_ip = '127.0.0.3'
baz3_server.context.user = 'zab'
- self.test_context.name = 'bar'
+ self.test_context._name = 'bar'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
self.test_context._user = 'bot'
self.test_context.stack = mock.Mock()
self.test_context.stack.outputs = {
'private_ip': '10.0.0.1',
'public_ip': '127.0.0.1',
}
- self.test_context.key_uuid = uuid.uuid4()
self.test_context._server_map = {
'baz3': baz3_server,
'foo2': foo2_server,
}
attr_name = {
- 'name': 'foo.bar',
+ 'name': 'foo.bar-12345678',
}
+
+ self.test_context.key_uuid = 'foo-42'
result = self.test_context._get_server(attr_name)
self.assertEqual(result['user'], 'bot')
# no private ip attr mapping in the map results in None value in the result
@@ -328,13 +547,14 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.public_ip = None
baz3_server.context.user = 'zab'
- self.test_context.name = 'bar1'
+ self.test_context._name = 'bar1'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = 'bar1-12345678'
self.test_context.stack = mock.Mock()
self.test_context.stack.outputs = {
'private_ip': '10.0.0.1',
'public_ip': '127.0.0.1',
}
- self.test_context.key_uuid = uuid.uuid4()
self.test_context.generate_routing_table = mock.MagicMock(return_value=[])
self.test_context._server_map = {
@@ -366,19 +586,19 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.public_ip = None
baz3_server.context.user = 'zab'
- self.test_context.name = 'bar1'
+ self.test_context._name = 'bar1'
self.test_context.stack = mock.Mock()
self.test_context.stack.outputs = {
'private_ip': '10.0.0.1',
'public_ip': '127.0.0.1',
}
- self.test_context.key_uuid = uuid.uuid4()
self.test_context._server_map = {
'baz3': baz3_server,
'foo2': foo2_server,
'wow4': None,
}
+ self.test_context.key_uuid = 'foo-42'
attr_name = 'wow4'
result = self.test_context._get_server(attr_name)
self.assertIsNone(result)
@@ -399,18 +619,21 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.public_ip = None
baz3_server.context.user = 'zab'
- self.test_context.name = 'bar1'
+ self.test_context._name = 'bar1'
+ self.test_context._task_id = '1235467890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
self.test_context.stack = mock.Mock()
self.test_context.stack.outputs = {
'private_ip': '10.0.0.1',
'public_ip': '127.0.0.1',
}
- self.test_context.key_uuid = uuid.uuid4()
self.test_context._server_map = {
'baz3': baz3_server,
'foo2': foo2_server,
}
+ self.test_context.key_uuid = 'foo-42'
attr_name = {
'name': 'foo.wow4',
'private_ip_attr': 'private_ip',
@@ -435,18 +658,18 @@ class HeatContextTestCase(unittest.TestCase):
baz3_server.public_ip = None
baz3_server.context.user = 'zab'
- self.mock_context.name = 'bar1'
+ self.mock_context._name = 'bar1'
self.test_context.stack = mock.Mock()
self.mock_context.stack.outputs = {
'private_ip': '10.0.0.1',
'public_ip': '127.0.0.1',
}
- self.mock_context.key_uuid = uuid.uuid4()
self.mock_context._server_map = {
'baz3': baz3_server,
'foo2': foo2_server,
}
+ self.test_context.key_uuid = 'foo-42'
attr_name = 'foo.wow4'
result = self.test_context._get_server(attr_name)
self.assertIsNone(result)
diff --git a/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py b/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
index e149e0d18..22153e4e8 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_kubernetes.py
@@ -10,13 +10,13 @@
import mock
import unittest
-from yardstick.benchmark.contexts.base import Context
from yardstick.benchmark.contexts import kubernetes
context_cfg = {
'type': 'Kubernetes',
'name': 'k8s',
+ 'task_id': '1234567890',
'servers': {
'host': {
'image': 'openretriever/yardstick',
@@ -40,11 +40,12 @@ class KubernetesTestCase(unittest.TestCase):
def setUp(self):
self.k8s_context = kubernetes.KubernetesContext()
+ self.addCleanup(self._remove_contexts)
self.k8s_context.init(context_cfg)
- def tearDown(self):
- # clear kubernetes contexts from global list so we don't break other tests
- Context.list = []
+ def _remove_contexts(self):
+ if self.k8s_context in self.k8s_context.list:
+ self.k8s_context._delete_context()
@mock.patch.object(kubernetes.KubernetesContext, '_delete_services')
@mock.patch.object(kubernetes.KubernetesContext, '_delete_ssh_key')
@@ -166,11 +167,3 @@ class KubernetesTestCase(unittest.TestCase):
def test_delete_services(self, mock_delete):
self.k8s_context._delete_services()
self.assertTrue(mock_delete.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/contexts/test_model.py b/yardstick/tests/unit/benchmark/contexts/test_model.py
index b5f5468ce..20cc00b4e 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_model.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_model.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
diff --git a/yardstick/tests/unit/benchmark/contexts/test_node.py b/yardstick/tests/unit/benchmark/contexts/test_node.py
index 5329d30f4..9761f6d53 100644
--- a/yardstick/tests/unit/benchmark/contexts/test_node.py
+++ b/yardstick/tests/unit/benchmark/contexts/test_node.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015-2017 Huawei Technologies Co.,Ltd and others.
#
@@ -9,9 +7,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.contexts.node
-
-from __future__ import absolute_import
import os
import unittest
import errno
@@ -21,10 +16,6 @@ from yardstick.common import constants as consts
from yardstick.benchmark.contexts import node
-# pylint: disable=unused-argument
-# disable this for now because I keep forgetting mock patch arg ordering
-
-
class NodeContextTestCase(unittest.TestCase):
PREFIX = 'yardstick.benchmark.contexts.node'
@@ -34,7 +25,17 @@ class NodeContextTestCase(unittest.TestCase):
def setUp(self):
self.test_context = node.NodeContext()
+ self.addCleanup(self._remove_contexts)
self.os_path_join = os.path.join
+ self.attrs = {
+ 'name': 'foo',
+ 'task_id': '1234567890',
+ 'file': self._get_file_abspath(self.NODES_SAMPLE)
+ }
+
+ def _remove_contexts(self):
+ if self.test_context in self.test_context.list:
+ self.test_context._delete_context()
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -42,7 +43,7 @@ class NodeContextTestCase(unittest.TestCase):
return file_path
def test___init__(self):
- self.assertIsNone(self.test_context.name)
+ self.assertIsNone(self.test_context._name)
self.assertIsNone(self.test_context.file_path)
self.assertEqual(self.test_context.nodes, [])
self.assertEqual(self.test_context.controllers, [])
@@ -74,6 +75,7 @@ class NodeContextTestCase(unittest.TestCase):
attrs = {
'name': 'foo',
+ 'task_id': '1234567890',
'file': error_path,
}
read_mock.side_effect = IOError(errno.EBUSY, 'busy')
@@ -97,37 +99,19 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(str(raised.exception), str(read_mock.side_effect))
def test_read_config_file(self):
-
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
+ self.test_context.init(self.attrs)
self.assertIsNotNone(self.test_context.read_config_file())
def test__dispatch_script(self):
-
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
+ self.test_context.init(self.attrs)
self.test_context.env = {'bash': [{'script': 'dummy'}]}
self.test_context._execute_script = mock.Mock()
self.assertEqual(self.test_context._dispatch_script('bash'), None)
def test__dispatch_ansible(self):
-
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
+ self.test_context.init(self.attrs)
self.test_context.env = {'ansible': [{'script': 'dummy'}]}
self.test_context._do_ansible_job = mock.Mock()
@@ -136,19 +120,13 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(self.test_context._dispatch_ansible('ansible'), None)
@mock.patch("{}.AnsibleCommon".format(PREFIX))
- def test__do_ansible_job(self, mock_ansible):
- self.assertEqual(None, self.test_context._do_ansible_job('dummy'))
-
- def test_successful_init(self):
-
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
+ def test__do_ansible_job(self, *args):
+ self.assertIsNone(self.test_context._do_ansible_job('dummy'))
- self.test_context.init(attrs)
+ def test_init(self):
+ self.test_context.init(self.attrs)
- self.assertEqual(self.test_context.name, "foo")
+ self.assertEqual(self.test_context.name, "foo-12345678")
self.assertEqual(len(self.test_context.nodes), 4)
self.assertEqual(len(self.test_context.controllers), 2)
self.assertEqual(len(self.test_context.computes), 1)
@@ -156,81 +134,44 @@ class NodeContextTestCase(unittest.TestCase):
self.assertEqual(len(self.test_context.baremetals), 1)
self.assertEqual(self.test_context.baremetals[0]["name"], "node4")
- def test__get_server_with_dic_attr_name(self):
-
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
-
- attr_name = {'name': 'foo.bar'}
- result = self.test_context._get_server(attr_name)
+ def test__get_server_with_dict_attr_name(self):
+ self.test_context.init(self.attrs)
+ result = self.test_context._get_server({'name': 'node1.foo-12345678'})
- self.assertEqual(result, None)
+ self.assertIsNone(result, None)
def test__get_server_not_found(self):
+ self.test_context.init(self.attrs)
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
-
- attr_name = 'bar.foo'
- result = self.test_context._get_server(attr_name)
-
- self.assertEqual(result, None)
+ self.assertIsNone(self.test_context._get_server('bar.foo-12345678'))
def test__get_server_mismatch(self):
+ self.test_context.init(self.attrs)
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
-
- attr_name = 'bar.foo1'
- result = self.test_context._get_server(attr_name)
-
- self.assertEqual(result, None)
+ self.assertIsNone(self.test_context._get_server('bar.foo1'))
def test__get_server_duplicate(self):
+ self.attrs['file'] = self._get_file_abspath(
+ self.NODES_DUPLICATE_SAMPLE)
+ self.test_context.init(self.attrs)
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
- }
-
- self.test_context.init(attrs)
-
- attr_name = 'node1.foo'
with self.assertRaises(ValueError):
- self.test_context._get_server(attr_name)
+ self.test_context._get_server('node1.foo-12345678')
def test__get_server_found(self):
+ self.test_context.init(self.attrs)
- attrs = {
- 'name': 'foo',
- 'file': self._get_file_abspath(self.NODES_SAMPLE)
- }
-
- self.test_context.init(attrs)
-
- attr_name = 'node1.foo'
- result = self.test_context._get_server(attr_name)
+ result = self.test_context._get_server('node1.foo-12345678')
self.assertEqual(result['ip'], '10.229.47.137')
- self.assertEqual(result['name'], 'node1.foo')
+ self.assertEqual(result['name'], 'node1.foo-12345678')
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
@mock.patch('{}.NodeContext._dispatch_script'.format(PREFIX))
def test_deploy(self, dispatch_script_mock):
obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
obj.env = {
'type': 'script'
}
@@ -240,6 +181,7 @@ class NodeContextTestCase(unittest.TestCase):
@mock.patch('{}.NodeContext._dispatch_ansible'.format(PREFIX))
def test_deploy_anisible(self, dispatch_ansible_mock):
obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
obj.env = {
'type': 'ansible'
}
@@ -268,6 +210,7 @@ class NodeContextTestCase(unittest.TestCase):
@mock.patch('{}.ssh.SSH.execute'.format(PREFIX))
def test_execute_remote_script(self, execute_mock, put_file_mock):
obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
obj.env = {'prefix': 'yardstick.benchmark.scenarios.compute'}
node_name_args = 'node5'
obj.nodes = [{
@@ -288,14 +231,18 @@ class NodeContextTestCase(unittest.TestCase):
def test_execute_script_local(self, local_execute_mock):
node_name = 'local'
info = {}
- node.NodeContext()._execute_script(node_name, info)
+ obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
+ obj._execute_script(node_name, info)
self.assertTrue(local_execute_mock.called)
@mock.patch('{}.NodeContext._execute_remote_script'.format(PREFIX))
def test_execute_script_remote(self, remote_execute_mock):
node_name = 'node5'
info = {}
- node.NodeContext()._execute_script(node_name, info)
+ obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
+ obj._execute_script(node_name, info)
self.assertTrue(remote_execute_mock.called)
def test_get_script(self):
@@ -303,13 +250,16 @@ class NodeContextTestCase(unittest.TestCase):
info_args = {
'script': script_args
}
- script, options = node.NodeContext()._get_script(info_args)
+ obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
+ script, options = obj._get_script(info_args)
self.assertEqual(script_args, script)
self.assertEqual('', options)
def test_node_info(self):
node_name_args = 'node5'
obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
obj.nodes = [{'name': node_name_args, 'check': node_name_args}]
node_info = obj._get_node_info(node_name_args)
self.assertEqual(node_info.get('check'), node_name_args)
@@ -318,6 +268,7 @@ class NodeContextTestCase(unittest.TestCase):
def test_get_client(self, wait_mock):
node_name_args = 'node5'
obj = node.NodeContext()
+ self.addCleanup(obj._delete_context)
obj.nodes = [{
'name': node_name_args,
'user': 'ubuntu',
@@ -328,26 +279,38 @@ class NodeContextTestCase(unittest.TestCase):
self.assertTrue(wait_mock.called)
def test_get_server(self):
- self.test_context.name = 'vnf1'
- self.test_context.nodes = [{'name': 'my', 'value': 100}]
+ self.test_context.init(self.attrs)
+ self.test_context._name = 'foo'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
+ self.assertEqual('foo-12345678', self.test_context.name)
+ self.assertIsNotNone(self.test_context._task_id)
- with self.assertRaises(ValueError):
- self.test_context.get_server('my.vnf2')
+ result = self.test_context.get_server('node1.foo-12345678')
- expected = {'name': 'my.vnf1', 'value': 100, 'interfaces': {}}
- result = self.test_context.get_server('my.vnf1')
- self.assertDictEqual(result, expected)
+ self.assertEqual(result['ip'], '10.229.47.137')
+ self.assertEqual(result['name'], 'node1.foo-12345678')
+ self.assertEqual(result['user'], 'root')
+ self.assertEqual(result['key_filename'], '/root/.yardstick_key')
+
+ def test_get_server_server_not_in_context(self):
+ self.test_context.init(self.attrs)
+
+ with self.assertRaises(ValueError):
+ self.test_context.get_server('my2.foo-12345678')
def test_get_context_from_server(self):
- self.test_context.name = 'vnf1'
+ self.test_context._name = 'vnf1'
+ self.test_context._task_id = '1234567890'
+ self.test_context._name_task_id = '{}-{}'.format(
+ self.test_context._name, self.test_context._task_id[:8])
self.test_context.nodes = [{'name': 'my', 'value': 100}]
self.test_context.attrs = {'attr1': 200}
- with self.assertRaises(ValueError):
- self.test_context.get_context_from_server('my.vnf2')
-
- result = self.test_context.get_context_from_server('my.vnf1')
- self.assertIs(result, self.test_context)
+ self.assertIs(
+ self.test_context.get_context_from_server('my.vnf1-12345678'),
+ self.test_context)
# TODO: Split this into more granular tests
def test__get_network(self):
@@ -393,11 +356,3 @@ class NodeContextTestCase(unittest.TestCase):
expected = network1
result = self.test_context._get_network(attr_name)
self.assertDictEqual(result, expected)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/core/test_report.py b/yardstick/tests/unit/benchmark/core/test_report.py
index 3d9a503b6..a684ad750 100644
--- a/yardstick/tests/unit/benchmark/core/test_report.py
+++ b/yardstick/tests/unit/benchmark/core/test_report.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2017 Rajesh Kudaka.
#
diff --git a/yardstick/tests/unit/benchmark/core/test_task.py b/yardstick/tests/unit/benchmark/core/test_task.py
index bac035fb9..82a90b172 100644
--- a/yardstick/tests/unit/benchmark/core/test_task.py
+++ b/yardstick/tests/unit/benchmark/core/test_task.py
@@ -7,13 +7,22 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import copy
+import io
import os
+import sys
import mock
+import six
import unittest
+import uuid
+from yardstick.benchmark.contexts import dummy
from yardstick.benchmark.core import task
from yardstick.common import constants as consts
+from yardstick.common import exceptions
+from yardstick.common import task_template
+from yardstick.common import utils
class TaskTestCase(unittest.TestCase):
@@ -48,9 +57,16 @@ class TaskTestCase(unittest.TestCase):
def test__do_output(self, mock_dispatcher):
t = task.Task()
output_config = {"DEFAULT": {"dispatcher": "file, http"}}
- mock_dispatcher.get = mock.MagicMock(return_value=[mock.MagicMock(),
- mock.MagicMock()])
- self.assertEqual(None, t._do_output(output_config, {}))
+
+ dispatcher1 = mock.MagicMock()
+ dispatcher1.__dispatcher_type__ = 'file'
+
+ dispatcher2 = mock.MagicMock()
+ dispatcher2.__dispatcher_type__ = 'http'
+
+ mock_dispatcher.get = mock.MagicMock(return_value=[dispatcher1,
+ dispatcher2])
+ self.assertIsNone(t._do_output(output_config, {}))
@mock.patch.object(task, 'Context')
def test_parse_networks_from_nodes(self, mock_context):
@@ -167,7 +183,6 @@ class TaskTestCase(unittest.TestCase):
'tests/opnfv/test_cases/opnfv_yardstick_tc037.yaml'))
self.assertEqual(task_files[1], self.change_to_abspath(
'tests/opnfv/test_cases/opnfv_yardstick_tc043.yaml'))
-
self.assertIsNone(task_args[0])
self.assertIsNone(task_args[1])
self.assertIsNone(task_args_fnames[0])
@@ -249,30 +264,37 @@ class TaskTestCase(unittest.TestCase):
actual_result = t._parse_options(options)
self.assertEqual(expected_result, actual_result)
+ def test_parse_options_no_teardown(self):
+ options = {
+ 'openstack': {
+ 'EXTERNAL_NETWORK': '$network'
+ },
+ 'nodes': ['node1', '$node'],
+ 'host': '$host',
+ 'contexts' : {'name': "my-context",
+ 'no_teardown': True}
+ }
- def test_change_server_name_host_str(self):
- scenario = {'host': 'demo'}
- suffix = '-8'
- task.change_server_name(scenario, suffix)
- self.assertEqual('demo-8', scenario['host'])
-
- def test_change_server_name_host_dict(self):
- scenario = {'host': {'name': 'demo'}}
- suffix = '-8'
- task.change_server_name(scenario, suffix)
- self.assertEqual('demo-8', scenario['host']['name'])
+ t = task.Task()
+ t.outputs = {
+ 'network': 'ext-net',
+ 'node': 'node2',
+ 'host': 'server.yardstick'
+ }
- def test_change_server_name_target_str(self):
- scenario = {'target': 'demo'}
- suffix = '-8'
- task.change_server_name(scenario, suffix)
- self.assertEqual('demo-8', scenario['target'])
+ expected_result = {
+ 'openstack': {
+ 'EXTERNAL_NETWORK': 'ext-net'
+ },
+ 'nodes': ['node1', 'node2'],
+ 'host': 'server.yardstick',
+ 'contexts': {'name': 'my-context',
+ 'no_teardown': True,
+ }
+ }
- def test_change_server_name_target_dict(self):
- scenario = {'target': {'name': 'demo'}}
- suffix = '-8'
- task.change_server_name(scenario, suffix)
- self.assertEqual('demo-8', scenario['target']['name'])
+ actual_result = t._parse_options(options)
+ self.assertEqual(expected_result, actual_result)
@mock.patch('six.moves.builtins.open', side_effect=mock.mock_open())
@mock.patch.object(task, 'utils')
@@ -292,9 +314,219 @@ class TaskTestCase(unittest.TestCase):
return os.path.join(consts.YARDSTICK_ROOT_PATH, filepath)
-def main():
- unittest.main()
+class TaskParserTestCase(unittest.TestCase):
+ TASK = """
+{% set value1 = value1 or 'var1' %}
+{% set value2 = value2 or 'var2' %}
+key1: {{ value1 }}
+key2:
+ - {{ value2 }}"""
-if __name__ == '__main__':
- main()
+ TASK_RENDERED_1 = u"""
+
+
+key1: var1
+key2:
+ - var2"""
+
+ TASK_RENDERED_2 = u"""
+
+
+key1: var3
+key2:
+ - var4"""
+
+ def setUp(self):
+ self.parser = task.TaskParser('fake/path')
+ self.scenario = {
+ 'host': 'athena.demo',
+ 'target': 'kratos.demo',
+ 'targets': [
+ 'ares.demo', 'mars.demo'
+ ],
+ 'options': {
+ 'server_name': {
+ 'host': 'jupiter.demo',
+ 'target': 'saturn.demo',
+ },
+ },
+ 'nodes': {
+ 'tg__0': 'tg_0.demo',
+ 'vnf__0': 'vnf_0.demo',
+ }
+ }
+
+ def test__change_node_names(self):
+
+ ctx_attrs = {
+ 'name': 'demo',
+ 'task_id': '1234567890',
+ 'servers': [
+ 'athena', 'kratos',
+ 'ares', 'mars',
+ 'jupiter', 'saturn',
+ 'tg_0', 'vnf_0'
+ ]
+ }
+
+ my_context = dummy.DummyContext()
+ my_context.init(ctx_attrs)
+
+ expected_scenario = {
+ 'host': 'athena.demo-12345678',
+ 'target': 'kratos.demo-12345678',
+ 'targets': [
+ 'ares.demo-12345678', 'mars.demo-12345678'
+ ],
+ 'options': {
+ 'server_name': {
+ 'host': 'jupiter.demo-12345678',
+ 'target': 'saturn.demo-12345678',
+ },
+ },
+ 'nodes': {
+ 'tg__0': 'tg_0.demo-12345678',
+ 'vnf__0': 'vnf_0.demo-12345678',
+ }
+ }
+
+ scenario = copy.deepcopy(self.scenario)
+
+ self.parser._change_node_names(scenario, [my_context])
+ self.assertEqual(scenario, expected_scenario)
+
+ def test__change_node_names_context_not_found(self):
+ scenario = copy.deepcopy(self.scenario)
+ self.assertRaises(exceptions.ScenarioConfigContextNameNotFound,
+ self.parser._change_node_names,
+ scenario, [])
+
+ def test__change_node_names_context_name_unchanged(self):
+ ctx_attrs = {
+ 'name': 'demo',
+ 'task_id': '1234567890',
+ 'flags': {
+ 'no_setup': True,
+ 'no_teardown': True
+ }
+ }
+
+ my_context = dummy.DummyContext()
+ my_context.init(ctx_attrs)
+
+ scenario = copy.deepcopy(self.scenario)
+ expected_scenario = copy.deepcopy(self.scenario)
+
+ self.parser._change_node_names(scenario, [my_context])
+ self.assertEqual(scenario, expected_scenario)
+
+ def test__parse_tasks(self):
+ task_obj = task.Task()
+ _uuid = uuid.uuid4()
+ task_obj.task_id = _uuid
+ task_files = ['/directory/task_file_name.yml']
+ mock_parser = mock.Mock()
+ mock_parser.parse_task.return_value = {'rendered': 'File content'}
+ mock_args = mock.Mock()
+ mock_args.render_only = False
+
+ tasks = task_obj._parse_tasks(mock_parser, task_files, mock_args,
+ ['arg1'], ['file_arg1'])
+ self.assertEqual(
+ [{'rendered': 'File content', 'case_name': 'task_file_name'}],
+ tasks)
+ mock_parser.parse_task.assert_called_once_with(
+ _uuid, 'arg1', 'file_arg1')
+
+ @mock.patch.object(sys, 'exit')
+ @mock.patch.object(utils, 'write_file')
+ @mock.patch.object(utils, 'makedirs')
+ def test__parse_tasks_render_only(self, mock_makedirs, mock_write_file,
+ mock_exit):
+ task_obj = task.Task()
+ _uuid = uuid.uuid4()
+ task_obj.task_id = _uuid
+ task_files = ['/directory/task_file_name.yml']
+ mock_parser = mock.Mock()
+ mock_parser.parse_task.return_value = {'rendered': 'File content'}
+ mock_args = mock.Mock()
+ mock_args.render_only = '/output_directory'
+
+ task_obj._parse_tasks(mock_parser, task_files, mock_args,
+ ['arg1'], ['file_arg1'])
+ mock_makedirs.assert_called_once_with('/output_directory')
+ mock_write_file.assert_called_once_with(
+ '/output_directory/000-task_file_name.yml', 'File content')
+ mock_exit.assert_called_once_with(0)
+
+ def test__render_task_no_args(self):
+ task_parser = task.TaskParser('task_file')
+ task_str = io.StringIO(six.text_type(self.TASK))
+ with mock.patch.object(six.moves.builtins, 'open',
+ return_value=task_str) as mock_open:
+ parsed, rendered = task_parser._render_task(None, None)
+
+ self.assertEqual(self.TASK_RENDERED_1, rendered)
+ self.assertEqual({'key1': 'var1', 'key2': ['var2']}, parsed)
+ mock_open.assert_called_once_with('task_file')
+
+ def test__render_task_arguments(self):
+ task_parser = task.TaskParser('task_file')
+ task_str = io.StringIO(six.text_type(self.TASK))
+ with mock.patch.object(six.moves.builtins, 'open',
+ return_value=task_str) as mock_open:
+ parsed, rendered = task_parser._render_task('value1: "var1"', None)
+
+ self.assertEqual(self.TASK_RENDERED_1, rendered)
+ self.assertEqual({'key1': 'var1', 'key2': ['var2']}, parsed)
+ mock_open.assert_called_once_with('task_file')
+
+ def test__render_task_file_arguments(self):
+ task_parser = task.TaskParser('task_file')
+ with mock.patch.object(six.moves.builtins, 'open') as mock_open:
+ mock_open.side_effect = (
+ io.StringIO(six.text_type('value2: var4')),
+ io.StringIO(six.text_type(self.TASK))
+ )
+ parsed, rendered = task_parser._render_task('value1: "var3"',
+ 'args_file')
+
+ self.assertEqual(self.TASK_RENDERED_2, rendered)
+ self.assertEqual({'key1': 'var3', 'key2': ['var4']}, parsed)
+ mock_open.assert_has_calls([mock.call('args_file'),
+ mock.call('task_file')])
+
+ def test__render_task_error_arguments(self):
+ with self.assertRaises(exceptions.TaskRenderArgumentError):
+ task.TaskParser('task_file')._render_task('value1="var3"', None)
+
+ def test__render_task_error_task_file(self):
+ task_parser = task.TaskParser('task_file')
+ with mock.patch.object(six.moves.builtins, 'open') as mock_open:
+ mock_open.side_effect = (
+ io.StringIO(six.text_type('value2: var4')),
+ IOError()
+ )
+ with self.assertRaises(exceptions.TaskReadError):
+ task_parser._render_task('value1: "var3"', 'args_file')
+
+ mock_open.assert_has_calls([mock.call('args_file'),
+ mock.call('task_file')])
+
+ def test__render_task_render_error(self):
+ task_parser = task.TaskParser('task_file')
+ with mock.patch.object(six.moves.builtins, 'open') as mock_open, \
+ mock.patch.object(task_template.TaskTemplate, 'render',
+ side_effect=TypeError) as mock_render:
+ mock_open.side_effect = (
+ io.StringIO(six.text_type('value2: var4')),
+ io.StringIO(six.text_type(self.TASK))
+ )
+ with self.assertRaises(exceptions.TaskRenderError):
+ task_parser._render_task('value1: "var3"', 'args_file')
+
+ mock_open.assert_has_calls([mock.call('args_file'),
+ mock.call('task_file')])
+ mock_render.assert_has_calls(
+ [mock.call(self.TASK, value1='var3', value2='var4')])
diff --git a/yardstick/tests/unit/benchmark/core/test_testcase.py b/yardstick/tests/unit/benchmark/core/test_testcase.py
index 1f5aad75e..119465887 100644
--- a/yardstick/tests/unit/benchmark/core/test_testcase.py
+++ b/yardstick/tests/unit/benchmark/core/test_testcase.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
@@ -35,11 +33,3 @@ class TestcaseUT(unittest.TestCase):
casename = Arg()
result = t.show(casename)
self.assertTrue(result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/runner/test_base.py b/yardstick/tests/unit/benchmark/runner/test_base.py
index 0fdc42347..727207f5a 100644
--- a/yardstick/tests/unit/benchmark/runner/test_base.py
+++ b/yardstick/tests/unit/benchmark/runner/test_base.py
@@ -11,6 +11,8 @@ import time
import mock
import unittest
+from subprocess import CalledProcessError
+
from yardstick.benchmark.runners import base
from yardstick.benchmark.runners import iteration
@@ -20,19 +22,19 @@ class ActionTestCase(unittest.TestCase):
@mock.patch("yardstick.benchmark.runners.base.subprocess")
def test__execute_shell_command(self, mock_subprocess):
- mock_subprocess.check_output.side_effect = Exception()
+ mock_subprocess.check_output.side_effect = CalledProcessError(-1, '')
self.assertEqual(base._execute_shell_command("")[0], -1)
@mock.patch("yardstick.benchmark.runners.base.subprocess")
def test__single_action(self, mock_subprocess):
- mock_subprocess.check_output.side_effect = Exception()
+ mock_subprocess.check_output.side_effect = CalledProcessError(-1, '')
base._single_action(0, "echo", mock.MagicMock())
@mock.patch("yardstick.benchmark.runners.base.subprocess")
def test__periodic_action(self, mock_subprocess):
- mock_subprocess.check_output.side_effect = Exception()
+ mock_subprocess.check_output.side_effect = CalledProcessError(-1, '')
base._periodic_action(0, "echo", mock.MagicMock())
@@ -40,7 +42,14 @@ class ActionTestCase(unittest.TestCase):
class RunnerTestCase(unittest.TestCase):
def setUp(self):
- self.runner = iteration.IterationRunner({})
+ config = {
+ 'output_config': {
+ 'DEFAULT': {
+ 'dispatcher': 'file'
+ }
+ }
+ }
+ self.runner = iteration.IterationRunner(config)
@mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
def test_get_output(self, *args):
@@ -81,11 +90,3 @@ class RunnerTestCase(unittest.TestCase):
with self.assertRaises(NotImplementedError):
runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/runner/test_search.py b/yardstick/tests/unit/benchmark/runner/test_search.py
index 1bc07448d..4e5b4fe77 100644
--- a/yardstick/tests/unit/benchmark/runner/test_search.py
+++ b/yardstick/tests/unit/benchmark/runner/test_search.py
@@ -17,15 +17,8 @@ import time
import mock
import unittest
-from yardstick.tests.unit import STL_MOCKS
-
-STLClient = mock.MagicMock()
-stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
-stl_patch.start()
-
-if stl_patch:
- from yardstick.benchmark.runners.search import SearchRunner
- from yardstick.benchmark.runners.search import SearchRunnerHelper
+from yardstick.benchmark.runners.search import SearchRunner
+from yardstick.benchmark.runners.search import SearchRunnerHelper
class TestSearchRunnerHelper(unittest.TestCase):
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
index f0921c0f6..d5c95a086 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_baremetal.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
index 612b5a662..c1b3c0d72 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_general.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Juan Qiu and others
# juan_ qiu@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
index 0a8e8322a..2e9f1c6bb 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_attacker_process.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
index 9bc04ebf4..ce972779d 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_basemonitor.py
@@ -113,7 +113,3 @@ class BaseMonitorTestCase(unittest.TestCase):
except Exception: # pylint: disable=broad-except
pass
self.assertIsNone(cls)
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
index ae74d241c..d4df02819 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseresultchecker.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py
index 72ce7b0d5..e49544e1c 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_director.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
index 7022ea678..5907c8b6a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_general.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
index 0d61d9b15..e9c680257 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_multi.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
index 41ce5445e..a6d2ca398 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_monitor_process.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py
index a965f7f64..2b09c0385 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_operation_general.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
index 234adcb6e..324a5bda2 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huan Li and others
# lihuansse@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py
index 548efe91b..4d97585d4 100644
--- a/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py
+++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_util.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Kanglin Yin and others
# 14_ykl@tongji.edu.cn
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_cachestat.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_cachestat.py
index b0ddfc6b4..6f66c30f9 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_cachestat.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_cachestat.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_computecapacity.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
index 7b9a5ad4a..4bef589f4 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_cpuload.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_cpuload.py
index 840ac7885..da6e6a22e 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_cpuload.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_cpuload.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
index 51ffd2488..f24ec24ec 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
#
@@ -166,10 +164,3 @@ class CyclictestTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, c.run, result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_lmbench.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_lmbench.py
index b3152d12c..9640ce000 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_lmbench.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_lmbench.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -193,10 +191,3 @@ class LmbenchTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, l.run, self.result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_memload.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_memload.py
index ebae9993d..8213d4490 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_memload.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_memload.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
@@ -109,11 +107,3 @@ class MEMLoadTestCase(unittest.TestCase):
with open(output) as f:
sample_output = f.read()
return sample_output
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_plugintest.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_plugintest.py
index 680f6ad65..875301729 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_plugintest.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_plugintest.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
index 26a26cdf7..03003d01f 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
#
@@ -157,11 +155,3 @@ class QemuMigrateTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, q.run, result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_ramspeed.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
index 4f71fbb36..dcc0e810d 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
@@ -235,10 +233,3 @@ class RamspeedTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'No such type_id: 30 for \
Ramspeed scenario')
self.assertRaises(RuntimeError, r.run, self.result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu.py
index 74612d7b6..643e1eae2 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
@@ -75,11 +73,3 @@ class SpecCPUTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, s.run, self.result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py
index c428e1fb8..74ef576b6 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_spec_cpu_for_vm.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
@@ -76,9 +74,3 @@ class SpecCPUforVMTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, s.run, self.result)
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/compute/test_unixbench.py b/yardstick/tests/unit/benchmark/scenarios/compute/test_unixbench.py
index fec355b45..6339a2dcd 100644
--- a/yardstick/tests/unit/benchmark/scenarios/compute/test_unixbench.py
+++ b/yardstick/tests/unit/benchmark/scenarios/compute/test_unixbench.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
#
@@ -162,10 +160,3 @@ class UnixbenchTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, u.run, result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/dummy/test_dummy.py b/yardstick/tests/unit/benchmark/scenarios/dummy/test_dummy.py
index bc5131806..875302da8 100644
--- a/yardstick/tests/unit/benchmark/scenarios/dummy/test_dummy.py
+++ b/yardstick/tests/unit/benchmark/scenarios/dummy/test_dummy.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
index bda07f723..98d967f2b 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_add_memory_load.py
@@ -55,11 +55,3 @@ class AddMemoryLoadTestCase(unittest.TestCase):
obj = AddMemoryLoad(scenario_cfg, context_cfg)
obj.run({})
self.assertTrue(mock_from_node.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
index 25b911d5e..a61195f66 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_attach_volume.py
@@ -24,11 +24,3 @@ class AttachVolumeTestCase(unittest.TestCase):
obj = AttachVolume(args, {})
obj.run({})
self.assertTrue(mock_attach_server_volume.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py
index 7188c29d5..a48353a4f 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_connectivity.py
@@ -76,11 +76,3 @@ class CheckConnectivityTestCase(unittest.TestCase):
obj.setup()
mock_ssh.SSH.execute.return_value = (0, '100', '')
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
index f983f9c5b..a50e752fa 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
@@ -74,11 +74,3 @@ class CheckNumaInfoTestCase(unittest.TestCase):
obj = CheckNumaInfo(scenario_cfg, {})
status = obj._check_vm2_status(info1, info2)
self.assertFalse(status)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py
index 5a40e7d8f..7a2324b3d 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_check_value.py
@@ -33,10 +33,3 @@ class CheckValueTestCase(unittest.TestCase):
obj = CheckValue(scenario_cfg, {})
self.assertRaises(AssertionError, obj.run, self.result)
self.assertEqual({}, self.result)
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
index 036ae952d..663ca5d5b 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_flavor.py
@@ -27,11 +27,3 @@ class CreateFlavorTestCase(unittest.TestCase):
obj = CreateFlavor(args, {})
obj.run({})
self.assertTrue(mock_create_flavor.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py
index b26957979..639cf2906 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_image.py
@@ -33,11 +33,3 @@ class CreateImageTestCase(unittest.TestCase):
obj.run({})
mock_create_image.assert_called_once()
mock_get_glance_client.assert_called_once()
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
index 10e351b5e..1c3d6cebc 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_keypair.py
@@ -25,11 +25,3 @@ class CreateKeypairTestCase(unittest.TestCase):
obj = create_keypair.CreateKeypair(args, {})
obj.run({})
mock_op_utils.create_keypair.assert_called_once()
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
index e0382851f..ad4adeeb2 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_network.py
@@ -28,11 +28,3 @@ class CreateNetworkTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_create_neutron_net.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
index 0f15058da..9a1611c3d 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_port.py
@@ -25,11 +25,3 @@ class CreatePortTestCase(unittest.TestCase):
obj = CreatePort(args, {})
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
index 8f3914b83..107921403 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_router.py
@@ -28,11 +28,3 @@ class CreateRouterTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_create_neutron_router.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
index c1c137cda..b55767360 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_sec_group.py
@@ -28,11 +28,3 @@ class CreateSecGroupTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_create_security_group_full.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
index 74003b995..faee98fd1 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_server.py
@@ -32,11 +32,3 @@ class CreateServerTestCase(unittest.TestCase):
self.assertTrue(mock_get_glance_client.called)
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_create_instance_and_wait_for_active.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
index b7f29dfe4..1536e83e0 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_subnet.py
@@ -30,11 +30,3 @@ class CreateSubnetTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_create_neutron_subnet.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
index ca055db2f..4bfec3252 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_create_volume.py
@@ -98,11 +98,3 @@ class CreateVolumeTestCase(unittest.TestCase):
self.assertTrue(mock_image_id.called)
self.assertTrue(mock_get_glance_client.called)
self.assertTrue(mock_get_cinder_client.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
index 4a91b8939..e345afe3c 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_flavor.py
@@ -25,11 +25,3 @@ class DeleteFlavorTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_nova_client.called)
self.assertTrue(mock_delete_flavor.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
index df2321292..be997199c 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_floating_ip.py
@@ -25,11 +25,3 @@ class DeleteFloatingIpTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_nova_client.called)
self.assertTrue(mock_delete_floating_ip.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
index 9edc2ff1d..eb3f9fc85 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_image.py
@@ -27,11 +27,3 @@ class DeleteImageTestCase(unittest.TestCase):
self.assertTrue(mock_delete_image.called)
self.assertTrue(mock_image_id.called)
self.assertTrue(mock_get_glance_client.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
index 73894a903..38cc929c0 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_keypair.py
@@ -25,11 +25,3 @@ class DeleteKeypairTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_nova_client.called)
self.assertTrue(mock_delete_keypair.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
index de3179b2d..008ed9168 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_port.py
@@ -23,11 +23,3 @@ class DeletePortTestCase(unittest.TestCase):
obj = DeletePort(args, {})
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
index 73cb81278..9b31566ac 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router.py
@@ -25,11 +25,3 @@ class DeleteRouterTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_delete_neutron_router.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
index 3cfc4ed21..e19c38d47 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py
@@ -25,11 +25,3 @@ class DeleteRouterGatewayTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_remove_gateway_router.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
index 67aff1091..6c4fdd5e3 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
@@ -26,11 +26,3 @@ class DeleteRouterInterfaceTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_neutron_client.called)
self.assertTrue(mock_remove_interface_router.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
index 622ead5ac..dedce2d4a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_server.py
@@ -25,11 +25,3 @@ class DeleteServerTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_nova_client.called)
self.assertTrue(mock_delete_instance.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
index 9438b077a..2ea82e2a4 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_volume.py
@@ -25,11 +25,3 @@ class DeleteVolumeTestCase(unittest.TestCase):
obj.run({})
self.assertTrue(mock_get_cinder_client.called)
self.assertTrue(mock_delete_volume.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
index 87af63a55..34fbac68c 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_detach_volume.py
@@ -24,11 +24,3 @@ class DetachVolumeTestCase(unittest.TestCase):
obj = DetachVolume(args, {})
obj.run({})
self.assertTrue(mock_detach_volume.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
index bf12e0a32..e9025f33f 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_flavor.py
@@ -23,11 +23,3 @@ class GetFlavorTestCase(unittest.TestCase):
obj = GetFlavor(args, {})
obj.run({})
self.assertTrue(mock_get_flavor_by_name.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
index f046c92ea..aa9f63e26 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_migrate_target_host.py
@@ -41,11 +41,3 @@ class GetMigrateTargetHostTestCase(unittest.TestCase):
host = obj._get_migrate_host('host5')
self.assertTrue(mock_get_nova_client.called)
self.assertEqual(host, 'host4')
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
index 50d5238d7..4b2132c2c 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_numa_info.py
@@ -101,11 +101,3 @@ class GetNumaInfoTestCase(unittest.TestCase):
obj = GetNumaInfo(scenario_cfg, {})
result = obj._get_current_host_name('1')
self.assertEqual(result, 'host5')
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
index aebbf5416..97b81ed60 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server.py
@@ -40,11 +40,3 @@ class GetServerTestCase(unittest.TestCase):
obj = GetServer(scenario_cfg, {})
obj.run({})
self.assertTrue(mock_get_nova_client.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py
index 3d20d5439..04fca16aa 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_get_server_ip.py
@@ -31,11 +31,3 @@ class GetServerIpTestCase(unittest.TestCase):
obj = GetServerIp(scenario_cfg, {})
result = obj.run({})
self.assertEqual(result, {'ip': '127.0.0.1'})
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
index 4d3745230..d6636383a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_iperf3.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -193,10 +191,3 @@ class IperfTestCase(unittest.TestCase):
with open(output) as f:
sample_output = f.read()
return sample_output
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf.py
index d82a00931..5907562c2 100755
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
@@ -121,10 +119,3 @@ class NetperfTestCase(unittest.TestCase):
with open(output) as f:
sample_output = f.read()
return sample_output
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf_node.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
index 8be9bb94d..956a9c078 100755
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
@@ -121,10 +119,3 @@ class NetperfNodeTestCase(unittest.TestCase):
with open(output) as f:
sample_output = f.read()
return sample_output
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_netutilization.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_netutilization.py
index 1227e056e..4cdfde6b1 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_netutilization.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_netutilization.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and other.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
index 3e7a3c5ee..36e8c8a77 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_networkcapacity.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_nstat.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_nstat.py
index 7dd5351b1..b02d58437 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_nstat.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_nstat.py
@@ -103,11 +103,3 @@ class NstatTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, n.run, result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py
index 06353249a..4adfab120 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_ping.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -92,10 +90,3 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, p.run, result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_ping6.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_ping6.py
index d2be6f576..4662c8537 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_ping6.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_ping6.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -116,10 +114,3 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.side_effect = [
(0, 'host1', ''), (1, '', 'FOOBAR')]
self.assertRaises(RuntimeError, p.run, result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py
index acd9027d3..6aea03aee 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen.py
@@ -665,11 +665,3 @@ class PktgenTestCase(unittest.TestCase):
expected_result["packets_received"] = 149300
expected_result["packetsize"] = 60
self.assertEqual(result, expected_result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
index 99399abdc..976087148 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
@@ -176,11 +176,3 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, p.run, result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
index 1b12bd507..e90fb07c7 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
##############################################################################
# Copyright (c) 2017 Nokia and others.
#
@@ -192,11 +191,3 @@ class PktgenDPDKTestCase(unittest.TestCase):
mock_ssh.SSH().execute.assert_called_with(
"sudo /dpdk/destdir/bin/dpdk-procinfo -- --stats-reset > /dev/null 2>&1")
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_sfc.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_sfc.py
index 78c0352dd..a5e5e39dc 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_sfc.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_sfc.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -68,10 +66,3 @@ class SfcTestCase(unittest.TestCase):
self.sfc.setup()
self.sfc.run(result)
self.sfc.teardown()
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
index fb55b5ea0..ec22d6147 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vnf_generic.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,27 +11,29 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-#
-
-# Unittest for yardstick.benchmark.scenarios.networking.test_vnf_generic
-
-from __future__ import absolute_import
+from copy import deepcopy
import os
-import errno
-import unittest
-import mock
+import sys
-from copy import deepcopy
+import mock
+import unittest
-from yardstick.tests.unit import STL_MOCKS
-from yardstick.benchmark.scenarios.networking.vnf_generic import \
- SshManager, NetworkServiceTestCase, IncorrectConfig, \
- open_relative_file
+from yardstick import tests
+from yardstick.common import utils
from yardstick.network_services.collector.subscriber import Collector
-from yardstick.network_services.vnf_generic.vnf.base import \
- GenericTrafficGen, GenericVNF
+from yardstick.network_services.traffic_profile import base
+from yardstick.network_services.vnf_generic import vnfdgen
+from yardstick.error import IncorrectConfig
+from yardstick.network_services.vnf_generic.vnf.base import GenericTrafficGen
+from yardstick.network_services.vnf_generic.vnf.base import GenericVNF
+
+
+stl_patch = mock.patch.dict(sys.modules, tests.STL_MOCKS)
+stl_patch.start()
+if stl_patch:
+ from yardstick.benchmark.scenarios.networking import vnf_generic
# pylint: disable=unused-argument
# disable this for now because I keep forgetting mock patch arg ordering
@@ -317,6 +317,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
'tc': 'tc_ipv4_1Mflow_64B_packetsize',
'traffic_profile': 'ipv4_throughput_vpe.yaml',
+ 'extra_args': {'arg1': 'value1', 'arg2': 'value2'},
'type': 'ISB',
'tc_options': {
'rfc2544': {
@@ -345,23 +346,14 @@ class TestNetworkServiceTestCase(unittest.TestCase):
},
}
- self.s = NetworkServiceTestCase(self.scenario_cfg, self.context_cfg)
+ self.s = vnf_generic.NetworkServiceTestCase(self.scenario_cfg,
+ self.context_cfg)
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(curr_path, filename)
return file_path
- def test_ssh_manager(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
- ssh.from_node.return_value = ssh_mock
- for _, node_dict in self.context_cfg["nodes"].items():
- with SshManager(node_dict) as conn:
- self.assertIsNotNone(conn)
-
def test___init__(self):
assert self.topology
@@ -415,7 +407,10 @@ class TestNetworkServiceTestCase(unittest.TestCase):
'public_ip': ['1.1.1.1'],
},
}
-
+ # NOTE(ralonsoh): check the expected output. This test could be
+ # incorrect
+ # result = {'flow': {'dst_ip0': '152.16.40.2-152.16.40.254',
+ # 'src_ip0': '152.16.100.2-152.16.100.254'}}
self.assertEqual({'flow': {}}, self.s._get_traffic_flow())
def test___get_traffic_flow_error(self):
@@ -425,16 +420,16 @@ class TestNetworkServiceTestCase(unittest.TestCase):
def test_get_vnf_imp(self):
vnfd = COMPLETE_TREX_VNFD['vnfd:vnfd-catalog']['vnfd'][0]['class-name']
- with mock.patch.dict("sys.modules", STL_MOCKS):
+ with mock.patch.dict(sys.modules, tests.STL_MOCKS):
self.assertIsNotNone(self.s.get_vnf_impl(vnfd))
- with self.assertRaises(IncorrectConfig) as raised:
- self.s.get_vnf_impl('NonExistentClass')
+ with self.assertRaises(vnf_generic.IncorrectConfig) as raised:
+ self.s.get_vnf_impl('NonExistentClass')
- exc_str = str(raised.exception)
- print(exc_str)
- self.assertIn('No implementation', exc_str)
- self.assertIn('found in', exc_str)
+ exc_str = str(raised.exception)
+ print(exc_str)
+ self.assertIn('No implementation', exc_str)
+ self.assertIn('found in', exc_str)
def test_load_vnf_models_invalid(self):
self.context_cfg["nodes"]['tg__1']['VNF model'] = \
@@ -456,39 +451,37 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.s.load_vnf_models(self.scenario_cfg, self.context_cfg))
def test_map_topology_to_infrastructure(self):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
- ssh.from_node.return_value = ssh_mock
- self.s.map_topology_to_infrastructure()
+ self.s.map_topology_to_infrastructure()
nodes = self.context_cfg["nodes"]
- self.assertEqual(
- "../../vnf_descriptors/tg_rfc2544_tpl.yaml", nodes['tg__1']['VNF model'])
- self.assertEqual("../../vnf_descriptors/vpe_vnf.yaml",
+ self.assertEqual('../../vnf_descriptors/tg_rfc2544_tpl.yaml',
+ nodes['tg__1']['VNF model'])
+ self.assertEqual('../../vnf_descriptors/vpe_vnf.yaml',
nodes['vnf__1']['VNF model'])
def test_map_topology_to_infrastructure_insufficient_nodes(self):
- del self.context_cfg['nodes']['vnf__1']
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(1, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
- ssh.from_node.return_value = ssh_mock
+ cfg = deepcopy(self.context_cfg)
+ del cfg['nodes']['vnf__1']
+ cfg_patch = mock.patch.object(self.s, 'context_cfg', cfg)
+ with cfg_patch:
with self.assertRaises(IncorrectConfig):
self.s.map_topology_to_infrastructure()
def test_map_topology_to_infrastructure_config_invalid(self):
- cfg = dict(self.context_cfg)
+ ssh_mock = mock.Mock()
+ ssh_mock.execute.return_value = 0, SYS_CLASS_NET + IP_ADDR_SHOW, ""
+
+ cfg = deepcopy(self.s.context_cfg)
+
+ # delete all, we don't know which will come first
del cfg['nodes']['vnf__1']['interfaces']['xe0']['local_mac']
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
- ssh.from_node.return_value = ssh_mock
+ del cfg['nodes']['vnf__1']['interfaces']['xe1']['local_mac']
+ del cfg['nodes']['tg__1']['interfaces']['xe0']['local_mac']
+ del cfg['nodes']['tg__1']['interfaces']['xe1']['local_mac']
+ config_patch = mock.patch.object(self.s, 'context_cfg', cfg)
+ with config_patch:
with self.assertRaises(IncorrectConfig):
self.s.map_topology_to_infrastructure()
@@ -503,10 +496,8 @@ class TestNetworkServiceTestCase(unittest.TestCase):
for interface in self.tg__1['interfaces'].values():
del interface['local_mac']
- with mock.patch(
- "yardstick.benchmark.scenarios.networking.vnf_generic.LOG"):
- with self.assertRaises(IncorrectConfig) as raised:
- self.s._resolve_topology()
+ with self.assertRaises(vnf_generic.IncorrectConfig) as raised:
+ self.s._resolve_topology()
self.assertIn('not found', str(raised.exception))
@@ -518,10 +509,8 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.s.topology["vld"][0]['vnfd-connection-point-ref'].append(
self.s.topology["vld"][0]['vnfd-connection-point-ref'][0])
- with mock.patch(
- "yardstick.benchmark.scenarios.networking.vnf_generic.LOG"):
- with self.assertRaises(IncorrectConfig) as raised:
- self.s._resolve_topology()
+ with self.assertRaises(vnf_generic.IncorrectConfig) as raised:
+ self.s._resolve_topology()
self.assertIn('wrong endpoint count', str(raised.exception))
@@ -529,10 +518,8 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.s.topology["vld"][0]['vnfd-connection-point-ref'] = \
self.s.topology["vld"][0]['vnfd-connection-point-ref'][:1]
- with mock.patch(
- "yardstick.benchmark.scenarios.networking.vnf_generic.LOG"):
- with self.assertRaises(IncorrectConfig) as raised:
- self.s._resolve_topology()
+ with self.assertRaises(vnf_generic.IncorrectConfig) as raised:
+ self.s._resolve_topology()
self.assertIn('wrong endpoint count', str(raised.exception))
@@ -578,7 +565,7 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs)
self.s._fill_traffic_profile = \
mock.Mock(return_value=TRAFFIC_PROFILE)
- self.assertEqual(None, self.s.setup())
+ self.assertIsNone(self.s.setup())
def test_setup_exception(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
@@ -625,15 +612,48 @@ class TestNetworkServiceTestCase(unittest.TestCase):
self.assertEqual({'imix': {'64B': 100}},
self.s._get_traffic_imix())
- def test__fill_traffic_profile(self):
- with mock.patch.dict("sys.modules", STL_MOCKS):
- self.scenario_cfg["traffic_profile"] = \
- self._get_file_abspath("ipv4_throughput_vpe.yaml")
- self.scenario_cfg["traffic_options"]["flow"] = \
- self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml")
- self.scenario_cfg["traffic_options"]["imix"] = \
- self._get_file_abspath("imix_voice.yaml")
- self.assertIsNotNone(self.s._fill_traffic_profile())
+ @mock.patch.object(base.TrafficProfile, 'get')
+ @mock.patch.object(vnfdgen, 'generate_vnfd')
+ def test__fill_traffic_profile(self, mock_generate, mock_tprofile_get):
+ fake_tprofile = mock.Mock()
+ fake_vnfd = mock.Mock()
+ with mock.patch.object(self.s, '_get_traffic_profile',
+ return_value=fake_tprofile) as mock_get_tp:
+ mock_generate.return_value = fake_vnfd
+ self.s._fill_traffic_profile()
+ mock_get_tp.assert_called_once()
+ mock_generate.assert_called_once_with(
+ fake_tprofile,
+ {'downlink': {},
+ 'extra_args': {'arg1': 'value1', 'arg2': 'value2'},
+ 'flow': {'flow': {}},
+ 'imix': {'imix': {'64B': 100}},
+ 'uplink': {}}
+ )
+ mock_tprofile_get.assert_called_once_with(fake_vnfd)
+
+ @mock.patch.object(utils, 'open_relative_file')
+ def test__get_topology(self, mock_open_path):
+ self.s.scenario_cfg['topology'] = 'fake_topology'
+ self.s.scenario_cfg['task_path'] = 'fake_path'
+ mock_open_path.side_effect = mock.mock_open(read_data='fake_data')
+ self.assertEqual('fake_data', self.s._get_topology())
+ mock_open_path.assert_called_once_with('fake_topology', 'fake_path')
+
+ @mock.patch.object(vnfdgen, 'generate_vnfd')
+ def test__render_topology(self, mock_generate):
+ fake_topology = 'fake_topology'
+ mock_generate.return_value = {'nsd:nsd-catalog': {'nsd': ['fake_nsd']}}
+ with mock.patch.object(self.s, '_get_topology',
+ return_value=fake_topology) as mock_get_topology:
+ self.s._render_topology()
+ mock_get_topology.assert_called_once()
+
+ mock_generate.assert_called_once_with(
+ fake_topology,
+ {'extra_args': {'arg1': 'value1', 'arg2': 'value2'}}
+ )
+ self.assertEqual(self.s.topology, 'fake_nsd')
def test_teardown(self):
vnf = mock.Mock(autospec=GenericVNF)
@@ -658,141 +678,3 @@ class TestNetworkServiceTestCase(unittest.TestCase):
mock.Mock(return_value=True)
with self.assertRaises(RuntimeError):
self.s.teardown()
-
- SAMPLE_NETDEVS = {
- 'enp11s0': {
- 'address': '0a:de:ad:be:ef:f5',
- 'device': '0x1533',
- 'driver': 'igb',
- 'ifindex': '2',
- 'interface_name': 'enp11s0',
- 'operstate': 'down',
- 'pci_bus_id': '0000:0b:00.0',
- 'subsystem_device': '0x1533',
- 'subsystem_vendor': '0x15d9',
- 'vendor': '0x8086'
- },
- 'lan': {
- 'address': '0a:de:ad:be:ef:f4',
- 'device': '0x153a',
- 'driver': 'e1000e',
- 'ifindex': '3',
- 'interface_name': 'lan',
- 'operstate': 'up',
- 'pci_bus_id': '0000:00:19.0',
- 'subsystem_device': '0x153a',
- 'subsystem_vendor': '0x15d9',
- 'vendor': '0x8086'
- }
- }
-
- SAMPLE_VM_NETDEVS = {
- 'eth1': {
- 'address': 'fa:de:ad:be:ef:5b',
- 'device': '0x0001',
- 'driver': 'virtio_net',
- 'ifindex': '3',
- 'interface_name': 'eth1',
- 'operstate': 'down',
- 'pci_bus_id': '0000:00:04.0',
- 'vendor': '0x1af4'
- }
- }
-
- def test_parse_netdev_info(self):
- output = """\
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/ifindex:2
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/address:0a:de:ad:be:ef:f5
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/operstate:down
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/vendor:0x8086
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/device:0x1533
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/subsystem_vendor:0x15d9
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/subsystem_device:0x1533
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/driver:igb
-/sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/pci_bus_id:0000:0b:00.0
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/ifindex:3
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/address:0a:de:ad:be:ef:f4
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/operstate:up
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/vendor:0x8086
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/device:0x153a
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/subsystem_vendor:0x15d9
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/device/subsystem_device:0x153a
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/driver:e1000e
-/sys/devices/pci0000:00/0000:00:19.0/net/lan/pci_bus_id:0000:00:19.0
-"""
- res = NetworkServiceTestCase.parse_netdev_info(output)
- assert res == self.SAMPLE_NETDEVS
-
- def test_parse_netdev_info_virtio(self):
- output = """\
-/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/ifindex:3
-/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/address:fa:de:ad:be:ef:5b
-/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/operstate:down
-/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/device/vendor:0x1af4
-/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/device/device:0x0001
-/sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/driver:virtio_net
-"""
- res = NetworkServiceTestCase.parse_netdev_info(output)
- assert res == self.SAMPLE_VM_NETDEVS
-
- def test_probe_missing_values(self):
- netdevs = self.SAMPLE_NETDEVS.copy()
- network = {'local_mac': '0a:de:ad:be:ef:f5'}
- NetworkServiceTestCase._probe_missing_values(netdevs, network)
- assert network['vpci'] == '0000:0b:00.0'
-
- network = {'local_mac': '0a:de:ad:be:ef:f4'}
- NetworkServiceTestCase._probe_missing_values(netdevs, network)
- assert network['vpci'] == '0000:00:19.0'
-
- # TODO: Split this into several tests, for different IOError sub-types
- def test_open_relative_path(self):
- mock_open = mock.mock_open()
- mock_open_result = mock_open()
- mock_open_call_count = 1 # initial call to get result
-
- module_name = \
- 'yardstick.benchmark.scenarios.networking.vnf_generic.open'
-
- # test
- with mock.patch(module_name, mock_open, create=True):
- self.assertEqual(open_relative_file(
- 'foo', 'bar'), mock_open_result)
-
- mock_open_call_count += 1 # one more call expected
- self.assertEqual(mock_open.call_count, mock_open_call_count)
- self.assertIn('foo', mock_open.call_args_list[-1][0][0])
- self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])
-
- def open_effect(*args, **kwargs):
- if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
- return mock_open_result
- raise IOError(errno.ENOENT, 'not found')
-
- mock_open.side_effect = open_effect
- self.assertEqual(open_relative_file(
- 'foo', 'bar'), mock_open_result)
-
- mock_open_call_count += 2 # two more calls expected
- self.assertEqual(mock_open.call_count, mock_open_call_count)
- self.assertIn('foo', mock_open.call_args_list[-1][0][0])
- self.assertIn('bar', mock_open.call_args_list[-1][0][0])
-
- # test an IOError of type ENOENT
- mock_open.side_effect = IOError(errno.ENOENT, 'not found')
- with self.assertRaises(IOError):
- # the second call still raises
- open_relative_file('foo', 'bar')
-
- mock_open_call_count += 2 # two more calls expected
- self.assertEqual(mock_open.call_count, mock_open_call_count)
- self.assertIn('foo', mock_open.call_args_list[-1][0][0])
- self.assertIn('bar', mock_open.call_args_list[-1][0][0])
-
- # test an IOError other than ENOENT
- mock_open.side_effect = IOError(errno.EBUSY, 'busy')
- with self.assertRaises(IOError):
- open_relative_file('foo', 'bar')
-
- mock_open_call_count += 1 # one more call expected
- self.assertEqual(mock_open.call_count, mock_open_call_count)
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf.py
index be8ac55d0..419605b26 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright 2016 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -126,11 +124,3 @@ class VsperfTestCase(unittest.TestCase):
result = {}
self.assertRaises(RuntimeError, p.run, result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
index 1923960e9..1d2278e21 100644
--- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
+++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
@@ -211,11 +211,3 @@ class VsperfDPDKTestCase(unittest.TestCase):
result = {}
self.assertRaises(RuntimeError, self.scenario.run, result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/parser/test_parser.py b/yardstick/tests/unit/benchmark/scenarios/parser/test_parser.py
index ee2bbc07d..9fd5cce38 100644
--- a/yardstick/tests/unit/benchmark/scenarios/parser/test_parser.py
+++ b/yardstick/tests/unit/benchmark/scenarios/parser/test_parser.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
#
@@ -70,10 +68,3 @@ class ParserTestCase(unittest.TestCase):
self.mock_call.return_value = 0
self.scenario.teardown()
self.assertTrue(self.scenario.teardown_done)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/storage/test_bonnie.py b/yardstick/tests/unit/benchmark/scenarios/storage/test_bonnie.py
index b98dceae7..d78506584 100644
--- a/yardstick/tests/unit/benchmark/scenarios/storage/test_bonnie.py
+++ b/yardstick/tests/unit/benchmark/scenarios/storage/test_bonnie.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
@@ -9,8 +7,6 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.storage.bonnie.Bonnie
-
from __future__ import absolute_import
import unittest
@@ -65,11 +61,3 @@ class BonnieTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, b.run, self.result)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/storage/test_fio.py b/yardstick/tests/unit/benchmark/scenarios/storage/test_fio.py
index 0cffea224..f149cee69 100644
--- a/yardstick/tests/unit/benchmark/scenarios/storage/test_fio.py
+++ b/yardstick/tests/unit/benchmark/scenarios/storage/test_fio.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Ericsson AB and others.
#
@@ -63,6 +61,22 @@ class FioTestCase(unittest.TestCase):
}
args = {'options': options}
p = fio.Fio(args, self.ctx)
+ mock_ssh.SSH.from_node().execute.return_value = (0, '/dev/vdb', '')
+ p.setup()
+
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.assertIsNotNone(p.client)
+ self.assertTrue(p.setup_done)
+
+ def test_fio_job_file_no_disk__setup(self, mock_ssh):
+
+ options = {
+ 'job_file': 'job_file.ini',
+ 'directory': '/FIO_Test'
+ }
+ args = {'options': options}
+ p = fio.Fio(args, self.ctx)
+ mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
p.setup()
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
@@ -263,11 +277,3 @@ class FioTestCase(unittest.TestCase):
with open(output) as f:
sample_output = f.read()
return sample_output
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py b/yardstick/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
index 095674f72..c1c731b0a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
+++ b/yardstick/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
#
@@ -99,10 +97,3 @@ class StorageCapacityTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, c.run, self.result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/storage/test_storperf.py b/yardstick/tests/unit/benchmark/scenarios/storage/test_storperf.py
index 52786d7cb..5844746ab 100644
--- a/yardstick/tests/unit/benchmark/scenarios/storage/test_storperf.py
+++ b/yardstick/tests/unit/benchmark/scenarios/storage/test_storperf.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2016 Huawei Technologies Co.,Ltd.
#
@@ -233,10 +231,3 @@ class StorPerfTestCase(unittest.TestCase):
s = storperf.StorPerf(args, self.ctx)
self.assertRaises(AssertionError, s.teardown(), self.result)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/benchmark/scenarios/test_base.py b/yardstick/tests/unit/benchmark/scenarios/test_base.py
index a95e6bc86..985338532 100644
--- a/yardstick/tests/unit/benchmark/scenarios/test_base.py
+++ b/yardstick/tests/unit/benchmark/scenarios/test_base.py
@@ -13,12 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
-import unittest
-
from yardstick.benchmark.scenarios import base
+from yardstick.tests.unit import base as ut_base
-class ScenarioTestCase(unittest.TestCase):
+class ScenarioTestCase(ut_base.BaseUnitTestCase):
def test_get_scenario_type(self):
scenario_type = 'dummy scenario'
@@ -87,7 +86,7 @@ class ScenarioTestCase(unittest.TestCase):
str(exc.exception))
-class IterScenarioClassesTestCase(unittest.TestCase):
+class IterScenarioClassesTestCase(ut_base.BaseUnitTestCase):
def test_no_scenario_type_defined(self):
some_existing_scenario_class_names = [
diff --git a/yardstick/tests/unit/common/banned_modules/__init__.py b/yardstick/tests/unit/common/banned_modules/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/unit/common/banned_modules/__init__.py
diff --git a/yardstick/tests/unit/common/banned_modules/banned_module.py b/yardstick/tests/unit/common/banned_modules/banned_module.py
new file mode 100644
index 000000000..f57f939d2
--- /dev/null
+++ b/yardstick/tests/unit/common/banned_modules/banned_module.py
@@ -0,0 +1,17 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+class BannedClass(object):
+ pass
diff --git a/yardstick/tests/unit/common/banned_modules/importing_module.py b/yardstick/tests/unit/common/banned_modules/importing_module.py
new file mode 100644
index 000000000..fc2542f0c
--- /dev/null
+++ b/yardstick/tests/unit/common/banned_modules/importing_module.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from yardstick.common import import_tools
+from yardstick.tests.unit.common.banned_modules import banned_module
+
+
+@import_tools.decorator_banned_modules
+class ImportingClass(banned_module.BannedClass):
+ pass
diff --git a/yardstick/tests/unit/common/test_ansible_common.py b/yardstick/tests/unit/common/test_ansible_common.py
index 89ea128af..b01195fcc 100644
--- a/yardstick/tests/unit/common/test_ansible_common.py
+++ b/yardstick/tests/unit/common/test_ansible_common.py
@@ -99,7 +99,7 @@ class AnsibleNodeTestCase(unittest.TestCase):
def test_ansible_node_getattr(self):
a = ansible_common.AnsibleNode({"name": "name"})
- self.assertEqual(getattr(a, "nosuch", None), None)
+ self.assertIsNone(getattr(a, "nosuch", None))
class AnsibleNodeDictTestCase(unittest.TestCase):
@@ -145,7 +145,7 @@ class AnsibleNodeDictTestCase(unittest.TestCase):
class AnsibleCommonTestCase(unittest.TestCase):
def test_get_timeouts(self):
- self.assertAlmostEquals(ansible_common.AnsibleCommon.get_timeout(-100), 1200.0)
+ self.assertAlmostEqual(ansible_common.AnsibleCommon.get_timeout(-100), 1200.0)
def test__init__(self):
ansible_common.AnsibleCommon({})
diff --git a/yardstick/tests/unit/common/test_httpClient.py b/yardstick/tests/unit/common/test_httpClient.py
index eb09d1a52..12a8be3a0 100644
--- a/yardstick/tests/unit/common/test_httpClient.py
+++ b/yardstick/tests/unit/common/test_httpClient.py
@@ -33,11 +33,3 @@ class HttpClientTestCase(unittest.TestCase):
url = 'http://localhost:5000/hello'
httpClient.HttpClient().get(url)
mock_requests.get.assert_called_with(url)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/common/test_import_tools.py b/yardstick/tests/unit/common/test_import_tools.py
new file mode 100644
index 000000000..c8fe5fde0
--- /dev/null
+++ b/yardstick/tests/unit/common/test_import_tools.py
@@ -0,0 +1,46 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+
+from yardstick.common import exceptions as y_exc
+from yardstick.common import import_tools
+
+
+@import_tools.decorator_banned_modules
+class DummyClass(object):
+ pass
+
+
+class DecoratorBannedModule(unittest.TestCase):
+
+ MODULE = 'yardstick.tests.unit.common.banned_modules.banned_module'
+
+ def test_passt(self):
+ self.assertIsNotNone(DummyClass())
+
+ def test_banned_module(self):
+ import_tools.BANNED_MODULES[self.MODULE] = 'Banned module!!'
+ from yardstick.tests.unit.common.banned_modules import importing_module
+ self.addCleanup(self._remove_module)
+
+ with self.assertRaises(y_exc.YardstickBannedModuleImported) as exc:
+ importing_module.ImportingClass()
+
+ msg = ('Module "%s" cannnot be imported. Reason: "Banned module!!"'
+ % self.MODULE)
+ self.assertEqual(msg, str(exc.exception))
+
+ def _remove_module(self):
+ del import_tools.BANNED_MODULES[self.MODULE]
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index 8a2f5f95b..4863f05c0 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -54,7 +54,7 @@ class GetNetworkIdTestCase(unittest.TestCase):
output = openstack_utils.get_network_id(mock_shade_client,
'network_name')
- self.assertEqual(None, output)
+ self.assertIsNone(output)
class DeleteNeutronNetTestCase(unittest.TestCase):
diff --git a/yardstick/tests/unit/common/test_packages.py b/yardstick/tests/unit/common/test_packages.py
new file mode 100644
index 000000000..ba59a3015
--- /dev/null
+++ b/yardstick/tests/unit/common/test_packages.py
@@ -0,0 +1,88 @@
+# Copyright (c) 2018 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import mock
+from pip import exceptions as pip_exceptions
+from pip.operations import freeze
+import unittest
+
+from yardstick.common import packages
+
+
+class PipExecuteActionTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self._mock_pip_main = mock.patch.object(packages, '_pip_main')
+ self.mock_pip_main = self._mock_pip_main.start()
+ self.mock_pip_main.return_value = 0
+ self._mock_freeze = mock.patch.object(freeze, 'freeze')
+ self.mock_freeze = self._mock_freeze.start()
+ self.addCleanup(self._cleanup)
+
+ def _cleanup(self):
+ self._mock_pip_main.stop()
+ self._mock_freeze.stop()
+
+ def test_pip_execute_action(self):
+ self.assertEqual(0, packages._pip_execute_action('test_package'))
+
+ def test_remove(self):
+ self.assertEqual(0, packages._pip_execute_action('test_package',
+ action='uninstall'))
+
+ def test_install(self):
+ self.assertEqual(0, packages._pip_execute_action(
+ 'test_package', action='install', target='temp_dir'))
+
+ def test_pip_execute_action_error(self):
+ self.mock_pip_main.return_value = 1
+ self.assertEqual(1, packages._pip_execute_action('test_package'))
+
+ def test_pip_execute_action_exception(self):
+ self.mock_pip_main.side_effect = pip_exceptions.PipError
+ self.assertEqual(1, packages._pip_execute_action('test_package'))
+
+ def test_pip_list(self):
+ pkg_input = [
+ 'XStatic-Rickshaw==1.5.0.0',
+ 'xvfbwrapper==0.2.9',
+ '-e git+https://git.opnfv.org/yardstick@50773a24afc02c9652b662ecca'
+ '2fc5621ea6097a#egg=yardstick',
+ 'zope.interface==4.4.3'
+ ]
+ pkg_dict = {
+ 'XStatic-Rickshaw': '1.5.0.0',
+ 'xvfbwrapper': '0.2.9',
+ 'yardstick': '50773a24afc02c9652b662ecca2fc5621ea6097a',
+ 'zope.interface': '4.4.3'
+ }
+ self.mock_freeze.return_value = pkg_input
+
+ pkg_output = packages.pip_list()
+ for pkg_name, pkg_version in pkg_output.items():
+ self.assertEqual(pkg_dict.get(pkg_name), pkg_version)
+
+ def test_pip_list_single_package(self):
+ pkg_input = [
+ 'XStatic-Rickshaw==1.5.0.0',
+ 'xvfbwrapper==0.2.9',
+ '-e git+https://git.opnfv.org/yardstick@50773a24afc02c9652b662ecca'
+ '2fc5621ea6097a#egg=yardstick',
+ 'zope.interface==4.4.3'
+ ]
+ self.mock_freeze.return_value = pkg_input
+
+ pkg_output = packages.pip_list(pkg_name='xvfbwrapper')
+ self.assertEqual(1, len(pkg_output))
+ self.assertEqual(pkg_output.get('xvfbwrapper'), '0.2.9')
diff --git a/yardstick/tests/unit/common/test_template_format.py b/yardstick/tests/unit/common/test_template_format.py
index 44aa80333..56253efbc 100644
--- a/yardstick/tests/unit/common/test_template_format.py
+++ b/yardstick/tests/unit/common/test_template_format.py
@@ -45,10 +45,3 @@ class TemplateFormatTestCase(unittest.TestCase):
"Resources: {}\n" \
"Outputs: {}"
self.assertRaises(ValueError, template_format.parse, yaml2)
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/common/test_utils.py b/yardstick/tests/unit/common/test_utils.py
index 033bb0243..e71d0ff0f 100644
--- a/yardstick/tests/unit/common/test_utils.py
+++ b/yardstick/tests/unit/common/test_utils.py
@@ -19,6 +19,8 @@ from six.moves import configparser
import unittest
import yardstick
+from yardstick import ssh
+import yardstick.error
from yardstick.common import utils
from yardstick.common import constants
@@ -125,6 +127,63 @@ class CommonUtilTestCase(unittest.TestCase):
("=".join(item) for item in sorted(flattened_data.items())))
self.assertEqual(result, line)
+ def test_get_key_with_default_negative(self):
+ with self.assertRaises(KeyError):
+ utils.get_key_with_default({}, 'key1')
+
+ @mock.patch('yardstick.common.utils.open', create=True)
+ def test_(self, mock_open):
+ mock_open.side_effect = IOError
+
+ with self.assertRaises(IOError):
+ utils.find_relative_file('my/path', 'task/path')
+
+ self.assertEqual(mock_open.call_count, 2)
+
+ @mock.patch('yardstick.common.utils.open', create=True)
+ def test_open_relative_path(self, mock_open):
+ mock_open_result = mock_open()
+ mock_open_call_count = 1 # initial call to get result
+
+ self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
+
+ mock_open_call_count += 1 # one more call expected
+ self.assertEqual(mock_open.call_count, mock_open_call_count)
+ self.assertIn('foo', mock_open.call_args_list[-1][0][0])
+ self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])
+
+ def open_effect(*args, **kwargs):
+ if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
+ return mock_open_result
+ raise IOError(errno.ENOENT, 'not found')
+
+ mock_open.side_effect = open_effect
+ self.assertEqual(utils.open_relative_file('foo', 'bar'), mock_open_result)
+
+ mock_open_call_count += 2 # two more calls expected
+ self.assertEqual(mock_open.call_count, mock_open_call_count)
+ self.assertIn('foo', mock_open.call_args_list[-1][0][0])
+ self.assertIn('bar', mock_open.call_args_list[-1][0][0])
+
+ # test an IOError of type ENOENT
+ mock_open.side_effect = IOError(errno.ENOENT, 'not found')
+ with self.assertRaises(IOError):
+ # the second call still raises
+ utils.open_relative_file('foo', 'bar')
+
+ mock_open_call_count += 2 # two more calls expected
+ self.assertEqual(mock_open.call_count, mock_open_call_count)
+ self.assertIn('foo', mock_open.call_args_list[-1][0][0])
+ self.assertIn('bar', mock_open.call_args_list[-1][0][0])
+
+ # test an IOError other than ENOENT
+ mock_open.side_effect = IOError(errno.EBUSY, 'busy')
+ with self.assertRaises(IOError):
+ utils.open_relative_file('foo', 'bar')
+
+ mock_open_call_count += 1 # one more call expected
+ self.assertEqual(mock_open.call_count, mock_open_call_count)
+
class TestMacAddressToHex(unittest.TestCase):
@@ -930,9 +989,9 @@ class TestUtils(unittest.TestCase):
def test_error_class(self):
with self.assertRaises(RuntimeError):
- utils.ErrorClass()
+ yardstick.error.ErrorClass()
- error_instance = utils.ErrorClass(test='')
+ error_instance = yardstick.error.ErrorClass(test='')
with self.assertRaises(AttributeError):
error_instance.get_name()
@@ -1075,8 +1134,27 @@ class SafeDecodeUtf8TestCase(unittest.TestCase):
self.assertEqual('this is a byte array', out)
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
+class ReadMeminfoTestCase(unittest.TestCase):
+
+ MEMINFO = (b'MemTotal: 65860500 kB\n'
+ b'MemFree: 28690900 kB\n'
+ b'MemAvailable: 52873764 kB\n'
+ b'Active(anon): 3015676 kB\n'
+ b'HugePages_Total: 8\n'
+ b'Hugepagesize: 1048576 kB')
+ MEMINFO_DICT = {'MemTotal': '65860500',
+ 'MemFree': '28690900',
+ 'MemAvailable': '52873764',
+ 'Active(anon)': '3015676',
+ 'HugePages_Total': '8',
+ 'Hugepagesize': '1048576'}
+
+ def test_read_meminfo(self):
+ ssh_client = ssh.SSH('user', 'host')
+ with mock.patch.object(ssh_client, 'get_file_obj') as \
+ mock_get_client, \
+ mock.patch.object(six, 'BytesIO',
+ return_value=six.BytesIO(self.MEMINFO)):
+ output = utils.read_meminfo(ssh_client)
+ mock_get_client.assert_called_once_with('/proc/meminfo', mock.ANY)
+ self.assertEqual(self.MEMINFO_DICT, output)
diff --git a/yardstick/tests/unit/common/test_yaml_loader.py b/yardstick/tests/unit/common/test_yaml_loader.py
index 6c2beb422..e621dcbc5 100644
--- a/yardstick/tests/unit/common/test_yaml_loader.py
+++ b/yardstick/tests/unit/common/test_yaml_loader.py
@@ -12,7 +12,6 @@
# yardstick: this file is copied from python-heatclient and slightly modified
-from __future__ import absolute_import
import unittest
from yardstick.common import yaml_loader
@@ -23,10 +22,3 @@ class TemplateFormatTestCase(unittest.TestCase):
def test_parse_to_value_exception(self):
self.assertEqual(yaml_loader.yaml_load("string"), u"string")
-
-
-def main():
- unittest.main()
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/dispatcher/test_influxdb.py b/yardstick/tests/unit/dispatcher/test_influxdb.py
index bca94e385..c844d4bbb 100644
--- a/yardstick/tests/unit/dispatcher/test_influxdb.py
+++ b/yardstick/tests/unit/dispatcher/test_influxdb.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
@@ -104,11 +102,3 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
mock_time.time.return_value = 1451461248.925574
self.assertEqual(influxdb._get_nano_timestamp(results),
'1451461248925574144')
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/orchestrator/test_heat.py b/yardstick/tests/unit/orchestrator/test_heat.py
index acf4991d2..aae2487aa 100644
--- a/yardstick/tests/unit/orchestrator/test_heat.py
+++ b/yardstick/tests/unit/orchestrator/test_heat.py
@@ -9,6 +9,7 @@
import tempfile
+import munch
import mock
from oslo_serialization import jsonutils
from oslo_utils import uuidutils
@@ -40,12 +41,16 @@ class HeatStackTestCase(unittest.TestCase):
self._mock_stack_delete = mock.patch.object(self.heatstack._cloud,
'delete_stack')
self.mock_stack_delete = self._mock_stack_delete.start()
+ self._mock_stack_get = mock.patch.object(self.heatstack._cloud,
+ 'get_stack')
+ self.mock_stack_get = self._mock_stack_get.start()
self.addCleanup(self._cleanup)
def _cleanup(self):
self._mock_stack_create.stop()
self._mock_stack_delete.stop()
+ self._mock_stack_get.stop()
heat._DEPLOYED_STACKS = {}
def test_create(self):
@@ -101,6 +106,88 @@ class HeatStackTestCase(unittest.TestCase):
self.assertFalse(heat._DEPLOYED_STACKS)
self.mock_stack_delete.assert_called_once_with(id, wait=True)
+ def test_get(self):
+ # make sure shade/get_stack is called with the appropriate vars
+ self.mock_stack_get.return_value = munch.Munch(
+ id="my-existing-stack-id",
+ outputs=[
+ {
+ u'output_value': u'b734d06a-dec7-...',
+ u'output_key': u'ares.demo-test-port-network_id',
+ u'description': u''
+ },
+ {u'output_value': u'b08da78c-2218-...',
+ u'output_key': u'ares.demo-test-port-subnet_id',
+ u'description': u''
+ },
+ {u'output_value': u'10.0.1.0/24',
+ u'output_key': u'demo-test-subnet-cidr',
+ u'description': u''
+ },
+ {u'output_value': u'b08da78c-2218-...',
+ u'output_key': u'demo-test-subnet',
+ u'description': u''
+ },
+ {u'output_value': u'b1a03624-aefc-...',
+ u'output_key': u'ares.demo',
+ u'description': u''
+ },
+ {u'output_value': u'266a8088-c630-...',
+ u'output_key': u'demo-secgroup',
+ u'description': u''
+ },
+ {u'output_value': u'10.0.1.5',
+ u'output_key': u'ares.demo-test-port',
+ u'description': u''
+ },
+ {u'output_value': u'10.0.1.1',
+ u'output_key': u'demo-test-subnet-gateway_ip',
+ u'description': u''
+ },
+ {u'output_value': u'',
+ u'output_key': u'ares.demo-test-port-device_id',
+ u'description': u''
+ },
+ {u'output_value': u'172.24.4.7',
+ u'output_key': u'ares.demo-fip',
+ u'description': u''
+ },
+ {u'output_value': u'fa:16:3e:6c:c3:0f',
+ u'output_key': u'ares.demo-test-port-mac_address',
+ u'description': u''}
+ ]
+ )
+ expected_outputs = {
+ 'ares.demo-test-port-network_id': 'b734d06a-dec7-...',
+ 'ares.demo-test-port-subnet_id': 'b08da78c-2218-...',
+ 'demo-test-subnet-cidr': '10.0.1.0/24',
+ 'demo-test-subnet': 'b08da78c-2218-...',
+ 'ares.demo': 'b1a03624-aefc-...',
+ 'demo-secgroup': '266a8088-c630-...',
+ 'ares.demo-test-port': '10.0.1.5',
+ 'demo-test-subnet-gateway_ip': '10.0.1.1',
+ 'ares.demo-test-port-device_id': '',
+ 'ares.demo-fip': '172.24.4.7',
+ 'ares.demo-test-port-mac_address': 'fa:16:3e:6c:c3:0f',
+ }
+
+ stack_id = "my-existing-stack-id"
+ self.heatstack.name = "my-existing-stack"
+ self.heatstack.get()
+
+ self.mock_stack_get.assert_called_once_with(self.heatstack.name)
+ self.assertEqual(expected_outputs, self.heatstack.outputs)
+ self.assertEqual(1, len(heat._DEPLOYED_STACKS))
+ self.assertEqual(self.heatstack._stack,
+ heat._DEPLOYED_STACKS[stack_id])
+
+ def test_get_invalid_name(self):
+ # No context matching this name exists
+ self.mock_stack_get.return_value = []
+ self.heatstack.name = 'not-a-stack'
+ self.heatstack.get()
+ self.assertEqual(0, len(heat._DEPLOYED_STACKS))
+
class HeatTemplateTestCase(unittest.TestCase):
@@ -160,7 +247,8 @@ class HeatTemplateTestCase(unittest.TestCase):
def test__add_resources_to_template_raw(self):
test_context = node.NodeContext()
- test_context.name = 'foo'
+ self.addCleanup(test_context._delete_context)
+ test_context._name = 'foo'
test_context.template_file = '/tmp/some-heat-file'
test_context.heat_parameters = {'image': 'cirros'}
test_context.key_filename = "/tmp/1234"
diff --git a/yardstick/tests/unit/orchestrator/test_kubernetes.py b/yardstick/tests/unit/orchestrator/test_kubernetes.py
index 33fa1dca6..f2bc5b0f4 100644
--- a/yardstick/tests/unit/orchestrator/test_kubernetes.py
+++ b/yardstick/tests/unit/orchestrator/test_kubernetes.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
##############################################################################
# Copyright (c) 2017 Intel Corporation
#
@@ -104,11 +102,3 @@ service ssh restart;while true ; do sleep 10000; done']
mock_get_pod_list.return_value.items = []
pods = k8s_template.get_rc_pods()
self.assertEqual(pods, [])
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/test_cmd/commands/test_env.py b/yardstick/tests/unit/test_cmd/commands/test_env.py
index 13c3ed44a..1156b6642 100644
--- a/yardstick/tests/unit/test_cmd/commands/test_env.py
+++ b/yardstick/tests/unit/test_cmd/commands/test_env.py
@@ -63,11 +63,3 @@ class EnvCommandTestCase(unittest.TestCase):
except Exception as e: # pylint: disable=broad-except
# NOTE(ralonsoh): try to reduce the scope of this exception.
self.assertIsInstance(e, IndexError)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/test_cmd/commands/test_testcase.py b/yardstick/tests/unit/test_cmd/commands/test_testcase.py
index 7ef157c19..f6f842e20 100644
--- a/yardstick/tests/unit/test_cmd/commands/test_testcase.py
+++ b/yardstick/tests/unit/test_cmd/commands/test_testcase.py
@@ -19,11 +19,3 @@ class TestcaseCommandsUT(unittest.TestCase):
mock_client.get.return_value = {'result': []}
TestcaseCommands().do_list({})
self.assertTrue(mock_print.called)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()
diff --git a/yardstick/tests/unit/test_cmd/test_NSBperf.py b/yardstick/tests/unit/test_cmd/test_NSBperf.py
index 483e82a13..d64b0c551 100644
--- a/yardstick/tests/unit/test_cmd/test_NSBperf.py
+++ b/yardstick/tests/unit/test_cmd/test_NSBperf.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -91,17 +89,17 @@ class TestYardstickNSCli(unittest.TestCase):
subprocess.check_output = mock.Mock(return_value=0)
args = {"vnf": "vpe",
"test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"}
- self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
+ self.assertIsNone(yardstick_ns_cli.run_test(args, test_path))
os.chdir(cur_dir)
args = {"vnf": "vpe1"}
- self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
+ self.assertIsNone(yardstick_ns_cli.run_test(args, test_path))
os.chdir(cur_dir)
args = {"vnf": "vpe",
"test": "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml."}
- self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
+ self.assertIsNone(yardstick_ns_cli.run_test(args, test_path))
os.chdir(cur_dir)
args = []
- self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
+ self.assertIsNone(yardstick_ns_cli.run_test(args, test_path))
os.chdir(cur_dir)
def test_terminate_if_less_options(self):
diff --git a/yardstick/tests/unit/test_ssh.py b/yardstick/tests/unit/test_ssh.py
index dbaae8c37..f92290070 100644
--- a/yardstick/tests/unit/test_ssh.py
+++ b/yardstick/tests/unit/test_ssh.py
@@ -21,12 +21,13 @@ import os
import socket
import unittest
from io import StringIO
+from itertools import count
import mock
from oslo_utils import encodeutils
from yardstick import ssh
-from yardstick.ssh import SSHError
+from yardstick.ssh import SSHError, SSHTimeout
from yardstick.ssh import SSH
from yardstick.ssh import AutoConnectSSH
@@ -508,13 +509,45 @@ class SSHRunTestCase(unittest.TestCase):
class TestAutoConnectSSH(unittest.TestCase):
- def test__connect_with_wait(self):
- auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=True)
- auto_connect_ssh._get_client = mock.Mock()
- auto_connect_ssh.wait = mock_wait = mock.Mock()
+ def test__connect_loop(self):
+ auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=0)
+ auto_connect_ssh._get_client = mock__get_client = mock.Mock()
auto_connect_ssh._connect()
- self.assertEqual(mock_wait.call_count, 1)
+ self.assertEqual(mock__get_client.call_count, 1)
+
+ def test___init___negative(self):
+ with self.assertRaises(TypeError):
+ AutoConnectSSH('user1', 'host1', wait=['wait'])
+
+ with self.assertRaises(ValueError):
+ AutoConnectSSH('user1', 'host1', wait='wait')
+
+ @mock.patch('yardstick.ssh.time')
+ def test__connect_loop_ssh_error(self, mock_time):
+ mock_time.time.side_effect = count()
+
+ auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=10)
+ auto_connect_ssh._get_client = mock__get_client = mock.Mock()
+ mock__get_client.side_effect = SSHError
+
+ with self.assertRaises(SSHTimeout):
+ auto_connect_ssh._connect()
+
+ self.assertEqual(mock_time.time.call_count, 12)
+
+ def test_get_file_obj(self):
+ auto_connect_ssh = AutoConnectSSH('user1', 'host1', wait=10)
+ auto_connect_ssh._get_client = mock__get_client = mock.Mock()
+ mock_client = mock__get_client()
+ mock_open_sftp = mock_client.open_sftp()
+ mock_sftp = mock.Mock()
+ mock_open_sftp.__enter__ = mock.Mock(return_value=mock_sftp)
+ mock_open_sftp.__exit__ = mock.Mock()
+
+ auto_connect_ssh.get_file_obj('remote/path', mock.Mock())
+
+ self.assertEqual(mock_sftp.getfo.call_count, 1)
def test__make_dict(self):
auto_connect_ssh = AutoConnectSSH('user1', 'host1')
@@ -527,7 +560,7 @@ class TestAutoConnectSSH(unittest.TestCase):
'key_filename': None,
'password': None,
'name': None,
- 'wait': True,
+ 'wait': AutoConnectSSH.DEFAULT_WAIT_TIMEOUT,
}
result = auto_connect_ssh._make_dict()
self.assertDictEqual(result, expected)
@@ -537,6 +570,13 @@ class TestAutoConnectSSH(unittest.TestCase):
self.assertEqual(auto_connect_ssh.get_class(), AutoConnectSSH)
+ def test_drop_connection(self):
+ auto_connect_ssh = AutoConnectSSH('user1', 'host1')
+ self.assertFalse(auto_connect_ssh._client)
+ auto_connect_ssh._client = True
+ auto_connect_ssh.drop_connection()
+ self.assertFalse(auto_connect_ssh._client)
+
@mock.patch('yardstick.ssh.SCPClient')
def test_put(self, mock_scp_client_type):
auto_connect_ssh = AutoConnectSSH('user1', 'host1')
@@ -562,11 +602,3 @@ class TestAutoConnectSSH(unittest.TestCase):
auto_connect_ssh.put_file('a', 'b')
self.assertEqual(mock_put_sftp.call_count, 1)
-
-
-def main():
- unittest.main()
-
-
-if __name__ == '__main__':
- main()