diff --git a/test/test_util.py b/test/test_util.py new file mode 100644 index 0000000..7e23556 --- /dev/null +++ b/test/test_util.py @@ -0,0 +1,19 @@ +import logging +from unittest.mock import patch + +from testcloud import util + + +def test_has_selinux_missing_command_does_not_configure_root_logging(): + root_logger = logging.getLogger() + handlers = root_logger.handlers[:] + + try: + root_logger.handlers = [] + + with patch("testcloud.util.subprocess.call", side_effect=FileNotFoundError): + assert util.has_selinux() is False + + assert root_logger.handlers == [] + finally: + root_logger.handlers = handlers diff --git a/testcloud/util.py b/testcloud/util.py index fcdcd2a..6d49e6e 100644 --- a/testcloud/util.py +++ b/testcloud/util.py @@ -132,8 +132,8 @@ def has_selinux() -> bool: selinux_active = subprocess.call(["selinuxenabled"]) return not bool(selinux_active) except FileNotFoundError: - logging.debug("selinuxenabled is not present (libselinux-utils package missing?)") - logging.debug("Assuming selinux is not installed and therefore disabled") + log.debug("selinuxenabled is not present (libselinux-utils package missing?)") + log.debug("Assuming selinux is not installed and therefore disabled") return False