Skip to content

Commit

Permalink
Merge branch 'openSUSE:openSUSE/release/3006.0' into openSUSE/release…
Browse files Browse the repository at this point in the history
…/3006.0
  • Loading branch information
winddss authored Sep 11, 2024
2 parents 2219140 + d933c8f commit d3c7d0c
Show file tree
Hide file tree
Showing 45 changed files with 485 additions and 158 deletions.
2 changes: 2 additions & 0 deletions changelog/64170.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed issue in salt-cloud so that multiple masters specified in the cloud
are written to the minion config properly
Empty file added doc/topics/releases/3007.0.rst
Empty file.
1 change: 1 addition & 0 deletions pkg/common/salt-minion.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Type=notify
NotifyAccess=all
LimitNOFILE=8192
ExecStart=/usr/bin/salt-minion
SELinuxContext=system_u:system_r:unconfined_t:s0

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions pkg/old/deb/salt-minion.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ KillMode=process
NotifyAccess=all
LimitNOFILE=8192
ExecStart=/usr/bin/salt-minion
SELinuxContext=system_u:system_r:unconfined_t:s0

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions pkg/old/suse/salt-minion.service
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ExecStart=/usr/bin/salt-minion
KillMode=process
Restart=on-failure
RestartSec=15
SELinuxContext=system_u:system_r:unconfined_t:s0

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions pkg/old/suse/salt-minion.service.rhel7
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ExecStart=/usr/bin/salt-minion
KillMode=process
Restart=on-failure
RestartSec=15
SELinuxContext=system_u:system_r:unconfined_t:s0

[Install]
WantedBy=multi-user.target
6 changes: 3 additions & 3 deletions salt/_logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TemporaryLoggingHandler(logging.NullHandler):

def __init__(self, level=logging.NOTSET, max_queue_size=10000):
warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}.TemporaryLoggingHandler'. "
"'{name}.TemporaryLoggingHandler' will go away after "
"{{date}}.".format(name=__name__),
Expand Down Expand Up @@ -225,7 +225,7 @@ class QueueHandler(
def __init__(self, queue): # pylint: disable=useless-super-delegation
super().__init__(queue)
warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}.QueueHandler' and instead "
"use 'logging.handlers.QueueHandler'. "
"'{name}.QueueHandler' will go away after "
Expand Down Expand Up @@ -283,7 +283,7 @@ class QueueHandler(
def __init__(self, queue): # pylint: disable=useless-super-delegation
super().__init__(queue)
warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}.QueueHandler' and instead "
"use 'logging.handlers.QueueHandler'. "
"'{name}.QueueHandler' will go away after "
Expand Down
15 changes: 10 additions & 5 deletions salt/_logging/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
QUIET = logging.QUIET = 1000

import salt.defaults.exitcodes # isort:skip pylint: disable=unused-import
import salt.utils.ctx

from salt._logging.handlers import DeferredStreamHandler # isort:skip
from salt._logging.handlers import RotatingFileHandler # isort:skip
from salt._logging.handlers import StreamHandler # isort:skip
from salt._logging.handlers import SysLogHandler # isort:skip
from salt._logging.handlers import WatchedFileHandler # isort:skip
from salt._logging.mixins import LoggingMixinMeta # isort:skip
from salt.exceptions import LoggingRuntimeError # isort:skip
from salt.utils.ctx import RequestContext # isort:skip
from salt.utils.immutabletypes import freeze, ImmutableDict # isort:skip
from salt.utils.textformat import TextFormat # isort:skip

