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.
21 from yardstick.benchmark.scenarios.networking import vsperf_dpdk
24 class VsperfDPDKTestCase(unittest.TestCase):
29 "ip": "10.229.47.137",
35 'task_id': "1234-5678",
37 'testname': 'pvp_tput',
38 'traffic_type': 'rfc2544_throughput',
40 'test_params': 'TRAFFICGEN_DURATION=30;',
41 'trafficgen_port1': 'ens4',
42 'trafficgen_port2': 'ens5',
43 'conf_file': 'vsperf-yardstick.conf',
44 'setup_script': 'setup_yardstick.sh',
45 'moongen_helper_file': '~/moongen.py',
46 'moongen_host_ip': '10.5.201.151',
47 'moongen_port1_mac': '8c:dc:d4:ae:7c:5c',
48 'moongen_port2_mac': '8c:dc:d4:ae:7c:5d',
49 'trafficgen_port1_nw': 'test2',
50 'trafficgen_port2_nw': 'test3',
53 'metrics': 'throughput_rx_fps',
54 'throughput_rx_fps': 500000,
59 self.scenario = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
61 self._mock_ssh = mock.patch(
62 'yardstick.benchmark.scenarios.networking.vsperf_dpdk.ssh')
63 self.mock_ssh = self._mock_ssh.start()
64 self._mock_subprocess_call = mock.patch.object(subprocess, 'call')
65 self.mock_subprocess_call = self._mock_subprocess_call.start()
67 self.addCleanup(self._cleanup)
71 self._mock_subprocess_call.stop()
74 # setup() specific mocks
75 self.mock_subprocess_call().execute.return_value = None
78 self.assertIsNotNone(self.scenario.client)
79 self.assertTrue(self.scenario.setup_done)
81 def test_teardown(self):
82 # setup() specific mocks
83 self.mock_subprocess_call().execute.return_value = None
86 self.assertIsNotNone(self.scenario.client)
87 self.assertTrue(self.scenario.setup_done)
89 self.scenario.teardown()
90 self.assertFalse(self.scenario.setup_done)
92 def test_is_dpdk_setup_no(self):
93 # setup() specific mocks
94 self.mock_subprocess_call().execute.return_value = None
97 self.assertIsNotNone(self.scenario.client)
98 self.assertTrue(self.scenario.setup_done)
100 # is_dpdk_setup() specific mocks
101 self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '')
103 result = self.scenario._is_dpdk_setup()
104 self.assertFalse(result)
106 def test_is_dpdk_setup_yes(self):
107 # setup() specific mocks
108 self.mock_subprocess_call().execute.return_value = None
110 self.scenario.setup()
111 self.assertIsNotNone(self.scenario.client)
112 self.assertTrue(self.scenario.setup_done)
114 # is_dpdk_setup() specific mocks
115 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
117 result = self.scenario._is_dpdk_setup()
118 self.assertTrue(result)
120 @mock.patch.object(time, 'sleep')
121 def test_dpdk_setup_first(self, *args):
122 # setup() specific mocks
123 self.mock_subprocess_call().execute.return_value = None
125 self.scenario.setup()
126 self.assertIsNotNone(self.scenario.client)
127 self.assertTrue(self.scenario.setup_done)
129 # is_dpdk_setup() specific mocks
130 self.mock_ssh.SSH.from_node().execute.return_value = (0, 'dummy', '')
132 self.scenario.dpdk_setup()
133 self.assertFalse(self.scenario._is_dpdk_setup())
134 self.assertTrue(self.scenario.dpdk_setup_done)
136 @mock.patch.object(time, 'sleep')
137 def test_dpdk_setup_next(self, *args):
138 # setup() specific mocks
139 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
140 self.mock_subprocess_call().execute.return_value = None
142 self.scenario.setup()
143 self.assertIsNotNone(self.scenario.client)
144 self.assertTrue(self.scenario.setup_done)
146 self.scenario.dpdk_setup()
147 self.assertTrue(self.scenario._is_dpdk_setup())
148 self.assertTrue(self.scenario.dpdk_setup_done)
150 @mock.patch.object(time, 'sleep')
151 def test_dpdk_setup_runtime_error(self, *args):
153 # setup specific mocks
154 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
155 self.mock_subprocess_call().execute.return_value = None
157 self.scenario.setup()
158 self.assertIsNotNone(self.scenario.client)
159 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
160 self.assertTrue(self.scenario.setup_done)
162 self.assertRaises(RuntimeError, self.scenario.dpdk_setup)
164 @mock.patch.object(subprocess, 'check_output')
165 @mock.patch('time.sleep')
166 def test_run_ok(self, *args):
167 # setup() specific mocks
168 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
169 self.mock_subprocess_call().execute.return_value = None
171 self.scenario.setup()
172 self.assertIsNotNone(self.scenario.client)
173 self.assertTrue(self.scenario.setup_done)
175 # run() specific mocks
176 self.mock_subprocess_call().execute.return_value = None
177 self.mock_ssh.SSH.from_node().execute.return_value = (
178 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
181 self.scenario.run(result)
183 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
185 def test_run_failed_vsperf_execution(self):
186 # setup() specific mocks
187 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
188 self.mock_subprocess_call().execute.return_value = None
190 self.scenario.setup()
191 self.assertIsNotNone(self.scenario.client)
192 self.assertTrue(self.scenario.setup_done)
194 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
197 self.assertRaises(RuntimeError, self.scenario.run, result)
199 def test_run_falied_csv_report(self):
200 # setup() specific mocks
201 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
202 self.mock_subprocess_call().execute.return_value = None
204 self.scenario.setup()
205 self.assertIsNotNone(self.scenario.client)
206 self.assertTrue(self.scenario.setup_done)
208 # run() specific mocks
209 self.mock_subprocess_call().execute.return_value = None
210 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', '')
213 self.assertRaises(RuntimeError, self.scenario.run, result)
220 if __name__ == '__main__':