Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

remove: selinux checks #285

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions ansible_bender/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,38 +265,12 @@ def __init__(self, playbook_path):
self.metadata = ImageMetadata()
self.build.metadata = self.metadata

def _check_selinux_iz_gud(self):
"""
This is a workaround for a weird behavior of ansible: if selinux is
in the enforcing mode and python3-libselinux is not installed, ansible freezes

https://bugzilla.redhat.com/show_bug.cgi?id=1696706
:return:
"""
try:
enforcing_status = Path("/sys/fs/selinux/enforce").read_text()
except FileNotFoundError:
logger.debug("this system is not using selinux, /sys/fs/selinux/enforce is not present")
return
logger.debug(f"selinux enforce status = {enforcing_status}")
# it can be enforcing or not, selinux python module needs to be present
try:
importlib.import_module("selinux")
except ModuleNotFoundError:
raise RuntimeError(
"\nThis system is using selinux(8) and selinux python module is not installed. "
"There is a known issue in ansible that it freezes in this setup:\n"
" https://bugzilla.redhat.com/show_bug.cgi?id=1696706\n"
"Please install libselinux python bindings (on Fedora the package name is python3-libselinux)."
)

def expand_pb_vars(self):
"""
populate vars from a playbook, defined in vars section

:return: dict with the content of ansible_bender var
"""
self._check_selinux_iz_gud()
with open(self.playbook_path) as fd:
plays = yaml.safe_load(fd)

Expand Down
11 changes: 0 additions & 11 deletions tests/unit/test_ansibla.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ def _f(name, package=None):
False
),
))
def test_ansible_selinux_workaround(mock_r_t, mock_i_m, should_raise):
mock_r_t()
mock_i_m()
p = PbVarsParser("")
if should_raise:
with pytest.raises(RuntimeError) as ex:
p._check_selinux_iz_gud()
assert "libselinux" in str(ex.value)
else:
p._check_selinux_iz_gud()


@pytest.mark.parametrize("di, error_message", (
(
Expand Down