1 ##############################################################################
2 # Copyright (c) 2017 Nokia and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.networking.pktgen.PktgenDPDK
12 from __future__ import absolute_import
15 from oslo_serialization import jsonutils
18 from yardstick.benchmark.scenarios.networking import pktgen_dpdk_throughput
21 # pylint: disable=unused-argument
22 # disable this for now because I keep forgetting mock patch arg ordering
25 @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh')
26 class PktgenDPDKTestCase(unittest.TestCase):
33 'key_filename': 'mykey.key'
38 'key_filename': 'mykey.key',
42 self._mock_time = mock.patch(
43 'yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time')
44 self.mock_time = self._mock_time.start()
46 self.addCleanup(self._cleanup)
49 self._mock_time.stop()
51 def test_pktgen_dpdk_throughput_successful_setup(self, mock_ssh):
53 'options': {'packetsize': 60},
55 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
58 mock_ssh.SSH().execute.return_value = (0, '', '')
59 self.assertIsNotNone(p.server)
60 self.assertIsNotNone(p.client)
61 self.assertTrue(p.setup_done)
63 def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh):
65 'options': {'packetsize': 60, 'number_of_ports': 10},
70 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
72 p.server = mock_ssh.SSH()
73 p.client = mock_ssh.SSH()
75 mock_dpdk_result = mock.Mock()
76 mock_dpdk_result.return_value = 149300
77 p._dpdk_get_result = mock_dpdk_result
79 sample_output = '{"packets_per_second": 9753, "errors": 0, \
80 "packets_sent": 149776, "flows": 110}'
81 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
84 expected_result = jsonutils.loads(sample_output)
85 expected_result["packets_received"] = 149300
86 expected_result["packetsize"] = 60
87 self.assertEqual(result, expected_result)
89 def test_pktgen_dpdk_throughput_successful_sla(self, mock_ssh):
91 'options': {'packetsize': 60, 'number_of_ports': 10},
92 'sla': {'max_ppm': 10000}
96 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
98 p.server = mock_ssh.SSH()
99 p.client = mock_ssh.SSH()
101 mock_dpdk_result = mock.Mock()
102 mock_dpdk_result.return_value = 149300
103 p._dpdk_get_result = mock_dpdk_result
105 sample_output = '{"packets_per_second": 9753, "errors": 0, \
106 "packets_sent": 149776, "flows": 110}'
107 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
110 expected_result = jsonutils.loads(sample_output)
111 expected_result["packets_received"] = 149300
112 expected_result["packetsize"] = 60
113 self.assertEqual(result, expected_result)
115 def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock_ssh):
117 'options': {'packetsize': 60, 'number_of_ports': 10},
118 'sla': {'max_ppm': 1000}
122 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
124 p.server = mock_ssh.SSH()
125 p.client = mock_ssh.SSH()
127 mock_dpdk_result = mock.Mock()
128 mock_dpdk_result.return_value = 149300
129 p._dpdk_get_result = mock_dpdk_result
131 sample_output = '{"packets_per_second": 9753, "errors": 0, \
132 "packets_sent": 149776, "flows": 110}'
133 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
134 self.assertRaises(AssertionError, p.run, result)
136 def test_pktgen_dpdk_throughput_unsuccessful_script_error(
139 'options': {'packetsize': 60, 'number_of_ports': 10},
140 'sla': {'max_ppm': 1000}
144 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
146 p.server = mock_ssh.SSH()
147 p.client = mock_ssh.SSH()
149 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
150 self.assertRaises(RuntimeError, p.run, result)
152 def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh):
154 'options': {'packetsize': 60},
156 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
157 p.server = mock_ssh.SSH()
159 mock_ssh.SSH().execute.return_value = (0, '', '')
161 p._is_dpdk_setup("server")
163 mock_ssh.SSH().execute.assert_called_with(
164 "ip a | grep eth1 2>/dev/null")
166 def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh):
168 'options': {'packetsize': 60},
170 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
171 p.server = mock_ssh.SSH()
172 p.client = mock_ssh.SSH()
174 mock_ssh.SSH().execute.return_value = (0, '', '')
178 self.assertTrue(p.dpdk_setup_done)
180 def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock_ssh):
182 'options': {'packetsize': 60},
184 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
185 p.server = mock_ssh.SSH()
186 p.client = mock_ssh.SSH()
188 mock_ssh.SSH().execute.return_value = (0, '10000', '')
192 mock_ssh.SSH().execute.assert_called_with(
193 "sudo /dpdk/destdir/bin/dpdk-procinfo -- --stats-reset > /dev/null 2>&1")