diff options
Diffstat (limited to 'ironic/tests/unit/drivers/modules')
3 files changed, 421 insertions, 21 deletions
diff --git a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py index da91ec61d..2cec2429f 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_inspect.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_inspect.py @@ -64,13 +64,16 @@ class IRMCInspectInternalMethodsTestCase(test_common.BaseIRMCTest): @mock.patch.object(irmc_inspect, '_get_mac_addresses', spec_set=True, autospec=True) - @mock.patch.object(irmc_inspect, 'scci', + @mock.patch.object(irmc_inspect.irmc, 'scci', spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, autospec=True) - def test__inspect_hardware( + def test__inspect_hardware_ipmi( self, get_irmc_report_mock, scci_mock, _get_mac_addresses_mock): # Set config flags + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + gpu_ids = ['0x1000/0x0079', '0x2100/0x0080'] cpu_fpgas = ['0x1000/0x0179', '0x2100/0x0180'] self.config(gpu_ids=gpu_ids, group='irmc') @@ -117,9 +120,68 @@ class IRMCInspectInternalMethodsTestCase(test_common.BaseIRMCTest): self.assertEqual((expected_props, inspected_macs, new_traits), result) + @mock.patch.object( + irmc_inspect, '_get_capabilities_properties_without_ipmi', + autospec=True) @mock.patch.object(irmc_inspect, '_get_mac_addresses', spec_set=True, autospec=True) - @mock.patch.object(irmc_inspect, 'scci', + @mock.patch.object(irmc_inspect.irmc, 'scci', + spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) + @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, + autospec=True) + def test__inspect_hardware_redfish( + self, get_irmc_report_mock, scci_mock, _get_mac_addresses_mock, + _get_cap_prop_without_ipmi_mock): + # Set config flags + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + + kwargs = {'sleep_flag': False} + + parsed_info = irmc_common.parse_driver_info(self.node) + inspected_props = { + 'memory_mb': '1024', + 'local_gb': 10, + 'cpus': 2, + 'cpu_arch': 'x86_64'} + inspected_capabilities = { + 'irmc_firmware_version': 'iRMC S6-2.00S', + 'server_model': 'TX2540M1F5', + 'rom_firmware_version': 'V4.6.5.4 R1.15.0 for D3099-B1x'} + formatted_caps = utils.get_updated_capabilities( + '', inspected_capabilities) + existing_traits = ['EXISTING_TRAIT'] + passed_cap_prop = {'irmc_firmware_version', + 'rom_firmware_version', 'server_model'} + inspected_macs = ['aa:aa:aa:aa:aa:aa', 'bb:bb:bb:bb:bb:bb'] + report = 'fake_report' + get_irmc_report_mock.return_value = report + scci_mock.get_essential_properties.return_value = inspected_props + _get_cap_prop_without_ipmi_mock.return_value = { + 'capabilities': formatted_caps, + **inspected_props} + _get_mac_addresses_mock.return_value = inspected_macs + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + result = irmc_inspect._inspect_hardware(task.node, + existing_traits, + **kwargs) + get_irmc_report_mock.assert_called_once_with(task.node) + scci_mock.get_essential_properties.assert_called_once_with( + report, irmc_inspect.IRMCInspect.ESSENTIAL_PROPERTIES) + _get_cap_prop_without_ipmi_mock.assert_called_once_with( + parsed_info, passed_cap_prop, '', inspected_props) + + expected_props = dict(inspected_props) + inspected_capabilities = utils.get_updated_capabilities( + '', inspected_capabilities) + expected_props['capabilities'] = inspected_capabilities + self.assertEqual((expected_props, inspected_macs, existing_traits), + result) + + @mock.patch.object(irmc_inspect, '_get_mac_addresses', spec_set=True, + autospec=True) + @mock.patch.object(irmc_inspect.irmc, 'scci', spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, autospec=True) @@ -130,8 +192,8 @@ class IRMCInspectInternalMethodsTestCase(test_common.BaseIRMCTest): get_irmc_report_mock.return_value = report side_effect = exception.SNMPFailure("fake exception") scci_mock.get_essential_properties.side_effect = side_effect - irmc_inspect.scci.SCCIInvalidInputError = Exception - irmc_inspect.scci.SCCIClientError = Exception + irmc_inspect.irmc.scci.SCCIInvalidInputError = Exception + irmc_inspect.irmc.scci.SCCIClientError = Exception with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: @@ -192,6 +254,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): autospec=True) def test_inspect_hardware(self, power_state_mock, _inspect_hardware_mock, port_mock, info_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + inspected_props = { 'memory_mb': '1024', 'local_gb': 10, @@ -247,6 +312,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): port_mock, info_mock, set_boot_device_mock, power_action_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + inspected_props = { 'memory_mb': '1024', 'local_gb': 10, @@ -297,6 +365,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): autospec=True) def test_inspect_hardware_inspect_exception( self, power_state_mock, _inspect_hardware_mock, port_mock): + self.node.set_driver_internal_info('irmc_fw_version', 'iRMC S4/7.82F') + self.node.save() + side_effect = exception.HardwareInspectionFailure("fake exception") _inspect_hardware_mock.side_effect = side_effect power_state_mock.return_value = states.POWER_ON @@ -321,6 +392,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): def test_inspect_hardware_mac_already_exist( self, power_state_mock, _inspect_hardware_mock, port_mock, warn_mock, trait_mock): + self.node.set_driver_internal_info('irmc_fw_version', 'iRMC S4/7.82F') + self.node.save() + inspected_props = { 'memory_mb': '1024', 'local_gb': 10, @@ -353,7 +427,7 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): spec_set=True, autospec=True) @mock.patch.object(irmc_inspect, '_get_mac_addresses', spec_set=True, autospec=True) - @mock.patch.object(irmc_inspect, 'scci', + @mock.patch.object(irmc_inspect.irmc, 'scci', spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, autospec=True) @@ -421,6 +495,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): self.assertEqual(expected_traits, result[2]) def test_inspect_hardware_existing_cap_in_props(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = ['0x1000/0x0079', '0x2100/0x0080'] cpu_fpgas = ['0x1000/0x0179', '0x2100/0x0180'] @@ -455,6 +532,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): expected_traits) def test_inspect_hardware_props_empty_gpu_ids_fpga_ids(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = [] cpu_fpgas = [] @@ -479,6 +559,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): expected_traits) def test_inspect_hardware_props_pci_gpu_devices_return_zero(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = ['0x1000/0x0079', '0x2100/0x0080'] cpu_fpgas = ['0x1000/0x0179', '0x2100/0x0180'] @@ -508,6 +591,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): def test_inspect_hardware_props_empty_gpu_ids_fpga_id_sand_existing_cap( self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = [] cpu_fpgas = [] @@ -538,6 +624,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): def test_inspect_hardware_props_gpu_cpu_fpgas_zero_and_existing_cap( self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = ['0x1000/0x0079', '0x2100/0x0080'] cpu_fpgas = ['0x1000/0x0179', '0x2100/0x0180'] @@ -569,6 +658,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): expected_traits) def test_inspect_hardware_props_trusted_boot_removed(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = ['0x1000/0x0079', '0x2100/0x0080'] cpu_fpgas = ['0x1000/0x0179', '0x2100/0x0180'] @@ -599,6 +691,9 @@ class IRMCInspectTestCase(test_common.BaseIRMCTest): def test_inspect_hardware_props_gpu_and_cpu_fpgas_results_are_different( self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + # Set config flags gpu_ids = ['0x1000/0x0079', '0x2100/0x0080'] cpu_fpgas = ['0x1000/0x0179', '0x2100/0x0180'] diff --git a/ironic/tests/unit/drivers/modules/irmc/test_management.py b/ironic/tests/unit/drivers/modules/irmc/test_management.py index 878c7d2cb..9e70e04bf 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_management.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_management.py @@ -30,6 +30,8 @@ from ironic.drivers.modules import ipmitool from ironic.drivers.modules.irmc import common as irmc_common from ironic.drivers.modules.irmc import management as irmc_management from ironic.drivers.modules.irmc import power as irmc_power +from ironic.drivers.modules.redfish import management as redfish_management +from ironic.drivers.modules.redfish import utils as redfish_util from ironic.drivers import utils as driver_utils from ironic.tests.unit.drivers.modules.irmc import test_common from ironic.tests.unit.drivers import third_party_driver_mock_specs \ @@ -155,26 +157,66 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): task.driver.deploy = fake.FakeDeploy() self.assertEqual(expected, task.driver.get_properties()) + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, autospec=True) - def test_validate(self, mock_drvinfo): + def test_validate_ipmi_success(self, mock_drvinfo, redfish_parsedr_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.driver.management.validate(task) mock_drvinfo.assert_called_once_with(task.node) + redfish_parsedr_mock.assert_not_called() + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, autospec=True) - def test_validate_fail(self, mock_drvinfo): + def test_validate_ipmi_fail(self, mock_drvinfo, redfish_parsedr_mock): side_effect = exception.InvalidParameterValue("Invalid Input") mock_drvinfo.side_effect = side_effect + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: self.assertRaises(exception.InvalidParameterValue, task.driver.management.validate, task) + mock_drvinfo.assert_called_once_with(task.node) + redfish_parsedr_mock.assert_not_called() + + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) + @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, + autospec=True) + def test_validate_redfish_success( + self, mock_drvinfo, redfish_parsedr_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + task.driver.management.validate(task) + redfish_parsedr_mock.assert_called_once_with(task.node) + mock_drvinfo.assert_called_once_with(task.node) - def test_management_interface_get_supported_boot_devices(self): + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) + @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, + autospec=True) + def test_validate_redfish_fail(self, mock_drvinfo, redfish_parsedr_mock): + side_effect = exception.InvalidParameterValue("Invalid Input") + redfish_parsedr_mock.side_effect = side_effect + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + mock_drvinfo.assert_not_called() + self.assertRaises(exception.InvalidParameterValue, + task.driver.management.validate, + task) + redfish_parsedr_mock.assert_called_once_with(task.node) + + def test_management_interface_get_supported_boot_devices_ipmi(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() with task_manager.acquire(self.context, self.node.uuid) as task: expected = [boot_devices.PXE, boot_devices.DISK, boot_devices.CDROM, boot_devices.BIOS, @@ -182,10 +224,20 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): self.assertEqual(sorted(expected), sorted(task.driver.management. get_supported_boot_devices(task))) + def test_management_interface_get_supported_boot_devices_redfish(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid) as task: + expected = list(redfish_management.BOOT_DEVICE_MAP_REV) + self.assertEqual(sorted(expected), sorted(task.driver.management. + get_supported_boot_devices(task))) + @mock.patch.object(irmc_management.ipmitool, "send_raw", spec_set=True, autospec=True) def _test_management_interface_set_boot_device_ok( self, boot_mode, params, expected_raw_code, send_raw_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() send_raw_mock.return_value = [None, None] with task_manager.acquire(self.context, self.node.uuid) as task: @@ -197,7 +249,10 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): mock.call(task, "0x00 0x08 0x03 0x08"), mock.call(task, expected_raw_code)]) - def test_management_interface_set_boot_device_ok_pxe(self): + def test_management_interface_set_boot_device_ok_pxe_ipmi(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + params = {'device': boot_devices.PXE, 'persistent': False} self._test_management_interface_set_boot_device_ok( None, @@ -226,7 +281,10 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): params, "0x00 0x08 0x05 0xe0 0x04 0x00 0x00 0x00") - def test_management_interface_set_boot_device_ok_disk(self): + def test_management_interface_set_boot_device_ok_disk_ipmi(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + params = {'device': boot_devices.DISK, 'persistent': False} self._test_management_interface_set_boot_device_ok( None, @@ -255,7 +313,10 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): params, "0x00 0x08 0x05 0xe0 0x08 0x00 0x00 0x00") - def test_management_interface_set_boot_device_ok_cdrom(self): + def test_management_interface_set_boot_device_ok_cdrom_ipmi(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + params = {'device': boot_devices.CDROM, 'persistent': False} self._test_management_interface_set_boot_device_ok( None, @@ -284,7 +345,10 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): params, "0x00 0x08 0x05 0xe0 0x20 0x00 0x00 0x00") - def test_management_interface_set_boot_device_ok_bios(self): + def test_management_interface_set_boot_device_ok_bios_ipmi(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + params = {'device': boot_devices.BIOS, 'persistent': False} self._test_management_interface_set_boot_device_ok( None, @@ -313,7 +377,10 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): params, "0x00 0x08 0x05 0xe0 0x18 0x00 0x00 0x00") - def test_management_interface_set_boot_device_ok_safe(self): + def test_management_interface_set_boot_device_ok_safe_ipmi(self): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + params = {'device': boot_devices.SAFE, 'persistent': False} self._test_management_interface_set_boot_device_ok( None, @@ -344,7 +411,10 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): @mock.patch.object(irmc_management.ipmitool, "send_raw", spec_set=True, autospec=True) - def test_management_interface_set_boot_device_ng(self, send_raw_mock): + def test_management_interface_set_boot_device_ng_ipmi(self, send_raw_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + """uefi mode, next boot only, unknown device.""" send_raw_mock.return_value = [None, None] @@ -355,11 +425,39 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): task, "unknown") + @mock.patch.object(irmc_management.ipmitool, 'send_raw', autospec=True) + @mock.patch.object(redfish_management.RedfishManagement, 'set_boot_device', + autospec=True) + def test_management_interfase_set_boot_device_success_redfish( + self, redfish_set_boot_dev_mock, ipmi_raw_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + ipmi_raw_mock.side_effect = exception.IPMIFailure + management_inst = irmc_management.IRMCManagement() + with task_manager.acquire(self.context, self.node.uuid) as task: + params = ['pxe', True] + management_inst.set_boot_device(task, *params) + redfish_set_boot_dev_mock.assert_called_once_with( + management_inst, task, *params) + + @mock.patch.object(redfish_management.RedfishManagement, 'set_boot_device', + autospec=True) + def test_management_interfase_set_boot_device_fail_redfish( + self, redfish_set_boot_dev_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + management_inst = irmc_management.IRMCManagement() + with task_manager.acquire(self.context, self.node.uuid) as task: + params = [task, 'safe', True] + self.assertRaises(exception.InvalidParameterValue, + management_inst.set_boot_device, *params) + redfish_set_boot_dev_mock.assert_not_called() + @mock.patch.object(irmc_management.irmc, 'scci', spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, autospec=True) - def test_management_interface_get_sensors_data_scci_ok( + def test_management_interface_get_sensors_data_scci_ok_ipmi( self, mock_get_irmc_report, mock_scci): """'irmc_sensor_method' = 'scci' specified and OK data.""" with open(os.path.join(os.path.dirname(__file__), @@ -371,6 +469,8 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): mock_scci.get_sensor_data.return_value = fake_xml.find( "./System/SensorDataRecords") + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() with task_manager.acquire(self.context, self.node.uuid) as task: task.node.driver_info['irmc_sensor_method'] = 'scci' sensor_dict = irmc_management.IRMCManagement().get_sensors_data( @@ -408,7 +508,83 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, autospec=True) - def test_management_interface_get_sensors_data_scci_ng( + def test_management_interface_get_sensors_data_scci_ok_redfish( + self, mock_get_irmc_report, mock_scci): + """'irmc_sensor_method' = 'scci' specified and OK data.""" + with open(os.path.join(os.path.dirname(__file__), + 'fake_sensors_data_ok.xml'), "r") as report: + fake_txt = report.read() + fake_xml = ET.fromstring(fake_txt) + + mock_get_irmc_report.return_value = fake_xml + mock_scci.get_sensor_data.return_value = fake_xml.find( + "./System/SensorDataRecords") + + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid) as task: + task.node.driver_info['irmc_sensor_method'] = 'scci' + sensor_dict = irmc_management.IRMCManagement().get_sensors_data( + task) + + expected = { + 'Fan (4)': { + 'FAN1 SYS (29)': { + 'Units': 'RPM', + 'Sensor ID': 'FAN1 SYS (29)', + 'Sensor Reading': '600 RPM' + }, + 'FAN2 SYS (29)': { + 'Units': 'None', + 'Sensor ID': 'FAN2 SYS (29)', + 'Sensor Reading': 'None None' + } + }, + 'Temperature (1)': { + 'Systemboard 1 (7)': { + 'Units': 'degree C', + 'Sensor ID': 'Systemboard 1 (7)', + 'Sensor Reading': '80 degree C' + }, + 'Ambient (55)': { + 'Units': 'degree C', + 'Sensor ID': 'Ambient (55)', + 'Sensor Reading': '42 degree C' + } + } + } + self.assertEqual(expected, sensor_dict) + + @mock.patch.object(irmc_management.irmc, 'scci', + spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) + @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, + autospec=True) + def test_management_interface_get_sensors_data_scci_ng_ipmi( + self, mock_get_irmc_report, mock_scci): + """'irmc_sensor_method' = 'scci' specified and NG data.""" + with open(os.path.join(os.path.dirname(__file__), + 'fake_sensors_data_ng.xml'), "r") as report: + fake_txt = report.read() + fake_xml = ET.fromstring(fake_txt) + + mock_get_irmc_report.return_value = fake_xml + mock_scci.get_sensor_data.return_value = fake_xml.find( + "./System/SensorDataRecords") + + self.node.set_driver_internal_info('irmc_fw_version', 'iRMC S5/2.00S') + self.node.save() + with task_manager.acquire(self.context, self.node.uuid) as task: + task.node.driver_info['irmc_sensor_method'] = 'scci' + sensor_dict = irmc_management.IRMCManagement().get_sensors_data( + task) + + self.assertEqual(len(sensor_dict), 0) + + @mock.patch.object(irmc_management.irmc, 'scci', + spec_set=mock_specs.SCCICLIENT_IRMC_SCCI_SPEC) + @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, + autospec=True) + def test_management_interface_get_sensors_data_scci_ng_redfish( self, mock_get_irmc_report, mock_scci): """'irmc_sensor_method' = 'scci' specified and NG data.""" with open(os.path.join(os.path.dirname(__file__), @@ -420,6 +596,8 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): mock_scci.get_sensor_data.return_value = fake_xml.find( "./System/SensorDataRecords") + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() with task_manager.acquire(self.context, self.node.uuid) as task: task.node.driver_info['irmc_sensor_method'] = 'scci' sensor_dict = irmc_management.IRMCManagement().get_sensors_data( @@ -429,16 +607,31 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): @mock.patch.object(ipmitool.IPMIManagement, 'get_sensors_data', spec_set=True, autospec=True) - def test_management_interface_get_sensors_data_ipmitool_ok( + def test_management_interface_get_sensors_data_ipmitool_ok_ipmi( self, get_sensors_data_mock): """'irmc_sensor_method' = 'ipmitool' specified.""" + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() with task_manager.acquire(self.context, self.node.uuid) as task: task.node.driver_info['irmc_sensor_method'] = 'ipmitool' task.driver.management.get_sensors_data(task) get_sensors_data_mock.assert_called_once_with( task.driver.management, task) + @mock.patch.object(ipmitool.IPMIManagement, 'get_sensors_data', + spec_set=True, autospec=True) + def test_management_interface_get_sensors_data_ipmitool_ng_redfish( + self, + get_sensors_data_mock): + """'irmc_sensor_method' = 'ipmitool' specified.""" + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid) as task: + task.node.driver_info['irmc_sensor_method'] = 'ipmitool' + self.assertRaises(exception.InvalidParameterValue, + task.driver.management.get_sensors_data, task) + @mock.patch.object(irmc_common, 'get_irmc_report', spec_set=True, autospec=True) def test_management_interface_get_sensors_data_exception( @@ -459,6 +652,36 @@ class IRMCManagementTestCase(test_common.BaseIRMCTest): self.assertEqual("Failed to get sensor data for node %s. " "Error: Fake Error" % self.node.uuid, str(e)) + @mock.patch.object(redfish_management.RedfishManagement, 'detect_vendor', + spec_set=True, autospec=True) + @mock.patch.object(ipmitool.IPMIManagement, 'detect_vendor', + spec_set=True, autospec=True) + def test_management_interface_detect_vendor_ipmi(self, + ipmimgmt_detectv_mock, + redfishmgmt_detectv_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + irmc_mgmt_inst = irmc_management.IRMCManagement() + with task_manager.acquire(self.context, self.node.uuid) as task: + irmc_mgmt_inst.detect_vendor(task) + ipmimgmt_detectv_mock.assert_called_once_with(irmc_mgmt_inst, task) + redfishmgmt_detectv_mock.assert_not_called() + + @mock.patch.object(redfish_management.RedfishManagement, 'detect_vendor', + spec_set=True, autospec=True) + @mock.patch.object(ipmitool.IPMIManagement, 'detect_vendor', + spec_set=True, autospec=True) + def test_management_interface_detect_vendor_redfish( + self, ipmimgmt_detectv_mock, redfishmgmt_detectv_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + ipmimgmt_detectv_mock.side_effect = exception.IPMIFailure + irmc_mgmt_inst = irmc_management.IRMCManagement() + with task_manager.acquire(self.context, self.node.uuid) as task: + irmc_mgmt_inst.detect_vendor(task) + redfishmgmt_detectv_mock.assert_called_once_with( + irmc_mgmt_inst, task) + @mock.patch.object(irmc_management.LOG, 'error', spec_set=True, autospec=True) @mock.patch.object(irmc_common, 'get_irmc_client', spec_set=True, diff --git a/ironic/tests/unit/drivers/modules/irmc/test_power.py b/ironic/tests/unit/drivers/modules/irmc/test_power.py index c4142202c..c2509af79 100644 --- a/ironic/tests/unit/drivers/modules/irmc/test_power.py +++ b/ironic/tests/unit/drivers/modules/irmc/test_power.py @@ -24,6 +24,8 @@ from ironic.conductor import task_manager from ironic.drivers.modules.irmc import boot as irmc_boot from ironic.drivers.modules.irmc import common as irmc_common from ironic.drivers.modules.irmc import power as irmc_power +from ironic.drivers.modules.redfish import power as redfish_power +from ironic.drivers.modules.redfish import utils as redfish_util from ironic.tests.unit.drivers.modules.irmc import test_common @@ -289,17 +291,32 @@ class IRMCPowerTestCase(test_common.BaseIRMCTest): for prop in irmc_common.COMMON_PROPERTIES: self.assertIn(prop, properties) + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, autospec=True) - def test_validate(self, mock_drvinfo): + def test_validate_default(self, mock_drvinfo, redfish_parsedr_mock): with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: task.driver.power.validate(task) mock_drvinfo.assert_called_once_with(task.node) + redfish_parsedr_mock.assert_not_called() + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, autospec=True) - def test_validate_fail(self, mock_drvinfo): + def test_validate_ipmi(self, mock_drvinfo, redfish_parsedr_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + task.driver.power.validate(task) + mock_drvinfo.assert_called_once_with(task.node) + redfish_parsedr_mock.assert_not_called() + + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) + @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, + autospec=True) + def test_validate_fail_ipmi(self, mock_drvinfo, redfish_parsedr_mock): side_effect = exception.InvalidParameterValue("Invalid Input") mock_drvinfo.side_effect = side_effect with task_manager.acquire(self.context, self.node.uuid, @@ -307,10 +324,40 @@ class IRMCPowerTestCase(test_common.BaseIRMCTest): self.assertRaises(exception.InvalidParameterValue, task.driver.power.validate, task) + redfish_parsedr_mock.assert_not_called() + + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) + @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, + autospec=True) + def test_validate_redfish(self, mock_drvinfo, redfish_parsedr_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + task.driver.power.validate(task) + mock_drvinfo.assert_called_once_with(task.node) + redfish_parsedr_mock.assert_called_once_with(task.node) + @mock.patch.object(redfish_util, 'parse_driver_info', autospec=True) + @mock.patch.object(irmc_common, 'parse_driver_info', spec_set=True, + autospec=True) + def test_validate_fail_redfish(self, mock_drvinfo, redfish_parsedr_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + side_effect = exception.InvalidParameterValue("Invalid Input") + redfish_parsedr_mock.side_effect = side_effect + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + self.assertRaises(exception.InvalidParameterValue, + task.driver.power.validate, + task) + mock_drvinfo.assert_called_once_with(task.node) + + @mock.patch.object(redfish_power.RedfishPower, 'get_power_state', + autospec=True) @mock.patch('ironic.drivers.modules.irmc.power.ipmitool.IPMIPower', spec_set=True, autospec=True) - def test_get_power_state(self, mock_IPMIPower): + def test_get_power_state_default(self, mock_IPMIPower, redfish_getpw_mock): ipmi_power = mock_IPMIPower.return_value ipmi_power.get_power_state.return_value = states.POWER_ON with task_manager.acquire(self.context, self.node.uuid, @@ -318,6 +365,41 @@ class IRMCPowerTestCase(test_common.BaseIRMCTest): self.assertEqual(states.POWER_ON, task.driver.power.get_power_state(task)) ipmi_power.get_power_state.assert_called_once_with(task) + redfish_getpw_mock.assert_not_called() + + @mock.patch.object(redfish_power.RedfishPower, 'get_power_state', + autospec=True) + @mock.patch('ironic.drivers.modules.irmc.power.ipmitool.IPMIPower', + spec_set=True, autospec=True) + def test_get_power_state_ipmi(self, mock_IPMIPower, redfish_getpw_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', True) + self.node.save() + ipmi_power = mock_IPMIPower.return_value + ipmi_power.get_power_state.return_value = states.POWER_ON + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + self.assertEqual(states.POWER_ON, + task.driver.power.get_power_state(task)) + ipmi_power.get_power_state.assert_called_once_with(task) + redfish_getpw_mock.assert_not_called() + + @mock.patch.object(redfish_power.RedfishPower, 'get_power_state', + autospec=True) + @mock.patch('ironic.drivers.modules.irmc.power.ipmitool.IPMIPower', + spec_set=True, autospec=True) + def test_get_power_state_redfish(self, mock_IPMIPower, redfish_getpw_mock): + self.node.set_driver_internal_info('irmc_ipmi_succeed', False) + self.node.save() + ipmipw_instance = mock_IPMIPower() + ipmipw_instance.get_power_state.side_effect = exception.IPMIFailure + redfish_getpw_mock.return_value = states.POWER_ON + irmc_power_inst = irmc_power.IRMCPower() + with task_manager.acquire(self.context, self.node.uuid, + shared=True) as task: + self.assertEqual(states.POWER_ON, + irmc_power_inst.get_power_state(task)) + ipmipw_instance.get_power_state.assert_called() + redfish_getpw_mock.assert_called_once_with(irmc_power_inst, task) @mock.patch.object(irmc_power, '_set_power_state', spec_set=True, autospec=True) |