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