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
19 class PingTestCase(unittest.TestCase):
28 'key_filename': "mykey.key",
33 "key_filename": "/root/.ssh/id_rsa",
41 def test_get_controller_node(self):
43 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
44 'sla': {'max_rtt': 50}
46 p = ping6.Ping6(args, self.ctx)
47 controller_node = p._get_controller_node(['host1', 'host2'])
48 self.assertEqual(controller_node, 'host1')
50 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
51 def test_ping_successful_setup(self, mock_ssh):
53 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
54 'sla': {'max_rtt': 50}
56 p = ping6.Ping6(args, self.ctx)
57 mock_ssh.SSH.from_node().execute.return_value = (0, '0', '')
60 self.assertTrue(p.setup_done)
62 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
63 def test_ping_successful_no_sla(self, mock_ssh):
65 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
70 p = ping6.Ping6(args, self.ctx)
71 p.client = mock_ssh.SSH.from_node()
72 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
74 self.assertEqual(result, {'rtt': 100.0})
76 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
77 def test_ping_successful_sla(self, mock_ssh):
79 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
80 'sla': {'max_rtt': 150}
84 p = ping6.Ping6(args, self.ctx)
85 p.client = mock_ssh.SSH.from_node()
86 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
88 self.assertEqual(result, {'rtt': 100.0})
90 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
91 def test_ping_unsuccessful_sla(self, mock_ssh):
93 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
94 'sla': {'max_rtt': 50}
98 p = ping6.Ping6(args, self.ctx)
99 p.client = mock_ssh.SSH.from_node()
100 mock_ssh.SSH.from_node().execute.side_effect = [(0, 'host1', ''), (0, 100, '')]
101 self.assertRaises(AssertionError, p.run, result)
103 @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
104 def test_ping_unsuccessful_script_error(self, mock_ssh):
107 'options': {'host': 'host1', 'packetsize': 200, 'ping_count': 5},
108 'sla': {'max_rtt': 150}
112 p = ping6.Ping6(args, self.ctx)
113 p.client = mock_ssh.SSH.from_node()
114 mock_ssh.SSH.from_node().execute.side_effect = [
115 (0, 'host1', ''), (1, '', 'FOOBAR')]
116 self.assertRaises(RuntimeError, p.run, result)