"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "ironic/tests/unit/drivers/modules/test_ipmitool.py" between
ironic-16.0.2.tar.gz and ironic-16.0.3.tar.gz

About: OpenStack Ironic (Optional Service: Bare-Metal Provisioning) aims to provision bare metal machines instead of virtual machines, forked from the Nova baremetal driver.
The "Victoria" series (latest release).

test_ipmitool.py  (ironic-16.0.2):test_ipmitool.py  (ironic-16.0.3)
skipping to change at line 61 skipping to change at line 61
from ironic.tests.unit.objects import utils as obj_utils from ironic.tests.unit.objects import utils as obj_utils
CONF = ironic.conf.CONF CONF = ironic.conf.CONF
INFO_DICT = db_utils.get_test_ipmi_info() INFO_DICT = db_utils.get_test_ipmi_info()
# BRIDGE_INFO_DICT will have all the bridging parameters appended # BRIDGE_INFO_DICT will have all the bridging parameters appended
BRIDGE_INFO_DICT = INFO_DICT.copy() BRIDGE_INFO_DICT = INFO_DICT.copy()
BRIDGE_INFO_DICT.update(db_utils.get_test_ipmi_bridging_parameters()) BRIDGE_INFO_DICT.update(db_utils.get_test_ipmi_bridging_parameters())
MC_INFO = """Device ID : 32
Device Revision : 1
Firmware Revision : 0.99
IPMI Version : 2.0
Manufacturer ID : 1234
Manufacturer Name : {vendor}
Product ID : 2001 (0x0801)
Product Name : Unknown (0x101)
Device Available : yes
Provides Device SDRs : no
Additional Device Support :
Sensor Device
SDR Repository Device
SEL Device
FRU Inventory Device
IPMB Event Receiver
IPMB Event Generator
Chassis Device
Aux Firmware Rev Info :
0x00
0x00
0x00
0x00
"""
class IPMIToolCheckInitTestCase(base.TestCase): class IPMIToolCheckInitTestCase(base.TestCase):
@mock.patch.object(ipmi, '_is_option_supported', autospec=True) @mock.patch.object(ipmi, '_is_option_supported', autospec=True)
@mock.patch.object(utils, 'check_dir', autospec=True) @mock.patch.object(utils, 'check_dir', autospec=True)
def test_power_init_calls(self, mock_check_dir, mock_support): def test_power_init_calls(self, mock_check_dir, mock_support):
mock_support.return_value = True mock_support.return_value = True
ipmi.TMP_DIR_CHECKED = None ipmi.TMP_DIR_CHECKED = None
ipmi.IPMIPower() ipmi.IPMIPower()
mock_support.assert_called_with(mock.ANY) mock_support.assert_called_with(mock.ANY)
mock_check_dir.assert_called_once_with() mock_check_dir.assert_called_once_with()
skipping to change at line 1506 skipping to change at line 1531
"power on": [None, None]} "power on": [None, None]}
return resp_dict.get(command, ["Bad\n", None]) return resp_dict.get(command, ["Bad\n", None])
mock_exec.side_effect = side_effect mock_exec.side_effect = side_effect
expected = [mock.call(self.info, "power on"), expected = [mock.call(self.info, "power on"),
mock.call(self.info, "power status", kill_on_timeout=True), mock.call(self.info, "power status", kill_on_timeout=True),
mock.call(self.info, "power status", kill_on_timeout=True)] mock.call(self.info, "power status", kill_on_timeout=True)]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
task.node.properties['vendor'] = 'lolcat'
self.assertRaises(exception.PowerStateFailure, self.assertRaises(exception.PowerStateFailure,
ipmi._power_on, task, self.info, timeout=2) ipmi._power_on, task, self.info, timeout=2)
self.assertEqual(expected, mock_exec.call_args_list) self.assertEqual(expected, mock_exec.call_args_list)
@mock.patch.object(ipmi.IPMIManagement, 'detect_vendor', autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True) @mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test__soft_power_off(self, sleep_mock, mock_exec): def test__soft_power_off(self, sleep_mock, mock_exec, mock_vendor):
def side_effect(driver_info, command, **kwargs): def side_effect(driver_info, command, **kwargs):
resp_dict = {"power status": ["Chassis Power is off\n", None], resp_dict = {"power status": ["Chassis Power is off\n", None],
"power soft": [None, None]} "power soft": [None, None]}
return resp_dict.get(command, ["Bad\n", None]) return resp_dict.get(command, ["Bad\n", None])
mock_vendor.return_value = None
mock_exec.side_effect = side_effect mock_exec.side_effect = side_effect
expected = [mock.call(self.info, "power soft"), expected = [mock.call(self.info, "power soft"),
mock.call(self.info, "power status", kill_on_timeout=True)] mock.call(self.info, "power status", kill_on_timeout=True)]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
state = ipmi._soft_power_off(task, self.info) state = ipmi._soft_power_off(task, self.info)
self.assertEqual(expected, mock_exec.call_args_list) self.assertEqual(expected, mock_exec.call_args_list)
self.assertEqual(states.POWER_OFF, state) self.assertEqual(states.POWER_OFF, state)
self.assertTrue(mock_vendor.called)
@mock.patch.object(ipmi.IPMIManagement, 'detect_vendor', autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True) @mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test__soft_power_off_max_retries(self, sleep_mock, mock_exec): def test__soft_power_off_max_retries(self, sleep_mock, mock_exec,
mock_vendor):
def side_effect(driver_info, command, **kwargs): def side_effect(driver_info, command, **kwargs):
resp_dict = {"power status": ["Chassis Power is on\n", None], resp_dict = {"power status": ["Chassis Power is on\n", None],
"power soft": [None, None]} "power soft": [None, None]}
return resp_dict.get(command, ["Bad\n", None]) return resp_dict.get(command, ["Bad\n", None])
mock_exec.side_effect = side_effect mock_exec.side_effect = side_effect
expected = [mock.call(self.info, "power soft"), expected = [mock.call(self.info, "power soft"),
mock.call(self.info, "power status", kill_on_timeout=True), mock.call(self.info, "power status", kill_on_timeout=True),
mock.call(self.info, "power status", kill_on_timeout=True)] mock.call(self.info, "power status", kill_on_timeout=True)]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
task.node.properties['vendor'] = 'meow5000'
self.assertRaises(exception.PowerStateFailure, self.assertRaises(exception.PowerStateFailure,
ipmi._soft_power_off, task, self.info, timeout=2) ipmi._soft_power_off, task, self.info, timeout=2)
self.assertEqual(expected, mock_exec.call_args_list) self.assertEqual(expected, mock_exec.call_args_list)
# Should be removed when detect_vendor automatic invocation is moved.
self.assertFalse(mock_vendor.called)
@mock.patch.object(ipmi, '_power_status', autospec=True) @mock.patch.object(ipmi, '_power_status', autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
@mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True) @mock.patch('oslo_utils.eventletutils.EventletEvent.wait', autospec=True)
def test___set_and_wait_no_needless_status_polling( def test___set_and_wait_no_needless_status_polling(
self, sleep_mock, mock_exec, mock_status): self, sleep_mock, mock_exec, mock_status):
# Check that if the call to power state change fails, it doesn't # Check that if the call to power state change fails, it doesn't
# call power_status(). # call power_status().
self.config(command_retry_timeout=2, group='ipmi') self.config(command_retry_timeout=2, group='ipmi')
skipping to change at line 1589 skipping to change at line 1622
expected = ipmi.COMMON_PROPERTIES expected = ipmi.COMMON_PROPERTIES
self.assertEqual(expected, self.power.get_properties()) self.assertEqual(expected, self.power.get_properties())
expected = list(ipmi.COMMON_PROPERTIES) + list(ipmi.CONSOLE_PROPERTIES) expected = list(ipmi.COMMON_PROPERTIES) + list(ipmi.CONSOLE_PROPERTIES)
self.assertEqual(sorted(expected), self.assertEqual(sorted(expected),
sorted(self.console.get_properties())) sorted(self.console.get_properties()))
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertEqual(sorted(expected), self.assertEqual(sorted(expected),
sorted(task.driver.get_properties())) sorted(task.driver.get_properties()))
@mock.patch.object(ipmi.IPMIManagement, 'detect_vendor', autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_get_power_state(self, mock_exec): def test_get_power_state(self, mock_exec, mock_detect):
returns = iter([["Chassis Power is off\n", None], returns = iter([["Chassis Power is off\n", None],
["Chassis Power is on\n", None], ["Chassis Power is on\n", None],
["\n", None]]) ["\n", None]])
expected = [mock.call(self.info, "power status", kill_on_timeout=True), expected = [mock.call(self.info, "power status", kill_on_timeout=True),
mock.call(self.info, "power status", kill_on_timeout=True), mock.call(self.info, "power status", kill_on_timeout=True),
mock.call(self.info, "power status", kill_on_timeout=True)] mock.call(self.info, "power status", kill_on_timeout=True)]
mock_exec.side_effect = returns mock_exec.side_effect = returns
mock_detect.return_value = None
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
pstate = self.power.get_power_state(task) pstate = self.power.get_power_state(task)
self.assertEqual(states.POWER_OFF, pstate) self.assertEqual(states.POWER_OFF, pstate)
pstate = self.power.get_power_state(task) pstate = self.power.get_power_state(task)
self.assertEqual(states.POWER_ON, pstate) self.assertEqual(states.POWER_ON, pstate)
pstate = self.power.get_power_state(task) pstate = self.power.get_power_state(task)
self.assertEqual(states.ERROR, pstate) self.assertEqual(states.ERROR, pstate)
self.assertEqual(mock_exec.call_args_list, expected) self.assertEqual(mock_exec.call_args_list, expected)
self.assertEqual(3, mock_detect.call_count)
@mock.patch.object(ipmi.IPMIManagement, 'detect_vendor', autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_get_power_state_exception(self, mock_exec): def test_get_power_state_exception(self, mock_exec, mock_vendor):
mock_exec.side_effect = processutils.ProcessExecutionError("error") mock_exec.side_effect = processutils.ProcessExecutionError("error")
mock_vendor.return_value = None
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.IPMIFailure, self.assertRaises(exception.IPMIFailure,
self.power.get_power_state, self.power.get_power_state,
task) task)
mock_exec.assert_called_once_with(self.info, "power status", mock_exec.assert_called_once_with(self.info, "power status",
kill_on_timeout=True) kill_on_timeout=True)
self.assertEqual(1, mock_vendor.call_count)
@mock.patch.object(ipmi, '_power_on', autospec=True) @mock.patch.object(ipmi, '_power_on', autospec=True)
@mock.patch.object(ipmi, '_power_off', autospec=True) @mock.patch.object(ipmi, '_power_off', autospec=True)
def test_set_power_on_ok(self, mock_off, mock_on): def test_set_power_on_ok(self, mock_off, mock_on):
self.config(command_retry_timeout=0, group='ipmi') self.config(command_retry_timeout=0, group='ipmi')
mock_on.return_value = states.POWER_ON mock_on.return_value = states.POWER_ON
with task_manager.acquire(self.context, with task_manager.acquire(self.context,
self.node.uuid) as task: self.node.uuid) as task:
self.power.set_power_state(task, states.POWER_ON) self.power.set_power_state(task, states.POWER_ON)
skipping to change at line 2225 skipping to change at line 2264
def test_management_interface_set_boot_device_uefi(self, mock_exec, def test_management_interface_set_boot_device_uefi(self, mock_exec,
mock_boot_mode): mock_boot_mode):
mock_boot_mode.return_value = 'uefi' mock_boot_mode.return_value = 'uefi'
mock_exec.return_value = [None, None] mock_exec.return_value = [None, None]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.management.set_boot_device(task, boot_devices.PXE) self.management.set_boot_device(task, boot_devices.PXE)
mock_calls = [ mock_calls = [
mock.call(self.info, "raw 0x00 0x08 0x03 0x08"), mock.call(self.info, "raw 0x00 0x08 0x03 0x08"),
mock.call(self.info, "chassis bootdev pxe options=efiboot") mock.call(self.info, "raw 0x00 0x08 0x05 0xa0 0x04 0x00 0x00 0x00")
] ]
mock_exec.assert_has_calls(mock_calls) mock_exec.assert_has_calls(mock_calls)
@mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy', @mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy',
autospec=True) autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_management_interface_set_boot_device_uefi_and_persistent( def test_management_interface_set_boot_device_uefi_and_persistent(
self, mock_exec, mock_boot_mode): self, mock_exec, mock_boot_mode):
mock_boot_mode.return_value = 'uefi' mock_boot_mode.return_value = 'uefi'
mock_exec.return_value = [None, None] mock_exec.return_value = [None, None]
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
self.management.set_boot_device(task, boot_devices.PXE, self.management.set_boot_device(task, boot_devices.PXE,
persistent=True) persistent=True)
mock_calls = [ mock_calls = [
mock.call(self.info, "raw 0x00 0x08 0x03 0x08"), mock.call(self.info, "raw 0x00 0x08 0x03 0x08"),
mock.call(self.info, "raw 0x00 0x08 0x05 0xe0 0x04 0x00 0x00 0x00") mock.call(self.info, "raw 0x00 0x08 0x05 0xe0 0x04 0x00 0x00 0x00")
] ]
mock_exec.assert_has_calls(mock_calls) mock_exec.assert_has_calls(mock_calls)
@mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy',
autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_management_interface_set_boot_device_uefi_and_persistent_smci(
self, mock_exec, mock_boot_mode):
mock_boot_mode.return_value = 'uefi'
mock_exec.return_value = [None, None]
properties = self.node.properties
properties['vendor'] = 'SuperMicro'
self.node.properties = properties
self.node.save()
with task_manager.acquire(self.context, self.node.uuid) as task:
self.management.set_boot_device(task, boot_devices.DISK,
persistent=True)
mock_calls = [
mock.call(self.info, "raw 0x00 0x08 0x03 0x08"),
mock.call(self.info, "raw 0x00 0x08 0x05 0xe0 "
"0x24 0x00 0x00 0x00")
]
mock_exec.assert_has_calls(mock_calls)
@mock.patch.object(boot_mode_utils, 'get_boot_mode_for_deploy',
autospec=True)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_management_interface_set_boot_device_uefi_and_onetime_smci(
self, mock_exec, mock_boot_mode):
mock_boot_mode.return_value = 'uefi'
mock_exec.return_value = [None, None]
properties = self.node.properties
properties['vendor'] = 'SuperMicro'
self.node.properties = properties
self.node.save()
with task_manager.acquire(self.context, self.node.uuid) as task:
self.management.set_boot_device(task, boot_devices.DISK,
persistent=False)
mock_calls = [
mock.call(self.info, "raw 0x00 0x08 0x03 0x08"),
mock.call(self.info, "raw 0x00 0x08 0x05 0xa0 "
"0x24 0x00 0x00 0x00")
]
mock_exec.assert_has_calls(mock_calls)
def test_management_interface_get_supported_boot_devices(self): def test_management_interface_get_supported_boot_devices(self):
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
expected = [boot_devices.PXE, boot_devices.DISK, expected = [boot_devices.PXE, boot_devices.DISK,
boot_devices.CDROM, boot_devices.BIOS, boot_devices.CDROM, boot_devices.BIOS,
boot_devices.SAFE] boot_devices.SAFE]
self.assertEqual(sorted(expected), sorted(task.driver.management. self.assertEqual(sorted(expected), sorted(task.driver.management.
get_supported_boot_devices(task))) get_supported_boot_devices(task)))
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True) @mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_management_interface_get_boot_device(self, mock_exec): def test_management_interface_get_boot_device(self, mock_exec):
skipping to change at line 2361 skipping to change at line 2442
with task_manager.acquire(self.context, self.node.uuid) as task: with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = ipmi._parse_driver_info(task.node) driver_info = ipmi._parse_driver_info(task.node)
self.assertRaises(exception.IPMIFailure, self.assertRaises(exception.IPMIFailure,
self.management.inject_nmi, self.management.inject_nmi,
task) task)
mock_exec.assert_called_once_with(driver_info, "power diag") mock_exec.assert_called_once_with(driver_info, "power diag")
self.assertTrue(mock_log.called) self.assertTrue(mock_log.called)
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
def test_detect_vendor(self, mock_exec):
mock_exec.return_value = (MC_INFO.format(vendor='LolCatMeow'),
None)
with task_manager.acquire(self.context, self.node.uuid) as task:
driver_info = ipmi._parse_driver_info(task.node)
vendor = self.management.detect_vendor(task)
mock_exec.assert_called_once_with(driver_info, 'mc info')
self.assertEqual('lolcatmeow', vendor)
def test__parse_ipmi_sensor_data_ok(self): def test__parse_ipmi_sensor_data_ok(self):
fake_sensors_data = """ fake_sensors_data = """
Sensor ID : Temp (0x1) Sensor ID : Temp (0x1)
Entity ID : 3.1 (Processor) Entity ID : 3.1 (Processor)
Sensor Type (Analog) : Temperature Sensor Type (Analog) : Temperature
Sensor Reading : -58 (+/- 1) degrees C Sensor Reading : -58 (+/- 1) degrees C
Status : ok Status : ok
Nominal Reading : 50.000 Nominal Reading : 50.000
Normal Minimum : 11.000 Normal Minimum : 11.000
Normal Maximum : 69.000 Normal Maximum : 69.000
 End of changes. 21 change blocks. 
6 lines changed or deleted 97 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)