summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVanou Ishii <ishii.vanou@fujitsu.com>2022-02-05 10:44:52 +0900
committerDmitry Tantsur <dtantsur@protonmail.com>2022-03-08 10:44:04 +0000
commit6488c5b442f15d355c1bfc4e5dc1e9ede27b82ff (patch)
tree161d3f947ccd3d4837b6a6e5b578cb9a8fca6db4
parent02ad3b264b49b60ddbae89ac7a0d3596c7117ae4 (diff)
downloadironic-python-agent-6488c5b442f15d355c1bfc4e5dc1e9ede27b82ff.tar.gz
Rescan device after filesystem creation
In work_on_disk function, IPA runs mkfs commands without following device rescan operation. This leads to incorrect content of uuids_to_return to be returned. These mkfs commands modify partition label but IPA fails to catch such changes because of no following device rescan operation. This commit adds call of device rescan function before uuids_to_return construction. Change-Id: I4e8b30deb5e2247f51ce8f10bd3271f64a264089 (cherry picked from commit fa70a1909b0f60e1c2c804cb28765fd989ed3fb9)
-rw-r--r--ironic_python_agent/partition_utils.py3
-rw-r--r--ironic_python_agent/tests/unit/test_partition_utils.py17
-rw-r--r--releasenotes/notes/rescan-device-after-mkfs-3f9d52a2e3b6fff3.yaml5
3 files changed, 21 insertions, 4 deletions
diff --git a/ironic_python_agent/partition_utils.py b/ironic_python_agent/partition_utils.py
index 18b4cfdb..42b90445 100644
--- a/ironic_python_agent/partition_utils.py
+++ b/ironic_python_agent/partition_utils.py
@@ -316,6 +316,9 @@ def work_on_disk(dev, root_mb, swap_mb, ephemeral_mb, ephemeral_format,
"formatted for node %(node)s",
{'ephemeral': ephemeral_part, 'node': node_uuid})
+ # Rescan device to get current status (e.g. reflect modification of mkfs)
+ disk_utils.trigger_device_rescan(dev)
+
uuids_to_return = {
'root uuid': root_part,
'efi system partition uuid': part_dict.get('efi system partition'),
diff --git a/ironic_python_agent/tests/unit/test_partition_utils.py b/ironic_python_agent/tests/unit/test_partition_utils.py
index f6f56695..88122ed5 100644
--- a/ironic_python_agent/tests/unit/test_partition_utils.py
+++ b/ironic_python_agent/tests/unit/test_partition_utils.py
@@ -408,6 +408,8 @@ class WorkOnDiskTestCase(base.IronicAgentTest):
cpu_arch="")
mock_unlink.assert_called_once_with('fake-path')
+ @mock.patch.object(disk_utils, 'trigger_device_rescan',
+ lambda d: None)
@mock.patch.object(utils, 'mkfs', lambda fs, path, label=None: None)
@mock.patch.object(disk_utils, 'block_uuid', lambda p: 'uuid')
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
@@ -442,6 +444,8 @@ class WorkOnDiskTestCase(base.IronicAgentTest):
self.assertEqual('uuid', res['root uuid'])
self.assertFalse(mock_populate.called)
+ @mock.patch.object(disk_utils, 'trigger_device_rescan',
+ lambda d: None)
@mock.patch.object(utils, 'mkfs', lambda fs, path, label=None: None)
@mock.patch.object(disk_utils, 'block_uuid', lambda p: 'uuid')
@mock.patch.object(disk_utils, 'populate_image', lambda image_path,
@@ -475,11 +479,12 @@ class WorkOnDiskTestCase(base.IronicAgentTest):
disk_label='gpt',
cpu_arch="")
+ @mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
@mock.patch.object(utils, 'mkfs', autospec=True)
def test_uefi_localboot(self, mock_mkfs, mock_populate_image,
- mock_block_uuid):
+ mock_block_uuid, mock_trigger_device_rescan):
"""Test that we create a fat filesystem with UEFI localboot."""
root_part = '/dev/fake-part1'
efi_part = '/dev/fake-part2'
@@ -510,12 +515,14 @@ class WorkOnDiskTestCase(base.IronicAgentTest):
root_part, conv_flags=None)
mock_block_uuid.assert_any_call(root_part)
mock_block_uuid.assert_any_call(efi_part)
+ mock_trigger_device_rescan.assert_called_once_with(self.dev)
+ @mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
@mock.patch.object(utils, 'mkfs', autospec=True)
def test_preserve_ephemeral(self, mock_mkfs, mock_populate_image,
- mock_block_uuid):
+ mock_block_uuid, mock_trigger_device_rescan):
"""Test that ephemeral partition doesn't get overwritten."""
ephemeral_part = '/dev/fake-part1'
root_part = '/dev/fake-part2'
@@ -543,11 +550,12 @@ class WorkOnDiskTestCase(base.IronicAgentTest):
cpu_arch="")
self.assertFalse(mock_mkfs.called)
+ @mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
@mock.patch.object(utils, 'mkfs', autospec=True)
def test_ppc64le_prep_part(self, mock_mkfs, mock_populate_image,
- mock_block_uuid):
+ mock_block_uuid, mock_trigger_device_rescan):
"""Test that PReP partition uuid is returned."""
prep_part = '/dev/fake-part1'
root_part = '/dev/fake-part2'
@@ -573,11 +581,12 @@ class WorkOnDiskTestCase(base.IronicAgentTest):
cpu_arch="ppc64le")
self.assertFalse(mock_mkfs.called)
+ @mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
@mock.patch.object(utils, 'mkfs', autospec=True)
def test_convert_to_sparse(self, mock_mkfs, mock_populate_image,
- mock_block_uuid):
+ mock_block_uuid, mock_trigger_device_rescan):
ephemeral_part = '/dev/fake-part1'
swap_part = '/dev/fake-part2'
root_part = '/dev/fake-part3'
diff --git a/releasenotes/notes/rescan-device-after-mkfs-3f9d52a2e3b6fff3.yaml b/releasenotes/notes/rescan-device-after-mkfs-3f9d52a2e3b6fff3.yaml
new file mode 100644
index 00000000..3a8d9e08
--- /dev/null
+++ b/releasenotes/notes/rescan-device-after-mkfs-3f9d52a2e3b6fff3.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+ - |
+ Adds device rescan operation after partitioning the root device to ensure
+ that updated UUIDs are reflected correctly