Swap partprobe and udev settle

On ubuntu based systems calling these in opposite causes a
race condition where partitions aren't ready when we read/use them

Closes-Bug: 2050013
Change-Id: Ied7e4f17786dfc0e7f54962013e48ff96c5faa88
This commit is contained in:
Luke Odom 2024-02-09 18:53:58 -08:00
parent 118da00f2f
commit ae53e8e4b3
2 changed files with 6 additions and 1 deletions

View File

@ -700,6 +700,7 @@ def trigger_device_rescan(device, attempts=None):
# kernel.
udev_settle()
partprobe(device, attempts=attempts)
udev_settle()
try:
# Also verify that the partitioning is correct now.
utils.execute('sgdisk', '-v', device, run_as_root=True)

View File

@ -260,6 +260,7 @@ class MakePartitionsTestCase(base.IronicLibTestCase):
mock.call('udevadm', 'settle'),
mock.call('partprobe', self.dev, attempts=10,
run_as_root=True),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', self.dev, run_as_root=True)]
mock_exc.assert_has_calls([parted_call, fuser_call] + sync_calls)
@ -730,6 +731,7 @@ class TriggerDeviceRescanTestCase(base.IronicLibTestCase):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', '/dev/fake', run_as_root=True, attempts=10),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', '/dev/fake', run_as_root=True),
])
@ -740,11 +742,12 @@ class TriggerDeviceRescanTestCase(base.IronicLibTestCase):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', '/dev/fake', run_as_root=True, attempts=1),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', '/dev/fake', run_as_root=True),
])
def test_fails(self, mock_execute):
mock_execute.side_effect = [('', '')] * 3 + [
mock_execute.side_effect = [('', '')] * 4 + [
processutils.ProcessExecutionError
]
self.assertFalse(disk_utils.trigger_device_rescan('/dev/fake'))
@ -752,6 +755,7 @@ class TriggerDeviceRescanTestCase(base.IronicLibTestCase):
mock.call('sync'),
mock.call('udevadm', 'settle'),
mock.call('partprobe', '/dev/fake', run_as_root=True, attempts=10),
mock.call('udevadm', 'settle'),
mock.call('sgdisk', '-v', '/dev/fake', run_as_root=True),
])