Ignore errorcode=4 when executing `cryptsetup remove` command

If an attached encrypted volume is failed to detach from the instance
when deleting that instance, user can not delete that instance at all.

This patch adds 4 in check_exit_code when executing `cryptsetup remove`
command to eat that exception.

PS: exit_code = 4 indicate ENODEV error which means no device(also includes
the crypt device inactive).

Closes-Bug: #1482066
Change-Id: I12e2a52068850528a4bd68486344b74eb9b82c88
This commit is contained in:
Eli Qiao 2015-10-13 14:08:31 +08:00
parent 02b7e64b29
commit 11e20dd6f9
2 changed files with 6 additions and 3 deletions

View File

@ -78,7 +78,7 @@ class CryptsetupEncryptorTestCase(test_base.VolumeEncryptorTestCase):
mock_execute.assert_has_calls([
mock.call('cryptsetup', 'remove', self.dev_name,
run_as_root=True, check_exit_code=True),
run_as_root=True, check_exit_code=[0, 4]),
])
self.assertEqual(1, mock_execute.call_count)
@ -88,7 +88,7 @@ class CryptsetupEncryptorTestCase(test_base.VolumeEncryptorTestCase):
mock_execute.assert_has_calls([
mock.call('cryptsetup', 'remove', self.dev_name,
run_as_root=True, check_exit_code=True),
run_as_root=True, check_exit_code=[0, 4]),
])
self.assertEqual(1, mock_execute.call_count)

View File

@ -103,8 +103,11 @@ class CryptsetupEncryptor(base.VolumeEncryptor):
def _close_volume(self, **kwargs):
"""Closes the device (effectively removes the dm-crypt mapping)."""
LOG.debug("closing encrypted volume %s", self.dev_path)
# cryptsetup returns 4 when attempting to destroy a non-active
# dm-crypt device. We are going to ignore this error code to make
# nova deleting that instance successfully.
utils.execute('cryptsetup', 'remove', self.dev_name,
run_as_root=True, check_exit_code=True)
run_as_root=True, check_exit_code=[0, 4])
def detach_volume(self, **kwargs):
"""Removes the dm-crypt mapping for the device."""