Skip to content

Commit

Permalink
Improper fix of tests and model related to the SELinux
Browse files Browse the repository at this point in the history
Proper fix will be delivered with separated PR.
Issue: #20
  • Loading branch information
pirat89 committed Dec 11, 2018
1 parent 22d6e50 commit 1363fe4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion repos/system_upgrade/el7toel8/models/systemfacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1363fe4

Please sign in to comment.