Merge "Remove tool provisioning from DpdkVnfSetupEnvHelper._setup_dpdk"
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / lib / test_get_numa_info.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd 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 import unittest
10 import mock
11
12 from yardstick.benchmark.scenarios.lib.get_numa_info import GetNumaInfo
13
14
15 # pylint: disable=unused-argument
16 # disable this for now because I keep forgetting mock patch arg ordering
17
18
19 BASE = 'yardstick.benchmark.scenarios.lib.get_numa_info'
20
21
22 class GetNumaInfoTestCase(unittest.TestCase):
23
24     @mock.patch('{}.GetNumaInfo._check_numa_node'.format(BASE))
25     @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE))
26     @mock.patch('yardstick.benchmark.scenarios.lib.get_numa_info.yaml_load')
27     @mock.patch('yardstick.common.task_template.TaskTemplate.render')
28     def test_get_numa_info(self,
29                            mock_render,
30                            mock_safe_load,
31                            mock_get_current_host_name,
32                            mock_check_numa_node):
33         scenario_cfg = {
34             'options': {
35                 'server': {
36                     'id': '1'
37                 },
38                 'file': 'yardstick/ssh.py'
39             },
40             'output': 'numa_info'
41         }
42         mock_safe_load.return_value = {
43             'nodes': []
44         }
45         obj = GetNumaInfo(scenario_cfg, {})
46         obj.run({})
47         self.assertTrue(mock_get_current_host_name.called)
48         self.assertTrue(mock_check_numa_node.called)
49
50     @mock.patch('yardstick.ssh.SSH.from_node')
51     @mock.patch('{}.GetNumaInfo._get_current_host_name'.format(BASE))
52     @mock.patch('yardstick.benchmark.scenarios.lib.get_numa_info.yaml_load')
53     @mock.patch('yardstick.common.task_template.TaskTemplate.render')
54     def test_check_numa_node(self,
55                              mock_render,
56                              mock_safe_load,
57                              mock_get_current_host_name,
58                              mock_from_node):
59         scenario_cfg = {
60             'options': {
61                 'server': {
62                     'id': '1'
63                 },
64                 'file': 'yardstick/ssh.py'
65             },
66             'output': 'numa_info'
67         }
68         mock_safe_load.return_value = {
69             'nodes': []
70         }
71         data = """
72         <data>
73         </data>
74         """
75         mock_from_node().execute.return_value = (0, data, '')
76         obj = GetNumaInfo(scenario_cfg, {})
77         result = obj._check_numa_node('1', 'host4')
78         self.assertEqual(result, {'pinning': [], 'vcpupin': []})
79
80     @mock.patch('{}.change_obj_to_dict'.format(BASE))
81     @mock.patch('{}.get_nova_client'.format(BASE))
82     @mock.patch('yardstick.benchmark.scenarios.lib.get_numa_info.yaml_load')
83     @mock.patch('yardstick.common.task_template.TaskTemplate.render')
84     def test_get_current_host_name(self,
85                                    mock_render,
86                                    mock_safe_load,
87                                    mock_get_nova_client,
88                                    mock_change_obj_to_dict):
89         scenario_cfg = {
90             'options': {
91                 'server': {
92                     'id': '1'
93                 },
94                 'file': 'yardstick/ssh.py'
95             },
96             'output': 'numa_info'
97         }
98         mock_get_nova_client().servers.get.return_value = ''
99         mock_change_obj_to_dict.return_value = {'OS-EXT-SRV-ATTR:host': 'host5'}
100
101         obj = GetNumaInfo(scenario_cfg, {})
102         result = obj._get_current_host_name('1')
103         self.assertEqual(result, 'host5')
104
105
106 def main():
107     unittest.main()
108
109
110 if __name__ == '__main__':
111     main()