From 4f0e7326ea529f392aa7cb3b8b8d763e0a2de00d Mon Sep 17 00:00:00 2001 From: mhecko Date: Mon, 21 Aug 2023 10:31:24 +0200 Subject: [PATCH] fix unit tests --- ...ltboot_forcedefaultboottotargetkernelversion.py | 1 + .../tests/test_targetinitramfsgenerator.py | 14 +++++++++++--- .../tests/test_kernelcmdlineconfig.py | 3 +++ .../libraries/scankernel.py | 1 + ...alledkernel_scaninstalledtargetkernelversion.py | 8 ++++++-- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/repos/system_upgrade/common/actors/forcedefaultboottotargetkernelversion/tests/test_forcedefaultboot_forcedefaultboottotargetkernelversion.py b/repos/system_upgrade/common/actors/forcedefaultboottotargetkernelversion/tests/test_forcedefaultboot_forcedefaultboottotargetkernelversion.py index 7279c5f22e..b903df45e9 100644 --- a/repos/system_upgrade/common/actors/forcedefaultboottotargetkernelversion/tests/test_forcedefaultboot_forcedefaultboottotargetkernelversion.py +++ b/repos/system_upgrade/common/actors/forcedefaultboottotargetkernelversion/tests/test_forcedefaultboot_forcedefaultboottotargetkernelversion.py @@ -125,6 +125,7 @@ def impl(*args): kernel_img_path = TARGET_KERNEL_PATH if case.kernel_exists else '' msg = InstalledTargetKernelInfo(pkg_nevra=TARGET_KERNEL_NEVRA, kernel_img_path=kernel_img_path, + uname_r='', initramfs_path=TARGET_INITRD_PATH) return iter((msg,)) return iter(()) diff --git a/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/tests/test_targetinitramfsgenerator.py b/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/tests/test_targetinitramfsgenerator.py index 57daca752f..b4c9dd8951 100644 --- a/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/tests/test_targetinitramfsgenerator.py +++ b/repos/system_upgrade/common/actors/initramfs/targetinitramfsgenerator/tests/test_targetinitramfsgenerator.py @@ -8,7 +8,7 @@ from leapp.models import ( # isort:skip InitrdIncludes, # deprecated - DracutModule, KernelModule, InstalledTargetKernelVersion, TargetInitramfsTasks) + DracutModule, KernelModule, InstalledTargetKernelInfo, TargetInitramfsTasks) FILES = ['/file1', '/file2', '/dir/subdir/subsubdir/file3', '/file4', '/file5'] MODULES = [ @@ -110,12 +110,20 @@ def test_no_kernel_version(monkeypatch, msgs): assert not run_mocked.called +def mk_kernel_info(kernel_ver): + kernel_info = InstalledTargetKernelInfo(pkg_nevra='nevra', + kernel_img_path='vmlinuz', + uname_r=kernel_ver, + initramfs_path='initramfs') + return kernel_info + + @pytest.mark.parametrize('msgs', TEST_CASES) def test_dracut_fail(monkeypatch, msgs): run_mocked = RunMocked(raise_err=True) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs)) monkeypatch.setattr(api, 'current_actor', - CurrentActorMocked(msgs=msgs + [InstalledTargetKernelVersion(version=KERNEL_VERSION)])) + CurrentActorMocked(msgs=msgs + [mk_kernel_info(KERNEL_VERSION)])) monkeypatch.setattr(targetinitramfsgenerator, 'run', run_mocked) # FIXME monkeypatch.setattr(targetinitramfsgenerator, '_copy_modules', lambda *_: None) @@ -185,7 +193,7 @@ def test_dracut_fail(monkeypatch, msgs): ([gen_TIT([], MODULES, FILES[0:3]), gen_InitrdIncludes(FILES[3:])], FILES, [], MODULES), ]) def test_flawless(monkeypatch, msgs, files, dracut_modules, kernel_modules): - _msgs = msgs + [InstalledTargetKernelVersion(version=KERNEL_VERSION)] + _msgs = msgs + [mk_kernel_info(KERNEL_VERSION)] run_mocked = RunMocked() monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=_msgs)) monkeypatch.setattr(targetinitramfsgenerator, 'run', run_mocked) diff --git a/repos/system_upgrade/common/actors/kernelcmdlineconfig/tests/test_kernelcmdlineconfig.py b/repos/system_upgrade/common/actors/kernelcmdlineconfig/tests/test_kernelcmdlineconfig.py index 3f34789924..3f9b2e5e7e 100644 --- a/repos/system_upgrade/common/actors/kernelcmdlineconfig/tests/test_kernelcmdlineconfig.py +++ b/repos/system_upgrade/common/actors/kernelcmdlineconfig/tests/test_kernelcmdlineconfig.py @@ -53,6 +53,7 @@ def __call__(self, cmd, *args, **kwargs): def test_kernelcmdline_config_valid_msgs(monkeypatch, msgs, expected_grubby_kernelopt_args): kernel_img_path = '/boot/vmlinuz-X' kernel_info = InstalledTargetKernelInfo(pkg_nevra=TARGET_KERNEL_NEVRA, + uname_r='', kernel_img_path=kernel_img_path, initramfs_path='/boot/initramfs-X') msgs += [kernel_info] @@ -80,6 +81,7 @@ def test_kernelcmdline_explicit_configs(monkeypatch): kernel_img_path = '/boot/vmlinuz-X' kernel_info = InstalledTargetKernelInfo(pkg_nevra=TARGET_KERNEL_NEVRA, + uname_r='', kernel_img_path=kernel_img_path, initramfs_path='/boot/initramfs-X') msgs = [kernel_info, TargetKernelCmdlineArgTasks(to_remove=[KernelCmdlineArg(key='key1', value='value1')])] @@ -103,6 +105,7 @@ def test_kernelcmdline_explicit_configs(monkeypatch): def test_kernelcmdline_config_no_args(monkeypatch): kernel_info = InstalledTargetKernelInfo(pkg_nevra=TARGET_KERNEL_NEVRA, + uname_r='', kernel_img_path='/boot/vmlinuz-X', initramfs_path='/boot/initramfs-X') diff --git a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py index e0121d5aa4..c1cc69ee96 100644 --- a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py +++ b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/libraries/scankernel.py @@ -106,4 +106,5 @@ def process(): else: # This is not expected, however, we are past the point that raising an exception would do any good. # It is better to finish the upgrade with 80% things done rather than falling into emergency mode + api.current_logger().warning('Failed to identify package providing the target kernel.') pass diff --git a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/tests/test_scaninstalledkernel_scaninstalledtargetkernelversion.py b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/tests/test_scaninstalledkernel_scaninstalledtargetkernelversion.py index 22034d44b9..570b67827b 100644 --- a/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/tests/test_scaninstalledkernel_scaninstalledtargetkernelversion.py +++ b/repos/system_upgrade/common/actors/scaninstalledtargetkernelversion/tests/test_scaninstalledkernel_scaninstalledtargetkernelversion.py @@ -79,6 +79,7 @@ def patched_get_boot_files(nevra): monkeypatch.setattr(api, 'produce', result.append) monkeypatch.setattr(scankernel, 'run', MockedRun(stdouts)) monkeypatch.setattr(scankernel, 'get_boot_files_provided_by_kernel_pkg', patched_get_boot_files) + monkeypatch.setattr(kernel_lib, 'get_uname_r_provided_by_kernel_pkg', lambda nevra: 'uname-r') scankernel.process() @@ -136,6 +137,7 @@ def patched_get_boot_content(target_nevra): monkeypatch.setattr(api, 'produce', result.append) monkeypatch.setattr(scankernel, 'run', MockedRun(stdouts)) monkeypatch.setattr(scankernel, 'get_boot_files_provided_by_kernel_pkg', patched_get_boot_content) + monkeypatch.setattr(kernel_lib, 'get_uname_r_provided_by_kernel_pkg', lambda nevra: 'uname-r') scankernel.process() @@ -156,6 +158,8 @@ def test_scaninstalledkernel_missing(monkeypatch): monkeypatch.setattr(api, 'current_logger', logger_mocked()) monkeypatch.setattr(api, 'produce', result.append) monkeypatch.setattr(scankernel, 'run', MockedRun({})) + monkeypatch.setattr(kernel_lib, 'get_uname_r_provided_by_kernel_pkg', lambda nevra: 'uname-r') - with pytest.raises(StopActorExecutionError): - scankernel.process() + scankernel.process() + + assert not result