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
This commit is contained in:
Julia Kreger 2017-09-06 19:15:06 +00:00
parent 51bc4b538b
commit 308cddc1bb
2 changed files with 14 additions and 1 deletions

View File

@ -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):

View File

@ -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