Move the salt loader `log_handlers` out of the internal logging package

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2022-02-24 16:26:28 +00:00 committed by Megan Wilhite
parent 8ea83784ac
commit 3d73e90796
23 changed files with 45 additions and 51 deletions

View file

@ -3,7 +3,7 @@
External Logging Handlers
-------------------------
.. currentmodule:: salt.log.handlers
.. currentmodule:: salt.log_handlers
.. autosummary::
:toctree:

View file

@ -1,5 +0,0 @@
============================
salt.log.handlers.fluent_mod
============================
.. automodule:: salt.log.handlers.fluent_mod

View file

@ -1,5 +0,0 @@
===============================
salt.log.handlers.log4mongo_mod
===============================
.. automodule:: salt.log.handlers.log4mongo_mod

View file

@ -1,5 +0,0 @@
==============================
salt.log.handlers.logstash_mod
==============================
.. automodule:: salt.log.handlers.logstash_mod

View file

@ -1,5 +0,0 @@
============================
salt.log.handlers.sentry_mod
============================
.. automodule:: salt.log.handlers.sentry_mod

View file

@ -0,0 +1,5 @@
============================
salt.log_handlers.fluent_mod
============================
.. automodule:: salt.log_handlers.fluent_mod

View file

@ -0,0 +1,5 @@
===============================
salt.log_handlers.log4mongo_mod
===============================
.. automodule:: salt.log_handlers.log4mongo_mod

View file

@ -0,0 +1,5 @@
==============================
salt.log_handlers.logstash_mod
==============================
.. automodule:: salt.log_handlers.logstash_mod

View file

@ -0,0 +1,5 @@
============================
salt.log_handlers.sentry_mod
============================
.. automodule:: salt.log_handlers.sentry_mod

View file

