3 ##############################################################################
4 # Copyright (c) 2015 ZTE and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
12 # Unittest for yardstick.benchmark.scenarios.networking.pktgen.Pktgen
14 from __future__ import absolute_import
19 import yardstick.common.utils as utils
20 from yardstick.benchmark.scenarios.networking import pktgen_dpdk
23 @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.time')
24 @mock.patch('yardstick.benchmark.scenarios.networking.pktgen_dpdk.ssh')
25 class PktgenDPDKLatencyTestCase(unittest.TestCase):
32 'key_filename': 'mykey.key'
37 'key_filename': 'mykey.key',
38 'ipaddr': '172.16.0.138'
42 def test_pktgen_dpdk_successful_setup(self, mock_ssh, mock_time):
45 'options': {'packetsize': 60},
47 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
50 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
51 self.assertIsNotNone(p.server)
52 self.assertIsNotNone(p.client)
53 self.assertEqual(p.setup_done, True)
55 def test_pktgen_dpdk_successful_get_port_ip(self, mock_ssh, mock_time):
58 'options': {'packetsize': 60},
60 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
61 p.server = mock_ssh.SSH.from_node()
63 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
65 utils.get_port_ip(p.server, "eth1")
67 mock_ssh.SSH.from_node().execute.assert_called_with(
68 "ifconfig eth1 |grep 'inet addr' |awk '{print $2}' |cut -d ':' -f2 ")
70 def test_pktgen_dpdk_unsuccessful_get_port_ip(self, mock_ssh, mock_time):
73 'options': {'packetsize': 60},
76 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
77 p.server = mock_ssh.SSH.from_node()
79 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
80 self.assertRaises(RuntimeError, utils.get_port_ip, p.server, "eth1")
82 def test_pktgen_dpdk_successful_get_port_mac(self, mock_ssh, mock_time):
85 'options': {'packetsize': 60},
87 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
88 p.server = mock_ssh.SSH.from_node()
90 mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
92 utils.get_port_mac(p.server, "eth1")
94 mock_ssh.SSH.from_node().execute.assert_called_with(
95 "ifconfig |grep HWaddr |grep eth1 |awk '{print $5}' ")
97 def test_pktgen_dpdk_unsuccessful_get_port_mac(self, mock_ssh, mock_time):
100 'options': {'packetsize': 60},
103 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
104 p.server = mock_ssh.SSH.from_node()
106 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
107 self.assertRaises(RuntimeError, utils.get_port_mac, p.server, "eth1")
109 def test_pktgen_dpdk_successful_no_sla(self, mock_ssh, mock_time):
112 'options': {'packetsize': 60},
116 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
118 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
119 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
122 # with python 3 we get float, might be due python division changes
123 # AssertionError: {'avg_latency': 132.33333333333334} != {
124 # 'avg_latency': 132}
125 delta = result['avg_latency'] - 132
126 self.assertLessEqual(delta, 1)
128 def test_pktgen_dpdk_successful_sla(self, mock_ssh, mock_time):
131 'options': {'packetsize': 60},
132 'sla': {'max_latency': 100}
136 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
138 sample_output = '100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n'
139 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
143 self.assertEqual(result, {"avg_latency": 100})
145 def test_pktgen_dpdk_unsuccessful_sla(self, mock_ssh, mock_time):
148 'options': {'packetsize': 60},
149 'sla': {'max_latency': 100}
153 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
155 p.server = mock_ssh.SSH.from_node()
156 p.client = mock_ssh.SSH.from_node()
158 sample_output = '100\n110\n112\n130\n149\n150\n90\n150\n200\n162\n'
159 mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
160 self.assertRaises(AssertionError, p.run, result)
162 def test_pktgen_dpdk_unsuccessful_script_error(self, mock_ssh, mock_time):
165 'options': {'packetsize': 60},
166 'sla': {'max_latency': 100}
170 p = pktgen_dpdk.PktgenDPDKLatency(args, self.ctx)
172 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
173 self.assertRaises(RuntimeError, p.run, result)
180 if __name__ == '__main__':