From 56e63ce36a72448e128c01605d98492c80dca38f Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Tue, 9 Nov 2021 12:50:46 +0100 Subject: [PATCH] Re-read the partition table with partx -a, part 2 Use add instead of update to re-read the partition table with partx. See [1] for more details. Co-authored-by: Arne Wiebalck [1] https: //opendev.org/openstack/ironic-python-agent/commit/dc8c1f16f9a00e2bff21612d1a9cf0ea0f3addf0 Change-Id: I2336e22dadc790cfbde87904612fcaa3b8c501db (cherry picked from commit 23e67b5fea58295d0320f99d4513a66d720f09ee) --- ironic_python_agent/hardware.py | 2 +- .../tests/unit/test_hardware.py | 84 +++++++++---------- ...x-rescan-device-raid-29aa1558b036b496.yaml | 7 ++ 3 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 releasenotes/notes/fix-rescan-device-raid-29aa1558b036b496.yaml diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 256af6f62..f2156f844 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -2043,7 +2043,7 @@ class GenericHardwareManager(HardwareManager): # The real difference between partx and partprobe is # unclear, but note that partprobe does not seem to # work synchronously for nvme drives... - utils.execute("partx", "-u", device, + utils.execute("partx", "-a", device, check_exit_code=False) except processutils.ProcessExecutionError as e: msg = "Failed to create partitions on {}: {}".format( diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py index ad3a8f652..573d28d58 100644 --- a/ironic_python_agent/tests/unit/test_hardware.py +++ b/ironic_python_agent/tests/unit/test_hardware.py @@ -2498,16 +2498,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('sgdisk', '-F', '/dev/sdb'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 2, '/dev/sda1', '/dev/sdb1'), @@ -2587,22 +2587,22 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('sgdisk', '-F', '/dev/sdc'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sdc', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdc', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdc', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sdc', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdc', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdc', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 3, '/dev/sda1', '/dev/sdb1', '/dev/sdc1'), @@ -2685,28 +2685,28 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('sgdisk', '-F', '/dev/sdd'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sdc', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdc', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdc', check_exit_code=False), mock.call('parted', '/dev/sdd', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdd', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdd', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sdc', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdc', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdc', check_exit_code=False), mock.call('parted', '/dev/sdd', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdd', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdd', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 4, '/dev/sda1', '/dev/sdb1', '/dev/sdc1', '/dev/sdd1'), @@ -2770,16 +2770,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('parted', '/dev/sdb', '-s', '--', 'mklabel', 'gpt'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '551MiB', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '551MiB', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 2, '/dev/sda1', '/dev/sdb1'), @@ -2849,16 +2849,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('parted', '/dev/sdb', '-s', '--', 'mklabel', 'gpt'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '8MiB', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '8MiB', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 2, '/dev/sda1', '/dev/sdb1'), @@ -2923,16 +2923,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('sgdisk', '-F', '/dev/sdb'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '30GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '30GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 2, '/dev/sda1', '/dev/sdb1'), @@ -2999,16 +2999,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('sgdisk', '-F', '/dev/sdb'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '20GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '20GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '20GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '20GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '0', '--raid-devices', 2, '/dev/sda1', '/dev/sdb1'), @@ -3086,16 +3086,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): mock.call('sgdisk', '-F', '/dev/sdb'), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '42s', '10GiB'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('parted', '/dev/sda', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sda', check_exit_code=False), + mock.call('partx', '-a', '/dev/sda', check_exit_code=False), mock.call('parted', '/dev/sdb', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/sdb', check_exit_code=False), + mock.call('partx', '-a', '/dev/sdb', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 2, '/dev/sda1', '/dev/sdb1'), @@ -3426,16 +3426,16 @@ class TestGenericHardwareManager(base.IronicAgentTest): 'gpt'), mock.call('parted', '/dev/nvme0n1', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '551MiB', '10GiB'), - mock.call('partx', '-u', '/dev/nvme0n1', check_exit_code=False), + mock.call('partx', '-a', '/dev/nvme0n1', check_exit_code=False), mock.call('parted', '/dev/nvme1n1', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '551MiB', '10GiB'), - mock.call('partx', '-u', '/dev/nvme1n1', check_exit_code=False), + mock.call('partx', '-a', '/dev/nvme1n1', check_exit_code=False), mock.call('parted', '/dev/nvme0n1', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/nvme0n1', check_exit_code=False), + mock.call('partx', '-a', '/dev/nvme0n1', check_exit_code=False), mock.call('parted', '/dev/nvme1n1', '-s', '-a', 'optimal', '--', 'mkpart', 'primary', '10GiB', '-1'), - mock.call('partx', '-u', '/dev/nvme1n1', check_exit_code=False), + mock.call('partx', '-a', '/dev/nvme1n1', check_exit_code=False), mock.call('mdadm', '--create', '/dev/md0', '--force', '--run', '--metadata=1', '--level', '1', '--raid-devices', 2, '/dev/nvme0n1p1', '/dev/nvme1n1p1'), diff --git a/releasenotes/notes/fix-rescan-device-raid-29aa1558b036b496.yaml b/releasenotes/notes/fix-rescan-device-raid-29aa1558b036b496.yaml new file mode 100644 index 000000000..7083b1185 --- /dev/null +++ b/releasenotes/notes/fix-rescan-device-raid-29aa1558b036b496.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes an issue where partitions are not visible due to an + incorrect call to have the partition table re-read during raid + configuration creation. +