Merge "Include wipefs --force option"

This commit is contained in:
Jenkins 2016-07-06 17:01:45 +00:00 committed by Gerrit Code Review
commit 6fec307e52
2 changed files with 29 additions and 8 deletions

View File

@ -328,10 +328,19 @@ def destroy_disk_metadata(dev, node_uuid):
# https://bugs.launchpad.net/ironic/+bug/1317647
LOG.debug("Start destroy disk metadata for node %(node)s.",
{'node': node_uuid})
utils.execute('wipefs', '--all', dev,
run_as_root=True,
check_exit_code=[0],
use_standard_locale=True)
try:
utils.execute('wipefs', '--force', '--all', dev,
run_as_root=True,
use_standard_locale=True)
except processutils.ProcessExecutionError as e:
# NOTE(zhenguo): Check if --force option is supported for wipefs,
# if not, we should try without it.
if '--force' in str(e):
utils.execute('wipefs', '--all', dev,
run_as_root=True,
use_standard_locale=True)
else:
raise e
LOG.info(_LI("Disk metadata on %(dev)s successfully destroyed for node "
"%(node)s"), {'dev': dev, 'node': node_uuid})

View File

@ -387,9 +387,8 @@ class DestroyMetaDataTestCase(test_base.BaseTestCase):
self.node_uuid = "12345678-1234-1234-1234-1234567890abcxyz"
def test_destroy_disk_metadata(self, mock_exec):
expected_calls = [mock.call('wipefs', '--all', 'fake-dev',
expected_calls = [mock.call('wipefs', '--force', '--all', 'fake-dev',
run_as_root=True,
check_exit_code=[0],
use_standard_locale=True)]
disk_utils.destroy_disk_metadata(self.dev, self.node_uuid)
mock_exec.assert_has_calls(expected_calls)
@ -397,9 +396,8 @@ class DestroyMetaDataTestCase(test_base.BaseTestCase):
def test_destroy_disk_metadata_wipefs_fail(self, mock_exec):
mock_exec.side_effect = processutils.ProcessExecutionError
expected_call = [mock.call('wipefs', '--all', 'fake-dev',
expected_call = [mock.call('wipefs', '--force', '--all', 'fake-dev',
run_as_root=True,
check_exit_code=[0],
use_standard_locale=True)]
self.assertRaises(processutils.ProcessExecutionError,
disk_utils.destroy_disk_metadata,
@ -407,6 +405,20 @@ class DestroyMetaDataTestCase(test_base.BaseTestCase):
self.node_uuid)
mock_exec.assert_has_calls(expected_call)
def test_destroy_disk_metadata_wipefs_not_support_force(self, mock_exec):
mock_exec.side_effect = iter(
[processutils.ProcessExecutionError(description='--force'),
(None, None)])
expected_call = [mock.call('wipefs', '--force', '--all', 'fake-dev',
run_as_root=True,
use_standard_locale=True),
mock.call('wipefs', '--all', 'fake-dev',
run_as_root=True,
use_standard_locale=True)]
disk_utils.destroy_disk_metadata(self.dev, self.node_uuid)
mock_exec.assert_has_calls(expected_call)
@mock.patch.object(utils, 'execute', autospec=True)
class GetDeviceBlockSizeTestCase(test_base.BaseTestCase):