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
17 class PktgenDPDKLatencyTestCase(unittest.TestCase):
24 'key_filename': 'mykey.key'
29 'key_filename': 'mykey.key',
30 'ipaddr': '172.16.0.138'
34 self._mock_ssh = mock.patch(
35 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
36 self.mock_ssh = self._mock_ssh.start()
37 self._mock_time = mock.patch(
38 'yardstick.benchmark.scenarios.networking.pktgen_dpdk.time')
39 self.mock_time = self._mock_time.start()
41 self.addCleanup(self._stop_mock)
45 self._mock_time.stop()
47 def test_pktgen_dpdk_successful_setup(self):
50 'options': {'packetsize': 60},
52 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
55 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
56 self.assertIsNotNone(p.server)
57 self.assertIsNotNone(p.client)
58 self.assertTrue(p.setup_done)
60 def test_pktgen_dpdk_successful_get_port_ip(self):
63 'options': {'packetsize': 60},
65 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
66 p.server = self.mock_ssh.SSH.from_node()
68 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
70 utils.get_port_ip(p.server, "eth1")
72 self.mock_ssh.SSH.from_node().execute.assert_called_with(
73 "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ")
75 def test_pktgen_dpdk_unsuccessful_get_port_ip(self):
78 'options': {'packetsize': 60},
81 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
82 p.server = self.mock_ssh.SSH.from_node()
84 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
85 self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1")
87 def test_pktgen_dpdk_successful_get_port_mac(self):
90 'options': {'packetsize': 60},
92 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
93 p.server = self.mock_ssh.SSH.from_node()
95 self.mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
97 utils.get_port_mac(p.server, "eth1")
99 self.mock_ssh.SSH.from_node().execute.assert_called_with(
100 "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ")
102 def test_pktgen_dpdk_unsuccessful_get_port_mac(self):
105 'options': {'packetsize': 60},
108 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
109 p.server = self.mock_ssh.SSH.from_node()
111 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
112 self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1")
114 def test_pktgen_dpdk_successful_no_sla(self):
117 'options': {'packetsize': 60},
121 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
123 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
124 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
127 # with python 3 we get float, might be due python division changes
128 # AssertionError: {'avg_latency': 132.33333333333334} != {
129 # 'avg_latency': 132}
130 delta = result['avg_latency'] - 132
131 self.assertLessEqual(delta, 1)
133 def test_pktgen_dpdk_successful_sla(self):
136 'options': {'packetsize': 60},
137 'sla': {'max_latency': 100}
141 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
143 sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
144 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
148 self.assertEqual(result, {"avg_latency": 100})
150 def test_pktgen_dpdk_unsuccessful_sla(self):
153 'options': {'packetsize': 60},
154 'sla': {'max_latency': 100}
158 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
160 p.server = self.mock_ssh.SSH.from_node()
161 p.client = self.mock_ssh.SSH.from_node()
163 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
164 self.mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
165 self.assertRaises(AssertionError, p.run, result)
167 def test_pktgen_dpdk_unsuccessful_script_error(self):
170 'options': {'packetsize': 60},
171 'sla': {'max_latency': 100}
175 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
177 self.mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
178 self.assertRaises(RuntimeError, p.run, result)
185 if __name__ == '__main__':