Add function for dump SDR to ipmitool driver
New dump_sdr() function for dumping SDR data to a file added. This changes intended for out of tree drivers which use ipmi and should not double Ironic code base, example: Iedbb3b906cef7bd5b2d768e926a59820ccd8c196 Change-Id: Ibe0efdbf5133356fc5e7d9129913f9dd0307e9af
This commit is contained in:
parent
30a60c9ba6
commit
5c6de4b3ce
|
@ -674,6 +674,34 @@ def send_raw(task, raw_bytes):
|
|||
raise exception.IPMIFailure(cmd=cmd)
|
||||
|
||||
|
||||
def dump_sdr(task, file_path):
|
||||
"""Dump SDR data to a file.
|
||||
|
||||
:param task: a TaskManager instance.
|
||||
:param file_path: the path to SDR dump file.
|
||||
:raises: IPMIFailure on an error from ipmitool.
|
||||
:raises: MissingParameterValue if a required parameter is missing.
|
||||
:raises: InvalidParameterValue when an invalid value is specified.
|
||||
|
||||
"""
|
||||
node_uuid = task.node.uuid
|
||||
LOG.debug('Dump SDR data for node %(node)s to file %(name)s',
|
||||
{'name': file_path, 'node': node_uuid})
|
||||
driver_info = _parse_driver_info(task.node)
|
||||
cmd = 'sdr dump %s' % file_path
|
||||
|
||||
try:
|
||||
out, err = _exec_ipmitool(driver_info, cmd)
|
||||
LOG.debug('dump SDR returned stdout: %(stdout)s, stderr:'
|
||||
' %(stderr)s', {'stdout': out, 'stderr': err})
|
||||
except (exception.PasswordFileFailedToCreate,
|
||||
processutils.ProcessExecutionError) as e:
|
||||
LOG.exception(_LE('IPMI "sdr dump" failed for node %(node_id)s '
|
||||
'with error: %(error)s.'),
|
||||
{'node_id': node_uuid, 'error': e})
|
||||
raise exception.IPMIFailure(cmd=cmd)
|
||||
|
||||
|
||||
def _check_temp_dir():
|
||||
"""Check for Valid temp directory."""
|
||||
global TMP_DIR_CHECKED
|
||||
|
|
|
@ -2090,3 +2090,20 @@ class IPMIToolDriverTestCase(db_base.DbTestCase):
|
|||
ipmi._parse_ipmi_sensors_data,
|
||||
self.node,
|
||||
fake_sensors_data)
|
||||
|
||||
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
|
||||
def test_dump_sdr_ok(self, mock_exec):
|
||||
mock_exec.return_value = (None, None)
|
||||
|
||||
with task_manager.acquire(self.context, self.node.uuid) as task:
|
||||
ipmi.dump_sdr(task, 'foo_file')
|
||||
|
||||
mock_exec.assert_called_once_with(self.info, 'sdr dump foo_file')
|
||||
|
||||
@mock.patch.object(ipmi, '_exec_ipmitool', autospec=True)
|
||||
def test_dump_sdr_fail(self, mock_exec):
|
||||
with task_manager.acquire(self.context, self.node.uuid) as task:
|
||||
mock_exec.side_effect = processutils.ProcessExecutionError()
|
||||
self.assertRaises(exception.IPMIFailure, ipmi.dump_sdr, task,
|
||||
'foo_file')
|
||||
mock_exec.assert_called_once_with(self.info, 'sdr dump foo_file')
|
||||
|
|
Loading…
Reference in New Issue