leapp-repository/0004-feat-livemode-exclude-DNF-cache-from-the-created-squ.patch
Petr Stodulka cb46739ce0 IPU 9.7 -> 10.1: CTC 1 candidate 1
- Require leapp-framework >= 6.1
- Simplified use of the LiveMode experimental feature with additional enhancements
- Fix the check of deprecated PCI devices and drivers
- Add RHEL 10.1 product certificates
- Gracefully handle CentOS OS versioning style
- Ensure the leapp-upgrade-el9toel10 RPM is not touched during the upgrade transaction
- Create proper error message when swap of RHUI clients fails
- Introduced the --enable-experimental-feature to simplify use of experimental features
- Manage RPM GPG keys during the upgrade respecting used linux distributions
- Prevent a crach during post-upgrade phases when no custom SELinux modules needs to be migrated
- Update leapp upgrade data files
- Minor fixes in reports
- Resolves: RHEL-49402, RHEL-72544, RHEL-77175, RHEL-80334, RHEL-80335, RHEL-80336, RHEL-80550, RHEL-86689
2025-05-14 10:46:55 +02:00

92 lines
4.7 KiB
Diff

From 11b9733cfe1c7cc10db675fba24d94c0c30f6b6e Mon Sep 17 00:00:00 2001
From: Michal Hecko <mhecko@redhat.com>
Date: Thu, 27 Feb 2025 10:18:17 +0100
Subject: [PATCH 04/37] feat(livemode): exclude DNF cache from the created
squashfs image
Exclude /var/cache/dnf from the generated squashfs image. The DNF
cache is not needed for the live system that we boot into, since leapp
will always use DNF cache stored within target userspace container
(/sysroot/var/lib/leapp/...). Therefore, this optimization saves
a lot of disk space for the user (2GB->700mb).
---
.../libraries/liveimagegenerator.py | 22 ++++++++++++++-----
.../tests/test_image_generation.py | 6 +++--
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/repos/system_upgrade/common/actors/livemode/liveimagegenerator/libraries/liveimagegenerator.py b/repos/system_upgrade/common/actors/livemode/liveimagegenerator/libraries/liveimagegenerator.py
index af8981d8..46118630 100644
--- a/repos/system_upgrade/common/actors/livemode/liveimagegenerator/libraries/liveimagegenerator.py
+++ b/repos/system_upgrade/common/actors/livemode/liveimagegenerator/libraries/liveimagegenerator.py
@@ -24,7 +24,7 @@ def lighten_target_userpace(context):
tree_to_prune, error)
-def build_squashfs(livemode_config, userspace_info):
+def build_squashfs(livemode_config, userspace_info, paths_to_exclude=None):
"""
Generate the live rootfs image based on the target userspace
@@ -34,8 +34,11 @@ def build_squashfs(livemode_config, userspace_info):
target_userspace_fullpath = userspace_info.path
squashfs_fullpath = livemode_config.squashfs_fullpath
- api.current_logger().info('Building the squashfs image %s from target userspace located at %s',
- squashfs_fullpath, target_userspace_fullpath)
+ if not paths_to_exclude:
+ paths_to_exclude = []
+
+ api.current_logger().info('Building the squashfs image %s from target userspace located at %s with excludes: %s',
+ squashfs_fullpath, target_userspace_fullpath, ', '.join(paths_to_exclude))
try:
if os.path.exists(squashfs_fullpath):
@@ -44,8 +47,13 @@ def build_squashfs(livemode_config, userspace_info):
api.current_logger().warning('Failed to remove already existing %s. Full error: %s',
squashfs_fullpath, error)
+ mksquashfs_command = ['mksquashfs', target_userspace_fullpath, squashfs_fullpath]
+ if paths_to_exclude:
+ mksquashfs_command.append('-e')
+ mksquashfs_command.extend(paths_to_exclude)
+
try:
- run(['mksquashfs', target_userspace_fullpath, squashfs_fullpath])
+ run(mksquashfs_command)
except CalledProcessError as error:
raise StopActorExecutionError(
'Cannot pack the target userspace into a squash image. ',
@@ -68,5 +76,9 @@ def generate_live_image_if_enabled():
with mounting.NspawnActions(base_dir=userspace_info.path) as context:
lighten_target_userpace(context)
- squashfs_path = build_squashfs(livemode_config, userspace_info)
+
+ # Exclude the DNF cache - we do not need it, leapp mounts /sysroot and uses userspace's dnf cache from there
+ paths_to_exclude = [os.path.join(userspace_info.path, 'var/cache/dnf')]
+
+ squashfs_path = build_squashfs(livemode_config, userspace_info, paths_to_exclude=paths_to_exclude)
api.produce(LiveModeArtifacts(squashfs_path=squashfs_path))
diff --git a/repos/system_upgrade/common/actors/livemode/liveimagegenerator/tests/test_image_generation.py b/repos/system_upgrade/common/actors/livemode/liveimagegenerator/tests/test_image_generation.py
index 5c434a6b..16ae0a09 100644
--- a/repos/system_upgrade/common/actors/livemode/liveimagegenerator/tests/test_image_generation.py
+++ b/repos/system_upgrade/common/actors/livemode/liveimagegenerator/tests/test_image_generation.py
@@ -78,10 +78,12 @@ def test_generate_live_image_if_enabled(monkeypatch, livemode_config, should_pro
def __exit__(self, *args, **kwargs):
pass
+ def build_squashfs_image_mock(livemode_config, userspace_info, *args, **kwargs):
+ return '/squashfs'
+
monkeypatch.setattr(mounting, 'NspawnActions', NspawnMock)
monkeypatch.setattr(live_image_generator_lib, 'lighten_target_userpace', lambda context: None)
- monkeypatch.setattr(live_image_generator_lib, 'build_squashfs',
- lambda livemode_config, userspace_info: '/squashfs')
+ monkeypatch.setattr(live_image_generator_lib, 'build_squashfs', build_squashfs_image_mock)
monkeypatch.setattr(api, 'produce', produce_mocked())
live_image_generator_lib.generate_live_image_if_enabled()
--
2.49.0