From eb39120ea14b48ca83838c3519eccf5d0a72c596 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Sat, 24 Aug 2024 07:05:52 -0400 Subject: [PATCH] kiwi/builder/live: Clean up leftover dracut configuration file The existence of this file breaks installers on live media that sync the full filesystem to disk and are not aware of this configuration before generating the target system initramfs. --- kiwi/builder/live.py | 2 ++ test/unit/builder/live_test.py | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/kiwi/builder/live.py b/kiwi/builder/live.py index 7ec4159ec14..6204cbeb483 100644 --- a/kiwi/builder/live.py +++ b/kiwi/builder/live.py @@ -190,6 +190,8 @@ def create(self) -> Result: config_file=self.root_dir + '/etc/dracut.conf.d/02-livecd.conf' ) self.boot_image.create_initrd(self.mbrid) + # Clean up leftover dracut config file (which can break installs) + os.unlink(self.root_dir + '/etc/dracut.conf.d/02-livecd.conf') if self.bootloader == 'systemd_boot': # make sure the initrd name follows the dracut # naming conventions diff --git a/test/unit/builder/live_test.py b/test/unit/builder/live_test.py index a8cce38dac1..a08a75cc394 100644 --- a/test/unit/builder/live_test.py +++ b/test/unit/builder/live_test.py @@ -152,10 +152,11 @@ def test_init_for_ix86_platform(self): @patch('kiwi.builder.live.FileSystem.new') @patch('kiwi.builder.live.SystemSize') @patch('kiwi.builder.live.Defaults.get_grub_boot_directory_name') + @patch('os.unlink') @patch('os.path.exists') @patch('os.chmod') def test_create_overlay_structure_boot_on_systemd_boot( - self, mock_chmod, mock_exists, mock_grub_dir, mock_size, + self, mock_chmod, mock_exists, mock_unlink, mock_grub_dir, mock_size, mock_filesystem, mock_isofs, mock_Iso, mock_tag, mock_shutil, mock_Temporary, mock_setup_media_loader_directory, mock_DeviceProvider, mock_Command_run, mock_LoopDevice, mock_create_boot_loader_config @@ -190,10 +191,11 @@ def test_create_overlay_structure_boot_on_systemd_boot( @patch('kiwi.builder.live.FileSystem.new') @patch('kiwi.builder.live.SystemSize') @patch('kiwi.builder.live.Defaults.get_grub_boot_directory_name') + @patch('os.unlink') @patch('os.path.exists') @patch('os.chmod') def test_create_overlay_structure_boot_on_grub( - self, mock_chmod, mock_exists, mock_grub_dir, mock_size, + self, mock_chmod, mock_exists, mock_unlink, mock_grub_dir, mock_size, mock_filesystem, mock_isofs, mock_Iso, mock_tag, mock_shutil, mock_Temporary, mock_setup_media_loader_directory, mock_DeviceProvider, mock_LoopDevice, mock_create_boot_loader_config, xml_filesystem @@ -204,6 +206,7 @@ def test_create_overlay_structure_boot_on_grub( loop_provider = Mock() mock_LoopDevice.return_value.__enter__.return_value = loop_provider mock_exists.return_value = True + mock_unlink.return_value = True mock_grub_dir.return_value = 'grub2' temp_squashfs = Mock() @@ -413,9 +416,10 @@ def side_effect(): @patch('kiwi.builder.live.IsoToolsBase.setup_media_loader_directory') @patch('kiwi.builder.live.Temporary') @patch('kiwi.builder.live.shutil') + @patch('os.unlink') def test_create_no_kernel_found( - self, mock_shutil, mock_Temporary, mock_setup_media_loader_directory, - mock_create_boot_loader_config + self, mock_unlink, mock_shutil, mock_Temporary, + mock_setup_media_loader_directory, mock_create_boot_loader_config ): self.firmware.bios_mode.return_value = False mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir' @@ -427,9 +431,10 @@ def test_create_no_kernel_found( @patch('kiwi.builder.live.IsoToolsBase.setup_media_loader_directory') @patch('kiwi.builder.live.Temporary') @patch('kiwi.builder.live.shutil') + @patch('os.unlink') def test_create_no_hypervisor_found( - self, mock_shutil, mock_Temporary, mock_setup_media_loader_directory, - mock_create_boot_loader_config + self, mock_unlink, mock_shutil, mock_Temporary, + mock_setup_media_loader_directory, mock_create_boot_loader_config ): self.firmware.bios_mode.return_value = False mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir' @@ -441,14 +446,16 @@ def test_create_no_hypervisor_found( @patch('kiwi.builder.live.IsoToolsBase.setup_media_loader_directory') @patch('kiwi.builder.live.Temporary') @patch('kiwi.builder.live.shutil') + @patch('os.unlink') @patch('os.path.exists') def test_create_no_initrd_found( - self, mock_exists, mock_shutil, mock_Temporary, + self, mock_exists, mock_unlink, mock_shutil, mock_Temporary, mock_setup_media_loader_directory, mock_create_boot_loader_config ): self.firmware.bios_mode.return_value = False mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir' mock_exists.return_value = False + mock_unlink.return_value = True with raises(KiwiLiveBootImageError): self.live_image.create()