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 ping
20 class PingTestCase(unittest.TestCase):
24 'host': '172.16.0.137',
26 'key_filename': "mykey.key"
29 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
30 def test_ping_successful_no_sla(self, mock_ssh):
32 p = ping.Ping(self.ctx)
35 'options': {'packetsize': 200},
36 'ipaddr': '172.16.0.138'
39 mock_ssh.SSH().execute.return_value = (0, '100', '')
41 self.assertEqual(result, float(mock_ssh.SSH().execute.return_value[1]))
43 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
44 def test_ping_successful_sla(self, mock_ssh):
46 p = ping.Ping(self.ctx)
49 'options': {'packetsize': 200},
50 'ipaddr': '172.16.0.138',
51 'sla': {'max_rtt': 150}
54 mock_ssh.SSH().execute.return_value = (0, '100', '')
56 self.assertEqual(result, float(mock_ssh.SSH().execute.return_value[1]))
58 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
59 def test_ping_unsuccessful_sla(self, mock_ssh):
61 p = ping.Ping(self.ctx)
64 'options': {'packetsize': 200},
65 'ipaddr': '172.16.0.138',
66 'sla': {'max_rtt': 50}
69 mock_ssh.SSH().execute.return_value = (0, '100', '')
70 self.assertRaises(AssertionError, p.run, args)
72 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
73 def test_ping_unsuccessful_script_error(self, mock_ssh):
75 p = ping.Ping(self.ctx)
78 'options': {'packetsize': 200},
79 'ipaddr': '172.16.0.138',
80 'sla': {'max_rtt': 50}
83 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
84 self.assertRaises(RuntimeError, p.run, args)
90 if __name__ == '__main__':