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):
27 'key_filename': "mykey.key"
30 "ipaddr": "10.229.17.105",
34 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
35 def test_ping_successful_no_sla(self, mock_ssh):
38 'options': {'packetsize': 200},
43 p = ping.Ping(args, self.ctx)
45 mock_ssh.SSH().execute.return_value = (0, '100', '')
47 self.assertEqual(result, {'rtt': {'ares': 100.0}})
49 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
50 def test_ping_successful_sla(self, mock_ssh):
53 'options': {'packetsize': 200},
54 'sla': {'max_rtt': 150},
59 p = ping.Ping(args, self.ctx)
61 mock_ssh.SSH().execute.return_value = (0, '100', '')
63 self.assertEqual(result, {'rtt': {'ares': 100.0}})
65 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
66 def test_ping_unsuccessful_sla(self, mock_ssh):
69 'options': {'packetsize': 200},
70 'sla': {'max_rtt': 50},
75 p = ping.Ping(args, self.ctx)
77 mock_ssh.SSH().execute.return_value = (0, '100', '')
78 self.assertRaises(AssertionError, p.run, result)
80 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
81 def test_ping_unsuccessful_script_error(self, mock_ssh):
84 'options': {'packetsize': 200},
85 'sla': {'max_rtt': 50},
90 p = ping.Ping(args, self.ctx)
92 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
93 self.assertRaises(RuntimeError, p.run, result)
99 if __name__ == '__main__':