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'
40 mock_ssh.SSH().execute.return_value = (0, '100', '')
42 self.assertEqual(result, {'rtt': 100.0})
44 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
45 def test_ping_successful_sla(self, mock_ssh):
47 p = ping.Ping(self.ctx)
50 'options': {'packetsize': 200},
51 'ipaddr': '172.16.0.138',
52 'sla': {'max_rtt': 150}
56 mock_ssh.SSH().execute.return_value = (0, '100', '')
58 self.assertEqual(result, {'rtt': 100.0})
60 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
61 def test_ping_unsuccessful_sla(self, mock_ssh):
63 p = ping.Ping(self.ctx)
66 'options': {'packetsize': 200},
67 'ipaddr': '172.16.0.138',
68 'sla': {'max_rtt': 50}
72 mock_ssh.SSH().execute.return_value = (0, '100', '')
73 self.assertRaises(AssertionError, p.run, args, result)
75 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
76 def test_ping_unsuccessful_script_error(self, mock_ssh):
78 p = ping.Ping(self.ctx)
81 'options': {'packetsize': 200},
82 'ipaddr': '172.16.0.138',
83 'sla': {'max_rtt': 50}
87 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
88 self.assertRaises(RuntimeError, p.run, args, result)
94 if __name__ == '__main__':