Skip to content

Commit 7217c6d

Browse files
vanoudtantsur
authored andcommitted
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 fa70a19)
1 parent a48f3f1 commit 7217c6d

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

ironic_python_agent/partition_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ def work_on_disk(dev, root_mb, swap_mb, ephemeral_mb, ephemeral_format,
312312
"formatted for node %(node)s",
313313
{'ephemeral': ephemeral_part, 'node': node_uuid})
314314

315+
# Rescan device to get current status (e.g. reflect modification of mkfs)
316+
disk_utils.trigger_device_rescan(dev)
317+
315318
uuids_to_return = {
316319
'root uuid': root_part,
317320
'efi system partition uuid': part_dict.get('efi system partition'),

ironic_python_agent/tests/unit/test_partition_utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ def test_no_configdrive_partition(self, mock_configdrive, mock_unlink):
406406
cpu_arch="")
407407
mock_unlink.assert_called_once_with('fake-path')
408408

409+
@mock.patch.object(disk_utils, 'trigger_device_rescan',
410+
lambda d: None)
409411
@mock.patch.object(utils, 'mkfs', lambda fs, path, label=None: None)
410412
@mock.patch.object(disk_utils, 'block_uuid', lambda p: 'uuid')
411413
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
@@ -440,6 +442,8 @@ def test_without_image(self, mock_populate):
440442
self.assertEqual('uuid', res['root uuid'])
441443
self.assertFalse(mock_populate.called)
442444

445+
@mock.patch.object(disk_utils, 'trigger_device_rescan',
446+
lambda d: None)
443447
@mock.patch.object(utils, 'mkfs', lambda fs, path, label=None: None)
444448
@mock.patch.object(disk_utils, 'block_uuid', lambda p: 'uuid')
445449
@mock.patch.object(disk_utils, 'populate_image', lambda image_path,
@@ -473,11 +477,12 @@ def test_gpt_disk_label(self):
473477
disk_label='gpt',
474478
cpu_arch="")
475479

480+
@mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
476481
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
477482
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
478483
@mock.patch.object(utils, 'mkfs', autospec=True)
479484
def test_uefi_localboot(self, mock_mkfs, mock_populate_image,
480-
mock_block_uuid):
485+
mock_block_uuid, mock_trigger_device_rescan):
481486
"""Test that we create a fat filesystem with UEFI localboot."""
482487
root_part = '/dev/fake-part1'
483488
efi_part = '/dev/fake-part2'
@@ -508,12 +513,14 @@ def test_uefi_localboot(self, mock_mkfs, mock_populate_image,
508513
root_part, conv_flags=None)
509514
mock_block_uuid.assert_any_call(root_part)
510515
mock_block_uuid.assert_any_call(efi_part)
516+
mock_trigger_device_rescan.assert_called_once_with(self.dev)
511517

518+
@mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
512519
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
513520
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
514521
@mock.patch.object(utils, 'mkfs', autospec=True)
515522
def test_preserve_ephemeral(self, mock_mkfs, mock_populate_image,
516-
mock_block_uuid):
523+
mock_block_uuid, mock_trigger_device_rescan):
517524
"""Test that ephemeral partition doesn't get overwritten."""
518525
ephemeral_part = '/dev/fake-part1'
519526
root_part = '/dev/fake-part2'
@@ -541,11 +548,12 @@ def test_preserve_ephemeral(self, mock_mkfs, mock_populate_image,
541548
cpu_arch="")
542549
self.assertFalse(mock_mkfs.called)
543550

551+
@mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
544552
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
545553
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
546554
@mock.patch.object(utils, 'mkfs', autospec=True)
547555
def test_ppc64le_prep_part(self, mock_mkfs, mock_populate_image,
548-
mock_block_uuid):
556+
mock_block_uuid, mock_trigger_device_rescan):
549557
"""Test that PReP partition uuid is returned."""
550558
prep_part = '/dev/fake-part1'
551559
root_part = '/dev/fake-part2'
@@ -571,11 +579,12 @@ def test_ppc64le_prep_part(self, mock_mkfs, mock_populate_image,
571579
cpu_arch="ppc64le")
572580
self.assertFalse(mock_mkfs.called)
573581

582+
@mock.patch.object(disk_utils, 'trigger_device_rescan', autospec=True)
574583
@mock.patch.object(disk_utils, 'block_uuid', autospec=True)
575584
@mock.patch.object(disk_utils, 'populate_image', autospec=True)
576585
@mock.patch.object(utils, 'mkfs', autospec=True)
577586
def test_convert_to_sparse(self, mock_mkfs, mock_populate_image,
578-
mock_block_uuid):
587+
mock_block_uuid, mock_trigger_device_rescan):
579588
ephemeral_part = '/dev/fake-part1'
580589
swap_part = '/dev/fake-part2'
581590
root_part = '/dev/fake-part3'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Adds device rescan operation after partitioning the root device to ensure
5+
that updated UUIDs are reflected correctly

0 commit comments

Comments
 (0)