diff options
Diffstat (limited to 'tests/unit/benchmark/scenarios/networking')
9 files changed, 161 insertions, 116 deletions
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) |