Add retry attempts for the partprobe command

The partprobe command may fail because the device is busy some
times. Add retry attempts to resolve this problem.

Closes-Bug: #1756760
Change-Id: Ic888e7b6c93e83511a76bf8000619531b1eec9e1
This commit is contained in:
fpxie 2018-02-08 14:15:08 +08:00
parent cdea1086d6
commit d2ade05278
2 changed files with 11 additions and 6 deletions

View File

@ -55,6 +55,10 @@ opts = [
default=3,
help='Maximum attempts to verify an iSCSI connection is '
'active, sleeping 1 second between attempts.'),
cfg.IntOpt('partprobe_attempts',
default=10,
help='Maximum number of attempts to try to read the '
'partition.'),
]
CONF = cfg.CONF
@ -627,7 +631,8 @@ def _get_labelled_partition(device_path, label, node_uuid):
returns None.
"""
try:
utils.execute('partprobe', device_path, run_as_root=True)
utils.execute('partprobe', device_path, run_as_root=True,
attempts=CONF.disk_utils.partprobe_attempts)
# lsblk command
output, err = utils.execute('lsblk', '-Po', 'name,label', device_path,

View File

@ -828,7 +828,7 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase):
self.node_uuid)
self.assertEqual(part_result, result)
execute_calls = [
mock.call('partprobe', self.dev, run_as_root=True),
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
mock.call('lsblk', '-Po', 'name,label', self.dev,
check_exit_code=[0, 1],
use_standard_locale=True, run_as_root=True)
@ -843,7 +843,7 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase):
self.node_uuid)
self.assertIsNone(result)
execute_calls = [
mock.call('partprobe', self.dev, run_as_root=True),
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
mock.call('lsblk', '-Po', 'name,label', self.dev,
check_exit_code=[0, 1],
use_standard_locale=True, run_as_root=True)
@ -861,7 +861,7 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase):
disk_utils._get_labelled_partition, self.dev,
self.config_part_label, self.node_uuid)
execute_calls = [
mock.call('partprobe', self.dev, run_as_root=True),
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
mock.call('lsblk', '-Po', 'name,label', self.dev,
check_exit_code=[0, 1],
use_standard_locale=True, run_as_root=True)
@ -875,8 +875,8 @@ class WholeDiskPartitionTestCases(base.IronicLibTestCase):
'Failed to retrieve partition labels',
disk_utils._get_labelled_partition, self.dev,
self.config_part_label, self.node_uuid)
mock_execute.assert_called_once_with('partprobe', self.dev,
run_as_root=True)
mock_execute.assert_called_once_with(
'partprobe', self.dev, run_as_root=True, attempts=10)
self.assertEqual(1, mock_log.call_count)
def _test_is_disk_larger_than_max_size(self, mock_execute, blk_out):