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 ##############################################################################
11 # Unittest for yardstick.benchmark.scenarios.networking.pktgen.PktgenDPDK
13 from __future__ import absolute_import
16 from oslo_serialization import jsonutils
19 from yardstick.benchmark.scenarios.networking import pktgen_dpdk_throughput
22 @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk_throughput.ssh')
23 class PktgenDPDKTestCase(unittest.TestCase):
30 'key_filename': 'mykey.key'
35 'key_filename': 'mykey.key',
39 def test_pktgen_dpdk_throughput_successful_setup(self, mock_ssh):
41 'options': {'packetsize': 60},
43 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
46 mock_ssh.SSH().execute.return_value = (0, '', '')
47 self.assertIsNotNone(p.server)
48 self.assertIsNotNone(p.client)
49 self.assertEqual(p.setup_done, True)
51 def test_pktgen_dpdk_throughput_successful_no_sla(self, mock_ssh):
53 'options': {'packetsize': 60, 'number_of_ports': 10},
58 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
60 p.server = mock_ssh.SSH()
61 p.client = mock_ssh.SSH()
63 mock_dpdk_result = mock.Mock()
64 mock_dpdk_result.return_value = 149300
65 p._dpdk_get_result = mock_dpdk_result
67 sample_output = '{"packets_per_second": 9753, "errors": 0, \
68 "packets_sent": 149776, "flows": 110}'
69 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
72 expected_result = jsonutils.loads(sample_output)
73 expected_result["packets_received"] = 149300
74 expected_result["packetsize"] = 60
75 self.assertEqual(result, expected_result)
77 def test_pktgen_dpdk_throughput_successful_sla(self, mock_ssh):
79 'options': {'packetsize': 60, 'number_of_ports': 10},
80 'sla': {'max_ppm': 10000}
84 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
86 p.server = mock_ssh.SSH()
87 p.client = mock_ssh.SSH()
89 mock_dpdk_result = mock.Mock()
90 mock_dpdk_result.return_value = 149300
91 p._dpdk_get_result = mock_dpdk_result
93 sample_output = '{"packets_per_second": 9753, "errors": 0, \
94 "packets_sent": 149776, "flows": 110}'
95 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
98 expected_result = jsonutils.loads(sample_output)
99 expected_result["packets_received"] = 149300
100 expected_result["packetsize"] = 60
101 self.assertEqual(result, expected_result)
103 def test_pktgen_dpdk_throughput_unsuccessful_sla(self, mock_ssh):
105 'options': {'packetsize': 60, 'number_of_ports': 10},
106 'sla': {'max_ppm': 1000}
110 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
112 p.server = mock_ssh.SSH()
113 p.client = mock_ssh.SSH()
115 mock_dpdk_result = mock.Mock()
116 mock_dpdk_result.return_value = 149300
117 p._dpdk_get_result = mock_dpdk_result
119 sample_output = '{"packets_per_second": 9753, "errors": 0, \
120 "packets_sent": 149776, "flows": 110}'
121 mock_ssh.SSH().execute.return_value = (0, sample_output, '')
122 self.assertRaises(AssertionError, p.run, result)
124 def test_pktgen_dpdk_throughput_unsuccessful_script_error(self, mock_ssh):
126 'options': {'packetsize': 60, 'number_of_ports': 10},
127 'sla': {'max_ppm': 1000}
131 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
133 p.server = mock_ssh.SSH()
134 p.client = mock_ssh.SSH()
136 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
137 self.assertRaises(RuntimeError, p.run, result)
139 def test_pktgen_dpdk_throughput_is_dpdk_setup(self, mock_ssh):
141 'options': {'packetsize': 60},
143 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
144 p.server = mock_ssh.SSH()
146 mock_ssh.SSH().execute.return_value = (0, '', '')
148 p._is_dpdk_setup("server")
150 mock_ssh.SSH().execute.assert_called_with(
151 "ip a | grep eth1 2>/dev/null")
153 def test_pktgen_dpdk_throughput_dpdk_setup(self, mock_ssh):
155 'options': {'packetsize': 60},
157 p = pktgen_dpdk_throughput.PktgenDPDK(args, self.ctx)
158 p.server = mock_ssh.SSH()
159 p.client = mock_ssh.SSH()
161 mock_ssh.SSH().execute.return_value = (0, '', '')
165 self.assertEqual(p.dpdk_setup_done, True)
167 def test_pktgen_dpdk_throughput_dpdk_get_result(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, '10000', '')
179 mock_ssh.SSH().execute.assert_called_with(
180 "sudo /dpdk/destdir/bin/dpdk-procinfo -- --stats-reset > /dev/null 2>&1")
185 if __name__ == '__main__':