From 44ee5e004f3af5dcdbbc1d172faba91b8419b6d6 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Wed, 10 Jan 2018 10:48:29 +0000 Subject: Make files pep8 compliant before using assertTrue|False JIRA: YARDSTICK-903 Signed-off-by: Emma Foley Change-Id: Id7912b5ddee36e7366bcfa824379853efd0a89f1 --- .../benchmark/contexts/standalone/test_ovs_dpdk.py | 35 +++++------ .../scenarios/availability/test_monitor_command.py | 35 ++++++----- .../scenarios/availability/test_serviceha.py | 28 ++++----- .../benchmark/scenarios/availability/test_util.py | 3 +- .../scenarios/lib/test_check_numa_info.py | 3 +- .../benchmark/scenarios/networking/test_nstat.py | 26 +++++---- .../benchmark/scenarios/networking/test_pktgen.py | 34 +++++++---- .../scenarios/networking/test_pktgen_dpdk.py | 67 +++++++++++++--------- .../networking/test_pktgen_dpdk_throughput.py | 29 +++++++--- .../scenarios/networking/test_vsperf_dpdk.py | 65 +++++++++++---------- .../unit/benchmark/scenarios/parser/test_parser.py | 2 +- tests/unit/network_services/nfvi/test_resource.py | 11 ++-- .../vnf_generic/vnf/test_tg_ping.py | 3 +- 13 files changed, 189 insertions(+), 152 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py b/tests/unit/benchmark/contexts/standalone/test_ovs_dpdk.py index 5d1b0421c..d0a0d4e08 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): @@ -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/scenarios/availability/test_monitor_command.py b/tests/unit/benchmark/scenarios/availability/test_monitor_command.py index 6a9b3b157..abef1e8bb 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,22 +55,22 @@ 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) 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) mock_log.error.assert_called_once() @@ -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..2b630da5a 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,7 +48,10 @@ 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) @@ -61,17 +61,19 @@ class ServicehaTestCase(unittest.TestCase): 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) - 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 03dc70e2a..55a0d160a 100644 --- a/tests/unit/benchmark/scenarios/availability/test_util.py +++ b/tests/unit/benchmark/scenarios/availability/test_util.py @@ -16,13 +16,14 @@ import unittest from yardstick.benchmark.scenarios.availability import util + 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() 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..45fbae45b 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, {}) diff --git a/tests/unit/benchmark/scenarios/networking/test_nstat.py b/tests/unit/benchmark/scenarios/networking/test_nstat.py index fe44cfdf4..84b559812 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): @@ -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_pktgen.py b/tests/unit/benchmark/scenarios/networking/test_pktgen.py index 3928aacde..71d20e5fe 100644 --- a/tests/unit/benchmark/scenarios/networking/test_pktgen.py +++ b/tests/unit/benchmark/scenarios/networking/test_pktgen.py @@ -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..19c84e855 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) - 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..8ac0763ba 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}, } @@ -49,7 +57,7 @@ class PktgenDPDKTestCase(unittest.TestCase): self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) - 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}, } @@ -165,7 +174,7 @@ class PktgenDPDKTestCase(unittest.TestCase): self.assertEqual(p.dpdk_setup_done, True) - 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_dpdk.py b/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py index 5759f0a90..ab3d815c5 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 @@ -73,7 +81,7 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertIsNotNone(p.client) self.assertEqual(p.setup_done, True) - 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 @@ -86,7 +94,7 @@ class VsperfDPDKTestCase(unittest.TestCase): p.teardown() self.assertEqual(p.setup_done, False) - 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 @@ -97,12 +105,12 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(p.setup_done, True) # 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) - 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 @@ -113,13 +121,13 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(p.setup_done, True) # 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) - @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 @@ -130,18 +138,18 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(p.setup_done, True) # 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) - @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() @@ -152,27 +160,27 @@ class VsperfDPDKTestCase(unittest.TestCase): self.assertEqual(p._is_dpdk_setup(), True) self.assertEqual(p.dpdk_setup_done, True) - @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.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') self.assertEqual(p.setup_done, True) 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() @@ -181,7 +189,7 @@ class VsperfDPDKTestCase(unittest.TestCase): # 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,12 +197,11 @@ 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() @@ -204,16 +211,16 @@ class VsperfDPDKTestCase(unittest.TestCase): # 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() @@ -223,8 +230,8 @@ class VsperfDPDKTestCase(unittest.TestCase): # 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..73d67f01f 100644 --- a/tests/unit/benchmark/scenarios/parser/test_parser.py +++ b/tests/unit/benchmark/scenarios/parser/test_parser.py @@ -45,7 +45,7 @@ class ParserTestCase(unittest.TestCase): sample_output = '{"yangtotosca": "success"}' p.run(result) - expected_result = jsonutils.loads(sample_output) + expected_result = jsonutils.loads(sample_output) # pylint: disable=unused-variable def test_parser_teardown_successful(self, mock_subprocess): diff --git a/tests/unit/network_services/nfvi/test_resource.py b/tests/unit/network_services/nfvi/test_resource.py index 4584b093d..2f953f227 100644 --- a/tests/unit/network_services/nfvi/test_resource.py +++ b/tests/unit/network_services/nfvi/test_resource.py @@ -136,11 +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") - def test__provide_config_file(self, *args): + 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, *args): + 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, *args): + 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") 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..8bf589281 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 @@ -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({})) -- cgit 1.2.3-korg From 298e2e529e815f31c7ae5e0e1154a7fdac92a067 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Tue, 19 Dec 2017 11:45:57 +0000 Subject: Replace assertEquals with assertEqual unittest.assertEquals is deprecated[1], and has been replaced with unittest.assertEqual. [1] https://docs.python.org/2/library/unittest.html#deprecated-aliases Change-Id: I9c6320e3a9ec5528036b529a9c32fc48b0bcfd62 JIRA: YARDSTICK-864 Signed-off-by: Emma Foley --- .../benchmark/scenarios/availability/test_util.py | 4 ++-- .../helpers/test_dpdkbindnic_helper.py | 21 ++++++++++----------- .../vnf_generic/vnf/test_sample_vnf.py | 4 ++-- .../vnf_generic/vnf/test_tg_ping.py | 2 +- .../vnf_generic/vnf/test_udp_replay.py | 2 +- yardstick/tests/unit/common/test_yaml_loader.py | 2 +- 6 files changed, 17 insertions(+), 18 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py index 55a0d160a..548efe91b 100644 --- a/tests/unit/benchmark/scenarios/availability/test_util.py +++ b/tests/unit/benchmark/scenarios/availability/test_util.py @@ -39,11 +39,11 @@ class ExecuteShellTestCase(unittest.TestCase): def test_read_stdout_item(self): result = util.read_stdout_item(self.std_output, 'id') - self.assertEquals('1', result) + self.assertEqual('1', result) def test_buildshellparams(self): result = util.buildshellparams(self.cmd_config, True) - self.assertEquals('/bin/bash -s {0} {1}', result) + self.assertEqual('/bin/bash -s {0} {1}', result) def test__fun_execute_shell_command_successful(self): cmd = "env" 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/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 8bf589281..f8ff60288 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 @@ -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): 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/yardstick/tests/unit/common/test_yaml_loader.py b/yardstick/tests/unit/common/test_yaml_loader.py index 90cbb8157..6c2beb422 100644 --- a/yardstick/tests/unit/common/test_yaml_loader.py +++ b/yardstick/tests/unit/common/test_yaml_loader.py @@ -22,7 +22,7 @@ class TemplateFormatTestCase(unittest.TestCase): def test_parse_to_value_exception(self): - self.assertEquals(yaml_loader.yaml_load("string"), u"string") + self.assertEqual(yaml_loader.yaml_load("string"), u"string") def main(): -- cgit 1.2.3-korg