X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=tests%2Funit%2Fbenchmark%2Fscenarios%2Fnetworking%2Ftest_vsperf.py;h=348aa4a63d5e0f0feecfebd57a68a9bcd63f6bdb;hb=355601ab1b2335550905574148b097292f214325;hp=cb5c09ab384c59965ac65b1a5e833d6c79817e41;hpb=0f1b872b3bbff6e0f2c8d56f3037064206dd068d;p=yardstick.git diff --git a/tests/unit/benchmark/scenarios/networking/test_vsperf.py b/tests/unit/benchmark/scenarios/networking/test_vsperf.py index cb5c09ab3..348aa4a63 100644 --- a/tests/unit/benchmark/scenarios/networking/test_vsperf.py +++ b/tests/unit/benchmark/scenarios/networking/test_vsperf.py @@ -16,17 +16,20 @@ # Unittest for yardstick.benchmark.scenarios.networking.vsperf.Vsperf -import mock +from __future__ import absolute_import +try: + from unittest import mock +except ImportError: + import mock import unittest -import os -import subprocess from yardstick.benchmark.scenarios.networking import vsperf @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess') @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh') -@mock.patch("__builtin__.open", return_value=None) +@mock.patch("yardstick.benchmark.scenarios.networking.vsperf.open", + mock.mock_open()) class VsperfTestCase(unittest.TestCase): def setUp(self): @@ -39,17 +42,17 @@ class VsperfTestCase(unittest.TestCase): } self.args = { 'options': { - 'testname': 'rfc2544_p2p_continuous', + 'testname': 'p2p_rfc2544_continuous', 'traffic_type': 'continuous', - 'pkt_sizes': '64', + 'frame_size': '64', 'bidirectional': 'True', 'iload': 100, - 'duration': 29, 'trafficgen_port1': 'eth1', 'trafficgen_port2': 'eth3', 'external_bridge': 'br-ex', - 'conf-file': 'vsperf-yardstick.conf', - 'setup-script': 'setup_yardstick.sh', + 'conf_file': 'vsperf-yardstick.conf', + 'setup_script': 'setup_yardstick.sh', + 'test_params': 'TRAFFICGEN_DURATION=30;', }, 'sla': { 'metrics': 'throughput_rx_fps', @@ -58,20 +61,20 @@ class VsperfTestCase(unittest.TestCase): } } - def test_vsperf_setup(self, mock_open, mock_ssh, mock_subprocess): + def test_vsperf_setup(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) - mock_ssh.SSH().execute.return_value = (0, '', '') + 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) - def test_vsperf_teardown(self, mock_open, mock_ssh, mock_subprocess): + def test_vsperf_teardown(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None p.setup() @@ -81,45 +84,47 @@ class VsperfTestCase(unittest.TestCase): p.teardown() self.assertEqual(p.setup_done, False) - def test_vsperf_run_ok(self, mock_open, mock_ssh, mock_subprocess): + def test_vsperf_run_ok(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None # run() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') - mock_ssh.SSH().execute.return_value = (0, 'throughput_rx_fps\r\n14797660.000\r\n', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = ( + 0, 'throughput_rx_fps\r\n14797660.000\r\n', '') result = {} p.run(result) self.assertEqual(result['throughput_rx_fps'], '14797660.000') - def test_vsperf_run_falied_vsperf_execution(self, mock_open, mock_ssh, mock_subprocess): + def test_vsperf_run_falied_vsperf_execution(self, mock_ssh, + mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None # run() specific mocks - mock_ssh.SSH().execute.return_value = (1, '', '') + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') result = {} self.assertRaises(RuntimeError, p.run, result) - def test_vsperf_run_falied_csv_report(self, mock_open, mock_ssh, mock_subprocess): + def test_vsperf_run_falied_csv_report(self, mock_ssh, mock_subprocess): p = vsperf.Vsperf(self.args, self.ctx) # setup() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') mock_subprocess.call().execute.return_value = None # run() specific mocks - mock_ssh.SSH().execute.return_value = (0, '', '') - mock_ssh.SSH().execute.return_value = (1, '', '') + mock_ssh.SSH.from_node().execute.return_value = (0, '', '') + mock_ssh.SSH.from_node().execute.return_value = (1, '', '') result = {} self.assertRaises(RuntimeError, p.run, result) @@ -128,5 +133,6 @@ class VsperfTestCase(unittest.TestCase): def main(): unittest.main() + if __name__ == '__main__': main()