3 # Copyright 2016 Intel Corporation.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Unittest for yardstick.benchmark.scenarios.networking.vsperf.Vsperf
19 from __future__ import absolute_import
21 from unittest import mock
26 from yardstick.benchmark.scenarios.networking import vsperf
29 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.subprocess')
30 @mock.patch('yardstick.benchmark.scenarios.networking.vsperf.ssh')
31 class VsperfTestCase(unittest.TestCase):
36 "ip": "10.229.47.137",
43 'testname': 'p2p_rfc2544_continuous',
44 'traffic_type': 'continuous',
46 'bidirectional': 'True',
48 'trafficgen_port1': 'eth1',
49 'trafficgen_port2': 'eth3',
50 'external_bridge': 'br-ex',
51 'conf_file': 'vsperf-yardstick.conf',
52 'setup_script': 'setup_yardstick.sh',
53 'test_params': 'TRAFFICGEN_DURATION=30;',
56 'metrics': 'throughput_rx_fps',
57 'throughput_rx_fps': 500000,
62 def test_vsperf_setup(self, mock_ssh, mock_subprocess):
63 p = vsperf.Vsperf(self.args, self.ctx)
64 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
65 mock_subprocess.call().execute.return_value = None
68 self.assertIsNotNone(p.client)
69 self.assertEqual(p.setup_done, True)
71 def test_vsperf_teardown(self, mock_ssh, mock_subprocess):
72 p = vsperf.Vsperf(self.args, self.ctx)
74 # setup() specific mocks
75 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
76 mock_subprocess.call().execute.return_value = None
79 self.assertIsNotNone(p.client)
80 self.assertEqual(p.setup_done, True)
83 self.assertEqual(p.setup_done, False)
85 def test_vsperf_run_ok(self, mock_ssh, mock_subprocess):
86 p = vsperf.Vsperf(self.args, self.ctx)
88 # setup() specific mocks
89 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
90 mock_subprocess.call().execute.return_value = None
92 # run() specific mocks
93 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
94 mock_ssh.SSH.from_node().execute.return_value = (
95 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
100 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
102 def test_vsperf_run_falied_vsperf_execution(self, mock_ssh,
104 p = vsperf.Vsperf(self.args, self.ctx)
106 # setup() specific mocks
107 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
108 mock_subprocess.call().execute.return_value = None
110 # run() specific mocks
111 mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
114 self.assertRaises(RuntimeError, p.run, result)
116 def test_vsperf_run_falied_csv_report(self, mock_ssh, mock_subprocess):
117 p = vsperf.Vsperf(self.args, self.ctx)
119 # setup() specific mocks
120 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
121 mock_subprocess.call().execute.return_value = None
123 # run() specific mocks
124 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
125 mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
128 self.assertRaises(RuntimeError, p.run, result)
135 if __name__ == '__main__':