1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 # Unittest for yardstick.benchmark.scenarios.networking.ping.Ping
12 from __future__ import absolute_import
16 from yardstick.benchmark.scenarios.networking import ping
17 from yardstick.common import exceptions as y_exc
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.from_node().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.from_node().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.from_node().execute.return_value = (0, '100', '')
78 self.assertRaises(y_exc.SLAValidationError, 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.from_node().execute.return_value = (1, '', 'FOOBAR')
93 self.assertRaises(RuntimeError, p.run, result)