From 308cddc1bb5d4ae8bb9f462d64ee6754f2d14d8d Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Wed, 6 Sep 2017 19:15:06 +0000 Subject: [PATCH] Fix OSError catch The _execute helper was catching OSError, except it was expecting the same attributes as ProcessExecutionError, which is incorrect. Added a separate catch and unit test to ensure that we at least properly catch and convert the error instead of raising an error about an attribute that does not exist. Change-Id: Id47715a5657478e4d9dd10ea7f360b1ededa27de Closes-Bug: #1715466 --- ironic_python_agent/extensions/iscsi.py | 6 +++++- ironic_python_agent/tests/unit/extensions/test_iscsi.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ironic_python_agent/extensions/iscsi.py b/ironic_python_agent/extensions/iscsi.py index 7d2fb3895..bc7ef0d44 100644 --- a/ironic_python_agent/extensions/iscsi.py +++ b/ironic_python_agent/extensions/iscsi.py @@ -36,10 +36,14 @@ DEFAULT_ISCSI_PORTAL_PORT = 3260 def _execute(cmd, error_msg, **kwargs): try: stdout, stderr = utils.execute(*cmd, **kwargs) - except (processutils.ProcessExecutionError, OSError) as e: + except processutils.ProcessExecutionError as e: LOG.error(error_msg) raise errors.ISCSICommandError(error_msg, e.exit_code, e.stdout, e.stderr) + except OSError as e: + LOG.error("Error: %(error)s: OS Error: %(os_error)s", + {'error': error_msg, 'os_error': e}) + raise errors.ISCSICommandError(e, e.errno, None, None) def _wait_for_tgtd(attempts=10): diff --git a/ironic_python_agent/tests/unit/extensions/test_iscsi.py b/ironic_python_agent/tests/unit/extensions/test_iscsi.py index e8a82d01d..383c6bbc5 100644 --- a/ironic_python_agent/tests/unit/extensions/test_iscsi.py +++ b/ironic_python_agent/tests/unit/extensions/test_iscsi.py @@ -134,6 +134,15 @@ class TestISCSIExtensionTgt(test_base.BaseTestCase): mock_execute.assert_has_calls(expected) mock_dispatch.assert_called_once_with('get_os_install_device') + def test_start_iscsi_target_fail_command_not_exist(self, mock_execute, + mock_dispatch, + mock_destroy): + mock_dispatch.return_value = self.fake_dev + mock_execute.side_effect = OSError('file not found') + self.assertRaises(errors.ISCSIError, + self.agent_extension.start_iscsi_target, + iqn=self.fake_iqn) + _ORIG_UTILS = iscsi.rtslib_fb.utils