Expand Down Expand Up @@ -242,10 +243,14 @@ def _log(
if extra is None:
extra = {}

# pylint: disable=no-member
current_jid = RequestContext.current.get("data", {}).get("jid", None)
log_fmt_jid = RequestContext.current.get("opts", {}).get("log_fmt_jid", None)
# pylint: enable=no-member
current_jid = (
salt.utils.ctx.get_request_context().get("data", {}).get("jid", None)
)
log_fmt_jid = (
salt.utils.ctx.get_request_context()
.get("opts", {})
.get("log_fmt_jid", None)
)

if current_jid is not None:
extra["jid"] = current_jid
Expand Down
27 changes: 24 additions & 3 deletions salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2432,10 +2432,31 @@ def _systemd():
"""
Return the systemd grain
"""
systemd_info = __salt__["cmd.run"]("systemctl --version").splitlines()
systemd_version = "UNDEFINED"
systemd_features = ""
try:
systemd_output = __salt__["cmd.run_all"]("systemctl --version")
except Exception: # pylint: disable=broad-except
log.error("Exception while executing `systemctl --version`", exc_info=True)
return {
"version": systemd_version,
"features": systemd_features,
}
if systemd_output.get("retcode") == 0:
systemd_info = systemd_output.get("stdout", "").splitlines()
try:
if systemd_info[0].startswith("systemd "):
systemd_version = systemd_info[0].split()[1]
systemd_features = systemd_info[1]
except IndexError:
pass
if systemd_version == "UNDEFINED" or systemd_features == "":
log.error(
"Unexpected output returned by `systemctl --version`: %s", systemd_output
)
return {
"version": systemd_info[0].split()[1],
"features": systemd_info[1],
"version": systemd_version,
"features": systemd_features,
}


Expand Down
2 changes: 1 addition & 1 deletion salt/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from salt.utils.versions import warn_until_date

warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}' and instead use 'salt._logging'. "
"'{name}' will go away after {{date}}.".format(name=__name__),
stacklevel=3,
Expand Down
2 changes: 1 addition & 1 deletion salt/log/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from salt.utils.versions import warn_until_date

warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}' and instead use 'salt._logging.handlers'. "
"'{name}' will go away after {{date}}.".format(name=__name__),
)
Expand Down
2 changes: 1 addition & 1 deletion salt/log/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# pylint: enable=unused-import

warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}' and instead use 'salt._logging.mixins'. "
"'{name}' will go away after {{date}}.".format(name=__name__),
)
4 changes: 2 additions & 2 deletions salt/log/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from salt.utils.versions import warn_until_date

