2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3
# not use this file except in compliance with the License. You may obtain
4
# a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
# License for the specific language governing permissions and limitations
15
Test class for iRMC Management Driver
19
import xml.etree.ElementTree as ET
23
from ironic.common import boot_devices
24
from ironic.common import driver_factory
25
from ironic.common import exception
26
from ironic.conductor import task_manager
27
from ironic.drivers.modules import ipmitool
28
from ironic.drivers.modules.irmc import common as irmc_common
29
from ironic.drivers.modules.irmc import management as irmc_management
30
from ironic.drivers import utils as driver_utils
31
from ironic.tests.conductor import utils as mgr_utils
32
from ironic.tests.db import base as db_base
33
from ironic.tests.db import utils as db_utils
34
from ironic.tests.objects import utils as obj_utils
36
INFO_DICT = db_utils.get_test_irmc_info()
39
class IRMCManagementTestCase(db_base.DbTestCase):
41
super(IRMCManagementTestCase, self).setUp()
42
driver_info = INFO_DICT
44
mgr_utils.mock_the_extension_manager(driver="fake_irmc")
45
self.driver = driver_factory.get_driver("fake_irmc")
46
self.node = obj_utils.create_test_node(self.context,
48
driver_info=driver_info)
49
self.info = irmc_common.parse_driver_info(self.node)
51
def test_get_properties(self):
52
expected = irmc_common.COMMON_PROPERTIES
53
expected.update(ipmitool.COMMON_PROPERTIES)
54
expected.update(ipmitool.CONSOLE_PROPERTIES)
55
with task_manager.acquire(self.context, self.node.uuid,
57
self.assertEqual(expected, task.driver.get_properties())
59
@mock.patch.object(irmc_common, 'parse_driver_info')
60
def test_validate(self, mock_drvinfo):
61
with task_manager.acquire(self.context, self.node.uuid,
63
task.driver.management.validate(task)
64
mock_drvinfo.assert_called_once_with(task.node)
66
@mock.patch.object(irmc_common, 'parse_driver_info')
67
def test_validate_fail(self, mock_drvinfo):
68
side_effect = exception.InvalidParameterValue("Invalid Input")
69
mock_drvinfo.side_effect = side_effect
70
with task_manager.acquire(self.context, self.node.uuid,
72
self.assertRaises(exception.InvalidParameterValue,
73
task.driver.management.validate,
76
def test_management_interface_get_supported_boot_devices(self):
77
with task_manager.acquire(self.context, self.node.uuid) as task:
78
expected = [boot_devices.PXE, boot_devices.DISK,
79
boot_devices.CDROM, boot_devices.BIOS,
81
self.assertEqual(sorted(expected), sorted(task.driver.management.
82
get_supported_boot_devices()))
84
@mock.patch.object(ipmitool.IPMIManagement, 'set_boot_device')
85
def test_management_interface_set_boot_device_no_mode_ok(
87
set_boot_device_mock):
88
"""no boot mode specified."""
89
with task_manager.acquire(self.context, self.node.uuid,
90
shared=False) as task:
91
task.driver.management.set_boot_device(task, boot_devices.PXE)
92
set_boot_device_mock.assert_called_once_with(
97
@mock.patch.object(ipmitool.IPMIManagement, 'set_boot_device')
98
def test_management_interface_set_boot_device_bios_ok(
100
set_boot_device_mock):
101
"""bios mode specified."""
102
with task_manager.acquire(self.context, self.node.uuid) as task:
103
driver_utils.add_node_capability(task, 'boot_mode', 'bios')
104
task.driver.management.set_boot_device(task, boot_devices.PXE)
105
set_boot_device_mock.assert_called_once_with(
110
@mock.patch.object(irmc_management.ipmitool, "send_raw", autospec=True)
111
def _test_management_interface_set_boot_device_uefi_ok(self, params,
114
send_raw_mock.return_value = [None, None]
116
with task_manager.acquire(self.context, self.node.uuid) as task:
117
task.node.properties['capabilities'] = ''
118
driver_utils.add_node_capability(task, 'boot_mode', 'uefi')
119
self.driver.management.set_boot_device(task, **params)
120
send_raw_mock.assert_has_calls([
121
mock.call(task, "0x00 0x08 0x03 0x08"),
122
mock.call(task, expected_raw_code)])
124
def test_management_interface_set_boot_device_uefi_ok_pxe(self):
125
params = {'device': boot_devices.PXE, 'persistent': False}
126
self._test_management_interface_set_boot_device_uefi_ok(
128
"0x00 0x08 0x05 0xa0 0x04 0x00 0x00 0x00")
130
params['persistent'] = True
131
self._test_management_interface_set_boot_device_uefi_ok(
133
"0x00 0x08 0x05 0xe0 0x04 0x00 0x00 0x00")
135
def test_management_interface_set_boot_device_uefi_ok_disk(self):
136
params = {'device': boot_devices.DISK, 'persistent': False}
137
self._test_management_interface_set_boot_device_uefi_ok(
139
"0x00 0x08 0x05 0xa0 0x08 0x00 0x00 0x00")
141
params['persistent'] = True
142
self._test_management_interface_set_boot_device_uefi_ok(
144
"0x00 0x08 0x05 0xe0 0x08 0x00 0x00 0x00")
146
def test_management_interface_set_boot_device_uefi_ok_cdrom(self):
147
params = {'device': boot_devices.CDROM, 'persistent': False}
148
self._test_management_interface_set_boot_device_uefi_ok(
150
"0x00 0x08 0x05 0xa0 0x14 0x00 0x00 0x00")
152
params['persistent'] = True
153
self._test_management_interface_set_boot_device_uefi_ok(
155
"0x00 0x08 0x05 0xe0 0x14 0x00 0x00 0x00")
157
def test_management_interface_set_boot_device_uefi_ok_bios(self):
158
params = {'device': boot_devices.BIOS, 'persistent': False}
159
self._test_management_interface_set_boot_device_uefi_ok(
161
"0x00 0x08 0x05 0xa0 0x18 0x00 0x00 0x00")
163
params['persistent'] = True
164
self._test_management_interface_set_boot_device_uefi_ok(
166
"0x00 0x08 0x05 0xe0 0x18 0x00 0x00 0x00")
168
def test_management_interface_set_boot_device_uefi_ok_safe(self):
169
params = {'device': boot_devices.SAFE, 'persistent': False}
170
self._test_management_interface_set_boot_device_uefi_ok(
172
"0x00 0x08 0x05 0xa0 0x0c 0x00 0x00 0x00")
174
params['persistent'] = True
175
self._test_management_interface_set_boot_device_uefi_ok(
177
"0x00 0x08 0x05 0xe0 0x0c 0x00 0x00 0x00")
179
@mock.patch.object(irmc_management.ipmitool, "send_raw", autospec=True)
180
def test_management_interface_set_boot_device_uefi_ng(self,
182
"""uefi mode, next boot only, unknown device."""
183
send_raw_mock.return_value = [None, None]
185
with task_manager.acquire(self.context, self.node.uuid) as task:
186
driver_utils.add_node_capability(task, 'boot_mode', 'uefi')
187
self.assertRaises(exception.InvalidParameterValue,
188
self.driver.management.set_boot_device,
192
@mock.patch.object(irmc_management, 'scci')
193
@mock.patch.object(irmc_common, 'get_irmc_report')
194
def test_management_interface_get_sensors_data_scci_ok(self,
195
mock_get_irmc_report,
197
"""'irmc_sensor_method' = 'scci' specified and OK data."""
198
with open(os.path.join(os.path.dirname(__file__),
199
'fake_sensors_data_ok.xml'), "r") as report:
200
fake_txt = report.read()
201
fake_xml = ET.fromstring(fake_txt)
203
mock_get_irmc_report.return_value = fake_xml
204
mock_scci.get_sensor_data.return_value = fake_xml.find(
205
"./System/SensorDataRecords")
207
with task_manager.acquire(self.context, self.node.uuid) as task:
208
task.node.driver_info['irmc_sensor_method'] = 'scci'
209
sensor_dict = self.driver.management.get_sensors_data(task)
215
'Sensor ID': 'FAN1 SYS (29)',
216
'Sensor Reading': '600 RPM'
220
'Sensor ID': 'FAN2 SYS (29)',
221
'Sensor Reading': 'None None'
225
'Systemboard 1 (7)': {
227
'Sensor ID': 'Systemboard 1 (7)',
228
'Sensor Reading': '80 degree C'
232
'Sensor ID': 'Ambient (55)',
233
'Sensor Reading': '42 degree C'
237
self.assertEqual(expected, sensor_dict)
239
@mock.patch.object(irmc_management, 'scci')
240
@mock.patch.object(irmc_common, 'get_irmc_report')
241
def test_management_interface_get_sensors_data_scci_ng(self,
242
mock_get_irmc_report,
244
"""'irmc_sensor_method' = 'scci' specified and NG data."""
245
with open(os.path.join(os.path.dirname(__file__),
246
'fake_sensors_data_ng.xml'), "r") as report:
247
fake_txt = report.read()
248
fake_xml = ET.fromstring(fake_txt)
250
mock_get_irmc_report.return_value = fake_xml
251
mock_scci.get_sensor_data.return_value = fake_xml.find(
252
"./System/SensorDataRecords")
254
with task_manager.acquire(self.context, self.node.uuid) as task:
255
task.node.driver_info['irmc_sensor_method'] = 'scci'
256
sensor_dict = self.driver.management.get_sensors_data(task)
258
self.assertEqual(len(sensor_dict), 0)
260
@mock.patch.object(ipmitool.IPMIManagement, 'get_sensors_data')
261
def test_management_interface_get_sensors_data_ipmitool_ok(
263
get_sensors_data_mock):
264
"""'irmc_sensor_method' = 'ipmitool' specified."""
265
with task_manager.acquire(self.context, self.node.uuid) as task:
266
task.node.driver_info['irmc_sensor_method'] = 'ipmitool'
267
task.driver.management.get_sensors_data(task)
268
get_sensors_data_mock.assert_called_once_with(task)
270
@mock.patch.object(irmc_common, 'get_irmc_report')
271
def test_management_interface_get_sensors_data_exception1(
273
get_irmc_report_mock):
274
"""'FailedToGetSensorData Exception."""
276
get_irmc_report_mock.side_effect = Exception("Report Error")
278
with task_manager.acquire(self.context, self.node.uuid) as task:
279
task.node.driver_info['irmc_sensor_method'] = 'scci'
280
e = self.assertRaises(exception.FailedToGetSensorData,
281
self.driver.management.get_sensors_data,
283
self.assertEqual("Failed to get sensor data for node 1be26c0b-" +
284
"03f2-4d2e-ae87-c02d7f33c123. Error: Report Error",