summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Bungert <[email protected]>2024-03-19 21:40:33 -0600
committerDan Bungert <[email protected]>2024-03-25 10:42:32 -0600
commit974c0d0c365fa3068fa1c43e38261189e622e17d (patch)
tree2bbd92c05101dd2620ac408f5caac616a814d4b6
parent63b0445343592036f6bad20bb4fc4339166149f7 (diff)
block/meta: add flock calls around disk wipe
LP: #2016860
-rw-r--r--curtin/commands/block_meta.py43
-rw-r--r--tests/unittests/test_commands_block_meta.py3
2 files changed, 26 insertions, 20 deletions
diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
index 58889b9a..dc26a8c6 100644
--- a/curtin/commands/block_meta.py
+++ b/curtin/commands/block_meta.py
@@ -795,26 +795,29 @@ def disk_handler(info, storage_config, context):
"table" % disk)
else:
# wipe the disk and create the partition table if instructed to do so
- if config.value_as_boolean(info.get('wipe')):
- block.wipe_volume(disk, mode=info.get('wipe'))
- if config.value_as_boolean(ptable):
- LOG.info("labeling device: '%s' with '%s' partition table", disk,
- ptable)
- if ptable == "gpt":
- # Wipe both MBR and GPT that may be present on the disk.
- # N.B.: wipe_volume wipes 1M at front and end of the disk.
- # This could destroy disk data in filesystems that lived
- # there.
- block.wipe_volume(disk, mode='superblock')
- elif ptable in _dos_names:
- util.subp(["parted", disk, "--script", "mklabel", "msdos"])
- elif ptable == "vtoc":
- util.subp(["fdasd", "-c", "/dev/null", disk])
- holders = clear_holders.get_holders(disk)
- if len(holders) > 0:
- LOG.info('Detected block holders on disk %s: %s', disk, holders)
- clear_holders.clear_holders(disk)
- clear_holders.assert_clear(disk)
+ with util.FlockEx(disk):
+ if config.value_as_boolean(info.get('wipe')):
+ block.wipe_volume(disk, mode=info.get('wipe'))
+ if config.value_as_boolean(ptable):
+ LOG.info("labeling device: '%s' with '%s' partition table",
+ disk, ptable)
+ if ptable == "gpt":
+ # Wipe both MBR and GPT that may be present on the disk.
+ # N.B.: wipe_volume wipes 1M at front and end of the disk.
+ # This could destroy disk data in filesystems that lived
+ # there.
+ block.wipe_volume(disk, mode='superblock')
+ elif ptable in _dos_names:
+ util.subp(["parted", disk, "--script", "mklabel", "msdos"])
+ elif ptable == "vtoc":
+ util.subp(["fdasd", "-c", "/dev/null", disk])
+ holders = clear_holders.get_holders(disk)
+ if len(holders) > 0:
+ LOG.info(
+ 'Detected block holders on disk %s: %s', disk, holders
+ )
+ clear_holders.clear_holders(disk)
+ clear_holders.assert_clear(disk)
# Make the name if needed
if info.get('name'):
diff --git a/tests/unittests/test_commands_block_meta.py b/tests/unittests/test_commands_block_meta.py
index 78cba06f..7320fc1e 100644
--- a/tests/unittests/test_commands_block_meta.py
+++ b/tests/unittests/test_commands_block_meta.py
@@ -5,6 +5,7 @@ from collections import OrderedDict
import copy
from unittest.mock import (
call,
+ MagicMock,
Mock,
patch,
)
@@ -685,6 +686,7 @@ class TestBlockMeta(CiTestCase):
self.m_mp.is_mpath_device.return_value = False
self.m_mp.is_mpath_member.return_value = False
+ @patch('curtin.commands.block_meta.util.FlockEx', new=MagicMock())
def test_disk_handler_calls_clear_holder(self):
info = self.storage_config.get('sda')
disk = info.get('path')
@@ -1789,6 +1791,7 @@ class TestDiskHandler(CiTestCase):
m_getpath.assert_called_with(info['id'], storage_config)
m_block.get_part_table_type.assert_called_with(disk_path)
+ @patch('curtin.commands.block_meta.util.FlockEx', new=MagicMock())
@patch('curtin.commands.block_meta.util.subp')
@patch('curtin.commands.block_meta.clear_holders.get_holders')
@patch('curtin.commands.block_meta.get_path_to_storage_volume')