warn_until_date(
"20240101",
"20260101",
"Please stop using '{name}' and instead use 'salt._logging'. "
"'{name}' will go away after {{date}}. Do note however that "
"'salt._logging' is now considered a non public implementation "
Expand All @@ -34,7 +34,7 @@ def _deprecated_warning(func):
@wraps(func)
def wrapper(*args, **kwargs):
warn_until_date(
"20240101",
"20260101",
"Please stop using 'salt.log.setup.{name}()' as it no longer does anything and "
"will go away after {{date}}.".format(name=func.__qualname__),
stacklevel=4,
Expand Down
12 changes: 3 additions & 9 deletions salt/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import salt.utils.args
import salt.utils.atomicfile
import salt.utils.crypt
import salt.utils.ctx
import salt.utils.event
import salt.utils.files
import salt.utils.gitfs
Expand All @@ -58,10 +59,8 @@
from salt.cli.batch_async import BatchAsync, batch_async_required
from salt.config import DEFAULT_INTERVAL
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.ext.tornado.stack_context import StackContext
from salt.transport import TRANSPORTS
from salt.utils.channel import iter_transport_opts
from salt.utils.ctx import RequestContext
from salt.utils.debug import (
enable_sigusr1_handler,
enable_sigusr2_handler,
Expand Down Expand Up @@ -1108,13 +1107,8 @@ def _handle_aes(self, data):
start = time.time()
self.stats[cmd]["runs"] += 1

def run_func(data):
return self.aes_funcs.run_func(data["cmd"], data)

with StackContext(
functools.partial(RequestContext, {"data": data, "opts": self.opts})
):
ret = run_func(data)
with salt.utils.ctx.request_context({"data": data, "opts": self.opts}):
ret = self.aes_funcs.run_func(data["cmd"], data)

if self.opts["master_stats"]:
self._post_stats(start, cmd)
Expand Down
10 changes: 2 additions & 8 deletions salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import salt.utils.args
import salt.utils.context
import salt.utils.crypt
import salt.utils.ctx
import salt.utils.data
import salt.utils.dictdiffer
import salt.utils.dictupdate
Expand Down Expand Up @@ -70,7 +71,6 @@
SaltSystemExit,
)
from salt.template import SLS_ENCODING
from salt.utils.ctx import RequestContext
from salt.utils.debug import enable_sigusr1_handler
from salt.utils.event import tagify
from salt.utils.network import parse_host_port
Expand Down Expand Up @@ -1805,18 +1805,12 @@ def _target(cls, minion_instance, opts, data, connected):
uid = salt.utils.user.get_uid(user=opts.get("user", None))
minion_instance.proc_dir = get_proc_dir(opts["cachedir"], uid=uid)

def run_func(minion_instance, opts, data):
with salt.utils.ctx.request_context({"data": data, "opts": opts}):
if isinstance(data["fun"], tuple) or isinstance(data["fun"], list):
return Minion._thread_multi_return(minion_instance, opts, data)
else:
return Minion._thread_return(minion_instance, opts, data)

with salt.ext.tornado.stack_context.StackContext(
functools.partial(RequestContext, {"data": data, "opts": opts})
):
with salt.ext.tornado.stack_context.StackContext(minion_instance.ctx):
run_func(minion_instance, opts, data)

def _execute_job_function(
self, function_name, function_args, executors, opts, data
):
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/aptpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3128,7 +3128,7 @@ def expand_repo_def(**kwargs):
NOT USABLE IN THE CLI
"""
warn_until_date(
"20250101",
"20260101",
"The pkg.expand_repo_def function is deprecated and set for removal "
"after {date}. This is only unsed internally by the apt pkg state "
"module. If that's not the case, please file an new issue requesting "
Expand Down
2 changes: 1 addition & 1 deletion salt/modules/cassandra_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __virtual__():
)

warn_until_date(
"20240101",
"20260101",
"The cassandra returner is broken and deprecated, and will be removed"
" after {date}. Use the cassandra_cql returner instead",
)
Expand Down
2 changes: 1 addition & 1 deletion salt/returners/cassandra_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __virtual__():
if not HAS_PYCASSA:
return False, "Could not import cassandra returner; pycassa is not installed."
warn_until_date(
"20240101",
"20260101",
"The cassandra returner is broken and deprecated, and will be removed"
" after {date}. Use the cassandra_cql returner instead",
)
Expand Down
2 changes: 1 addition & 1 deletion salt/returners/django_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def returner_callback(sender, ret):

def __virtual__():
warn_until_date(
"20240101",
"20260101",
"The django returner is broken and deprecated, and will be removed"
" after {date}.",
)
Expand Down
10 changes: 10 additions & 0 deletions salt/utils/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,16 @@ def wait_for_passwd(
time.sleep(trysleep)


def _format_master_param(master):
"""
If the master is a list, we need to convert it to a comma delimited string
Otherwise, we just return master
"""
if isinstance(master, list):
return ",".join(master)
return master


def deploy_windows(
host,
port=445,
Expand Down
60 changes: 19 additions & 41 deletions salt/utils/ctx.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
import threading
import contextlib

try:
# Try the stdlib C extension first
import _contextvars as contextvars
except ImportError:
# Py<3.7
import contextvars

class ClassProperty(property):
"""
Use a classmethod as a property
http://stackoverflow.com/a/1383402/1258307
"""
DEFAULT_CTX_VAR = "request_ctxvar"
request_ctxvar = contextvars.ContextVar(DEFAULT_CTX_VAR)

def __get__(self, cls, owner):
return self.fget.__get__(None, owner)() # pylint: disable=no-member


class RequestContext:
@contextlib.contextmanager
def request_context(data):
"""
A context manager that saves some per-thread state globally.
Intended for use with Tornado's StackContext.
https://gist.github.com/simon-weber/7755289
Simply import this class into any module and access the current request handler by this
class's class method property 'current'. If it returns None, there's no active request.
.. code:: python
from raas.utils.ctx import RequestContext
current_request_handler = RequestContext.current
A context manager that sets and un-sets the loader context
"""
tok = request_ctxvar.set(data)
try:
yield
finally:
request_ctxvar.reset(tok)

_state = threading.local()
_state.current_request = {}

def __init__(self, current_request):
self._current_request = current_request

@ClassProperty
@classmethod
def current(cls):
if not hasattr(cls._state, "current_request"):
return {}
return cls._state.current_request

def __enter__(self):
self._prev_request = self.__class__.current
self.__class__._state.current_request = self._current_request

def __exit__(self, *exc):
self.__class__._state.current_request = self._prev_request
del self._prev_request
return False

def __call__(self):
return self
def get_request_context():
return request_ctxvar.get({})
Loading

0 comments on commit d3c7d0c

Please sign in to comment.