1 # Copyright 2016 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Unittest for yardstick.benchmark.scenarios.networking.vsperf.Vsperf
17 from __future__ import absolute_import
19 from unittest import mock
24 from yardstick.benchmark.scenarios.networking import vsperf
27 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess')
28 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh')
29 class VsperfTestCase(unittest.TestCase):
34 "ip": "10.229.47.137",
41 'testname': 'p2p_rfc2544_continuous',
42 'traffic_type': 'continuous',
44 'bidirectional': 'True',
46 'trafficgen_port1': 'eth1',
47 'trafficgen_port2': 'eth3',
48 'external_bridge': 'br-ex',
49 'conf_file': 'vsperf-yardstick.conf',
50 'setup_script': 'setup_yardstick.sh',
51 'test_params': 'TRAFFICGEN_DURATION=30;',
54 'metrics': 'throughput_rx_fps',
55 'throughput_rx_fps': 500000,
60 def test_vsperf_setup(self, mock_ssh, mock_subprocess):
61 p = vsperf.Vsperf(self.args, self.ctx)
62 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
63 mock_subprocess.call().execute.return_value = None
66 self.assertIsNotNone(p.client)
67 self.assertTrue(p.setup_done)
69 def test_vsperf_teardown(self, mock_ssh, mock_subprocess):
70 p = vsperf.Vsperf(self.args, self.ctx)
72 # setup() specific mocks
73 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
74 mock_subprocess.call().execute.return_value = None
77 self.assertIsNotNone(p.client)
78 self.assertTrue(p.setup_done)
81 self.assertFalse(p.setup_done)
83 def test_vsperf_run_ok(self, mock_ssh, mock_subprocess):
84 p = vsperf.Vsperf(self.args, self.ctx)
86 # setup() specific mocks
87 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
88 mock_subprocess.call().execute.return_value = None
90 # run() specific mocks
91 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
92 mock_ssh.SSH.from_node().execute.return_value = (
93 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
98 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
100 def test_vsperf_run_falied_vsperf_execution(self, mock_ssh,
102 p = vsperf.Vsperf(self.args, self.ctx)
104 # setup() specific mocks
105 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
106 mock_subprocess.call().execute.return_value = None
108 # run() specific mocks
109 mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
112 self.assertRaises(RuntimeError, p.run, result)
114 def test_vsperf_run_falied_csv_report(self, mock_ssh, mock_subprocess):
115 p = vsperf.Vsperf(self.args, self.ctx)
117 # setup() specific mocks
118 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
119 mock_subprocess.call().execute.return_value = None
121 # run() specific mocks
122 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
123 mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
126 self.assertRaises(RuntimeError, p.run, result)