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},
42 p = ping.Ping(args, self.ctx)
44 mock_ssh.SSH().execute.return_value = (0, '100', '')
46 self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
48 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
49 def test_ping_successful_sla(self, mock_ssh):
52 'options': {'packetsize': 200},
53 'sla': {'max_rtt': 150}
57 p = ping.Ping(args, self.ctx)
59 mock_ssh.SSH().execute.return_value = (0, '100', '')
61 self.assertEqual(result, {'rtt': {'10.229.17.105': 100.0}})
63 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
64 def test_ping_unsuccessful_sla(self, mock_ssh):
67 'options': {'packetsize': 200},
68 'sla': {'max_rtt': 50}
72 p = ping.Ping(args, self.ctx)
74 mock_ssh.SSH().execute.return_value = (0, '100', '')
75 self.assertRaises(AssertionError, p.run, result)
77 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
78 def test_ping_unsuccessful_script_error(self, mock_ssh):
81 'options': {'packetsize': 200},
82 'sla': {'max_rtt': 50}
86 p = ping.Ping(args, self.ctx)
88 mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
89 self.assertRaises(RuntimeError, p.run, result)
95 if __name__ == '__main__':