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