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 ping6
21 class PingTestCase(unittest.TestCase):
30 'key_filename': "mykey.key",
35 "key_filename": "/root/.ssh/id_rsa",
43 def test_get_controller_node(self):
45 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
46 'sla': {'max_rtt': 50}
48 p = ping6.Ping6(args, self.ctx)
49 controller_node = p._get_controller_node(['host1', 'host2'])
50 self.assertEqual(controller_node, 'host1')
52 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
53 def test_ping_successful_setup(self, mock_ssh):
55 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
56 'sla': {'max_rtt': 50}
58 p = ping6.Ping6(args, self.ctx)
59 mock_ssh.SSH.from_node().execute.return_value = (0, '0', '')
62 self.assertTrue(p.setup_done)
64 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
65 def test_ping_successful_no_sla(self, mock_ssh):
67 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
72 p = ping6.Ping6(args, self.ctx)
73 p.client = mock_ssh.SSH.from_node()
74 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
76 self.assertEqual(result, {'rtt': 100.0})
78 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
79 def test_ping_successful_sla(self, mock_ssh):
81 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
82 'sla': {'max_rtt': 150}
86 p = ping6.Ping6(args, self.ctx)
87 p.client = mock_ssh.SSH.from_node()
88 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
90 self.assertEqual(result, {'rtt': 100.0})
92 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
93 def test_ping_unsuccessful_sla(self, mock_ssh):
95 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
96 'sla': {'max_rtt': 50}
100 p = ping6.Ping6(args, self.ctx)
101 p.client = mock_ssh.SSH.from_node()
102 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
103 self.assertRaises(AssertionError, p.run, result)
105 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
106 def test_ping_unsuccessful_script_error(self, mock_ssh):
109 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
110 'sla': {'max_rtt': 150}
114 p = ping6.Ping6(args, self.ctx)
115 p.client = mock_ssh.SSH.from_node()
116 mock_ssh.SSH.from_node().execute.side_effect = [
117 (0, 'host1', ''), (1, '', 'FOOBAR')]
118 self.assertRaises(RuntimeError, p.run, result)
124 if __name__ == '__main__':