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 ping6
17 from yardstick.common import exceptions as y_exc
20 class PingTestCase(unittest.TestCase):
29 'key_filename': "mykey.key",
34 "key_filename": "/root/.ssh/id_rsa",
42 def test_get_controller_node(self):
44 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
45 'sla': {'max_rtt': 50}
47 p = ping6.Ping6(args, self.ctx)
48 controller_node = p._get_controller_node(['host1', 'host2'])
49 self.assertEqual(controller_node, 'host1')
51 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
52 def test_ping_successful_setup(self, mock_ssh):
54 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
55 'sla': {'max_rtt': 50}
57 p = ping6.Ping6(args, self.ctx)
58 mock_ssh.SSH.from_node().execute.return_value = (0, '0', '')
61 self.assertTrue(p.setup_done)
63 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
64 def test_ping_successful_no_sla(self, mock_ssh):
66 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
71 p = ping6.Ping6(args, self.ctx)
72 p.client = mock_ssh.SSH.from_node()
73 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
75 self.assertEqual(result, {'rtt': 100.0})
77 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
78 def test_ping_successful_sla(self, mock_ssh):
80 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
81 'sla': {'max_rtt': 150}
85 p = ping6.Ping6(args, self.ctx)
86 p.client = mock_ssh.SSH.from_node()
87 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
89 self.assertEqual(result, {'rtt': 100.0})
91 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
92 def test_ping_unsuccessful_sla(self, mock_ssh):
94 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
95 'sla': {'max_rtt': 50}
99 p = ping6.Ping6(args, self.ctx)
100 p.client = mock_ssh.SSH.from_node()
101 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
102 self.assertRaises(y_exc.SLAValidationError, p.run, result)
104 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
105 def test_ping_unsuccessful_script_error(self, mock_ssh):
108 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
109 'sla': {'max_rtt': 150}
113 p = ping6.Ping6(args, self.ctx)
114 p.client = mock_ssh.SSH.from_node()
115 mock_ssh.SSH.from_node().execute.side_effect = [
116 (0, 'host1', ''), (1, '', 'FOOBAR')]
117 self.assertRaises(RuntimeError, p.run, result)