Bug fix and extended unit tests
[yardstick.git] / tests / unit / benchmark / scenarios / networking / test_sfc.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.sfc
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.scenarios.networking import sfc
18
19
20 class SfcTestCase(unittest.TestCase):
21
22     def setUp(self):
23         scenario_cfg = dict()
24         context_cfg = dict()
25
26         # Used in Sfc.setup()
27         context_cfg['target'] = dict()
28         context_cfg['target']['user'] = 'root'
29         context_cfg['target']['password'] = 'opnfv'
30         context_cfg['target']['ip'] = '127.0.0.1' 
31
32         # Used in Sfc.run()
33         context_cfg['host'] = dict()
34         context_cfg['host']['user'] = 'root'
35         context_cfg['host']['password'] = 'opnfv'
36         context_cfg['host']['ip'] = None
37         context_cfg['target'] = dict()
38         context_cfg['target']['ip'] = '127.0.0.1'
39
40         self.sfc = sfc.Sfc(scenario_cfg=scenario_cfg, context_cfg=context_cfg)
41
42     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.ssh')
43     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.sfc_openstack')
44     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess')
45     def test_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh):
46         # Mock a successfull SSH in Sfc.setup() and Sfc.run()
47         mock_ssh.SSH().execute.return_value = (0, '100', '')
48         mock_openstack.get_an_IP.return_value = "127.0.0.1"
49         mock_subprocess.call.return_value = 'mocked!'
50
51         result = {}
52         self.sfc.setup()
53         self.sfc.run(result)
54         self.sfc.teardown()
55
56     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.ssh')
57     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.sfc_openstack')
58     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess')
59     def test2_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh):
60         # Mock a successfull SSH in Sfc.setup() and Sfc.run()
61         mock_ssh.SSH().execute.return_value = (0, 'vxlan_tool.py', 'succeeded timed out')
62         mock_openstack.get_an_IP.return_value = "127.0.0.1"
63         mock_subprocess.call.return_value = 'mocked!'
64
65         result = {}
66         self.sfc.setup()
67         self.sfc.run(result)
68         self.sfc.teardown()
69
70
71 def main():
72     unittest.main()
73
74 if __name__ == '__main__':
75     main()