3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB 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.ping.Ping
17 from yardstick.benchmark.scenarios.networking import ping6
20 class PingTestCase(unittest.TestCase):
27 'key_filename': "mykey.key",
32 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
33 def test_pktgen_successful_setup(self, mock_ssh):
35 p = ping6.Ping6({}, self.ctx)
36 mock_ssh.SSH().execute.return_value = (0, '0', '')
39 self.assertEqual(p.setup_done, True)
41 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
42 def test_ping_successful_no_sla(self, mock_ssh):
46 p = ping6.Ping6({}, self.ctx)
47 p.client = mock_ssh.SSH()
48 mock_ssh.SSH().execute.return_value = (0, '100', '')
50 self.assertEqual(result, {'rtt': 100.0})
52 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
53 def test_ping_successful_sla(self, mock_ssh):
56 'sla': {'max_rtt': 150}
60 p = ping6.Ping6(args, self.ctx)
61 p.client = mock_ssh.SSH()
62 mock_ssh.SSH().execute.return_value = (0, '100', '')
64 self.assertEqual(result, {'rtt': 100.0})
66 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
67 def test_ping_unsuccessful_sla(self, mock_ssh):
70 'options': {'packetsize': 200},
71 'sla': {'max_rtt': 50}
75 p = ping6.Ping6(args, self.ctx)
76 p.client = mock_ssh.SSH()
77 mock_ssh.SSH().execute.return_value = (0, '100', '')
78 self.assertRaises(AssertionError, p.run, result)
80 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
81 def test_ping_unsuccessful_script_error(self, mock_ssh):
84 'options': {'packetsize': 200},
85 'sla': {'max_rtt': 50}
89 p = ping6.Ping6(args, self.ctx)
90 p.client = mock_ssh.SSH()
91 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
92 self.assertRaises(RuntimeError, p.run, result)
98 if __name__ == '__main__':