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):
28 'key_filename': "mykey.key",
34 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
35 def test_ping_successful_setup(self, mock_ssh):
37 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
38 'sla': {'max_rtt': 50}
40 p = ping6.Ping6(args, self.ctx)
41 mock_ssh.SSH().execute.return_value = (0, '0', '')
44 self.assertEqual(p.setup_done, True)
46 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
47 def test_ping_successful_no_sla(self, mock_ssh):
49 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
54 p = ping6.Ping6(args, self.ctx)
55 p.client = mock_ssh.SSH()
56 mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
58 self.assertEqual(result, {'rtt': 100.0})
60 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
61 def test_ping_successful_sla(self, mock_ssh):
64 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
65 'sla': {'max_rtt': 150}
69 p = ping6.Ping6(args, self.ctx)
70 p.client = mock_ssh.SSH()
71 mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
73 self.assertEqual(result, {'rtt': 100.0})
75 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
76 def test_ping_unsuccessful_sla(self, mock_ssh):
79 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
80 'sla': {'max_rtt': 50}
84 p = ping6.Ping6(args, self.ctx)
85 p.client = mock_ssh.SSH()
86 mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
87 self.assertRaises(AssertionError, p.run, result)
89 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
90 def test_ping_unsuccessful_script_error(self, mock_ssh):
93 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
94 'sla': {'max_rtt': 150}
98 p = ping6.Ping6(args, self.ctx)
99 p.client = mock_ssh.SSH()
100 mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(1, '', 'FOOBAR')]
101 self.assertRaises(RuntimeError, p.run, result)
107 if __name__ == '__main__':