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.
18 import yardstick.ssh as ssh
20 from yardstick.benchmark.scenarios.networking import vsperf
21 from yardstick import exceptions as y_exc
24 class VsperfTestCase(unittest.TestCase):
29 "ip": "10.229.47.137",
36 'testname': 'p2p_rfc2544_continuous',
37 'traffic_type': 'continuous',
39 'bidirectional': 'True',
41 'trafficgen_port1': 'eth1',
42 'trafficgen_port2': 'eth3',
43 'external_bridge': 'br-ex',
44 'conf_file': 'vsperf-yardstick.conf',
45 'setup_script': 'setup_yardstick.sh',
46 'test_params': 'TRAFFICGEN_DURATION=30;',
49 'metrics': 'throughput_rx_fps',
50 'throughput_rx_fps': 500000,
55 self._mock_SSH = mock.patch.object(ssh, 'SSH')
56 self.mock_SSH = self._mock_SSH.start()
57 self.mock_SSH.from_node().execute.return_value = (
58 0, 'throughput_rx_fps\r\n14797660.000\r\n', '')
60 self._mock_subprocess_call = mock.patch.object(subprocess, 'call')
61 self.mock_subprocess_call = self._mock_subprocess_call.start()
62 self.mock_subprocess_call.return_value = None
64 self.addCleanup(self._stop_mock)
66 self.scenario = vsperf.Vsperf(self.scenario_cfg, self.context_cfg)
70 self._mock_subprocess_call.stop()
74 self.assertIsNotNone(self.scenario.client)
75 self.assertTrue(self.scenario.setup_done)
77 def test_setup_tg_port_not_set(self):
78 del self.scenario_cfg['options']['trafficgen_port1']
79 del self.scenario_cfg['options']['trafficgen_port2']
80 scenario = vsperf.Vsperf(self.scenario_cfg, self.context_cfg)
83 self.mock_subprocess_call.assert_called_once_with(
84 'setup_yardstick.sh setup', shell=True)
85 self.assertIsNone(scenario.tg_port1)
86 self.assertIsNone(scenario.tg_port2)
87 self.assertIsNotNone(scenario.client)
88 self.assertTrue(scenario.setup_done)
90 def test_setup_no_setup_script(self):
91 del self.scenario_cfg['options']['setup_script']
92 scenario = vsperf.Vsperf(self.scenario_cfg, self.context_cfg)
95 self.mock_subprocess_call.assert_has_calls(
96 (mock.call('sudo bash -c "ovs-vsctl add-port br-ex eth1"',
98 mock.call('sudo bash -c "ovs-vsctl add-port br-ex eth3"',
100 self.assertEqual(2, self.mock_subprocess_call.call_count)
101 self.assertIsNone(scenario.setup_script)
102 self.assertIsNotNone(scenario.client)
103 self.assertTrue(scenario.setup_done)
105 def test_run_ok(self):
106 self.scenario.setup()
109 self.scenario.run(result)
111 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
113 def test_run_ok_setup_not_done(self):
115 self.scenario.run(result)
117 self.assertTrue(self.scenario.setup_done)
118 self.assertEqual(result['throughput_rx_fps'], '14797660.000')
120 def test_run_ssh_command_call_counts(self):
121 self.scenario.run({})
123 self.assertEqual(self.mock_SSH.from_node().execute.call_count, 2)
124 self.mock_SSH.from_node().run.assert_called_once()
126 def test_run_sla_fail(self):
127 self.mock_SSH.from_node().execute.return_value = (
128 0, 'throughput_rx_fps\r\n123456.000\r\n', '')
130 with self.assertRaises(y_exc.SLAValidationError) as raised:
131 self.scenario.run({})
133 self.assertTrue('VSPERF_throughput_rx_fps(123456.000000) < '
134 'SLA_throughput_rx_fps(500000.000000)'
135 in str(raised.exception))
137 def test_run_sla_fail_metric_not_collected(self):
138 self.mock_SSH.from_node().execute.return_value = (
139 0, 'nonexisting_metric\r\n14797660.000\r\n', '')
141 with self.assertRaises(y_exc.SLAValidationError) as raised:
142 self.scenario.run({})
144 self.assertTrue('throughput_rx_fps was not collected by VSPERF'
145 in str(raised.exception))
147 def test_run_faulty_result_csv(self):
148 self.mock_SSH.from_node().execute.return_value = (
149 0, 'faulty output not csv', '')
151 with self.assertRaises(y_exc.SLAValidationError) as raised:
152 self.scenario.run({})
154 self.assertTrue('throughput_rx_fps was not collected by VSPERF'
155 in str(raised.exception))
157 def test_run_sla_fail_metric_not_defined_in_sla(self):
158 del self.scenario_cfg['sla']['throughput_rx_fps']
159 scenario = vsperf.Vsperf(self.scenario_cfg, self.context_cfg)
162 with self.assertRaises(y_exc.SLAValidationError) as raised:
164 self.assertTrue('throughput_rx_fps is not defined in SLA'
165 in str(raised.exception))
167 def test_teardown(self):
168 self.scenario.setup()
169 self.assertIsNotNone(self.scenario.client)
170 self.assertTrue(self.scenario.setup_done)
172 self.scenario.teardown()
173 self.assertFalse(self.scenario.setup_done)
175 def test_teardown_tg_port_not_set(self):
176 del self.scenario_cfg['options']['trafficgen_port1']
177 del self.scenario_cfg['options']['trafficgen_port2']
178 scenario = vsperf.Vsperf(self.scenario_cfg, self.context_cfg)
181 self.mock_subprocess_call.assert_called_once_with(
182 'setup_yardstick.sh teardown', shell=True)
183 self.assertFalse(scenario.setup_done)
185 def test_teardown_no_setup_script(self):
186 del self.scenario_cfg['options']['setup_script']
187 scenario = vsperf.Vsperf(self.scenario_cfg, self.context_cfg)
190 self.mock_subprocess_call.assert_has_calls(
191 (mock.call('sudo bash -c "ovs-vsctl del-port br-ex eth1"',
193 mock.call('sudo bash -c "ovs-vsctl del-port br-ex eth3"',
195 self.assertEqual(2, self.mock_subprocess_call.call_count)
196 self.assertFalse(scenario.setup_done)