Suppress errors from iscsi session cleanup

In some cases, where the rts library is not installed, IPA
was recently changed to try and tear down the local side of
the iscsi connection by trying to tear down bond and target
being offered. The whole attempt with this is to ensure that
no disk locks are in place which can prevent partition table
updates.

Since we added this logic, in some cases these commands can
fail and cause the deployment process to fail when it would
have otherwise succeeded. As such, suppress the errors.

Change-Id: I0e04936ad337b394dd68e9b0396a9f1203218f9f
This commit is contained in:
Julia Kreger 2019-11-01 06:40:13 -07:00
parent 68fb8006e0
commit c5956bdada
3 changed files with 45 additions and 10 deletions

View File

@ -114,18 +114,28 @@ def clean_up(device):
try:
rts_root = rtslib_fb.RTSRoot()
except (OSError, EnvironmentError, rtslib_fb.RTSLibError) as exc:
LOG.info('Linux-IO is not available, attemting to stop tgtd mapping. '
'Error: %s.', exc)
cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
'unbind', '--tid', '1', '--initiator-address', 'ALL']
_execute(cmd, "Error when cleaning up iscsi binds.")
try:
LOG.info('Linux-IO is not available, attemting to stop tgtd '
'mapping. Error: %s.', exc)
cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
'unbind', '--tid', '1', '--initiator-address', 'ALL']
_execute(cmd, "Error when cleaning up iscsi binds.")
except errors.ISCSICommandError:
# This command may fail if the target was already torn down
# and that is okay, we just want to ensure it has been torn
# down so there should be no disk locks persisting.
pass
cmd = ['sync']
_execute(cmd, "Error flushing buffers to disk.")
cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
'delete', '--tid', '1']
_execute(cmd, "Error deleting the iscsi target configuration.")
try:
cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
'delete', '--tid', '1']
_execute(cmd, "Error deleting the iscsi target configuration.")
except errors.ISCSICommandError:
# This command should remove the target from being offered.
# It is just proper clean-up, and often previously the IPA
# side, or "target" was never really torn down in many cases.
pass
return
storage = None

View File

@ -304,6 +304,19 @@ class TestISCSIExtensionCleanUpFallback(base.IronicAgentTest):
iscsi.clean_up(self.fake_dev)
mock_execute.assert_has_calls(expected)
def test_commands_fail(self, mock_execute):
mock_execute.side_effect = [processutils.ProcessExecutionError(),
('', ''),
processutils.ProcessExecutionError()]
expected = [mock.call('tgtadm', '--lld', 'iscsi', '--mode',
'target', '--op', 'unbind', '--tid', '1',
'--initiator-address', 'ALL'),
mock.call('sync'),
mock.call('tgtadm', '--lld', 'iscsi', '--mode', 'target',
'--op', 'delete', '--tid', '1')]
iscsi.clean_up(self.fake_dev)
mock_execute.assert_has_calls(expected)
@mock.patch.object(iscsi.rtslib_fb, 'RTSRoot', autospec=True)
class TestISCSIExtensionCleanUp(base.IronicAgentTest):

View File

@ -0,0 +1,12 @@
---
fixes:
- |
Fixes an issue in fallback error handling where native iSCSI controls
are unavailable due to the composition of the IPA ramdisk and where direct
``tgtadm`` commands also fails.
Before fallback error handling was added, the teardown was skipped
completely in the event of the native iSCSI controls being unavailable.
The end user behavior is now as it was previously prior to the fallback
error handling being added, but IPA will still continue to attempt to
clean up the iSCSI session.