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
19 class PingTestCase(unittest.TestCase):
26 'key_filename': "mykey.key"
29 "ipaddr": "10.229.17.105",
33 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
34 def test_ping_successful_no_sla(self, mock_ssh):
37 'options': {'packetsize': 200},
42 p = ping.Ping(args, self.ctx)
44 mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
46 self.assertEqual(result, {'rtt.ares': 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},
58 p = ping.Ping(args, self.ctx)
60 mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
62 self.assertEqual(result, {'rtt.ares': 100.0})
64 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
65 def test_ping_unsuccessful_sla(self, mock_ssh):
68 'options': {'packetsize': 200},
69 'sla': {'max_rtt': 50},
74 p = ping.Ping(args, self.ctx)
76 mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
77 self.assertRaises(AssertionError, p.run, result)
79 @mock.patch('yardstick.benchmark.scenarios.networking.ping.ssh')
80 def test_ping_unsuccessful_script_error(self, mock_ssh):
83 'options': {'packetsize': 200},
84 'sla': {'max_rtt': 50},
89 p = ping.Ping(args, self.ctx)
91 mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
92 self.assertRaises(RuntimeError, p.run, result)