diff options
author | Zuul <zuul@review.opendev.org> | 2019-09-24 12:00:00 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-09-24 12:00:00 +0000 |
commit | 74c8cd581bee2da059845bb95de5160774b5f191 (patch) | |
tree | b4e171b689e489ab3782f47cc9fb6c6f54e9a60d | |
parent | 3968ec9d5ad48f8ed13fc66ef31bef4b79a8c690 (diff) | |
parent | 8be4cb689cac5755f09eaa27cdde86a30b2633f8 (diff) | |
download | ironic-python-agent-74c8cd581bee2da059845bb95de5160774b5f191.tar.gz |
Merge "Attempt tgtd session detach"5.0.0
-rw-r--r-- | ironic_python_agent/extensions/iscsi.py | 15 | ||||
-rw-r--r-- | ironic_python_agent/tests/unit/extensions/test_iscsi.py | 28 |
2 files changed, 37 insertions, 6 deletions
diff --git a/ironic_python_agent/extensions/iscsi.py b/ironic_python_agent/extensions/iscsi.py index bc7ef0d4..7fca4154 100644 --- a/ironic_python_agent/extensions/iscsi.py +++ b/ironic_python_agent/extensions/iscsi.py @@ -113,8 +113,19 @@ def clean_up(device): """Clean up iSCSI for a given device.""" try: rts_root = rtslib_fb.RTSRoot() - except (EnvironmentError, rtslib_fb.RTSLibError) as exc: - LOG.info('Linux-IO is not available, not cleaning up. Error: %s.', exc) + 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.") + + 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.") return storage = None diff --git a/ironic_python_agent/tests/unit/extensions/test_iscsi.py b/ironic_python_agent/tests/unit/extensions/test_iscsi.py index 3dc50905..f275c0fc 100644 --- a/ironic_python_agent/tests/unit/extensions/test_iscsi.py +++ b/ironic_python_agent/tests/unit/extensions/test_iscsi.py @@ -281,6 +281,30 @@ class TestISCSIExtensionLIO(base.IronicAgentTest): mock_destroy.assert_called_once_with('/dev/fake', 'my_node_uuid') +@mock.patch.object(utils, 'execute', autospec=True) +class TestISCSIExtensionCleanUpFallback(base.IronicAgentTest): + + def setUp(self): + super(TestISCSIExtensionCleanUpFallback, self).setUp() + self.agent_extension = iscsi.ISCSIExtension() + self.fake_dev = '/dev/fake' + self.fake_iqn = 'iqn-fake' + self.rtsmock = mock.patch.object( + iscsi.rtslib_fb, 'RTSRoot', + side_effect=EnvironmentError(), autospec=True) + + def test_lio_not_available(self, mock_execute): + mock_execute.return_value = ('', '') + 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): @@ -290,10 +314,6 @@ class TestISCSIExtensionCleanUp(base.IronicAgentTest): self.fake_dev = '/dev/fake' self.fake_iqn = 'iqn-fake' - def test_lio_not_available(self, mock_rtslib): - mock_rtslib.side_effect = IOError() - iscsi.clean_up(self.fake_dev) - def test_device_not_found(self, mock_rtslib): mock_rtslib.return_value.storage_objects = [] iscsi.clean_up(self.fake_dev) |