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 import exceptions as y_exc
22 from yardstick.benchmark.scenarios.networking import vsperf_dpdk
23 from yardstick.common import exceptions as y_exc
24 from yardstick import ssh
27 class VsperfDPDKTestCase(unittest.TestCase):
32 "ip": "10.229.47.137",
38 'task_id': "1234-5678",
40 'testname': 'pvp_tput',
41 'traffic_type': 'rfc2544_throughput',
43 'test_params': 'TRAFFICGEN_DURATION=30;',
44 'trafficgen_port1': 'ens4',
45 'trafficgen_port2': 'ens5',
46 'conf_file': 'vsperf-yardstick.conf',
47 'setup_script': 'setup_yardstick.sh',
48 'moongen_helper_file': '~/moongen.py',
49 'moongen_host_ip': '10.5.201.151',
50 'moongen_port1_mac': '8c:dc:d4:ae:7c:5c',
51 'moongen_port2_mac': '8c:dc:d4:ae:7c:5d',
52 'trafficgen_port1_nw': 'test2',
53 'trafficgen_port2_nw': 'test3',
56 'metrics': 'throughput_rx_fps',
57 'throughput_rx_fps': 500000,
61 self._mock_ssh = mock.patch.object(ssh, 'SSH')
62 self.mock_ssh = self._mock_ssh.start()
63 self._mock_subprocess_call = mock.patch.object(subprocess, 'call')
64 self.mock_subprocess_call = self._mock_subprocess_call.start()
65 mock_call_obj = mock.Mock()
66 mock_call_obj.execute.return_value = None
67 self.mock_subprocess_call.return_value = mock_call_obj
69 self._mock_log_info = mock.patch.object(vsperf_dpdk.LOG, 'info')
70 self.mock_log_info = self._mock_log_info.start()
72 self.addCleanup(self._cleanup)
74 self.scenario = vsperf_dpdk.VsperfDPDK(self.args, self.ctx)
79 self._mock_subprocess_call.stop()
80 self._mock_log_info.stop()
83 self.assertIsNotNone(self.scenario.client)
84 self.assertTrue(self.scenario.setup_done)
86 def test_teardown(self):
87 self.scenario.teardown()
88 self.assertFalse(self.scenario.setup_done)
90 def test_is_dpdk_setup_no(self):
91 # is_dpdk_setup() specific mocks
92 self.mock_ssh.from_node().execute.return_value = (0, 'dummy', '')
94 self.assertFalse(self.scenario._is_dpdk_setup())
96 def test_is_dpdk_setup_yes(self):
97 # is_dpdk_setup() specific mocks
98 self.mock_ssh.from_node().execute.return_value = (0, '', '')
100 self.assertTrue(self.scenario._is_dpdk_setup())
102 @mock.patch.object(time, 'sleep')
103 def test_dpdk_setup_first(self, *args):
104 # is_dpdk_setup() specific mocks
105 self.mock_ssh.from_node().execute.return_value = (0, 'dummy', '')
107 self.scenario.dpdk_setup()
108 self.assertFalse(self.scenario._is_dpdk_setup())
109 self.assertTrue(self.scenario.dpdk_setup_done)
111 @mock.patch.object(time, 'sleep')
112 def test_dpdk_setup_next(self, *args):
113 self.mock_ssh.from_node().execute.return_value = (0, '', '')
115 self.scenario.dpdk_setup()
116 self.assertTrue(self.scenario._is_dpdk_setup())
117 self.assertTrue(self.scenario.dpdk_setup_done)
119 @mock.patch.object(time, 'sleep')
120 def test_dpdk_setup_runtime_error(self, *args):
121 self.assertIsNotNone(self.scenario.client)
122 self.mock_ssh.from_node().execute.return_value = (1, '', '')
123 self.assertTrue(self.scenario.setup_done)
125 self.assertRaises(RuntimeError, self.scenario.dpdk_setup)
127 @mock.patch.object(time, 'sleep')
128 @mock.patch.object(subprocess, 'check_output')
129 def test_run_ok(self, *args):
130 # run() specific mocks
131 self.mock_ssh.from_node().execute.return_value = (
132 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
135 self.scenario.run(result)
136 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
138 def test_run_failed_vsperf_execution(self):
139 self.mock_ssh.from_node().execute.return_value = (1, '', '')
141 self.assertRaises(RuntimeError, self.scenario.run, {})
143 def test_run_falied_csv_report(self):
144 # run() specific mocks
145 self.mock_ssh.from_node().execute.return_value = (1, '', '')
147 self.assertRaises(RuntimeError, self.scenario.run, {})
149 @mock.patch.object(time, 'sleep')
150 @mock.patch.object(subprocess, 'check_output')
151 def test_vsperf_run_sla_fail(self, *args):
152 self.mock_ssh.from_node().execute.return_value = (
153 0, 'throughput_rx_fps\r\n123456.000\r\n', '')
155 with self.assertRaises(y_exc.SLAValidationError) as raised:
156 self.scenario.run({})
158 self.assertIn('VSPERF_throughput_rx_fps(123456.000000) < '
159 'SLA_throughput_rx_fps(500000.000000)',
160 str(raised.exception))
162 @mock.patch.object(time, 'sleep')
163 @mock.patch.object(subprocess, 'check_output')
164 def test_vsperf_run_sla_fail_metric_not_collected(self, *args):
165 self.mock_ssh.from_node().execute.return_value = (
166 0, 'nonexisting_metric\r\n123456.000\r\n', '')
168 with self.assertRaises(y_exc.SLAValidationError) as raised:
169 self.scenario.run({})
171 self.assertIn('throughput_rx_fps was not collected by VSPERF',
172 str(raised.exception))
174 @mock.patch.object(time, 'sleep')
175 @mock.patch.object(subprocess, 'check_output')
176 def test_vsperf_run_sla_fail_sla_not_defined(self, *args):
177 del self.scenario.scenario_cfg['sla']['throughput_rx_fps']
178 self.scenario.setup()
180 self.mock_ssh.from_node().execute.return_value = (
181 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
183 with self.assertRaises(y_exc.SLAValidationError) as raised:
184 self.scenario.run({})
186 self.assertIn('throughput_rx_fps is not defined in SLA',
187 str(raised.exception))