1 ##############################################################################
2 # Copyright (c) 2015 ZTE 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 ##############################################################################
13 import yardstick.common.utils as utils
14 from yardstick.benchmark.scenarios.networking import pktgen_dpdk
15 from yardstick.common import exceptions as y_exc
18 class PktgenDPDKLatencyTestCase(unittest.TestCase):
25 'key_filename': 'mykey.key'
30 'key_filename': 'mykey.key',
31 'ipaddr': '172.16.0.138'
35 self._mock_ssh = mock.patch(
36 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
37 self.mock_ssh = self._mock_ssh.start()
38 self._mock_time = mock.patch(
39 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.time')
40 self.mock_time = self._mock_time.start()
42 self.addCleanup(self._stop_mock)
46 self._mock_time.stop()
48 def test_pktgen_dpdk_successful_setup(self):
51 'options': {'packetsize': 60},
53 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
56 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
57 self.assertIsNotNone(p.server)
58 self.assertIsNotNone(p.client)
59 self.assertTrue(p.setup_done)
61 def test_pktgen_dpdk_successful_get_port_ip(self):
64 'options': {'packetsize': 60},
66 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
67 p.server = self.mock_ssh.SSH.from_node()
69 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
71 utils.get_port_ip(p.server, "eth1")
73 self.mock_ssh.SSH.from_node().execute.assert_called_with(
74 "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ")
76 def test_pktgen_dpdk_unsuccessful_get_port_ip(self):
79 'options': {'packetsize': 60},
82 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
83 p.server = self.mock_ssh.SSH.from_node()
85 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
86 self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1")
88 def test_pktgen_dpdk_successful_get_port_mac(self):
91 'options': {'packetsize': 60},
93 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
94 p.server = self.mock_ssh.SSH.from_node()
96 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
98 utils.get_port_mac(p.server, "eth1")
100 self.mock_ssh.SSH.from_node().execute.assert_called_with(
101 "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ")
103 def test_pktgen_dpdk_unsuccessful_get_port_mac(self):
106 'options': {'packetsize': 60},
109 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
110 p.server = self.mock_ssh.SSH.from_node()
112 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
113 self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1")
115 def test_pktgen_dpdk_successful_no_sla(self):
118 'options': {'packetsize': 60},
122 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
124 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
125 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
128 # with python 3 we get float, might be due python division changes
129 # AssertionError: {'avg_latency': 132.33333333333334} != {
130 # 'avg_latency': 132}
131 delta = result['avg_latency'] - 132
132 self.assertLessEqual(delta, 1)
134 def test_pktgen_dpdk_successful_sla(self):
137 'options': {'packetsize': 60},
138 'sla': {'max_latency': 100}
142 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
144 sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
145 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
149 self.assertEqual(result, {"avg_latency": 100})
151 def test_pktgen_dpdk_unsuccessful_sla(self):
154 'options': {'packetsize': 60},
155 'sla': {'max_latency': 100}
159 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
161 p.server = self.mock_ssh.SSH.from_node()
162 p.client = self.mock_ssh.SSH.from_node()
164 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
165 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
166 self.assertRaises(y_exc.SLAValidationError, p.run, result)
168 def test_pktgen_dpdk_run_unsuccessful_get_port_mac(self):
171 'options': {'packetsize': 60},
172 'sla': {'max_latency': 100}
176 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
178 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
179 self.assertRaises(RuntimeError, p.run, result)
181 def test_pktgen_dpdk_run_unsuccessful_script_error(self):
183 'options': {'packetsize': 60}
186 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
188 self.mock_ssh.SSH.from_node().execute.side_effect = ((0, '', ''),
194 self.assertRaises(y_exc.SSHError, p.run, {})
195 self.assertEqual(self.mock_ssh.SSH.from_node().execute.call_count, 6)