diff options
-rw-r--r-- | yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py | 126 |
1 files changed, 27 insertions, 99 deletions
diff --git a/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py b/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py index db6f9cc89..b305fc93b 100644 --- a/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py +++ b/yardstick/tests/unit/benchmark/scenarios/networking/test_vsperf_dpdk.py @@ -20,6 +20,8 @@ import unittest from yardstick import exceptions as y_exc from yardstick.benchmark.scenarios.networking import vsperf_dpdk +from yardstick.common import exceptions as y_exc +from yardstick import ssh class VsperfDPDKTestCase(unittest.TestCase): @@ -56,80 +58,51 @@ class VsperfDPDKTestCase(unittest.TestCase): 'action': 'monitor', } } - - self.scenario = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) - - self._mock_ssh = mock.patch.object(vsperf_dpdk, 'ssh') + self._mock_ssh = mock.patch.object(ssh, 'SSH') self.mock_ssh = self._mock_ssh.start() self._mock_subprocess_call = mock.patch.object(subprocess, 'call') self.mock_subprocess_call = self._mock_subprocess_call.start() + mock_call_obj = mock.Mock() + mock_call_obj.execute.return_value = None + self.mock_subprocess_call.return_value = mock_call_obj + self._mock_log_info = mock.patch.object(vsperf_dpdk.LOG, 'info') self.mock_log_info = self._mock_log_info.start() + self.addCleanup(self._cleanup) + self.scenario = vsperf_dpdk.VsperfDPDK(self.args, self.ctx) + self.scenario.setup() + def _cleanup(self): self._mock_ssh.stop() self._mock_subprocess_call.stop() self._mock_log_info.stop() def test_setup(self): - # setup() specific mocks - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() self.assertIsNotNone(self.scenario.client) self.assertTrue(self.scenario.setup_done) def test_teardown(self): - # setup() specific mocks - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - self.scenario.teardown() self.assertFalse(self.scenario.setup_done) def test_is_dpdk_setup_no(self): - # setup() specific mocks - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - # is_dpdk_setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '') + self.mock_ssh.from_node().execute.return_value = (0, 'dummy', '') - result = self.scenario._is_dpdk_setup() - self.assertFalse(result) + self.assertFalse(self.scenario._is_dpdk_setup()) def test_is_dpdk_setup_yes(self): - # setup() specific mocks - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - # is_dpdk_setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + self.mock_ssh.from_node().execute.return_value = (0, '', '') - result = self.scenario._is_dpdk_setup() - self.assertTrue(result) + self.assertTrue(self.scenario._is_dpdk_setup()) @mock.patch.object(time, 'sleep') def test_dpdk_setup_first(self, *args): - # setup() specific mocks - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - # is_dpdk_setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '') + self.mock_ssh.from_node().execute.return_value = (0, 'dummy', '') self.scenario.dpdk_setup() self.assertFalse(self.scenario._is_dpdk_setup()) @@ -137,13 +110,7 @@ class VsperfDPDKTestCase(unittest.TestCase): @mock.patch.object(time, 'sleep') def test_dpdk_setup_next(self, *args): - # setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) + self.mock_ssh.from_node().execute.return_value = (0, '', '') self.scenario.dpdk_setup() self.assertTrue(self.scenario._is_dpdk_setup()) @@ -151,75 +118,38 @@ class VsperfDPDKTestCase(unittest.TestCase): @mock.patch.object(time, 'sleep') def test_dpdk_setup_runtime_error(self, *args): - - # setup specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() self.assertIsNotNone(self.scenario.client) - self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.mock_ssh.from_node().execute.return_value = (1, '', '') self.assertTrue(self.scenario.setup_done) self.assertRaises(RuntimeError, self.scenario.dpdk_setup) + @mock.patch.object(time, 'sleep') @mock.patch.object(subprocess, 'check_output') - @mock.patch('time.sleep') def test_run_ok(self, *args): - # setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - # run() specific mocks - self.mock_subprocess_call().execute.return_value = None - self.mock_ssh.SSH.from_node().execute.return_value = ( + self.mock_ssh.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') result = {} self.scenario.run(result) - self.assertEqual(result['throughput_rx_fps'], '14797660.000') def test_run_failed_vsperf_execution(self): - # setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - self.mock_subprocess_call().execute.return_value = None + self.mock_ssh.from_node().execute.return_value = (1, '', '') - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - - self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') - - result = {} - self.assertRaises(RuntimeError, self.scenario.run, result) + self.assertRaises(RuntimeError, self.scenario.run, {}) def test_run_falied_csv_report(self): - # setup() specific mocks - self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '') - self.mock_subprocess_call().execute.return_value = None - - self.scenario.setup() - self.assertIsNotNone(self.scenario.client) - self.assertTrue(self.scenario.setup_done) - # run() specific mocks - self.mock_subprocess_call().execute.return_value = None - self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '') + self.mock_ssh.from_node().execute.return_value = (1, '', '') - result = {} - self.assertRaises(RuntimeError, self.scenario.run, result) + self.assertRaises(RuntimeError, self.scenario.run, {}) @mock.patch.object(time, 'sleep') @mock.patch.object(subprocess, 'check_output') def test_vsperf_run_sla_fail(self, *args): - self.scenario.setup() - - self.mock_ssh.SSH.from_node().execute.return_value = ( + self.mock_ssh.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n123456.000\r\n', '') with self.assertRaises(y_exc.SLAValidationError) as raised: @@ -232,9 +162,7 @@ class VsperfDPDKTestCase(unittest.TestCase): @mock.patch.object(time, 'sleep') @mock.patch.object(subprocess, 'check_output') def test_vsperf_run_sla_fail_metric_not_collected(self, *args): - self.scenario.setup() - - self.mock_ssh.SSH.from_node().execute.return_value = ( + self.mock_ssh.from_node().execute.return_value = ( 0, 'nonexisting_metric\r\n123456.000\r\n', '') with self.assertRaises(y_exc.SLAValidationError) as raised: @@ -249,7 +177,7 @@ class VsperfDPDKTestCase(unittest.TestCase): del self.scenario.scenario_cfg['sla']['throughput_rx_fps'] self.scenario.setup() - self.mock_ssh.SSH.from_node().execute.return_value = ( + self.mock_ssh.from_node().execute.return_value = ( 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') with self.assertRaises(y_exc.SLAValidationError) as raised: |