Merge "Fix report generation"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / networking / test_sfc.py
1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 #
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 ##############################################################################
9
10 # Unittest for yardstick.benchmark.scenarios.networking.sfc
11
12 from __future__ import absolute_import
13 import mock
14 import unittest
15
16 from yardstick.benchmark.scenarios.networking import sfc
17
18
19 class SfcTestCase(unittest.TestCase):
20
21     def setUp(self):
22         scenario_cfg = {}
23         context_cfg = {
24             # Used in Sfc.setup()
25             'target': {
26                 'user': 'root',
27                 'password': 'opnfv',
28                 'ip': '127.0.0.1',
29             },
30
31             # Used in Sfc.run()
32             'host': {
33                 'user': 'root',
34                 'password': 'opnfv',
35                 'ip': None,
36             }
37         }
38
39         self.sfc = sfc.Sfc(scenario_cfg=scenario_cfg, context_cfg=context_cfg)
40
41     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.ssh')
42     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.sfc_openstack')
43     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess')
44     def test_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh):
45         # Mock a successfull SSH in Sfc.setup() and Sfc.run()
46         mock_ssh.SSH.from_node().execute.return_value = (0, '100', '')
47         mock_openstack.get_an_IP.return_value = "127.0.0.1"
48         mock_subprocess.call.return_value = 'mocked!'
49
50         result = {}
51         self.sfc.setup()
52         self.sfc.run(result)
53         self.sfc.teardown()
54
55     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.ssh')
56     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.sfc_openstack')
57     @mock.patch('yardstick.benchmark.scenarios.networking.sfc.subprocess')
58     def test2_run_for_success(self, mock_subprocess, mock_openstack, mock_ssh):
59         # Mock a successfull SSH in Sfc.setup() and Sfc.run()
60         mock_ssh.SSH.from_node().execute.return_value = (
61             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()