add ping6 parameters
[yardstick.git] / tests / unit / benchmark / scenarios / networking / test_ping6.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 #
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 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.networking.ping.Ping
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.networking import ping6
18
19
20 class PingTestCase(unittest.TestCase):
21
22     def setUp(self):
23         self.ctx = {
24             'nodes':{
25             'host1': {
26                 'ip': '172.16.0.137',
27                 'user': 'cirros',
28                 'key_filename': "mykey.key",
29                 'password': "root"
30                 },
31             }
32         }
33
34     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
35     def test_ping_successful_setup(self, mock_ssh):
36         args = {
37             'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
38             'sla': {'max_rtt': 50}
39         }
40         p = ping6.Ping6(args, self.ctx)
41         mock_ssh.SSH().execute.return_value = (0, '0', '')
42         p.setup()
43
44         self.assertEqual(p.setup_done, True)
45
46     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
47     def test_ping_successful_no_sla(self, mock_ssh):
48         args = {
49             'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
50
51         }
52         result = {}
53
54         p = ping6.Ping6(args, self.ctx)
55         p.client = mock_ssh.SSH()
56         mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
57         p.run(result)
58         self.assertEqual(result, {'rtt': 100.0})
59
60     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
61     def test_ping_successful_sla(self, mock_ssh):
62
63         args = {
64             'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
65             'sla': {'max_rtt': 150}
66         }
67         result = {}
68
69         p = ping6.Ping6(args, self.ctx)
70         p.client = mock_ssh.SSH()
71         mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
72         p.run(result)
73         self.assertEqual(result, {'rtt': 100.0})
74
75     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
76     def test_ping_unsuccessful_sla(self, mock_ssh):
77
78         args = {
79             'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
80             'sla': {'max_rtt': 50}
81         }
82         result = {}
83
84         p = ping6.Ping6(args, self.ctx)
85         p.client = mock_ssh.SSH()
86         mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(0, 100, '')]
87         self.assertRaises(AssertionError, p.run, result)
88
89     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
90     def test_ping_unsuccessful_script_error(self, mock_ssh):
91
92         args = {
93             'options': {'host': 'host1','packetsize': 200, 'ping_count': 5},
94             'sla': {'max_rtt': 150}
95         }
96         result = {}
97
98         p = ping6.Ping6(args, self.ctx)
99         p.client = mock_ssh.SSH()
100         mock_ssh.SSH().execute.side_effect = [(0, 'host1', ''),(1, '', 'FOOBAR')]
101         self.assertRaises(RuntimeError, p.run, result)
102
103
104 def main():
105     unittest.main()
106
107 if __name__ == '__main__':
108     main()