Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhecko committed Aug 21, 2023
1 parent f6b3a26 commit 4f0e732
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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')])]
Expand All @@ -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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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

0 comments on commit 4f0e732

Please sign in to comment.