From ae53e8e4b386992ed2c6cfc1648f3b2f3062e156 Mon Sep 17 00:00:00 2001 From: Luke Odom Date: Fri, 9 Feb 2024 18:53:58 -0800 Subject: [PATCH] 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 --- ironic_lib/disk_utils.py | 1 + ironic_lib/tests/test_disk_utils.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ironic_lib/disk_utils.py b/ironic_lib/disk_utils.py index 7765cf68..d28e1fe5 100644 --- a/ironic_lib/disk_utils.py +++ b/ironic_lib/disk_utils.py @@ -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) diff --git a/ironic_lib/tests/test_disk_utils.py b/ironic_lib/tests/test_disk_utils.py index d5ccba69..c3184930 100644 --- a/ironic_lib/tests/test_disk_utils.py +++ b/ironic_lib/tests/test_disk_utils.py @@ -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), ])