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
19 from yardstick.common import exceptions as y_exc
22 # pylint: disable=unused-argument
23 # disable this for now because I keep forgetting mock patch arg ordering
26 @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh')
27 class PktgenDPDKTestCase(unittest.TestCase):
34 'key_filename': 'mykey.key'
39 'key_filename': 'mykey.key',
43 self._mock_time = mock.patch(
44 'yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.time')
45 self.mock_time = self._mock_time.start()
47 self.addCleanup(self._cleanup)
50 self._mock_time.stop()
52 def test_pktgen_dpdk_throughput_successful_setup(self, mock_ssh):
54 'options': {'packetsize': 60},
56 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
59 mock_ssh.SSH().execute.return_value = (0, '', '')
60 self.assertIsNotNone(p.server)
61 self.assertIsNotNone(p.client)
62 self.assertTrue(p.setup_done)
64 def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh):
66 'options': {'packetsize': 60, 'number_of_ports': 10},
71 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
73 p.server = mock_ssh.SSH()
74 p.client = mock_ssh.SSH()
76 mock_dpdk_result = mock.Mock()
77 mock_dpdk_result.return_value = 149300
78 p._dpdk_get_result = mock_dpdk_result
80 sample_output = '{"packets_per_second": 9753, "errors": 0, \
81 "packets_sent": 149776, "flows": 110}'
82 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
85 expected_result = jsonutils.loads(sample_output)
86 expected_result["packets_received"] = 149300
87 expected_result["packetsize"] = 60
88 self.assertEqual(result, expected_result)
90 def test_pktgen_dpdk_throughput_successful_sla(self, mock_ssh):
92 'options': {'packetsize': 60, 'number_of_ports': 10},
93 'sla': {'max_ppm': 10000}
97 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
99 p.server = mock_ssh.SSH()
100 p.client = mock_ssh.SSH()
102 mock_dpdk_result = mock.Mock()
103 mock_dpdk_result.return_value = 149300
104 p._dpdk_get_result = mock_dpdk_result
106 sample_output = '{"packets_per_second": 9753, "errors": 0, \
107 "packets_sent": 149776, "flows": 110}'
108 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
111 expected_result = jsonutils.loads(sample_output)
112 expected_result["packets_received"] = 149300
113 expected_result["packetsize"] = 60
114 self.assertEqual(result, expected_result)
116 def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock_ssh):
118 'options': {'packetsize': 60, 'number_of_ports': 10},
119 'sla': {'max_ppm': 1000}
123 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
125 p.server = mock_ssh.SSH()
126 p.client = mock_ssh.SSH()
128 mock_dpdk_result = mock.Mock()
129 mock_dpdk_result.return_value = 149300
130 p._dpdk_get_result = mock_dpdk_result
132 sample_output = '{"packets_per_second": 9753, "errors": 0, \
133 "packets_sent": 149776, "flows": 110}'
134 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
135 self.assertRaises(y_exc.SLAValidationError, p.run, result)
137 def test_pktgen_dpdk_throughput_unsuccessful_script_error(
140 'options': {'packetsize': 60, 'number_of_ports': 10},
141 'sla': {'max_ppm': 1000}
145 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
147 p.server = mock_ssh.SSH()
148 p.client = mock_ssh.SSH()
150 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
151 self.assertRaises(RuntimeError, p.run, result)
153 def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh):
155 'options': {'packetsize': 60},
157 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
158 p.server = mock_ssh.SSH()
160 mock_ssh.SSH().execute.return_value = (0, '', '')
162 p._is_dpdk_setup("server")
164 mock_ssh.SSH().execute.assert_called_with(
165 "ip a | grep eth1 2>/dev/null")
167 def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh):
169 'options': {'packetsize': 60},
171 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
172 p.server = mock_ssh.SSH()
173 p.client = mock_ssh.SSH()
175 mock_ssh.SSH().execute.return_value = (0, '', '')
179 self.assertTrue(p.dpdk_setup_done)
181 def test_pktgen_dpdk_throughput_dpdk_get_result(self, mock_ssh):
183 'options': {'packetsize': 60},
185 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
186 p.server = mock_ssh.SSH()
187 p.client = mock_ssh.SSH()
189 mock_ssh.SSH().execute.return_value = (0, '10000', '')
193 mock_ssh.SSH().execute.assert_called_with(
194 "sudo /dpdk/destdir/bin/dpdk-procinfo -- --stats-reset > /dev/null 2>&1")