aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_model.py75
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py37
-rw-r--r--tests/unit/benchmark/contexts/standalone/test_sriov.py2
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_monitor_command.py39
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_serviceha.py32
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_util.py39
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_cyclictest.py2
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_qemumigrate.py2
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_unixbench.py2
-rw-r--r--tests/unit/benchmark/scenarios/dummy/test_dummy.py4
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_check_numa_info.py9
-rw-r--r--tests/unit/benchmark/scenarios/lib/test_create_volume.py83
-rwxr-xr-xtests/unit/benchmark/scenarios/networking/test_netperf.py2
-rwxr-xr-xtests/unit/benchmark/scenarios/networking/test_netperf_node.py2
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_nstat.py28
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_ping6.py2
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_pktgen.py36
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py69
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py33
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vsperf.py6
-rw-r--r--tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py99
-rw-r--r--tests/unit/benchmark/scenarios/parser/test_parser.py67
-rw-r--r--tests/unit/benchmark/scenarios/storage/test_fio.py4
-rw-r--r--tests/unit/dispatcher/__init__.py0
-rw-r--r--tests/unit/dispatcher/test_influxdb.py119
-rw-r--r--tests/unit/dispatcher/test_influxdb_line_protocol.py64
-rw-r--r--tests/unit/network_services/helpers/test_dpdkbindnic_helper.py21
-rw-r--r--tests/unit/network_services/nfvi/test_resource.py33
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py12
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py4
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py7
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py2
-rw-r--r--tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py11
-rw-r--r--tests/unit/orchestrator/__init__.py0
-rw-r--r--tests/unit/orchestrator/test_heat.py339
-rw-r--r--tests/unit/orchestrator/test_kubernetes.py114
-rw-r--r--tests/unit/test_cmd/__init__.py0
-rw-r--r--tests/unit/test_cmd/commands/__init__.py0
-rw-r--r--tests/unit/test_cmd/commands/test_env.py73
-rw-r--r--tests/unit/test_cmd/commands/test_testcase.py29
-rw-r--r--tests/unit/test_cmd/test_NSBperf.py120
42 files changed, 451 insertions, 1173 deletions
diff --git a/tests/unit/benchmark/contexts/standalone/test_model.py b/tests/unit/benchmark/contexts/standalone/test_model.py
index 31ec2b7d1..6090356b6 100644
--- a/tests/unit/benchmark/contexts/standalone/test_model.py
+++ b/tests/unit/benchmark/contexts/standalone/test_model.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");
@@ -14,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# Unittest for yardstick.benchmark.contexts.standalone.model
-
-from __future__ import absolute_import
import copy
import os
import unittest
@@ -24,9 +19,9 @@ import mock
from xml.etree import ElementTree
+from yardstick.benchmark.contexts.standalone.model import Libvirt
from yardstick.benchmark.contexts.standalone import model
from yardstick.network_services import utils
-from yardstick.network_services.helpers import cpu
XML_SAMPLE = """<?xml version="1.0"?>
@@ -134,9 +129,9 @@ class ModelLibvirtTestCase(unittest.TestCase):
as mock_parse:
xml = copy.deepcopy(self.xml)
mock_parse.return_value = xml
- vf_pci = '0001:05:04.2'
+ vm_pci = '0001:05:04.2'
model.Libvirt.add_sriov_interfaces(
- self.pci_address_str, vf_pci, self.mac, xml_input)
+ vm_pci, self.pci_address_str, self.mac, xml_input)
mock_parse.assert_called_once_with(xml_input)
self.mock_write_xml.assert_called_once_with(xml_input)
interface = xml.find('devices').find('interface')
@@ -145,8 +140,29 @@ class ModelLibvirtTestCase(unittest.TestCase):
mac = interface.find('mac')
self.assertEqual(self.mac, mac.get('address'))
source = interface.find('source')
+ source_address = source.find('address')
self.assertIsNotNone(source.find('address'))
- self.assertIsNotNone(interface.find('address'))
+
+ self.assertEqual('pci', source_address.get('type'))
+ self.assertEqual('0x' + self.pci_address_str.split(':')[0],
+ source_address.get('domain'))
+ self.assertEqual('0x' + self.pci_address_str.split(':')[1],
+ source_address.get('bus'))
+ self.assertEqual('0x' + self.pci_address_str.split(':')[2].split('.')[0],
+ source_address.get('slot'))
+ self.assertEqual('0x' + self.pci_address_str.split(':')[2].split('.')[1],
+ source_address.get('function'))
+
+ interface_address = interface.find('address')
+ self.assertEqual('pci', interface_address.get('type'))
+ self.assertEqual('0x' + vm_pci.split(':')[0],
+ interface_address.get('domain'))
+ self.assertEqual('0x' + vm_pci.split(':')[1],
+ interface_address.get('bus'))
+ self.assertEqual('0x' + vm_pci.split(':')[2].split('.')[0],
+ interface_address.get('slot'))
+ self.assertEqual('0x' + vm_pci.split(':')[2].split('.')[1],
+ interface_address.get('function'))
def test_create_snapshot_qemu(self):
result = "/var/lib/libvirt/images/0.qcow2"
@@ -164,6 +180,8 @@ class ModelLibvirtTestCase(unittest.TestCase):
*args):
# NOTE(ralonsoh): this test doesn't cover function execution. This test
# should also check mocked function calls.
+ cfg_file = 'test_config_file.cfg'
+ self.addCleanup(os.remove, cfg_file)
result = [4]
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
@@ -172,7 +190,7 @@ class ModelLibvirtTestCase(unittest.TestCase):
ssh.return_value = ssh_mock
mock_create_snapshot_qemu.return_value = "0.img"
- status = model.Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0)
+ status = model.Libvirt.build_vm_xml(ssh_mock, {}, cfg_file, 'vm_0', 0)
self.assertEqual(status[0], result[0])
def test_update_interrupts_hugepages_perf(self):
@@ -181,21 +199,23 @@ class ModelLibvirtTestCase(unittest.TestCase):
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
- # NOTE(ralonsoh): this test doesn't cover function execution. This test
- # should also check mocked function calls.
- model.Libvirt.update_interrupts_hugepages_perf(ssh_mock)
-
- @mock.patch.object(cpu.CpuSysCores, 'get_core_socket')
- def test_pin_vcpu_for_perf(self, mock_get_core_socket):
- mock_get_core_socket.return_value = {
- 'cores_per_socket': 1,
- 'thread_per_core': 1,
- '0': [1, 2]
- }
- # NOTE(ralonsoh): this test doesn't cover function execution. This
- # function needs more tests.
- model.Libvirt.pin_vcpu_for_perf(mock.Mock())
-
+ # NOTE(ralonsoh): 'update_interrupts_hugepages_perf' always return
+ # None, this check is trivial.
+ #status = Libvirt.update_interrupts_hugepages_perf(ssh_mock)
+ #self.assertIsNone(status)
+ Libvirt.update_interrupts_hugepages_perf(ssh_mock)
+
+ @mock.patch("yardstick.benchmark.contexts.standalone.model.CpuSysCores")
+ @mock.patch.object(model.Libvirt, 'update_interrupts_hugepages_perf')
+ def test_pin_vcpu_for_perf(self, *args):
+ # NOTE(ralonsoh): test mocked methods/variables.
+ with mock.patch("yardstick.ssh.SSH") as ssh:
+ ssh_mock = mock.Mock(autospec=ssh.SSH)
+ ssh_mock.execute = \
+ mock.Mock(return_value=(0, "a", ""))
+ ssh.return_value = ssh_mock
+ status = Libvirt.pin_vcpu_for_perf(ssh_mock, 4)
+ self.assertIsNotNone(status)
class StandaloneContextHelperTestCase(unittest.TestCase):
@@ -247,8 +267,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase):
def test_get_nic_details(self, mock_get_kernel_module):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(1, "i40e ixgbe", ""))
+ ssh_mock.execute = mock.Mock(return_value=(1, "i40e ixgbe", ""))
ssh.return_value = ssh_mock
mock_get_kernel_module.return_value = "i40e"
# NOTE(ralonsoh): this test doesn't cover function execution. This test
@@ -296,6 +315,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase):
@mock.patch('yardstick.ssh.SSH')
def test_get_mgmt_ip(self, *args):
+ # NOTE(ralonsoh): test mocked methods/variables.
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = mock.Mock(
@@ -309,6 +329,7 @@ class StandaloneContextHelperTestCase(unittest.TestCase):
@mock.patch('yardstick.ssh.SSH')
def test_get_mgmt_ip_no(self, *args):
+ # NOTE(ralonsoh): test mocked methods/variables.
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
diff --git a/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
index 5d1b0421c..e39ecf4f2 100644
--- a/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
+++ b/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py
@@ -17,12 +17,9 @@
from __future__ import absolute_import
import os
import unittest
-import errno
import mock
-from yardstick.common import constants as consts
from yardstick.benchmark.contexts.standalone import ovs_dpdk
-from yardstick.network_services.utils import PciAddress
class OvsDpdkContextTestCase(unittest.TestCase):
@@ -68,7 +65,7 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.ovs_dpdk.helper = mock_helper
self.ovs_dpdk.vnf_node = mock_server
self.assertIsNone(self.ovs_dpdk.file_path)
- self.assertEqual(self.ovs_dpdk.first_run, True)
+ self.assertTrue(self.ovs_dpdk.first_run)
def test_init(self):
self.ovs_dpdk.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}])
@@ -149,12 +146,9 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.assertRaises(Exception, self.ovs_dpdk.check_ovs_dpdk_env)
@mock.patch('yardstick.ssh.SSH')
- def test_deploy(self, mock_ssh):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "a", ""))
- ssh.return_value = ssh_mock
+ def test_deploy(self, ssh_mock):
+ ssh_mock.execute.return_value = (0, "a", "")
+
self.ovs_dpdk.vm_deploy = False
self.assertIsNone(self.ovs_dpdk.deploy())
@@ -168,22 +162,21 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.ovs_dpdk.setup_ovs_bridge_add_flows = mock.Mock(return_value={})
self.ovs_dpdk.setup_ovs_dpdk_context = mock.Mock(return_value={})
self.ovs_dpdk.wait_for_vnfs_to_start = mock.Mock(return_value={})
+ # TODO(elfoley): This test should check states/sideeffects instead of
+ # output.
self.assertIsNone(self.ovs_dpdk.deploy())
- @mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt')
+ @mock.patch('yardstick.benchmark.contexts.standalone.model.Libvirt')
@mock.patch('yardstick.ssh.SSH')
- def test_undeploy(self, mock_ssh, mock_libvirt):
- with mock.patch("yardstick.ssh.SSH") as ssh:
- ssh_mock = mock.Mock(autospec=ssh.SSH)
- ssh_mock.execute = \
- mock.Mock(return_value=(0, "a", ""))
- ssh.return_value = ssh_mock
+ def test_undeploy(self, ssh_mock, _):
+ ssh_mock.execute.return_value = (0, "a", "")
+
self.ovs_dpdk.vm_deploy = False
self.assertIsNone(self.ovs_dpdk.undeploy())
self.ovs_dpdk.vm_deploy = True
- self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
+ self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.drivers = ['vm_0', 'vm_1']
self.ovs_dpdk.cleanup_ovs_dpdk_env = mock.Mock()
self.ovs_dpdk.networks = self.NETWORKS
@@ -326,8 +319,8 @@ class OvsDpdkContextTestCase(unittest.TestCase):
self.ovs_dpdk.get_vf_datas = mock.Mock(return_value="")
self.assertIsNone(self.ovs_dpdk.configure_nics_for_ovs_dpdk())
- @mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt')
- def test__enable_interfaces(self, mock_add_ovs_interface):
+ @mock.patch('yardstick.benchmark.contexts.standalone.model.Libvirt.add_ovs_interface')
+ def test__enable_interfaces(self, _):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
@@ -343,7 +336,7 @@ class OvsDpdkContextTestCase(unittest.TestCase):
@mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt')
@mock.patch('yardstick.benchmark.contexts.standalone.model.Server')
- def test_setup_ovs_dpdk_context(self, mock_server, mock_libvirt):
+ def test_setup_ovs_dpdk_context(self, _, mock_libvirt):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
@@ -372,6 +365,6 @@ class OvsDpdkContextTestCase(unittest.TestCase):
mock_libvirt.build_vm_xml = mock.Mock(return_value=[6, "00:00:00:00:00:01"])
self.ovs_dpdk._enable_interfaces = mock.Mock(return_value="")
mock_libvirt.virsh_create_vm = mock.Mock(return_value="")
- mock_libvirt.pin_vcpu_for_perf= mock.Mock(return_value="")
+ mock_libvirt.pin_vcpu_for_perf = mock.Mock(return_value="")
self.ovs_dpdk.vnf_node.generate_vnf_instance = mock.Mock(return_value={})
self.assertIsNotNone(self.ovs_dpdk.setup_ovs_dpdk_context())
diff --git a/tests/unit/benchmark/contexts/standalone/test_sriov.py b/tests/unit/benchmark/contexts/standalone/test_sriov.py
index 3ea673abc..7f11a7d59 100644
--- a/tests/unit/benchmark/contexts/standalone/test_sriov.py
+++ b/tests/unit/benchmark/contexts/standalone/test_sriov.py
@@ -70,7 +70,7 @@ class SriovContextTestCase(unittest.TestCase):
self.sriov.helper = mock_helper
self.sriov.vnf_node = mock_server
self.assertIsNone(self.sriov.file_path)
- self.assertEqual(self.sriov.first_run, True)
+ self.assertTrue(self.sriov.first_run)
def test_init(self):
self.sriov.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}])
diff --git a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
index 6a9b3b157..b84cef23c 100644
--- a/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
+++ b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py
@@ -19,30 +19,26 @@ import unittest
from yardstick.benchmark.scenarios.availability.monitor import monitor_command
-@mock.patch(
- 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
- '.subprocess')
+@mock.patch('subprocess.check_output')
class ExecuteShellTestCase(unittest.TestCase):
- def test__fun_execute_shell_command_successful(self, mock_subprocess):
+ def test__fun_execute_shell_command_successful(self, mock_subprocess_check_output):
cmd = "env"
- mock_subprocess.check_output.return_value = (0, 'unittest')
- exitcode, output = monitor_command._execute_shell_command(cmd)
+ mock_subprocess_check_output.return_value = (0, 'unittest')
+ exitcode, _ = monitor_command._execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log,
- mock_subprocess):
+ mock_subprocess_check_output):
cmd = "env"
- mock_subprocess.check_output.side_effect = RuntimeError
- exitcode, output = monitor_command._execute_shell_command(cmd)
+ mock_subprocess_check_output.side_effect = RuntimeError
+ exitcode, _ = monitor_command._execute_shell_command(cmd)
self.assertEqual(exitcode, -1)
mock_log.error.assert_called_once()
-@mock.patch(
- 'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
- '.subprocess')
+@mock.patch('subprocess.check_output')
class MonitorOpenstackCmdTestCase(unittest.TestCase):
def setUp(self):
@@ -59,24 +55,24 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase):
'sla': {'max_outage_time': 5}
}
- def test__monitor_command_monitor_func_successful(self, mock_subprocess):
+ def test__monitor_command_monitor_func_successful(self, mock_subprocess_check_output):
instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
instance.setup()
- mock_subprocess.check_output.return_value = (0, 'unittest')
+ mock_subprocess_check_output.return_value = (0, 'unittest')
ret = instance.monitor_func()
- self.assertEqual(ret, True)
+ self.assertTrue(ret)
instance._result = {"outage_time": 0}
instance.verify_SLA()
@mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
- def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess):
- mock_subprocess.check_output.return_value = (1, 'unittest')
+ def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess_check_output):
+ mock_subprocess_check_output.return_value = (1, 'unittest')
instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
instance.setup()
- mock_subprocess.check_output.side_effect = RuntimeError
+ mock_subprocess_check_output.side_effect = RuntimeError
ret = instance.monitor_func()
- self.assertEqual(ret, False)
+ self.assertFalse(ret)
mock_log.error.assert_called_once()
instance._result = {"outage_time": 10}
instance.verify_SLA()
@@ -84,12 +80,13 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase):
@mock.patch(
'yardstick.benchmark.scenarios.availability.monitor.monitor_command'
'.ssh')
- def test__monitor_command_ssh_monitor_successful(self, mock_ssh,
- mock_subprocess):
+ def test__monitor_command_ssh_monitor_successful(self, mock_ssh, mock_subprocess_check_output):
+ mock_subprocess_check_output.return_value = (0, 'unittest')
self.config["host"] = "node1"
instance = monitor_command.MonitorOpenstackCmd(
self.config, self.context, {"nova-api": 10})
instance.setup()
mock_ssh.SSH.from_node().execute.return_value = (0, "0", '')
ret = instance.monitor_func()
+ self.assertTrue(ret)
diff --git a/tests/unit/benchmark/scenarios/availability/test_serviceha.py b/tests/unit/benchmark/scenarios/availability/test_serviceha.py
index 4ae508958..97d534894 100644
--- a/tests/unit/benchmark/scenarios/availability/test_serviceha.py
+++ b/tests/unit/benchmark/scenarios/availability/test_serviceha.py
@@ -18,9 +18,6 @@ import unittest
from yardstick.benchmark.scenarios.availability import serviceha
-@mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor')
-@mock.patch(
- 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker')
class ServicehaTestCase(unittest.TestCase):
def setUp(self):
@@ -51,27 +48,32 @@ class ServicehaTestCase(unittest.TestCase):
sla = {"outage_time": 5}
self.args = {"options": options, "sla": sla}
- def test__serviceha_setup_run_successful(self, mock_attacker,
+ @mock.patch('yardstick.benchmark.scenarios.availability.serviceha.basemonitor')
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.availability.serviceha.baseattacker')
+ def test__serviceha_setup_run_successful(self, _,
mock_monitor):
p = serviceha.ServiceHA(self.args, self.ctx)
p.setup()
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
mock_monitor.MonitorMgr().verify_SLA.return_value = True
ret = {}
p.run(ret)
p.teardown()
-"""
- def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor):
- p = serviceha.ServiceHA(self.args, self.ctx)
p.setup()
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
- result = {}
- result["outage_time"] = 10
- mock_monitor.Monitor().get_result.return_value = result
+# def test__serviceha_run_sla_error(self, mock_attacker, mock_monitor):
+# p = serviceha.ServiceHA(self.args, self.ctx)
- ret = {}
- self.assertRaises(AssertionError, p.run, ret)
-"""
+# p.setup()
+# self.assertTrue(p.setup_done)
+#
+# result = {}
+# result["outage_time"] = 10
+# mock_monitor.Monitor().get_result.return_value = result
+
+# ret = {}
+# self.assertRaises(AssertionError, p.run, ret)
diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py
index 0974f385a..548efe91b 100644
--- a/tests/unit/benchmark/scenarios/availability/test_util.py
+++ b/tests/unit/benchmark/scenarios/availability/test_util.py
@@ -16,36 +16,43 @@ import unittest
from yardstick.benchmark.scenarios.availability import util
-@mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess')
+
class ExecuteShellTestCase(unittest.TestCase):
def setUp(self):
self.param_config = {'serviceName': '@serviceName', 'value': 1}
self.intermediate_variables = {'@serviceName': 'nova-api'}
self.std_output = '| id | 1 |'
- self.cmd_config = {'cmd':'ls','param':'-a'}
+ self.cmd_config = {'cmd': 'ls', 'param': '-a'}
+
+ self._mock_subprocess = mock.patch.object(util, 'subprocess')
+ self.mock_subprocess = self._mock_subprocess.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_subprocess.stop()
- def test_util_build_command_shell(self,mock_subprocess):
+ def test_util_build_command_shell(self):
result = util.build_shell_command(self.param_config, True,
self.intermediate_variables)
- self.assertEqual("nova-api" in result, True)
+ self.assertIn("nova-api", result)
- def test_read_stdout_item(self,mock_subprocess):
- result = util.read_stdout_item(self.std_output,'id')
- self.assertEquals('1',result)
+ def test_read_stdout_item(self):
+ result = util.read_stdout_item(self.std_output, 'id')
+ self.assertEqual('1', result)
- def test_buildshellparams(self,mock_subprocess):
- result = util.buildshellparams(self.cmd_config,True)
- self.assertEquals('/bin/bash -s {0} {1}', result)
+ def test_buildshellparams(self):
+ result = util.buildshellparams(self.cmd_config, True)
+ self.assertEqual('/bin/bash -s {0} {1}', result)
- def test__fun_execute_shell_command_successful(self, mock_subprocess):
+ def test__fun_execute_shell_command_successful(self):
cmd = "env"
- mock_subprocess.check_output.return_value = (0, 'unittest')
- exitcode, output = util.execute_shell_command(cmd)
+ self.mock_subprocess.check_output.return_value = (0, 'unittest')
+ exitcode, _ = util.execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
- def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
+ def test__fun_execute_shell_command_fail_cmd_exception(self):
cmd = "env"
- mock_subprocess.check_output.side_effect = RuntimeError
- exitcode, output = util.execute_shell_command(cmd)
+ self.mock_subprocess.check_output.side_effect = RuntimeError
+ exitcode, _ = util.execute_shell_command(cmd)
self.assertEqual(exitcode, -1)
diff --git a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
index dc52a80c7..51ffd2488 100644
--- a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
+++ b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
@@ -74,7 +74,7 @@ class CyclictestTestCase(unittest.TestCase):
c.setup()
self.assertIsNotNone(c.guest)
self.assertIsNotNone(c.host)
- self.assertEqual(c.setup_done, True)
+ self.assertTrue(c.setup_done)
def test_cyclictest_successful_no_sla(self, mock_ssh):
result = {}
diff --git a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
index 1f0ff3c29..fb55b809f 100644
--- a/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
+++ b/tests/unit/benchmark/scenarios/compute/test_qemumigrate.py
@@ -71,7 +71,7 @@ class QemuMigrateTestCase(unittest.TestCase):
q.setup()
self.assertIsNotNone(q.host)
- self.assertEqual(q.setup_done, True)
+ self.assertTrue(q.setup_done)
def test_qemu_migrate_successful_no_sla(self, mock_ssh):
result = {}
diff --git a/tests/unit/benchmark/scenarios/compute/test_unixbench.py b/tests/unit/benchmark/scenarios/compute/test_unixbench.py
index 7d071e91c..fec355b45 100644
--- a/tests/unit/benchmark/scenarios/compute/test_unixbench.py
+++ b/tests/unit/benchmark/scenarios/compute/test_unixbench.py
@@ -40,7 +40,7 @@ class UnixbenchTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
self.assertIsNotNone(u.client)
- self.assertEqual(u.setup_done, True)
+ self.assertTrue(u.setup_done)
def test_unixbench_successful_no_sla(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/dummy/test_dummy.py b/tests/unit/benchmark/scenarios/dummy/test_dummy.py
index 560675d09..bc5131806 100644
--- a/tests/unit/benchmark/scenarios/dummy/test_dummy.py
+++ b/tests/unit/benchmark/scenarios/dummy/test_dummy.py
@@ -24,11 +24,11 @@ class DummyTestCase(unittest.TestCase):
self.assertIsNone(self.test_context.scenario_cfg)
self.assertIsNone(self.test_context.context_cfg)
- self.assertEqual(self.test_context.setup_done, False)
+ self.assertFalse(self.test_context.setup_done)
def test_run(self):
result = {}
self.test_context.run(result)
self.assertEqual(result["hello"], "yardstick")
- self.assertEqual(self.test_context.setup_done, True)
+ self.assertTrue(self.test_context.setup_done)
diff --git a/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py b/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
index bdf1e66e5..1dd461d41 100644
--- a/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
+++ b/tests/unit/benchmark/scenarios/lib/test_check_numa_info.py
@@ -14,7 +14,8 @@ from yardstick.benchmark.scenarios.lib.check_numa_info import CheckNumaInfo
class CheckNumaInfoTestCase(unittest.TestCase):
- @mock.patch('yardstick.benchmark.scenarios.lib.check_numa_info.CheckNumaInfo._check_vm2_status')
+ @mock.patch(
+ 'yardstick.benchmark.scenarios.lib.check_numa_info.CheckNumaInfo._check_vm2_status')
def test_check_numa_info(self, mock_check_vm2):
scenario_cfg = {'info1': {}, 'info2': {}}
obj = CheckNumaInfo(scenario_cfg, {})
@@ -37,7 +38,7 @@ class CheckNumaInfoTestCase(unittest.TestCase):
scenario_cfg = {'info1': info1, 'info2': info2}
obj = CheckNumaInfo(scenario_cfg, {})
status = obj._check_vm2_status(info1, info2)
- self.assertEqual(status, True)
+ self.assertTrue(status)
def test_check_vm2_status_length_gt_1(self):
info1 = {
@@ -55,7 +56,7 @@ class CheckNumaInfoTestCase(unittest.TestCase):
scenario_cfg = {'info1': info1, 'info2': info2}
obj = CheckNumaInfo(scenario_cfg, {})
status = obj._check_vm2_status(info1, info2)
- self.assertEqual(status, False)
+ self.assertFalse(status)
def test_check_vm2_status_length_not_in_set(self):
info1 = {
@@ -73,7 +74,7 @@ class CheckNumaInfoTestCase(unittest.TestCase):
scenario_cfg = {'info1': info1, 'info2': info2}
obj = CheckNumaInfo(scenario_cfg, {})
status = obj._check_vm2_status(info1, info2)
- self.assertEqual(status, False)
+ self.assertFalse(status)
def main():
diff --git a/tests/unit/benchmark/scenarios/lib/test_create_volume.py b/tests/unit/benchmark/scenarios/lib/test_create_volume.py
index fc633139e..ef2c0ccaf 100644
--- a/tests/unit/benchmark/scenarios/lib/test_create_volume.py
+++ b/tests/unit/benchmark/scenarios/lib/test_create_volume.py
@@ -9,28 +9,79 @@
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.create_volume import CreateVolume
+import yardstick.benchmark.scenarios.lib.create_volume
class CreateVolumeTestCase(unittest.TestCase):
+ def setUp(self):
+ self._mock_cinder_client = mock.patch(
+ 'yardstick.common.openstack_utils.get_cinder_client')
+ self.mock_cinder_client = self._mock_cinder_client.start()
+ self._mock_glance_client = mock.patch(
+ 'yardstick.common.openstack_utils.get_glance_client')
+ self.mock_glance_client = self._mock_glance_client.start()
+ self.addCleanup(self._stop_mock)
+
+ self.scenario_cfg = {
+ "options" :
+ {
+ 'volume_name': 'yardstick_test_volume_01',
+ 'size': '256',
+ 'image': 'cirros-0.3.5'
+ }
+ }
+
+ self.scenario = (
+ yardstick.benchmark.scenarios.lib.create_volume.CreateVolume(
+ scenario_cfg=self.scenario_cfg,
+ context_cfg={}))
+
+ def _stop_mock(self):
+ self._mock_cinder_client.stop()
+ self._mock_glance_client.stop()
+
+ def test_init(self):
+ self.mock_cinder_client.return_value = "All volumes are equal"
+ self.mock_glance_client.return_value = "Images are more equal"
+
+ expected_vol_name = self.scenario_cfg["options"]["volume_name"]
+ expected_vol_size = self.scenario_cfg["options"]["size"]
+ expected_im_name = self.scenario_cfg["options"]["image"]
+ expected_im_id = None
+
+ scenario = (
+ yardstick.benchmark.scenarios.lib.create_volume.CreateVolume(
+ scenario_cfg=self.scenario_cfg,
+ context_cfg={}))
+
+ self.assertEqual(expected_vol_name, scenario.volume_name)
+ self.assertEqual(expected_vol_size, scenario.volume_size)
+ self.assertEqual(expected_im_name, scenario.image_name)
+ self.assertEqual(expected_im_id, scenario.image_id)
+ self.assertEqual("All volumes are equal", scenario.cinder_client)
+ self.assertEqual("Images are more equal", scenario.glance_client)
+
+ def test_setup(self):
+ self.assertFalse(self.scenario.setup_done)
+ self.scenario.setup()
+ self.assertTrue(self.scenario.setup_done)
+
@mock.patch('yardstick.common.openstack_utils.create_volume')
@mock.patch('yardstick.common.openstack_utils.get_image_id')
- @mock.patch('yardstick.common.openstack_utils.get_cinder_client')
- @mock.patch('yardstick.common.openstack_utils.get_glance_client')
- def test_create_volume(self, mock_get_glance_client, mock_get_cinder_client, mock_image_id, mock_create_volume):
- options = {
- 'volume_name': 'yardstick_test_volume_01',
- 'size': '256',
- 'image': 'cirros-0.3.5'
- }
- args = {"options": options}
- obj = CreateVolume(args, {})
- obj.run({})
- self.assertTrue(mock_create_volume.called)
- self.assertTrue(mock_image_id.called)
- self.assertTrue(mock_get_glance_client.called)
- self.assertTrue(mock_get_cinder_client.called)
+ def test_run(self, mock_image_id, mock_create_volume):
+ self.scenario.run()
+
+ mock_image_id.assert_called_once()
+ mock_create_volume.assert_called_once()
+
+ @mock.patch.object(
+ yardstick.benchmark.scenarios.lib.create_volume.CreateVolume, 'setup')
+ def test_run_no_setup(self, scenario_setup):
+ self.scenario.setup_done = False
+ self.scenario.run()
+ scenario_setup.assert_called_once()
+
def main():
unittest.main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf.py b/tests/unit/benchmark/scenarios/networking/test_netperf.py
index d0f862fb5..d82a00931 100755
--- a/tests/unit/benchmark/scenarios/networking/test_netperf.py
+++ b/tests/unit/benchmark/scenarios/networking/test_netperf.py
@@ -48,7 +48,7 @@ class NetperfTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.server)
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
def test_netperf_successful_no_sla(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
index 62874cc44..8be9bb94d 100755
--- a/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
+++ b/tests/unit/benchmark/scenarios/networking/test_netperf_node.py
@@ -48,7 +48,7 @@ class NetperfNodeTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.server)
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
def test_netperf_node_successful_no_sla(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/networking/test_nstat.py b/tests/unit/benchmark/scenarios/networking/test_nstat.py
index fe44cfdf4..4b58e06c1 100644
--- a/tests/unit/benchmark/scenarios/networking/test_nstat.py
+++ b/tests/unit/benchmark/scenarios/networking/test_nstat.py
@@ -19,6 +19,7 @@ import mock
from yardstick.benchmark.scenarios.networking import nstat
+
@mock.patch('yardstick.benchmark.scenarios.networking.nstat.ssh')
class NstatTestCase(unittest.TestCase):
@@ -38,7 +39,7 @@ class NstatTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
self.assertIsNotNone(n.client)
- self.assertEqual(n.setup_done, True)
+ self.assertTrue(n.setup_done)
def test_nstat_successful_no_sla(self, mock_ssh):
@@ -51,17 +52,17 @@ class NstatTestCase(unittest.TestCase):
n = nstat.Nstat(args, self.ctx)
result = {}
- sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n'
+ sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n' # pylint: disable=line-too-long
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
n.run(result)
expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318,
- "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
- "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
- "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
- "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
- "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
+ "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
+ "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
+ "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
+ "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
+ "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
self.assertEqual(result, expected_result)
def test_nstat_successful_sla(self, mock_ssh):
@@ -79,17 +80,17 @@ class NstatTestCase(unittest.TestCase):
n = nstat.Nstat(args, self.ctx)
result = {}
- sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n'
+ sample_output = '#kernel\nIpInReceives 1837 0.0\nIpInHdrErrors 0 0.0\nIpInAddrErrors 2 0.0\nIcmpInMsgs 319 0.0\nIcmpInErrors 0 0.0\nTcpInSegs 36 0.0\nTcpInErrs 0 0.0\nUdpInDatagrams 1318 0.0\nUdpInErrors 0 0.0\n' # pylint: disable=line-too-long
mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
n.run(result)
expected_result = {"TcpInErrs": 0, "UdpInDatagrams": 1318,
- "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
- "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
- "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
- "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
- "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
+ "Tcp_segment_error_rate": 0.0, "IpInAddrErrors": 2,
+ "IpInHdrErrors": 0, "IcmpInErrors": 0, "IpErrors": 2,
+ "TcpInSegs": 36, "IpInReceives": 1837, "IcmpInMsgs": 319,
+ "IP_datagram_error_rate": 0.001, "Udp_datagram_error_rate": 0.0,
+ "Icmp_message_error_rate": 0.0, "UdpInErrors": 0}
self.assertEqual(result, expected_result)
def test_nstat_unsuccessful_cmd_error(self, mock_ssh):
@@ -114,5 +115,6 @@ class NstatTestCase(unittest.TestCase):
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_ping6.py b/tests/unit/benchmark/scenarios/networking/test_ping6.py
index ecce7cee5..d2be6f576 100644
--- a/tests/unit/benchmark/scenarios/networking/test_ping6.py
+++ b/tests/unit/benchmark/scenarios/networking/test_ping6.py
@@ -59,7 +59,7 @@ class PingTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '0', '')
p.setup()
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
@mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
def test_ping_successful_no_sla(self, mock_ssh):
diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen.py b/tests/unit/benchmark/scenarios/networking/test_pktgen.py
index 3928aacde..005b53177 100644
--- a/tests/unit/benchmark/scenarios/networking/test_pktgen.py
+++ b/tests/unit/benchmark/scenarios/networking/test_pktgen.py
@@ -50,7 +50,7 @@ class PktgenTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
self.assertIsNotNone(p.server)
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
def test_pktgen_successful_iptables_setup(self, mock_ssh):
@@ -632,9 +632,13 @@ class PktgenTestCase(unittest.TestCase):
def test_pktgen_run_with_setup_done(self, mock_ssh):
args = {
- 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True},
- 'sla': {'max_ppm': 1}
- }
+ 'options': {
+ 'packetsize': 60,
+ 'number_of_ports': 10,
+ 'duration': 20,
+ 'multiqueue': True},
+ 'sla': {
+ 'max_ppm': 1}}
result = {}
p = pktgen.Pktgen(args, self.ctx)
p.server = mock_ssh.SSH.from_node()
@@ -659,9 +663,13 @@ class PktgenTestCase(unittest.TestCase):
def test_pktgen_run_with_ovs_multiqueque(self, mock_ssh):
args = {
- 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True},
- 'sla': {'max_ppm': 1}
- }
+ 'options': {
+ 'packetsize': 60,
+ 'number_of_ports': 10,
+ 'duration': 20,
+ 'multiqueue': True},
+ 'sla': {
+ 'max_ppm': 1}}
result = {}
p = pktgen.Pktgen(args, self.ctx)
@@ -683,7 +691,7 @@ class PktgenTestCase(unittest.TestCase):
mock_result3 = mock.Mock()
mock_result3.return_value = 4
- p._enable_ovs_multiqueue = mock_result3
+ p._enable_ovs_multiqueue = mock_result3
mock_result4 = mock.Mock()
p._setup_irqmapping_ovs = mock_result4
@@ -704,9 +712,13 @@ class PktgenTestCase(unittest.TestCase):
def test_pktgen_run_with_sriov_multiqueque(self, mock_ssh):
args = {
- 'options': {'packetsize': 60, 'number_of_ports': 10, 'duration': 20, 'multiqueue': True},
- 'sla': {'max_ppm': 1}
- }
+ 'options': {
+ 'packetsize': 60,
+ 'number_of_ports': 10,
+ 'duration': 20,
+ 'multiqueue': True},
+ 'sla': {
+ 'max_ppm': 1}}
result = {}
p = pktgen.Pktgen(args, self.ctx)
@@ -739,8 +751,10 @@ class PktgenTestCase(unittest.TestCase):
expected_result["packetsize"] = 60
self.assertEqual(result, expected_result)
+
def main():
unittest.main()
+
if __name__ == '__main__':
main()
diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
index b4b87522c..c9eec4b94 100644
--- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
+++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk.py
@@ -20,8 +20,6 @@ import yardstick.common.utils as utils
from yardstick.benchmark.scenarios.networking import pktgen_dpdk
-@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.time')
-@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
class PktgenDPDKLatencyTestCase(unittest.TestCase):
def setUp(self):
@@ -39,7 +37,20 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
}
}
- def test_pktgen_dpdk_successful_setup(self, mock_ssh, mock_time):
+ self._mock_ssh = mock.patch(
+ 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
+ self.mock_ssh = self._mock_ssh.start()
+ self._mock_time = mock.patch(
+ 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.time')
+ self.mock_time = self._mock_time.start()
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_ssh.stop()
+ self._mock_time.stop()
+
+ def test_pktgen_dpdk_successful_setup(self):
args = {
'options': {'packetsize': 60},
@@ -47,66 +58,66 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
p.setup()
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
self.assertIsNotNone(p.server)
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
- def test_pktgen_dpdk_successful_get_port_ip(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_successful_get_port_ip(self):
args = {
'options': {'packetsize': 60},
}
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
- p.server = mock_ssh.SSH.from_node()
+ p.server = self.mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
utils.get_port_ip(p.server, "eth1")
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ self.mock_ssh.SSH.from_node().execute.assert_called_with(
"ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ")
- def test_pktgen_dpdk_unsuccessful_get_port_ip(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_unsuccessful_get_port_ip(self):
args = {
'options': {'packetsize': 60},
}
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
- p.server = mock_ssh.SSH.from_node()
+ p.server = self.mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
+ self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1")
- def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_successful_get_port_mac(self):
args = {
'options': {'packetsize': 60},
}
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
- p.server = mock_ssh.SSH.from_node()
+ p.server = self.mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
utils.get_port_mac(p.server, "eth1")
- mock_ssh.SSH.from_node().execute.assert_called_with(
+ self.mock_ssh.SSH.from_node().execute.assert_called_with(
"ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ")
- def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_unsuccessful_get_port_mac(self):
args = {
'options': {'packetsize': 60},
}
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
- p.server = mock_ssh.SSH.from_node()
+ p.server = self.mock_ssh.SSH.from_node()
- mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
+ self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1")
- def test_pktgen_dpdk_successful_no_sla(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_successful_no_sla(self):
args = {
'options': {'packetsize': 60},
@@ -116,7 +127,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
- mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
p.run(result)
# with python 3 we get float, might be due python division changes
@@ -125,7 +136,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
delta = result['avg_latency'] - 132
self.assertLessEqual(delta, 1)
- def test_pktgen_dpdk_successful_sla(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_successful_sla(self):
args = {
'options': {'packetsize': 60},
@@ -136,13 +147,13 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
- mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
p.run(result)
self.assertEqual(result, {"avg_latency": 100})
- def test_pktgen_dpdk_unsuccessful_sla(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_unsuccessful_sla(self):
args = {
'options': {'packetsize': 60},
@@ -152,14 +163,14 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
- p.server = mock_ssh.SSH.from_node()
- p.client = mock_ssh.SSH.from_node()
+ p.server = self.mock_ssh.SSH.from_node()
+ p.client = self.mock_ssh.SSH.from_node()
sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
- mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
self.assertRaises(AssertionError, p.run, result)
- def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh, mock_time):
+ def test_pktgen_dpdk_unsuccessful_script_error(self):
args = {
'options': {'packetsize': 60},
@@ -169,7 +180,7 @@ class PktgenDPDKLatencyTestCase(unittest.TestCase):
p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
- mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
+ self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, p.run, result)
diff --git a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
index d34097008..c2e35af75 100644
--- a/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
+++ b/tests/unit/benchmark/scenarios/networking/test_pktgen_dpdk_throughput.py
@@ -20,7 +20,6 @@ from yardstick.benchmark.scenarios.networking import pktgen_dpdk_throughput
@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh')
-@mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time')
class PktgenDPDKTestCase(unittest.TestCase):
def setUp(self):
@@ -37,7 +36,16 @@ class PktgenDPDKTestCase(unittest.TestCase):
}
}
- def test_pktgen_dpdk_throughput_successful_setup(self, mock__time, mock_ssh):
+ self._mock_time = mock.patch(
+ 'yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time')
+ self.mock_time = self._mock_time.start()
+
+ self.addCleanup(self._cleanup)
+
+ def _cleanup(self):
+ self._mock_time.stop()
+
+ def test_pktgen_dpdk_throughput_successful_setup(self, mock_ssh):
args = {
'options': {'packetsize': 60},
}
@@ -47,9 +55,9 @@ class PktgenDPDKTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, '', '')
self.assertIsNotNone(p.server)
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
- def test_pktgen_dpdk_throughput_successful_no_sla(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh):
args = {
'options': {'packetsize': 60, 'number_of_ports': 10},
}
@@ -75,7 +83,7 @@ class PktgenDPDKTestCase(unittest.TestCase):
expected_result["packetsize"] = 60
self.assertEqual(result, expected_result)
- def test_pktgen_dpdk_throughput_successful_sla(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_successful_sla(self, mock_ssh):
args = {
'options': {'packetsize': 60, 'number_of_ports': 10},
'sla': {'max_ppm': 10000}
@@ -101,7 +109,7 @@ class PktgenDPDKTestCase(unittest.TestCase):
expected_result["packetsize"] = 60
self.assertEqual(result, expected_result)
- def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock_ssh):
args = {
'options': {'packetsize': 60, 'number_of_ports': 10},
'sla': {'max_ppm': 1000}
@@ -122,7 +130,8 @@ class PktgenDPDKTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (0, sample_output, '')
self.assertRaises(AssertionError, p.run, result)
- def test_pktgen_dpdk_throughput_unsuccessful_script_error(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_unsuccessful_script_error(
+ self, mock_ssh):
args = {
'options': {'packetsize': 60, 'number_of_ports': 10},
'sla': {'max_ppm': 1000}
@@ -137,7 +146,7 @@ class PktgenDPDKTestCase(unittest.TestCase):
mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
self.assertRaises(RuntimeError, p.run, result)
- def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh):
args = {
'options': {'packetsize': 60},
}
@@ -151,7 +160,7 @@ class PktgenDPDKTestCase(unittest.TestCase):
mock_ssh.SSH().execute.assert_called_with(
"ip a | grep eth1 2>/dev/null")
- def test_pktgen_dpdk_throughput_dpdk_setup(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh):
args = {
'options': {'packetsize': 60},
}
@@ -163,9 +172,9 @@ class PktgenDPDKTestCase(unittest.TestCase):
p.dpdk_setup()
- self.assertEqual(p.dpdk_setup_done, True)
+ self.assertTrue(p.dpdk_setup_done)
- def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock__time, mock_ssh):
+ def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock_ssh):
args = {
'options': {'packetsize': 60},
}
@@ -180,8 +189,10 @@ 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/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/tests/unit/benchmark/scenarios/networking/test_vsperf.py
index cbbfc2b34..be8ac55d0 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vsperf.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vsperf.py
@@ -66,7 +66,7 @@ class VsperfTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
def test_vsperf_teardown(self, mock_ssh, mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
@@ -77,10 +77,10 @@ class VsperfTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
p.teardown()
- self.assertEqual(p.setup_done, False)
+ self.assertFalse(p.setup_done)
def test_vsperf_run_ok(self, mock_ssh, mock_subprocess):
p = vsperf.Vsperf(self.args, self.ctx)
diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
index 5759f0a90..fbe3ed804 100644
--- a/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
+++ b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py
@@ -27,7 +27,6 @@ from yardstick.benchmark.scenarios.networking import vsperf_dpdk
@mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.subprocess')
-@mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.ssh')
class VsperfDPDKTestCase(unittest.TestCase):
def setUp(self):
@@ -63,7 +62,16 @@ class VsperfDPDKTestCase(unittest.TestCase):
}
}
- def test_vsperf_dpdk_setup(self, mock_ssh, mock_subprocess):
+ self._mock_ssh = mock.patch(
+ 'yardstick.benchmark.scenarios.networking.vsperf_dpdk.ssh')
+ self.mock_ssh = self._mock_ssh.start()
+
+ self.addCleanup(self._cleanup)
+
+ def _cleanup(self):
+ self._mock_ssh.stop()
+
+ def test_vsperf_dpdk_setup(self, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
@@ -71,9 +79,9 @@ class VsperfDPDKTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
- def test_vsperf_dpdk_teardown(self, mock_ssh, mock_subprocess):
+ def test_vsperf_dpdk_teardown(self, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
@@ -81,12 +89,12 @@ class VsperfDPDKTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
p.teardown()
- self.assertEqual(p.setup_done, False)
+ self.assertFalse(p.setup_done)
- def test_vsperf_dpdk_is_dpdk_setup_no(self, mock_ssh, mock_subprocess):
+ def test_vsperf_dpdk_is_dpdk_setup_no(self, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
@@ -94,15 +102,15 @@ class VsperfDPDKTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
# is_dpdk_setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '')
result = p._is_dpdk_setup()
- self.assertEqual(result, False)
+ self.assertFalse(result)
- def test_vsperf_dpdk_is_dpdk_setup_yes(self, mock_ssh, mock_subprocess):
+ def test_vsperf_dpdk_is_dpdk_setup_yes(self, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
@@ -110,16 +118,16 @@ class VsperfDPDKTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
# is_dpdk_setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
result = p._is_dpdk_setup()
- self.assertEqual(result, True)
+ self.assertTrue(result)
- @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
- def test_vsperf_dpdk_dpdk_setup_first(self, mock_time, mock_ssh, mock_subprocess):
+ @mock.patch('time.sleep')
+ def test_vsperf_dpdk_dpdk_setup_first(self, _, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
@@ -127,61 +135,61 @@ class VsperfDPDKTestCase(unittest.TestCase):
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
# is_dpdk_setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '')
p.dpdk_setup()
- self.assertEqual(p._is_dpdk_setup(), False)
- self.assertEqual(p.dpdk_setup_done, True)
+ self.assertFalse(p._is_dpdk_setup())
+ self.assertTrue(p.dpdk_setup_done)
- @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
- def test_vsperf_dpdk_dpdk_setup_next(self, mock_time, mock_ssh, mock_subprocess):
+ @mock.patch('time.sleep')
+ def test_vsperf_dpdk_dpdk_setup_next(self, _, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
p.dpdk_setup()
- self.assertEqual(p._is_dpdk_setup(), True)
- self.assertEqual(p.dpdk_setup_done, True)
+ self.assertTrue(p._is_dpdk_setup())
+ self.assertTrue(p.dpdk_setup_done)
- @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
- def test_vsperf_dpdk_dpdk_setup_fail(self, mock_time, mock_ssh, mock_subprocess):
+ @mock.patch('time.sleep')
+ def test_vsperf_dpdk_dpdk_setup_fail(self, _, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
- self.assertEqual(p.setup_done, True)
+ self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ self.assertTrue(p.setup_done)
self.assertRaises(RuntimeError, p.dpdk_setup)
- @mock.patch('yardstick.benchmark.scenarios.networking.vsperf_dpdk.time')
- def test_vsperf_dpdk_run_ok(self, mock_time, mock_ssh, mock_subprocess):
+ @mock.patch('time.sleep')
+ def test_vsperf_dpdk_run_ok(self, _, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
# run() specific mocks
mock_subprocess.call().execute.return_value = None
- mock_ssh.SSH.from_node().execute.return_value = (
+ self.mock_ssh.SSH.from_node().execute.return_value = (
0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
result = {}
@@ -189,42 +197,41 @@ class VsperfDPDKTestCase(unittest.TestCase):
self.assertEqual(result['throughput_rx_fps'], '14797660.000')
- def test_vsperf_dpdk_run_falied_vsperf_execution(self, mock_ssh,
- mock_subprocess):
+ def test_vsperf_dpdk_run_falied_vsperf_execution(self, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
# run() specific mocks
mock_subprocess.call().execute.return_value = None
mock_subprocess.call().execute.return_value = None
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
result = {}
self.assertRaises(RuntimeError, p.run, result)
- def test_vsperf_dpdk_run_falied_csv_report(self, mock_ssh, mock_subprocess):
+ def test_vsperf_dpdk_run_falied_csv_report(self, mock_subprocess):
p = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
# setup() specific mocks
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
mock_subprocess.call().execute.return_value = None
p.setup()
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
# run() specific mocks
mock_subprocess.call().execute.return_value = None
mock_subprocess.call().execute.return_value = None
- mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
- mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+ self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
result = {}
self.assertRaises(RuntimeError, p.run, result)
diff --git a/tests/unit/benchmark/scenarios/parser/test_parser.py b/tests/unit/benchmark/scenarios/parser/test_parser.py
index 59b98a092..ee2bbc07d 100644
--- a/tests/unit/benchmark/scenarios/parser/test_parser.py
+++ b/tests/unit/benchmark/scenarios/parser/test_parser.py
@@ -9,50 +9,67 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.parser.Parser
-
-from __future__ import absolute_import
+import subprocess
import unittest
-
import mock
+
from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.parser import parser
-@mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess')
class ParserTestCase(unittest.TestCase):
def setUp(self):
- pass
-
- def test_parser_successful_setup(self, mock_subprocess):
-
- p = parser.Parser({}, {})
- mock_subprocess.call().return_value = 0
- p.setup()
- self.assertEqual(p.setup_done, True)
-
- def test_parser_successful(self, mock_subprocess):
args = {
'options': {'yangfile': '/root/yardstick/samples/yang.yaml',
'toscafile': '/root/yardstick/samples/tosca.yaml'},
}
- p = parser.Parser(args, {})
+ self.scenario = parser.Parser(scenario_cfg=args, context_cfg={})
+
+ self._mock_popen = mock.patch.object(subprocess, 'Popen')
+ self.mock_popen = self._mock_popen.start()
+ self._mock_call = mock.patch.object(subprocess, 'call')
+ self.mock_call = self._mock_call.start()
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_popen.stop()
+ self._mock_call.stop()
+
+ def test_setup_successful(self):
+
+ self.mock_call.return_value = 0
+ self.scenario.setup()
+ self.assertTrue(self.scenario.setup_done)
+
+ def test_run_successful(self):
+
result = {}
- mock_subprocess.call().return_value = 0
- sample_output = '{"yangtotosca": "success"}'
- p.run(result)
- expected_result = jsonutils.loads(sample_output)
+ self.mock_popen().returncode = 0
+
+ expected_result = jsonutils.loads('{"yangtotosca": "success"}')
+
+ self.scenario.run(result)
+ self.assertEqual(result, expected_result)
+
+ def test_run_fail(self):
+ result = {}
+
+ self.mock_popen().returncode = 1
+ expected_result = jsonutils.loads('{"yangtotosca": "fail"}')
+
+ self.scenario.run(result)
+ self.assertEqual(result, expected_result)
- def test_parser_teardown_successful(self, mock_subprocess):
+ def test_teardown_successful(self):
- p = parser.Parser({}, {})
- mock_subprocess.call().return_value = 0
- p.teardown()
- self.assertEqual(p.teardown_done, True)
+ self.mock_call.return_value = 0
+ self.scenario.teardown()
+ self.assertTrue(self.scenario.teardown_done)
def main():
diff --git a/tests/unit/benchmark/scenarios/storage/test_fio.py b/tests/unit/benchmark/scenarios/storage/test_fio.py
index 17594b9f4..0cffea224 100644
--- a/tests/unit/benchmark/scenarios/storage/test_fio.py
+++ b/tests/unit/benchmark/scenarios/storage/test_fio.py
@@ -53,7 +53,7 @@ class FioTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
def test_fio_job_file_successful_setup(self, mock_ssh):
@@ -67,7 +67,7 @@ class FioTestCase(unittest.TestCase):
mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
self.assertIsNotNone(p.client)
- self.assertEqual(p.setup_done, True)
+ self.assertTrue(p.setup_done)
def test_fio_successful_no_sla(self, mock_ssh):
diff --git a/tests/unit/dispatcher/__init__.py b/tests/unit/dispatcher/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/unit/dispatcher/__init__.py
+++ /dev/null
diff --git a/tests/unit/dispatcher/test_influxdb.py b/tests/unit/dispatcher/test_influxdb.py
deleted file mode 100644
index 7ebe8c90b..000000000
--- a/tests/unit/dispatcher/test_influxdb.py
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/usr/bin/env python
-
-##############################################################################
-# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-# Unittest for yardstick.dispatcher.influxdb
-
-from __future__ import absolute_import
-import unittest
-
-
-try:
- from unittest import mock
-except ImportError:
- import mock
-
-from yardstick import _init_logging
-_init_logging()
-
-from yardstick.dispatcher.influxdb import InfluxdbDispatcher
-
-
-class InfluxdbDispatcherTestCase(unittest.TestCase):
-
- def setUp(self):
- self.data1 = {
- "runner_id": 8921,
- "context_cfg": {
- "host": {
- "ip": "10.229.43.154",
- "key_filename":
- "/root/yardstick/yardstick/resources/files"
- "/yardstick_key",
- "name": "kvm.LF",
- "user": "root"
- },
- "target": {
- "ipaddr": "10.229.44.134"
- }
- },
- "scenario_cfg": {
- "runner": {
- "interval": 1,
- "object": "yardstick.benchmark.scenarios.networking.ping"
- ".Ping",
- "output_filename": "/tmp/yardstick.out",
- "runner_id": 8921,
- "duration": 10,
- "type": "Duration"
- },
- "host": "kvm.LF",
- "type": "Ping",
- "target": "10.229.44.134",
- "sla": {
- "action": "monitor",
- "max_rtt": 10
- },
- "tc": "ping",
- "task_id": "ea958583-c91e-461a-af14-2a7f9d7f79e7"
- }
- }
- self.data2 = {
- "benchmark": {
- "timestamp": "1451478117.883505",
- "errors": "",
- "data": {
- "rtt": 0.613
- },
- "sequence": 1
- },
- "runner_id": 8921
- }
-
- self.yardstick_conf = {'dispatcher_influxdb': {}}
-
- @mock.patch('yardstick.dispatcher.influxdb.requests')
- def test_record_result_data(self, mock_requests):
- type(mock_requests.post.return_value).status_code = 204
- influxdb = InfluxdbDispatcher(self.yardstick_conf)
- data = {
- 'status': 1,
- 'result': {
- 'criteria': 'PASS',
- 'info': {
- },
- 'task_id': 'b9e2bbc2-dfd8-410d-8c24-07771e9f7979',
- 'testcases': {
- }
- }
- }
- self.assertEqual(influxdb.flush_result_data(data), 0)
-
- def test__get_nano_timestamp(self):
- influxdb = InfluxdbDispatcher(self.yardstick_conf)
- results = {'timestamp': '1451461248.925574'}
- self.assertEqual(influxdb._get_nano_timestamp(results),
- '1451461248925574144')
-
- @mock.patch('yardstick.dispatcher.influxdb.time')
- def test__get_nano_timestamp_except(self, mock_time):
- results = {}
- influxdb = InfluxdbDispatcher(self.yardstick_conf)
- 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/tests/unit/dispatcher/test_influxdb_line_protocol.py b/tests/unit/dispatcher/test_influxdb_line_protocol.py
deleted file mode 100644
index 51dc39e3c..000000000
--- a/tests/unit/dispatcher/test_influxdb_line_protocol.py
+++ /dev/null
@@ -1,64 +0,0 @@
-##############################################################################
-# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-# Unittest for yardstick.dispatcher.influxdb_line_protocol
-
-# yardstick comment: this file is a modified copy of
-# influxdb-python/influxdb/tests/test_line_protocol.py
-
-from __future__ import absolute_import
-import unittest
-from third_party.influxdb.influxdb_line_protocol import make_lines
-
-
-class TestLineProtocol(unittest.TestCase):
-
- def test_make_lines(self):
- data = {
- "tags": {
- "empty_tag": "",
- "none_tag": None,
- "integer_tag": 2,
- "string_tag": "hello"
- },
- "points": [
- {
- "measurement": "test",
- "fields": {
- "string_val": "hello!",
- "int_val": 1,
- "float_val": 1.1,
- "none_field": None,
- "bool_val": True,
- }
- }
- ]
- }
-
- self.assertEqual(
- make_lines(data),
- 'test,integer_tag=2,string_tag=hello '
- 'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n'
- )
-
- def test_string_val_newline(self):
- data = {
- "points": [
- {
- "measurement": "m1",
- "fields": {
- "multi_line": "line1\nline1\nline3"
- }
- }
- ]
- }
-
- self.assertEqual(
- make_lines(data),
- 'm1 multi_line="line1\\nline1\\nline3"\n'
- )
diff --git a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py b/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py
index 0f1cf7d92..9bb5ed3a7 100644
--- a/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py
+++ b/tests/unit/network_services/helpers/test_dpdkbindnic_helper.py
@@ -25,8 +25,6 @@ from yardstick.network_services.helpers.dpdkbindnic_helper import CRYPTO_DPDK
from yardstick.network_services.helpers.dpdkbindnic_helper import NETWORK_OTHER
from yardstick.network_services.helpers.dpdkbindnic_helper import CRYPTO_OTHER
-pass
-
class TestDpdkBindHelper(unittest.TestCase):
EXAMPLE_OUTPUT = """
@@ -116,8 +114,8 @@ Other crypto devices
dpdk_bind_helper = DpdkBindHelper(conn)
- self.assertEquals(conn, dpdk_bind_helper.ssh_helper)
- self.assertEquals(self.CLEAN_STATUS, dpdk_bind_helper.dpdk_status)
+ self.assertEqual(conn, dpdk_bind_helper.ssh_helper)
+ self.assertEqual(self.CLEAN_STATUS, dpdk_bind_helper.dpdk_status)
self.assertIsNone(dpdk_bind_helper.status_nic_row_re)
self.assertIsNone(dpdk_bind_helper._dpdk_nic_bind_attr)
self.assertIsNone(dpdk_bind_helper._status_cmd_attr)
@@ -127,7 +125,8 @@ Other crypto devices
conn.execute = mock.Mock(return_value=(0, 'output', 'error'))
conn.provision_tool = mock.Mock(return_value='tool_path')
dpdk_bind_helper = DpdkBindHelper(conn)
- self.assertEquals((0, 'output', 'error'), dpdk_bind_helper._dpdk_execute('command'))
+ self.assertEqual((0, 'output', 'error'),
+ dpdk_bind_helper._dpdk_execute('command'))
def test__dpdk_execute_failure(self):
conn = mock.Mock()
@@ -145,7 +144,7 @@ Other crypto devices
dpdk_bind_helper._addline(NETWORK_KERNEL, self.ONE_INPUT_LINE)
self.assertIsNotNone(dpdk_bind_helper.dpdk_status)
- self.assertEquals(self.ONE_INPUT_LINE_PARSED, dpdk_bind_helper.dpdk_status[NETWORK_KERNEL])
+ self.assertEqual(self.ONE_INPUT_LINE_PARSED, dpdk_bind_helper.dpdk_status[NETWORK_KERNEL])
def test__switch_active_dict_by_header(self):
line = "Crypto devices using DPDK-compatible driver"
@@ -165,7 +164,7 @@ Other crypto devices
dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
self.maxDiff = None
- self.assertEquals(self.PARSED_EXAMPLE, dpdk_bind_helper.dpdk_status)
+ self.assertEqual(self.PARSED_EXAMPLE, dpdk_bind_helper.dpdk_status)
def test_read_status(self):
conn = mock.Mock()
@@ -174,7 +173,7 @@ Other crypto devices
dpdk_bind_helper = DpdkBindHelper(conn)
- self.assertEquals(self.PARSED_EXAMPLE, dpdk_bind_helper.read_status())
+ self.assertEqual(self.PARSED_EXAMPLE, dpdk_bind_helper.read_status())
def test__get_bound_pci_addresses(self):
conn = mock.Mock()
@@ -183,9 +182,9 @@ Other crypto devices
dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
- self.assertEquals(['0000:00:04.0', '0000:00:05.0'],
+ self.assertEqual(['0000:00:04.0', '0000:00:05.0'],
dpdk_bind_helper._get_bound_pci_addresses(NETWORK_DPDK))
- self.assertEquals(['0000:00:03.0'],
+ self.assertEqual(['0000:00:03.0'],
dpdk_bind_helper._get_bound_pci_addresses(NETWORK_KERNEL))
def test_interface_driver_map(self):
@@ -195,7 +194,7 @@ Other crypto devices
dpdk_bind_helper.parse_dpdk_status_output(self.EXAMPLE_OUTPUT)
- self.assertEquals({'0000:00:04.0': 'igb_uio',
+ self.assertEqual({'0000:00:04.0': 'igb_uio',
'0000:00:03.0': 'virtio-pci',
'0000:00:05.0': 'igb_uio',
},
diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py
index 5c2f890e8..7ad166249 100644
--- a/tests/unit/network_services/nfvi/test_resource.py
+++ b/tests/unit/network_services/nfvi/test_resource.py
@@ -12,11 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import absolute_import
-import unittest
-
import errno
+
import mock
+import unittest
from yardstick.network_services.nfvi.resource import ResourceProfile
from yardstick.network_services.nfvi import resource, collectd
@@ -103,16 +102,18 @@ class TestResourceProfile(unittest.TestCase):
self.resource_profile.connection = self.ssh_mock
def test___init__(self):
- self.assertEqual(True, self.resource_profile.enable)
+ self.assertTrue(self.resource_profile.enable)
- def test_check_if_sa_running(self):
- self.assertEqual(self.resource_profile.check_if_sa_running("collectd"),
+ def test_check_if_system_agent_running(self):
+ self.assertEqual(self.resource_profile.check_if_system_agent_running("collectd"),
(0, ""))
- def test_check_if_sa_running_excetion(self):
+ def test_check_if_system_agent_running_excetion(self):
with mock.patch.object(self.resource_profile.connection, "execute") as mock_execute:
mock_execute.side_effect = OSError(errno.ECONNRESET, "error")
- self.assertEqual(self.resource_profile.check_if_sa_running("collectd"), (1, None))
+ self.assertEqual(
+ self.resource_profile.check_if_system_agent_running("collectd"),
+ (1, None))
def test_get_cpu_data(self):
reskey = ["", "cpufreq", "cpufreq-0"]
@@ -135,12 +136,12 @@ class TestResourceProfile(unittest.TestCase):
self.resource_profile._prepare_collectd_conf("/opt/nsb_bin"))
def test__setup_ovs_stats(self):
+ # TODO(elfoley): This method doesn't actually return anything, the side
+ # effects should be checked
self.assertIsNone(
self.resource_profile._setup_ovs_stats(self.ssh_mock))
- @mock.patch("yardstick.network_services.nfvi.resource.open")
- @mock.patch("yardstick.network_services.nfvi.resource.os")
- def test__provide_config_file(self, mock_open, mock_os):
+ def test__provide_config_file(self,):
loadplugin = range(5)
port_names = range(5)
kwargs = {
@@ -151,14 +152,12 @@ class TestResourceProfile(unittest.TestCase):
self.resource_profile._provide_config_file("/opt/nsb_bin", "collectd.conf", kwargs)
self.ssh_mock.execute.assert_called_once()
- @mock.patch("yardstick.network_services.nfvi.resource.open")
- def test_initiate_systemagent(self, mock_open):
+ def test_initiate_systemagent(self):
self.resource_profile._start_collectd = mock.Mock()
self.assertIsNone(
self.resource_profile.initiate_systemagent("/opt/nsb_bin"))
- @mock.patch("yardstick.network_services.nfvi.resource.open")
- def test_initiate_systemagent_raise(self, mock_open):
+ def test_initiate_systemagent_raise(self):
self.resource_profile._start_collectd = mock.Mock(side_effect=RuntimeError)
with self.assertRaises(RuntimeError):
self.resource_profile.initiate_systemagent("/opt/nsb_bin")
@@ -267,8 +266,10 @@ class TestResourceProfile(unittest.TestCase):
def test_stop(self):
self.assertIsNone(self.resource_profile.stop())
- def test_stop(self):
+ def test_stop_amqp_not_running(self):
self.resource_profile.amqp_client = mock.MagicMock()
+ # TODO(efoley): Fix this incorrect test.
+ # Should check that we don't try to stop amqp when it's not running
self.assertIsNone(self.resource_profile.stop())
if __name__ == '__main__':
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
index ed49c7000..0ac46c632 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_prox_helpers.py
@@ -16,15 +16,17 @@
#
from itertools import repeat, chain
-import mock
import os
import socket
import time
+
+import mock
import unittest
from tests.unit import STL_MOCKS
from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
+
STLClient = mock.MagicMock()
stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
stl_patch.start()
@@ -1433,9 +1435,9 @@ class TestProxResourceHelper(unittest.TestCase):
helper = ProxResourceHelper(mock.MagicMock())
helper.resource = resource = mock.MagicMock()
- resource.check_if_sa_running.return_value = 0, '1234'
+ resource.check_if_system_agent_running.return_value = 0, '1234'
resource.amqp_collect_nfvi_kpi.return_value = 543
- resource.check_if_sa_running.return_value = (0, None)
+ resource.check_if_system_agent_running.return_value = (0, None)
expected = {'core': 543}
result = helper.collect_collectd_kpi()
@@ -1447,9 +1449,9 @@ class TestProxResourceHelper(unittest.TestCase):
helper._result = {'z': 123}
helper.resource = resource = mock.MagicMock()
- resource.check_if_sa_running.return_value = 0, '1234'
+ resource.check_if_system_agent_running.return_value = 0, '1234'
resource.amqp_collect_nfvi_kpi.return_value = 543
- resource.check_if_sa_running.return_value = (0, None)
+ resource.check_if_system_agent_running.return_value = (0, None)
queue.empty.return_value = False
queue.get.return_value = {'a': 789}
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
index beb4f8f9f..af941c04f 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_sample_vnf.py
@@ -704,8 +704,8 @@ class TestDpdkVnfSetupEnvHelper(unittest.TestCase):
intf_0 = vnfd_helper.vdu[0]['external-interface'][0]['virtual-interface']
intf_1 = vnfd_helper.vdu[0]['external-interface'][1]['virtual-interface']
- self.assertEquals(0, intf_0['dpdk_port_num'])
- self.assertEquals(1, intf_1['dpdk_port_num'])
+ self.assertEqual(0, intf_0['dpdk_port_num'])
+ self.assertEqual(1, intf_1['dpdk_port_num'])
def test_tear_down(self):
vnfd_helper = VnfdHelper(self.VNFD_0)
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
index 63b2ac4ab..fb26f20b5 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_ping.py
@@ -80,7 +80,7 @@ class TestPingParser(unittest.TestCase):
ping_parser = PingParser(q_out)
ping_parser.write(sample_out)
ping_parser.clear()
- self.assertEqual(True, q_out.empty())
+ self.assertTrue(q_out.empty())
def test_close(self):
q_out = Queue()
@@ -238,7 +238,7 @@ class TestPingTrafficGen(unittest.TestCase):
self.assertIsInstance(ping_traffic_gen.setup_helper, PingSetupEnvHelper)
self.assertIsInstance(ping_traffic_gen.resource_helper, PingResourceHelper)
- self.assertEquals(ping_traffic_gen._result, {})
+ self.assertEqual(ping_traffic_gen._result, {})
@mock.patch("yardstick.ssh.SSH")
def test__bind_device_kernel_with_failure(self, ssh):
@@ -282,8 +282,7 @@ class TestPingTrafficGen(unittest.TestCase):
self.assertEqual(self.CMD_KWARGS, ping_traffic_gen.resource_helper.cmd_kwargs)
self.assertIsNotNone(ping_traffic_gen._result)
- @mock.patch("yardstick.ssh.SSH")
- def test_listen_traffic(self, *args):
+ def test_listen_traffic(self):
ping_traffic_gen = PingTrafficGen('vnf1', self.VNFD_0)
self.assertIsNone(ping_traffic_gen.listen_traffic({}))
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
index 7b4d79e02..0104e7f63 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_tg_prox.py
@@ -330,7 +330,7 @@ class TestProxTrafficGen(unittest.TestCase):
prox_traffic_gen = ProxTrafficGen(NAME, self.VNFD0)
prox_traffic_gen._vnf_wrapper.resource_helper.resource = mock.MagicMock(
- **{"check_if_sa_running.return_value": [False]})
+ **{"self.check_if_system_agent_running.return_value": [False]})
prox_traffic_gen._vnf_wrapper.vnf_execute = mock.Mock(return_value="")
self.assertEqual({}, prox_traffic_gen.collect_kpi())
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py b/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
index 635ce2735..cda3852fe 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_udp_replay.py
@@ -447,7 +447,7 @@ class TestUdpReplayApproxVnf(unittest.TestCase):
udp_replay_approx_vnf._vnf_process.is_alive = mock.Mock(return_value=1)
udp_replay_approx_vnf._vnf_process.exitcode = 0
- self.assertEquals(udp_replay_approx_vnf.wait_for_instantiate(), 0)
+ self.assertEqual(udp_replay_approx_vnf.wait_for_instantiate(), 0)
@mock.patch("yardstick.network_services.vnf_generic.vnf.sample_vnf.Context")
@mock.patch('yardstick.ssh.SSH')
diff --git a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
index 55cd4d2e8..1abc53688 100644
--- a/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
+++ b/tests/unit/network_services/vnf_generic/vnf/test_vpe_vnf.py
@@ -15,11 +15,12 @@
# limitations under the License.
#
-import mock
from multiprocessing import Process, Queue
import os
-import six.moves.configparser as configparser
import time
+
+import mock
+import six.moves.configparser as configparser
import unittest
from tests.unit import STL_MOCKS
@@ -543,9 +544,9 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
- resource.check_if_sa_running.return_value = 1, ''
+ resource.check_if_system_agent_running.return_value = 1, ''
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
- resource.check_if_sa_running.return_value = (1, None)
+ resource.check_if_system_agent_running.return_value = (1, None)
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
vpe_approx_vnf.q_in = mock.MagicMock()
@@ -567,7 +568,7 @@ class TestVpeApproxVnf(unittest.TestCase):
mock_ssh(ssh)
resource = mock.Mock(autospec=ResourceProfile)
- resource.check_if_sa_running.return_value = 0, '1234'
+ resource.check_if_system_agent_running.return_value = 0, '1234'
resource.amqp_collect_nfvi_kpi.return_value = {'foo': 234}
vpe_approx_vnf = VpeApproxVnf(NAME, self.VNFD_0)
diff --git a/tests/unit/orchestrator/__init__.py b/tests/unit/orchestrator/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/unit/orchestrator/__init__.py
+++ /dev/null
diff --git a/tests/unit/orchestrator/test_heat.py b/tests/unit/orchestrator/test_heat.py
deleted file mode 100644
index c34ea53fc..000000000
--- a/tests/unit/orchestrator/test_heat.py
+++ /dev/null
@@ -1,339 +0,0 @@
-#!/usr/bin/env python
-
-##############################################################################
-# Copyright (c) 2017 Intel Corporation
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-# Unittest for yardstick.benchmark.orchestrator.heat
-from contextlib import contextmanager
-from itertools import count
-from tempfile import NamedTemporaryFile
-import unittest
-import uuid
-import time
-import mock
-
-from yardstick.benchmark.contexts import node
-from yardstick.orchestrator import heat
-
-
-TARGET_MODULE = 'yardstick.orchestrator.heat'
-
-
-def mock_patch_target_module(inner_import):
- return mock.patch('.'.join([TARGET_MODULE, inner_import]))
-
-
-@contextmanager
-def timer():
- start = time.time()
- data = {'start': start}
- try:
- yield data
- finally:
- data['end'] = end = time.time()
- data['delta'] = end - start
-
-
-def index_value_iter(index, index_value, base_value=None):
- for current_index in count():
- if current_index == index:
- yield index_value
- else:
- yield base_value
-
-
-def get_error_message(error):
- try:
- # py2
- return error.message
- except AttributeError:
- # py3
- return next((arg for arg in error.args if isinstance(arg, str)), None)
-
-
-class HeatContextTestCase(unittest.TestCase):
-
- def test_get_short_key_uuid(self):
- u = uuid.uuid4()
- k = heat.get_short_key_uuid(u)
- self.assertEqual(heat.HEAT_KEY_UUID_LENGTH, len(k))
- self.assertIn(k, str(u))
-
-class HeatTemplateTestCase(unittest.TestCase):
-
- def setUp(self):
- self.template = heat.HeatTemplate('test')
-
- def test_add_tenant_network(self):
- self.template.add_network('some-network')
-
- self.assertEqual(self.template.resources['some-network']['type'], 'OS::Neutron::Net')
-
- def test_add_provider_network(self):
- self.template.add_network('some-network', 'physnet2', 'sriov')
-
- self.assertEqual(self.template.resources['some-network']['type'], 'OS::Neutron::ProviderNet')
- self.assertEqual(self.template.resources['some-network']['properties']['physical_network'], 'physnet2')
-
- def test_add_subnet(self):
- netattrs = {'cidr': '10.0.0.0/24', 'provider': None, 'external_network': 'ext_net'}
- self.template.add_subnet('some-subnet', "some-network", netattrs['cidr'])
-
- self.assertEqual(self.template.resources['some-subnet']['type'], 'OS::Neutron::Subnet')
- self.assertEqual(self.template.resources['some-subnet']['properties']['cidr'], '10.0.0.0/24')
-
- def test_add_router(self):
- self.template.add_router('some-router', 'ext-net', 'some-subnet')
-
- self.assertEqual(self.template.resources['some-router']['type'], 'OS::Neutron::Router')
- self.assertIn('some-subnet', self.template.resources['some-router']['depends_on'])
-
- def test_add_router_interface(self):
- self.template.add_router_interface('some-router-if', 'some-router', 'some-subnet')
-
- self.assertEqual(self.template.resources['some-router-if']['type'], 'OS::Neutron::RouterInterface')
- self.assertIn('some-subnet', self.template.resources['some-router-if']['depends_on'])
-
- def test_add_servergroup(self):
- self.template.add_servergroup('some-server-group', 'anti-affinity')
-
- self.assertEqual(self.template.resources['some-server-group']['type'], 'OS::Nova::ServerGroup')
- self.assertEqual(self.template.resources['some-server-group']['properties']['policies'], ['anti-affinity'])
-
- def test__add_resources_to_template_raw(self):
- test_context = node.NodeContext()
- test_context.name = 'foo'
- test_context.template_file = '/tmp/some-heat-file'
- test_context.heat_parameters = {'image': 'cirros'}
- test_context.key_filename = "/tmp/1234"
- test_context.keypair_name = "foo-key"
- test_context.secgroup_name = "foo-secgroup"
- test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b"
- heat_object = heat.HeatObject()
-
- heat_stack = heat.HeatStack("tmpStack")
- self.assertTrue(heat_stack.stacks_exist())
-
- test_context.tmpfile = NamedTemporaryFile(delete=True, mode='w+t')
- test_context.tmpfile.write("heat_template_version: 2015-04-30")
- test_context.tmpfile.flush()
- test_context.tmpfile.seek(0)
- heat_template = heat.HeatTemplate(heat_object)
- heat_template.resources = {}
-
- heat_template.add_network("network1")
- heat_template.add_network("network2")
- heat_template.add_security_group("sec_group1")
- heat_template.add_security_group("sec_group2")
- heat_template.add_subnet("subnet1", "network1", "cidr1")
- heat_template.add_subnet("subnet2", "network2", "cidr2")
- heat_template.add_router("router1", "gw1", "subnet1")
- heat_template.add_router_interface("router_if1", "router1", "subnet1")
- heat_template.add_port("port1", "network1", "subnet1", "normal")
- heat_template.add_port("port2", "network2", "subnet2", "normal", sec_group_id="sec_group1",provider="not-sriov")
- heat_template.add_port("port3", "network2", "subnet2", "normal", sec_group_id="sec_group1",provider="sriov")
- heat_template.add_floating_ip("floating_ip1", "network1", "port1", "router_if1")
- heat_template.add_floating_ip("floating_ip2", "network2", "port2", "router_if2", "foo-secgroup")
- heat_template.add_floating_ip_association("floating_ip1_association", "floating_ip1", "port1")
- heat_template.add_servergroup("server_grp2", "affinity")
- heat_template.add_servergroup("server_grp3", "anti-affinity")
- heat_template.add_security_group("security_group")
- heat_template.add_server(name="server1", image="image1", flavor="flavor1", flavors=[])
- heat_template.add_server_group(name="servergroup", policies=["policy1","policy2"])
- heat_template.add_server_group(name="servergroup", policies="policy1")
- heat_template.add_server(name="server2", image="image1", flavor="flavor1", flavors=[], ports=["port1", "port2"],
- networks=["network1", "network2"], scheduler_hints="hints1", user="user1",
- key_name="foo-key", user_data="user", metadata={"cat": 1, "doc": 2},
- additional_properties={"prop1": 1, "prop2": 2})
- heat_template.add_server(name="server2", image="image1", flavor="flavor1", flavors=["flavor1", "flavor2"],
- ports=["port1", "port2"],
- networks=["network1", "network2"], scheduler_hints="hints1", user="user1",
- key_name="foo-key", user_data="user", metadata={"cat": 1, "doc": 2},
- additional_properties={"prop1": 1, "prop2": 2} )
- heat_template.add_server(name="server2", image="image1", flavor="flavor1", flavors=["flavor3", "flavor4"],
- ports=["port1", "port2"],
- networks=["network1", "network2"], scheduler_hints="hints1", user="user1",
- key_name="foo-key", user_data="user", metadata={"cat": 1, "doc": 2},
- additional_properties={"prop1": 1, "prop2": 2})
- heat_template.add_flavor(name="flavor1", vcpus=1, ram=2048, disk=1,extra_specs={"cat": 1, "dog": 2})
- heat_template.add_flavor(name=None, vcpus=1, ram=2048)
- heat_template.add_server(name="server1",
- image="image1",
- flavor="flavor1",
- flavors=[],
- ports=["port1", "port2"],
- networks=["network1", "network2"],
- scheduler_hints="hints1",
- user="user1",
- key_name="foo-key",
- user_data="user",
- metadata={"cat": 1, "doc": 2},
- additional_properties= {"prop1": 1, "prop2": 2} )
- heat_template.add_network("network1")
-
- heat_template.add_flavor("test")
- self.assertEqual(heat_template.resources['test']['type'], 'OS::Nova::Flavor')
-
- @mock_patch_target_module('op_utils')
- @mock_patch_target_module('heatclient')
- def test_create_negative(self, mock_heat_client_class, mock_op_utils):
- self.template.HEAT_WAIT_LOOP_INTERVAL = 0
- mock_heat_client = mock_heat_client_class() # get the constructed mock
-
- # populate attributes of the constructed mock
- mock_heat_client.stacks.get().stack_status_reason = 'the reason'
-
- expected_status_calls = 0
- expected_constructor_calls = 1 # above, to get the instance
- expected_create_calls = 0
- expected_op_utils_usage = 0
-
- with mock.patch.object(self.template, 'status', return_value=None) as mock_status:
- # block with timeout hit
- timeout = 0
- with self.assertRaises(RuntimeError) as raised, timer() as time_data:
- self.template.create(block=True, timeout=timeout)
-
- # ensure op_utils was used
- expected_op_utils_usage += 1
- self.assertEqual(mock_op_utils.get_session.call_count, expected_op_utils_usage)
- self.assertEqual(mock_op_utils.get_endpoint.call_count, expected_op_utils_usage)
- self.assertEqual(mock_op_utils.get_heat_api_version.call_count, expected_op_utils_usage)
-
- # ensure the constructor and instance were used
- self.assertEqual(mock_heat_client_class.call_count, expected_constructor_calls)
- self.assertEqual(mock_heat_client.stacks.create.call_count, expected_create_calls)
-
- # ensure that the status was used
- self.assertGreater(mock_status.call_count, expected_status_calls)
- expected_status_calls = mock_status.call_count # synchronize the value
-
- # ensure the expected exception was raised
- error_message = get_error_message(raised.exception)
- self.assertIn('timeout', error_message)
- self.assertNotIn('the reason', error_message)
-
- # block with create failed
- timeout = 10
- mock_status.side_effect = iter([None, None, u'CREATE_FAILED'])
- with self.assertRaises(RuntimeError) as raised, timer() as time_data:
- self.template.create(block=True, timeout=timeout)
-
- # ensure the existing heat_client was used and op_utils was used again
- self.assertEqual(mock_op_utils.get_session.call_count, expected_op_utils_usage)
- self.assertEqual(mock_op_utils.get_endpoint.call_count, expected_op_utils_usage)
- self.assertEqual(mock_op_utils.get_heat_api_version.call_count, expected_op_utils_usage)
-
- # ensure the constructor was not used but the instance was used
- self.assertEqual(mock_heat_client_class.call_count, expected_constructor_calls)
- self.assertEqual(mock_heat_client.stacks.create.call_count, expected_create_calls)
-
- # ensure that the status was used three times
- expected_status_calls += 3
- self.assertEqual(mock_status.call_count, expected_status_calls)
-
- @mock_patch_target_module('op_utils')
- @mock_patch_target_module('heatclient')
- def test_create(self, mock_heat_client_class, mock_op_utils):
- self.template.HEAT_WAIT_LOOP_INTERVAL = 0.2
- mock_heat_client = mock_heat_client_class()
-
- # populate attributes of the constructed mock
- mock_heat_client.stacks.get().outputs = [
- {'output_key': 'key1', 'output_value': 'value1'},
- {'output_key': 'key2', 'output_value': 'value2'},
- {'output_key': 'key3', 'output_value': 'value3'},
- ]
- expected_outputs = {
- 'key1': 'value1',
- 'key2': 'value2',
- 'key3': 'value3',
- }
-
- expected_status_calls = 0
- expected_constructor_calls = 1 # above, to get the instance
- expected_create_calls = 0
- expected_op_utils_usage = 0
-
- with mock.patch.object(self.template, 'status') as mock_status:
- self.template.name = 'no block test'
- mock_status.return_value = None
-
- # no block
- self.assertIsInstance(self.template.create(block=False, timeout=2), heat.HeatStack)
-
- # ensure op_utils was used
- expected_op_utils_usage += 1
- self.assertEqual(mock_op_utils.get_session.call_count, expected_op_utils_usage)
- self.assertEqual(mock_op_utils.get_endpoint.call_count, expected_op_utils_usage)
- self.assertEqual(mock_op_utils.get_heat_api_version.call_count, expected_op_utils_usage)
-
- # ensure the constructor and instance were used
- self.assertEqual(mock_heat_client_class.call_count, expected_constructor_calls)
- self.assertEqual(mock_heat_client.stacks.create.call_count, expected_create_calls)
-
- # ensure that the status was not used
- self.assertEqual(mock_status.call_count, expected_status_calls)
-
- # ensure no outputs because this requires blocking
- self.assertEqual(self.template.outputs, {})
-
- # block with immediate complete
- self.template.name = 'block, immediate complete test'
-
- mock_status.return_value = self.template.HEAT_CREATE_COMPLETE_STATUS
- self.assertIsInstance(self.template.create(block=True, timeout=2), heat.HeatStack)
-
- # ensure existing instance was re-used and op_utils was not used
- self.assertEqual(mock_heat_client_class.call_count, expected_constructor_calls)
- self.assertEqual(mock_heat_client.stacks.create.call_count, expected_create_calls)
-
- # ensure status was checked once
- expected_status_calls += 1
- self.assertEqual(mock_status.call_count, expected_status_calls)
-
- # reset template outputs
- self.template.outputs = None
-
- # block with delayed complete
- self.template.name = 'block, delayed complete test'
-
- success_index = 2
- mock_status.side_effect = index_value_iter(success_index,
- self.template.HEAT_CREATE_COMPLETE_STATUS)
- self.assertIsInstance(self.template.create(block=True, timeout=2), heat.HeatStack)
-
- # ensure existing instance was re-used and op_utils was not used
- self.assertEqual(mock_heat_client_class.call_count, expected_constructor_calls)
- self.assertEqual(mock_heat_client.stacks.create.call_count, expected_create_calls)
-
- # ensure status was checked three more times
- expected_status_calls += 1 + success_index
- self.assertEqual(mock_status.call_count, expected_status_calls)
-
-
-class HeatStackTestCase(unittest.TestCase):
-
- def test_delete_calls__delete_multiple_times(self):
- stack = heat.HeatStack('test')
- stack.uuid = 1
- with mock.patch.object(stack, "_delete") as delete_mock:
- stack.delete()
- # call once and then call again if uuid is not none
- self.assertGreater(delete_mock.call_count, 1)
-
- @mock.patch('yardstick.orchestrator.heat.op_utils')
- def test_delete_all_calls_delete(self, mock_op):
- # we must patch the object before we create an instance
- # so we can override delete() in all the instances
- with mock.patch.object(heat.HeatStack, "delete") as delete_mock:
- stack = heat.HeatStack('test')
- stack.uuid = 1
- stack.delete_all()
- self.assertGreater(delete_mock.call_count, 0)
diff --git a/tests/unit/orchestrator/test_kubernetes.py b/tests/unit/orchestrator/test_kubernetes.py
deleted file mode 100644
index 1a3291c89..000000000
--- a/tests/unit/orchestrator/test_kubernetes.py
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/usr/bin/env python
-
-##############################################################################
-# Copyright (c) 2017 Intel Corporation
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-# Unittest for yardstick.benchmark.orchestrator.heat
-import unittest
-import mock
-
-from yardstick.orchestrator.kubernetes import KubernetesObject
-from yardstick.orchestrator.kubernetes import KubernetesTemplate
-
-
-class GetTemplateTestCase(unittest.TestCase):
-
- def test_get_template(self):
- output_t = {
- "apiVersion": "v1",
- "kind": "ReplicationController",
- "metadata": {
- "name": "host-k8s-86096c30"
- },
- "spec": {
- "replicas": 1,
- "template": {
- "metadata": {
- "labels": {
- "app": "host-k8s-86096c30"
- }
- },
- "spec": {
- "containers": [
- {
- "args": [
- "-c",
- "chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
-service ssh restart;while true ; do sleep 10000; done"
- ],
- "command": [
- "/bin/bash"
- ],
- "image": "openretriever/yardstick",
- "name": "host-k8s-86096c30-container",
- "volumeMounts": [
- {
- "mountPath": "/root/.ssh/",
- "name": "k8s-86096c30-key"
- }
- ]
- }
- ],
- "volumes": [
- {
- "configMap": {
- "name": "k8s-86096c30-key"
- },
- "name": "k8s-86096c30-key"
- }
- ],
- "nodeSelector": {
- "kubernetes.io/hostname": "node-01"
- }
- }
- }
- }
- }
- input_s = {
- 'command': '/bin/bash',
- 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
-service ssh restart;while true ; do sleep 10000; done'],
- 'ssh_key': 'k8s-86096c30-key',
- 'nodeSelector': { 'kubernetes.io/hostname': 'node-01'}
- }
- name = 'host-k8s-86096c30'
- output_r = KubernetesObject(name, **input_s).get_template()
- self.assertEqual(output_r, output_t)
-
-
-class GetRcPodsTestCase(unittest.TestCase):
-
- @mock.patch('yardstick.orchestrator.kubernetes.k8s_utils.get_pod_list')
- def test_get_rc_pods(self, mock_get_pod_list):
- servers = {
- 'host': {
- 'image': 'openretriever/yardstick',
- 'command': '/bin/bash',
- 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
-service ssh restart;while true ; do sleep 10000; done']
- },
- 'target': {
- 'image': 'openretriever/yardstick',
- 'command': '/bin/bash',
- 'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
-service ssh restart;while true ; do sleep 10000; done']
- }
- }
- k8s_template = KubernetesTemplate('k8s-86096c30', servers)
- 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/tests/unit/test_cmd/__init__.py b/tests/unit/test_cmd/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/unit/test_cmd/__init__.py
+++ /dev/null
diff --git a/tests/unit/test_cmd/commands/__init__.py b/tests/unit/test_cmd/commands/__init__.py
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/unit/test_cmd/commands/__init__.py
+++ /dev/null
diff --git a/tests/unit/test_cmd/commands/test_env.py b/tests/unit/test_cmd/commands/test_env.py
deleted file mode 100644
index 13c3ed44a..000000000
--- a/tests/unit/test_cmd/commands/test_env.py
+++ /dev/null
@@ -1,73 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-from __future__ import absolute_import
-import unittest
-import mock
-import uuid
-
-from yardstick.cmd.commands.env import EnvCommand
-
-
-class EnvCommandTestCase(unittest.TestCase):
-
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
- def test_do_influxdb(self, check_status_mock, start_async_task_mock):
- env = EnvCommand()
- env.do_influxdb({})
- self.assertTrue(start_async_task_mock.called)
- self.assertTrue(check_status_mock.called)
-
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
- def test_do_grafana(self, check_status_mock, start_async_task_mock):
- env = EnvCommand()
- env.do_grafana({})
- self.assertTrue(start_async_task_mock.called)
- self.assertTrue(check_status_mock.called)
-
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
- def test_do_prepare(self, check_status_mock, start_async_task_mock):
- env = EnvCommand()
- env.do_prepare({})
- self.assertTrue(start_async_task_mock.called)
- self.assertTrue(check_status_mock.called)
-
- @mock.patch('yardstick.cmd.commands.env.HttpClient.post')
- def test_start_async_task(self, post_mock):
- data = {'action': 'create_grafana'}
- EnvCommand()._start_async_task(data)
- self.assertTrue(post_mock.called)
-
- @mock.patch('yardstick.cmd.commands.env.HttpClient.get')
- @mock.patch('yardstick.cmd.commands.env.EnvCommand._print_status')
- def test_check_status(self, print_mock, get_mock):
- # pylint: disable=unused-argument
- # NOTE(ralonsoh): the pylint exception must be removed. The mocked
- # command call must be tested.
- task_id = str(uuid.uuid4())
- get_mock.return_value = {'status': 2, 'result': 'error'}
- status = EnvCommand()._check_status(task_id, 'hello world')
- self.assertEqual(status, 2)
-
- def test_print_status(self):
- try:
- EnvCommand()._print_status('hello', 'word')
- except Exception as e: # 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/tests/unit/test_cmd/commands/test_testcase.py b/tests/unit/test_cmd/commands/test_testcase.py
deleted file mode 100644
index 7ef157c19..000000000
--- a/tests/unit/test_cmd/commands/test_testcase.py
+++ /dev/null
@@ -1,29 +0,0 @@
-##############################################################################
-# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-import unittest
-from mock import patch
-
-from yardstick.cmd.commands.testcase import TestcaseCommands
-
-
-class TestcaseCommandsUT(unittest.TestCase):
- @patch('yardstick.cmd.commands.testcase.TestcaseCommands._format_print')
- @patch('yardstick.cmd.commands.client')
- def test_do_list(self, mock_client, mock_print):
- 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/tests/unit/test_cmd/test_NSBperf.py b/tests/unit/test_cmd/test_NSBperf.py
deleted file mode 100644
index 19eb0afa0..000000000
--- a/tests/unit/test_cmd/test_NSBperf.py
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/usr/bin/env python
-
-# Copyright (c) 2016-2017 Intel Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-from __future__ import absolute_import
-import unittest
-import mock
-import subprocess
-import os
-
-from yardstick.cmd.NSBperf import YardstickNSCli
-from yardstick.cmd import NSBperf
-
-
-@mock.patch('six.moves.input', return_value='0')
-class TestHandler(unittest.TestCase):
-
- def test_handler(self, *args):
- subprocess.call = mock.Mock(return_value=0)
- self.assertRaises(SystemExit, NSBperf.sigint_handler)
-
-
-class TestYardstickNSCli(unittest.TestCase):
- def test___init__(self):
- yardstick_ns_cli = YardstickNSCli()
- self.assertIsNotNone(yardstick_ns_cli)
-
- def test_generate_final_report(self):
- yardstick_ns_cli = YardstickNSCli()
- test_case = "tc_baremetal_rfc2544_ipv4_1flow_1518B.yaml"
- if os.path.isfile("/tmp/yardstick.out"):
- os.remove('/tmp/yardstick.out')
- self.assertIsNone(yardstick_ns_cli.generate_final_report(test_case))
-
- def test_generate_kpi_results(self):
- yardstick_ns_cli = YardstickNSCli()
- tkey = "cpu"
- tgen = {"cpu": {"ipc": 0}}
- self.assertIsNone(yardstick_ns_cli.generate_kpi_results(tkey, tgen))
-
- def test_generate_nfvi_results(self):
- yardstick_ns_cli = YardstickNSCli()
- nfvi = {"collect_stats": {"cpu": {"ipc": 0, "Hz": 2.6}}}
- self.assertIsNone(yardstick_ns_cli.generate_nfvi_results(nfvi))
-
- def test_handle_list_options(self):
- yardstick_ns_cli = YardstickNSCli()
- CLI_PATH = os.path.dirname(os.path.realpath(__file__))
- repo_dir = CLI_PATH + "/../../"
- test_path = os.path.join(repo_dir, "../samples/vnf_samples/nsut/")
- args = {"list_vnfs": True, "list": False}
- self.assertRaises(SystemExit, yardstick_ns_cli.handle_list_options,
- args, test_path)
- args = {"list_vnfs": False, "list": True}
- self.assertRaises(SystemExit,
- yardstick_ns_cli.handle_list_options,
- args, test_path)
-
- def test_main(self):
- yardstick_ns_cli = YardstickNSCli()
- yardstick_ns_cli.parse_arguments = mock.Mock(return_value=0)
- yardstick_ns_cli.handle_list_options = mock.Mock(return_value=0)
- yardstick_ns_cli.terminate_if_less_options = mock.Mock(return_value=0)
- yardstick_ns_cli.run_test = mock.Mock(return_value=0)
- self.assertIsNone(yardstick_ns_cli.main())
-
- def test_parse_arguments(self):
- yardstick_ns_cli = YardstickNSCli()
- self.assertRaises(SystemExit, yardstick_ns_cli.parse_arguments)
-
- def test_run_test(self):
- cur_dir = os.getcwd()
- CLI_PATH = os.path.dirname(os.path.realpath(__file__))
- YARDSTICK_REPOS_DIR = os.path.join(CLI_PATH + "/../../")
- test_path = os.path.join(YARDSTICK_REPOS_DIR,
- "../samples/vnf_samples/nsut/")
- yardstick_ns_cli = YardstickNSCli()
- 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))
- os.chdir(cur_dir)
- args = {"vnf": "vpe1"}
- self.assertEqual(None, 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))
- os.chdir(cur_dir)
- args = []
- self.assertEqual(None, yardstick_ns_cli.run_test(args, test_path))
- os.chdir(cur_dir)
-
- def test_terminate_if_less_options(self):
- yardstick_ns_cli = YardstickNSCli()
- args = {"vnf": False}
- self.assertRaises(SystemExit,
- yardstick_ns_cli.terminate_if_less_options, args)
-
- def test_validate_input(self):
- yardstick_ns_cli = YardstickNSCli()
- self.assertEqual(1, yardstick_ns_cli.validate_input("", 4))
- NSBperf.input = lambda _: 'yes'
- self.assertEqual(1, yardstick_ns_cli.validate_input(5, 4))
- subprocess.call = mock.Mock(return_value=0)
- self.assertEqual(0, yardstick_ns_cli.validate_input(2, 4))
- subprocess.call = mock.Mock(return_value=0)