Check GPT table with sgdisk insread of partprobe

On centos7.2, it doesn't happen every time, but sometimes, partprobe
fails with error `Device or resource busy` in _fix_gpt_structs. In fact,
this is not a problem, I tried ignoring this error and ran remain code.
Things went well. The target of running `partprobe` is to check GPT
table, we can run `sgdisk -v` instead.

This patch is to replace `partprobe` command in _fix_gpt_structs to
avoid `Device or resource busy` error.

Change-Id: I43182f17b1c6229132814313f7582ab30245f6bb
This commit is contained in:
cheng 2018-08-22 18:05:58 +08:00
parent 03accb9e49
commit b9a109c65f
2 changed files with 14 additions and 19 deletions

View File

@ -742,12 +742,10 @@ def _fix_gpt_structs(device, node_uuid):
commands fail.
"""
try:
output, err = utils.execute('partprobe', device,
use_standard_locale=True,
run_as_root=True)
output, _err = utils.execute('sgdisk', '-v', device, run_as_root=True)
search_str = "fix the GPT to use all of the space"
if search_str in err:
search_str = "it doesn't reside\nat the end of the disk"
if search_str in output:
utils.execute('sgdisk', '-e', device, run_as_root=True)
except (processutils.UnknownArgumentError,
processutils.ProcessExecutionError, OSError) as e:

View File

@ -1022,18 +1022,17 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase):
self.assertEqual(1, mock_log.call_count)
def test_fix_gpt_structs_fix_required(self, mock_execute):
partprobe_err = """
Error: The backup GPT table is not at the end of the disk, as it should be.
This might mean that another operating system believes the disk is smaller.
Fix, by moving the backup to the end (and removing the old backup)?
Warning: Not all of the space available to /dev/sdb appears to be used,
you can fix the GPT to use all of the space (an extra 581456476 blocks)
or continue with the current setting?
sgdisk_v_output = """
Problem: The secondary header's self-pointer indicates that it doesn't reside
at the end of the disk. If you've added a disk to a RAID array, use the 'e'
option on the experts' menu to adjust the secondary header's and partition
table's locations.
Identified 1 problems!
"""
mock_execute.return_value = ('', partprobe_err)
mock_execute.return_value = (sgdisk_v_output, '')
execute_calls = [
mock.call('partprobe', '/dev/fake', use_standard_locale=True,
run_as_root=True),
mock.call('sgdisk', '-v', '/dev/fake', run_as_root=True),
mock.call('sgdisk', '-e', '/dev/fake', run_as_root=True)
]
disk_utils._fix_gpt_structs('/dev/fake', self.node_uuid)
@ -1043,8 +1042,7 @@ or continue with the current setting?
mock_execute.return_value = ('', '')
disk_utils._fix_gpt_structs('/dev/fake', self.node_uuid)
mock_execute.assert_called_once_with('partprobe', '/dev/fake',
use_standard_locale=True,
mock_execute.assert_called_once_with('sgdisk', '-v', '/dev/fake',
run_as_root=True)
@mock.patch.object(disk_utils.LOG, 'error', autospec=True)
@ -1054,8 +1052,7 @@ or continue with the current setting?
'Failed to fix GPT data structures on disk',
disk_utils._fix_gpt_structs,
self.dev, self.node_uuid)
mock_execute.assert_called_once_with('partprobe', '/dev/fake',
use_standard_locale=True,
mock_execute.assert_called_once_with('sgdisk', '-v', '/dev/fake',
run_as_root=True)
self.assertEqual(1, mock_log.call_count)