diff --git a/repos/system_upgrade/el7toel8/actors/checkselinux/tests/test_checkselinux.py b/repos/system_upgrade/el7toel8/actors/checkselinux/tests/test_checkselinux.py index 36d25b0079..ba385e68f8 100644 --- a/repos/system_upgrade/el7toel8/actors/checkselinux/tests/test_checkselinux.py +++ b/repos/system_upgrade/el7toel8/actors/checkselinux/tests/test_checkselinux.py @@ -2,31 +2,63 @@ from leapp.models import (SystemFacts, CheckResult, SELinux, SelinuxPermissiveDecision, SelinuxRelabelDecision) +# import needed just to be able to create valid model, but not important for test +from leapp.models import FirewallStatus, Firewalls + + +# FIXME: fix the file properly regarding the fix of the issue: +# # https://github.com/oamg/leapp-repository/issues/20 +def create_selinux(static_mode, enabled, policy='targeted', mls_enabled=True): + runtime_mode = static_mode if static_mode != 'disabled' else None + + return SELinux( + runtime_mode=runtime_mode, + static_mode=static_mode, + enabled=enabled, + policy=policy, + mls_enabled=mls_enabled, + ) + + +def create_sysfacts(selinux): + return SystemFacts( + sysctl_variables=[], + kernel_modules=[], + users=[], + groups=[], + repositories=[], + selinux=selinux, + firewalls=Firewalls( + firewalld=FirewallStatus(enabled=True, active=True), + iptables=FirewallStatus(enabled=True, active=True), + ), + ) + def test_actor_schedule_relabelling(current_actor_context): - options = [SELinux(static_mode='permissive', enabled=True), - SELinux(static_mode='enforcing', enabled=True)] + options = [create_selinux(static_mode='permissive', enabled=True), + create_selinux(static_mode='enforcing', enabled=True)] for option in options: - current_actor_context.feed(SystemFacts(selinux=option)) + current_actor_context.feed(create_sysfacts(selinux=option)) current_actor_context.run() assert current_actor_context.consume(CheckResult) assert current_actor_context.consume(SelinuxRelabelDecision)[0].set_relabel def test_actor_set_permissive(current_actor_context): - relabel = SELinux(static_mode='enforcing', enabled=True) + relabel = create_selinux(static_mode='enforcing', enabled=True) - current_actor_context.feed(SystemFacts(selinux=relabel)) + current_actor_context.feed(create_sysfacts(selinux=relabel)) current_actor_context.run() assert current_actor_context.consume(CheckResult) assert current_actor_context.consume(SelinuxPermissiveDecision)[0].set_permissive def test_actor_selinux_disabled(current_actor_context): - disabled = SELinux(enabled=False) + disabled = create_selinux(enabled=False, static_mode='disabled') - current_actor_context.feed(SystemFacts(selinux=disabled)) + current_actor_context.feed(create_sysfacts(selinux=disabled)) current_actor_context.run() assert not current_actor_context.consume(SelinuxRelabelDecision) assert not current_actor_context.consume(SelinuxPermissiveDecision) diff --git a/repos/system_upgrade/el7toel8/models/systemfacts.py b/repos/system_upgrade/el7toel8/models/systemfacts.py index d1a56bc6af..1488e4492f 100644 --- a/repos/system_upgrade/el7toel8/models/systemfacts.py +++ b/repos/system_upgrade/el7toel8/models/systemfacts.py @@ -60,7 +60,9 @@ class ActiveKernelModule(Model): class SELinux(Model): topic = SystemInfoTopic - runtime_mode = fields.StringEnum(['enforcing', 'permissive']) + # FIXME: fixme properly regarding the issue: + # # https://github.com/oamg/leapp-repository/issues/20 + runtime_mode = fields.Nullable(fields.StringEnum(['enforcing', 'permissive'])) static_mode = fields.StringEnum(['enforcing', 'permissive', 'disabled']) enabled = fields.Boolean() policy = fields.String()