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
14 from __future__ import absolute_import
18 from yardstick.benchmark.scenarios.networking import ping
21 class PingTestCase(unittest.TestCase):
28 'key_filename': "mykey.key"
31 "ipaddr": "10.229.17.105",
35 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
36 def test_ping_successful_no_sla(self, mock_ssh):
39 'options': {'packetsize': 200},
44 p = ping.Ping(args, self.ctx)
46 mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
48 self.assertEqual(result, {'rtt.ares': 100.0})
50 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
51 def test_ping_successful_sla(self, mock_ssh):
54 'options': {'packetsize': 200},
55 'sla': {'max_rtt': 150},
60 p = ping.Ping(args, self.ctx)
62 mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
64 self.assertEqual(result, {'rtt.ares': 100.0})
66 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
67 def test_ping_unsuccessful_sla(self, mock_ssh):
70 'options': {'packetsize': 200},
71 'sla': {'max_rtt': 50},
76 p = ping.Ping(args, self.ctx)
78 mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
79 self.assertRaises(AssertionError, p.run, result)
81 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
82 def test_ping_unsuccessful_script_error(self, mock_ssh):
85 'options': {'packetsize': 200},
86 'sla': {'max_rtt': 50},
91 p = ping.Ping(args, self.ctx)
93 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
94 self.assertRaises(RuntimeError, p.run, result)
100 if __name__ == '__main__':