Implementation of opnfv-yardstick-tc021 in Yardstick
[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             'host': {
25                 'ip': '172.16.0.137',
26                 'user': 'cirros',
27                 'key_filename': "mykey.key",
28                 'password': "root"
29             },
30         }
31
32     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
33     def test_pktgen_successful_setup(self, mock_ssh):
34
35         p = ping6.Ping6({}, self.ctx)
36         mock_ssh.SSH().execute.return_value = (0, '0', '')
37         p.setup()
38
39         self.assertEqual(p.setup_done, True)
40
41     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
42     def test_ping_successful_no_sla(self, mock_ssh):
43
44         result = {}
45
46         p = ping6.Ping6({}, self.ctx)
47         p.client = mock_ssh.SSH()
48         mock_ssh.SSH().execute.return_value = (0, '100', '')
49         p.run(result)
50         self.assertEqual(result, {'rtt': 100.0})
51
52     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
53     def test_ping_successful_sla(self, mock_ssh):
54
55         args = {
56             'sla': {'max_rtt': 150}
57             }
58         result = {}
59
60         p = ping6.Ping6(args, self.ctx)
61         p.client = mock_ssh.SSH()
62         mock_ssh.SSH().execute.return_value = (0, '100', '')
63         p.run(result)
64         self.assertEqual(result, {'rtt': 100.0})
65
66     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
67     def test_ping_unsuccessful_sla(self, mock_ssh):
68
69         args = {
70             'options': {'packetsize': 200},
71             'sla': {'max_rtt': 50}
72         }
73         result = {}
74
75         p = ping6.Ping6(args, self.ctx)
76         p.client = mock_ssh.SSH()
77         mock_ssh.SSH().execute.return_value = (0, '100', '')
78         self.assertRaises(AssertionError, p.run, result)
79
80     @mock.patch('yardstick.benchmark.scenarios.networking.ping6.ssh')
81     def test_ping_unsuccessful_script_error(self, mock_ssh):
82
83         args = {
84             'options': {'packetsize': 200},
85             'sla': {'max_rtt': 50}
86         }
87         result = {}
88
89         p = ping6.Ping6(args, self.ctx)
90         p.client = mock_ssh.SSH()
91         mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
92         self.assertRaises(RuntimeError, p.run, result)
93
94
95 def main():
96     unittest.main()
97
98 if __name__ == '__main__':
99     main()