Skip to content

Commit

Permalink
add_upgrade_boot_entry: fix unit tests
Browse files Browse the repository at this point in the history
reworking how args are managed means that leapp can now more precisely
automatically identify what has been added - therefore, args like
rd.plymouth=0 that leapp adds is now being removed, whereas it has
been kept previously as a upgrade byproduct
  • Loading branch information
Michal Hecko committed Sep 5, 2024
1 parent 60c063a commit cf484ce
Showing 1 changed file with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def get_boot_file_paths_mocked():
assert addupgradebootentry.run.args[1] == run_args.args_add
assert api.produce.model_instances == [
LateTargetKernelCmdlineArgTasks(to_remove=[KernelCmdlineArg(key='debug'),
KernelCmdlineArg(key='enforcing', value='0')])
KernelCmdlineArg(key='enforcing', value='0'),
KernelCmdlineArg(key='plymouth.enable', value='0'),
KernelCmdlineArg(key='rd.plymouth', value='0')])
]

if run_args.args_zipl:
Expand All @@ -104,15 +106,16 @@ def get_boot_file_paths_mocked():
CurrentActorMocked(envars={'LEAPP_DEBUG': str(int(is_leapp_invoked_with_debug))}))

addupgradebootentry.add_boot_entry()
assert len(api.produce.model_instances) == 1

produced_msg = api.produce.model_instances[0]
assert isinstance(produced_msg, LateTargetKernelCmdlineArgTasks)

debug_kernel_cmline_arg = KernelCmdlineArg(key='debug')
if is_leapp_invoked_with_debug:
expected_args_to_remove = [KernelCmdlineArg(key='debug'), KernelCmdlineArg(key='enforcing', value='0')]
assert debug_kernel_cmline_arg in produced_msg.to_remove
else:
expected_args_to_remove = [KernelCmdlineArg(key='enforcing', value='0')]

expected_produced_messages = [LateTargetKernelCmdlineArgTasks(to_remove=expected_args_to_remove)]

assert api.produce.model_instances == expected_produced_messages
assert debug_kernel_cmline_arg not in produced_msg.to_remove


def test_add_boot_entry_configs(monkeypatch):
Expand All @@ -133,7 +136,9 @@ def get_boot_file_paths_mocked():
assert addupgradebootentry.run.args[3] == run_args_add + ['-c', CONFIGS[1]]
assert api.produce.model_instances == [
LateTargetKernelCmdlineArgTasks(to_remove=[KernelCmdlineArg(key='debug'),
KernelCmdlineArg(key='enforcing', value='0')])
KernelCmdlineArg(key='enforcing', value='0'),
KernelCmdlineArg(key='plymouth.enable', value='0'),
KernelCmdlineArg(key='rd.plymouth', value='0')])
]


Expand Down Expand Up @@ -183,7 +188,7 @@ def test_fix_grub_config_error(monkeypatch, error_type, test_file_name):
(False, False),
)
)
def test_collect_boot_args(monkeypatch, is_debug_enabled, network_enablement_type):
def test_collect_upgrade_kernel_args(monkeypatch, is_debug_enabled, network_enablement_type):
env_vars = {'LEAPP_DEBUG': str(int(is_debug_enabled))}
if network_enablement_type:
env_vars['LEAPP_DEVEL_INITRAM_NETWORK'] = network_enablement_type
Expand All @@ -192,7 +197,8 @@ def test_collect_boot_args(monkeypatch, is_debug_enabled, network_enablement_typ
monkeypatch.setattr(addupgradebootentry, 'construct_cmdline_args_for_livemode',
lambda *args: {'livemodearg': 'value'})

args = addupgradebootentry.collect_boot_args(livemode_enabled=True)
arg_set = addupgradebootentry.collect_upgrade_kernel_args(livemode_enabled=True)
args = dict(arg_set)

assert args['enforcing'] == '0'
assert args['rd.plymouth'] == '0'
Expand Down Expand Up @@ -320,16 +326,3 @@ def readlink_mock(path):
uuid = addupgradebootentry._get_device_uuid(path)

assert uuid == 'MY_UUID1'


@pytest.mark.parametrize(
('args', 'expected_result'),
(
([('argA', 'val'), ('argB', 'valB'), ('argC', None), ], 'argA=val argB=valB argC'),
([('argA', ('val1', 'val2'))], 'argA=val1 argA=val2')
)
)
def test_format_grubby_args_from_args_dict(args, expected_result):
actual_result = addupgradebootentry.format_grubby_args_from_args_dict(dict(args))

assert actual_result == expected_result

0 comments on commit cf484ce

Please sign in to comment.