Merge "Make close on cryptsetup volumes idempotent"
This commit is contained in:
commit
a5c60d94d8
@ -169,11 +169,13 @@ class CryptsetupEncryptor(base.VolumeEncryptor):
|
|||||||
def _close_volume(self, **kwargs):
|
def _close_volume(self, **kwargs):
|
||||||
"""Closes the device (effectively removes the dm-crypt mapping)."""
|
"""Closes the device (effectively removes the dm-crypt mapping)."""
|
||||||
LOG.debug("closing encrypted volume %s", self.dev_path)
|
LOG.debug("closing encrypted volume %s", self.dev_path)
|
||||||
# cryptsetup returns 4 when attempting to destroy a non-active
|
# NOTE(mdbooth): remove will return 4 (wrong device specified) if
|
||||||
# dm-crypt device. We are going to ignore this error code to make
|
# the device doesn't exist. We assume here that the caller hasn't
|
||||||
# nova deleting that instance successfully.
|
# specified the wrong device, and that it doesn't exist because it
|
||||||
|
# isn't open. We don't fail in this case in order to make this
|
||||||
|
# operation idempotent.
|
||||||
self._execute('cryptsetup', 'remove', self.dev_name,
|
self._execute('cryptsetup', 'remove', self.dev_name,
|
||||||
run_as_root=True, check_exit_code=True,
|
run_as_root=True, check_exit_code=[0, 4],
|
||||||
root_helper=self._root_helper)
|
root_helper=self._root_helper)
|
||||||
|
|
||||||
def detach_volume(self, **kwargs):
|
def detach_volume(self, **kwargs):
|
||||||
|
@ -88,7 +88,7 @@ class CryptsetupEncryptorTestCase(test_base.VolumeEncryptorTestCase):
|
|||||||
mock_execute.assert_has_calls([
|
mock_execute.assert_has_calls([
|
||||||
mock.call('cryptsetup', 'remove', self.dev_name,
|
mock.call('cryptsetup', 'remove', self.dev_name,
|
||||||
root_helper=self.root_helper,
|
root_helper=self.root_helper,
|
||||||
run_as_root=True, check_exit_code=True),
|
run_as_root=True, check_exit_code=[0, 4]),
|
||||||
])
|
])
|
||||||
|
|
||||||
@mock.patch('os_brick.executor.Executor._execute')
|
@mock.patch('os_brick.executor.Executor._execute')
|
||||||
@ -98,7 +98,7 @@ class CryptsetupEncryptorTestCase(test_base.VolumeEncryptorTestCase):
|
|||||||
mock_execute.assert_has_calls([
|
mock_execute.assert_has_calls([
|
||||||
mock.call('cryptsetup', 'remove', self.dev_name,
|
mock.call('cryptsetup', 'remove', self.dev_name,
|
||||||
root_helper=self.root_helper,
|
root_helper=self.root_helper,
|
||||||
run_as_root=True, check_exit_code=True),
|
run_as_root=True, check_exit_code=[0, 4]),
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_init_volume_encryption_not_supported(self):
|
def test_init_volume_encryption_not_supported(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user