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
17 from yardstick.benchmark.scenarios.networking import ping6
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().execute.return_value = (0, '0', '')
61 self.assertEqual(p.setup_done, True)
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()
73 mock_ssh.SSH().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):
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()
88 mock_ssh.SSH().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):
96 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
97 'sla': {'max_rtt': 50}
101 p = ping6.Ping6(args, self.ctx)
102 p.client = mock_ssh.SSH()
103 mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
104 self.assertRaises(AssertionError, p.run, result)
106 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
107 def test_ping_unsuccessful_script_error(self, mock_ssh):
110 'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
111 'sla': {'max_rtt': 150}
115 p = ping6.Ping6(args, self.ctx)
116 p.client = mock_ssh.SSH()
117 mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(1, '', 'FOOBAR')]
118 self.assertRaises(RuntimeError, p.run, result)
124 if __name__ == '__main__':