@ -56,7 +56,7 @@ SALT_INTERNAL_LOADERS_PATHS = (
str(SALT_BASE_PATH / "executors"),
str(SALT_BASE_PATH / "fileserver"),
str(SALT_BASE_PATH / "grains"),
str(SALT_BASE_PATH / "log" / "handlers"),
str(SALT_BASE_PATH / "log_handlers"),
str(SALT_BASE_PATH / "matchers"),
str(SALT_BASE_PATH / "metaproxy"),
str(SALT_BASE_PATH / "modules"),
@ -691,8 +691,6 @@ def log_handlers(opts):
_module_dirs(
opts,
"log_handlers",
int_type="handlers",
base_path=str(SALT_BASE_PATH / "log"),
),
opts,
tag="log_handlers",

View file

@ -920,6 +920,8 @@ def gen_min(
"salt/pillar",
"salt/pillar/__init__.py",
"salt/utils/textformat.py",
"salt/log_handlers",
"salt/log_handlers/__init__.py",
"salt/_logging/__init__.py",
"salt/_logging/handlers.py",
"salt/_logging/impl.py",

View file

@ -315,9 +315,9 @@ def check_module_indexes(ctx, files):
package = "cloud"
if package == "file_server":
package = "fileserver"
if package == "configuration":
package = "log"
path_parts = ["handlers"]
if package == "configuration" and path_parts == ["logging"]:
package = "log_handlers"
path_parts = []
python_package = SALT_CODE_DIR.joinpath(package, *path_parts).relative_to(
CODE_DIR
)

View file

@ -77,15 +77,9 @@ MISSING_DOCSTRINGS = {
"salt/grains/philips_hue.py": ["vendor", "kernel", "os", "os_family", "product"],
"salt/grains/rest_sample.py": ["kernel", "os", "os_family", "location", "os_data"],
"salt/grains/ssh_sample.py": ["location", "os_data", "kernel"],
"salt/log/handlers/fluent_mod.py": ["setup", "setup_handlers", "get_global_sender"],
"salt/log/handlers/log4mongo_mod.py": ["setup_handlers"],
"salt/log/handlers/logstash_mod.py": ["setup_handlers"],
"salt/metaproxy/proxy.py": [
"post_master_init",
"target",
"handle_payload",
"target_load",
],
"salt/log_handlers/fluent_mod.py": ["setup", "setup_handlers", "get_global_sender"],
"salt/log_handlers/log4mongo_mod.py": ["setup_handlers"],
"salt/log_handlers/logstash_mod.py": ["setup_handlers"],
"salt/modules/chassis.py": ["chassis_credentials", "cmd"],
"salt/modules/csf.py": [
"disable_testing_mode",

View file

@ -6,7 +6,7 @@ import time
import pytest
import salt.utils.stringutils
import zmq
from salt.log.handlers.logstash_mod import DatagramLogstashHandler, ZMQLogstashHander
from salt.log_handlers.logstash_mod import DatagramLogstashHandler, ZMQLogstashHander
from saltfactories.utils.ports import get_unused_localhost_port
log = logging.getLogger(__name__)

View file

@ -1,8 +1,8 @@
"""
Tests for salt.log.handlers.sentry_mod
Tests for salt.log_handlers.sentry_mod
"""
import pytest
import salt.log.handlers.sentry_mod
import salt.log_handlers.sentry_mod
from tests.support.mock import MagicMock, patch
@ -11,7 +11,7 @@ def configure_loader_modules():
"""
Sentry log handler loader modules.
"""
return {salt.log.handlers.sentry_mod: {"__grains__": {}, "__salt__": {}}}
return {salt.log_handlers.sentry_mod: {"__grains__": {}, "__salt__": {}}}
@pytest.fixture
@ -30,28 +30,28 @@ def test___virtual___success(sentry_handler):
"""
Test `__virtual__()` returns `__virtualname__`.
"""
with patch("salt.log.handlers.sentry_mod.HAS_RAVEN", True), patch(
"salt.log.handlers.sentry_mod.__opts__", sentry_handler
with patch("salt.log_handlers.sentry_mod.HAS_RAVEN", True), patch(
"salt.log_handlers.sentry_mod.__opts__", sentry_handler
):
ret = salt.log.handlers.sentry_mod.__virtual__()
assert ret is salt.log.handlers.sentry_mod.__virtualname__
ret = salt.log_handlers.sentry_mod.__virtual__()
assert ret is salt.log_handlers.sentry_mod.__virtualname__
def test___virtual___fail(sentry_handler):
"""
Test `__virtual__()` returns a reason for not loading.
"""
with patch("salt.log.handlers.sentry_mod.HAS_RAVEN", False), patch(
"salt.log.handlers.sentry_mod.__opts__", sentry_handler
with patch("salt.log_handlers.sentry_mod.HAS_RAVEN", False), patch(
"salt.log_handlers.sentry_mod.__opts__", sentry_handler
):
ret = salt.log.handlers.sentry_mod.__virtual__()
ret = salt.log_handlers.sentry_mod.__virtual__()
assert ret[0] is False
assert ret[1] == "Cannot find 'raven' python library"
with patch("salt.log.handlers.sentry_mod.HAS_RAVEN", True), patch(
"salt.log.handlers.sentry_mod.__opts__", {}
with patch("salt.log_handlers.sentry_mod.HAS_RAVEN", True), patch(
"salt.log_handlers.sentry_mod.__opts__", {}
):
ret = salt.log.handlers.sentry_mod.__virtual__()
ret = salt.log_handlers.sentry_mod.__virtual__()
assert ret[0] is False
assert ret[1] == "'sentry_handler' config is empty or not defined"
@ -64,7 +64,7 @@ def test_setup_handlers_disabled_bypass_dunders():
with patch("salt.loader.grains", MagicMock()) as grains_loader, patch(
"salt.loader.minion_mods", MagicMock()
) as salt_loader:
ret = salt.log.handlers.sentry_mod.setup_handlers()
ret = salt.log_handlers.sentry_mod.setup_handlers()
assert ret is False
grains_loader.assert_not_called()
salt_loader.assert_not_called()