2021-01-08 13:41:50 +01:00
|
|
|
From 4e6cc0c401bd6c9e47b324fc2df99e3bd679da33 Mon Sep 17 00:00:00 2001
|
2020-05-08 17:22:25 +02:00
|
|
|
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
|
|
|
|
<psuarezhernandez@suse.com>
|
|
|
|
Date: Wed, 22 Jan 2020 08:19:55 +0000
|
|
|
|
Subject: [PATCH] Prevent logging deadlock on salt-api subprocesses
|
|
|
|
(bsc#1159284)
|
|
|
|
|
|
|
|
---
|
2021-01-08 13:41:50 +01:00
|
|
|
salt/_logging/impl.py | 127 +++++++++++++++-------------------
|
|
|
|
salt/client/ssh/__init__.py | 12 +++-
|
|
|
|
salt/client/ssh/client.py | 21 +++---
|
|
|
|
salt/client/ssh/wrapper/cp.py | 10 +--
|
|
|
|
salt/loader.py | 2 +-
|
|
|
|
salt/utils/lazy.py | 10 +--
|
|
|
|
6 files changed, 85 insertions(+), 97 deletions(-)
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
diff --git a/salt/_logging/impl.py b/salt/_logging/impl.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 5a6292b445..2f15bf0025 100644
|
2020-05-08 17:22:25 +02:00
|
|
|
--- a/salt/_logging/impl.py
|
|
|
|
+++ b/salt/_logging/impl.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1,4 +1,3 @@
|
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
salt._logging.impl
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
@@ -6,15 +5,12 @@
|
|
|
|
Salt's logging implementation classes/functionality
|
|
|
|
"""
|
|
|
|
|
|
|
|
-# Import python libs
|
|
|
|
-from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import types
|
|
|
|
|
|
|
|
-# Import 3rd-party libs
|
|
|
|
import salt.ext.six as six
|
|
|
|
|
|
|
|
# Let's define these custom logging levels before importing the salt._logging.mixins
|
|
|
|
@@ -23,8 +19,8 @@ PROFILE = logging.PROFILE = 15
|
2020-05-08 17:22:25 +02:00
|
|
|
TRACE = logging.TRACE = 5
|
|
|
|
GARBAGE = logging.GARBAGE = 1
|
|
|
|
QUIET = logging.QUIET = 1000
|
|
|
|
+DEBUG = logging.DEBUG = 10
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
-# Import Salt libs
|
|
|
|
from salt._logging.handlers import StreamHandler # isort:skip
|
|
|
|
|
|
|
|
# from salt._logging.handlers import SysLogHandler # isort:skip
|
|
|
|
@@ -52,7 +48,7 @@ LOG_LEVELS = {
|
|
|
|
"warning": logging.WARNING,
|
|
|
|
}
|
|
|
|
|
|
|
|
-LOG_VALUES_TO_LEVELS = dict((v, k) for (k, v) in LOG_LEVELS.items())
|
|
|
|
+LOG_VALUES_TO_LEVELS = {v: k for (k, v) in LOG_LEVELS.items()}
|
|
|
|
|
|
|
|
LOG_COLORS = {
|
|
|
|
"levels": {
|
|
|
|
@@ -96,9 +92,7 @@ LOG_COLORS = {
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make a list of log level names sorted by log level
|
|
|
|
-SORTED_LEVEL_NAMES = [
|
|
|
|
- l[0] for l in sorted(six.iteritems(LOG_LEVELS), key=lambda x: x[1])
|
|
|
|
-]
|
|
|
|
+SORTED_LEVEL_NAMES = [l[0] for l in sorted(LOG_LEVELS.items(), key=lambda x: x[1])]
|
|
|
|
|
|
|
|
MODNAME_PATTERN = re.compile(r"(?P<name>%%\(name\)(?:\-(?P<digits>[\d]+))?s)")
|
|
|
|
|
|
|
|
@@ -168,8 +162,7 @@ def set_log_record_factory(factory):
|
|
|
|
Set the logging log record factory
|
|
|
|
"""
|
|
|
|
get_log_record_factory.__factory__ = factory
|
|
|
|
- if not six.PY2:
|
|
|
|
- logging.setLogRecordFactory(factory)
|
|
|
|
+ logging.setLogRecordFactory(factory)
|
|
|
|
|
|
|
|
|
|
|
|
set_log_record_factory(SaltLogRecord)
|
|
|
|
@@ -180,7 +173,7 @@ LOGGING_LOGGER_CLASS = logging.getLoggerClass()
|
|
|
|
|
|
|
|
|
|
|
|
class SaltLoggingClass(
|
|
|
|
- six.with_metaclass(LoggingMixinMeta, LOGGING_LOGGER_CLASS, NewStyleClassMixin)
|
|
|
|
+ LOGGING_LOGGER_CLASS, NewStyleClassMixin, metaclass=LoggingMixinMeta
|
|
|
|
):
|
|
|
|
def __new__(cls, *args):
|
|
|
|
"""
|
|
|
|
@@ -194,13 +187,11 @@ class SaltLoggingClass(
|
|
|
|
logging.getLogger(__name__)
|
|
|
|
|
|
|
|
"""
|
|
|
|
- instance = super(SaltLoggingClass, cls).__new__(cls)
|
|
|
|
+ instance = super().__new__(cls)
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
- try:
|
2021-01-08 13:41:50 +01:00
|
|
|
- max_logger_length = len(
|
|
|
|
- max(list(logging.Logger.manager.loggerDict), key=len)
|
|
|
|
- )
|
2020-05-08 17:22:25 +02:00
|
|
|
- for handler in logging.root.handlers:
|
2021-01-08 13:41:50 +01:00
|
|
|
+ max_logger_length = len(max(list(logging.Logger.manager.loggerDict), key=len))
|
2020-05-08 17:22:25 +02:00
|
|
|
+ for handler in logging.root.handlers:
|
|
|
|
+ try:
|
2021-01-08 13:41:50 +01:00
|
|
|
if handler in (
|
|
|
|
LOGGING_NULL_HANDLER,
|
|
|
|
LOGGING_STORE_HANDLER,
|
|
|
|
@@ -221,18 +212,15 @@ class SaltLoggingClass(
|
2020-05-08 17:22:25 +02:00
|
|
|
match = MODNAME_PATTERN.search(fmt)
|
|
|
|
if not match:
|
|
|
|
# Not matched. Release handler and return.
|
|
|
|
- handler.release()
|
|
|
|
return instance
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
if "digits" not in match.groupdict():
|
2020-05-08 17:22:25 +02:00
|
|
|
# No digits group. Release handler and return.
|
|
|
|
- handler.release()
|
|
|
|
return instance
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
digits = match.group("digits")
|
2020-05-08 17:22:25 +02:00
|
|
|
if not digits or not (digits and digits.isdigit()):
|
|
|
|
# No valid digits. Release handler and return.
|
|
|
|
- handler.release()
|
|
|
|
return instance
|
|
|
|
|
|
|
|
if int(digits) < max_logger_length:
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -243,9 +231,14 @@ class SaltLoggingClass(
|
2020-05-08 17:22:25 +02:00
|
|
|
)
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
handler.release()
|
|
|
|
- except ValueError:
|
|
|
|
- # There are no registered loggers yet
|
|
|
|
- pass
|
|
|
|
+ except ValueError:
|
|
|
|
+ # There are no registered loggers yet
|
|
|
|
+ pass
|
|
|
|
+ finally:
|
|
|
|
+ try:
|
|
|
|
+ handler.release()
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
return instance
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
def _log(
|
|
|
|
@@ -279,7 +272,7 @@ class SaltLoggingClass(
|
|
|
|
"Only one of 'exc_info' and 'exc_info_on_loglevel' is " "permitted"
|
|
|
|
)
|
|
|
|
if exc_info_on_loglevel is not None:
|
|
|
|
- if isinstance(exc_info_on_loglevel, six.string_types):
|
|
|
|
+ if isinstance(exc_info_on_loglevel, str):
|
|
|
|
exc_info_on_loglevel = LOG_LEVELS.get(
|
|
|
|
exc_info_on_loglevel, logging.ERROR
|
|
|
|
)
|
|
|
|
@@ -295,31 +288,37 @@ class SaltLoggingClass(
|
2020-05-08 17:22:25 +02:00
|
|
|
else:
|
2021-01-08 13:41:50 +01:00
|
|
|
extra["exc_info_on_loglevel"] = exc_info_on_loglevel
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
- if sys.version_info < (3,):
|
|
|
|
- LOGGING_LOGGER_CLASS._log(
|
|
|
|
- self, level, msg, args, exc_info=exc_info, extra=extra
|
|
|
|
- )
|
|
|
|
- elif sys.version_info < (3, 8):
|
|
|
|
- LOGGING_LOGGER_CLASS._log(
|
2021-01-08 13:41:50 +01:00
|
|
|
- self,
|
|
|
|
- level,
|
|
|
|
- msg,
|
|
|
|
- args,
|
|
|
|
- exc_info=exc_info,
|
|
|
|
- extra=extra,
|
|
|
|
- stack_info=stack_info,
|
2020-05-08 17:22:25 +02:00
|
|
|
- )
|
|
|
|
- else:
|
|
|
|
- LOGGING_LOGGER_CLASS._log(
|
2021-01-08 13:41:50 +01:00
|
|
|
- self,
|
|
|
|
- level,
|
|
|
|
- msg,
|
|
|
|
- args,
|
|
|
|
- exc_info=exc_info,
|
|
|
|
- extra=extra,
|
|
|
|
- stack_info=stack_info,
|
|
|
|
- stacklevel=stacklevel,
|
2020-05-08 17:22:25 +02:00
|
|
|
- )
|
|
|
|
+ try:
|
|
|
|
+ logging._acquireLock()
|
|
|
|
+ if sys.version_info < (3,):
|
|
|
|
+ LOGGING_LOGGER_CLASS._log(
|
|
|
|
+ self, level, msg, args, exc_info=exc_info, extra=extra
|
|
|
|
+ )
|
|
|
|
+ elif sys.version_info < (3, 8):
|
|
|
|
+ LOGGING_LOGGER_CLASS._log(
|
2021-01-08 13:41:50 +01:00
|
|
|
+ self,
|
|
|
|
+ level,
|
|
|
|
+ msg,
|
|
|
|
+ args,
|
|
|
|
+ exc_info=exc_info,
|
|
|
|
+ extra=extra,
|
|
|
|
+ stack_info=stack_info,
|
2020-05-08 17:22:25 +02:00
|
|
|
+ )
|
|
|
|
+ else:
|
|
|
|
+ LOGGING_LOGGER_CLASS._log(
|
2021-01-08 13:41:50 +01:00
|
|
|
+ self,
|
|
|
|
+ level,
|
|
|
|
+ msg,
|
|
|
|
+ args,
|
|
|
|
+ exc_info=exc_info,
|
|
|
|
+ extra=extra,
|
|
|
|
+ stack_info=stack_info,
|
|
|
|
+ stacklevel=stacklevel,
|
2020-05-08 17:22:25 +02:00
|
|
|
+ )
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+ finally:
|
|
|
|
+ logging._releaseLock()
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
def makeRecord(
|
|
|
|
self,
|
|
|
|
@@ -357,7 +356,7 @@ class SaltLoggingClass(
|
|
|
|
except NameError:
|
|
|
|
salt_system_encoding = "utf-8"
|
|
|
|
|
|
|
|
- if isinstance(msg, six.string_types) and not isinstance(msg, six.text_type):
|
|
|
|
+ if isinstance(msg, str) and not isinstance(msg, str):
|
|
|
|
try:
|
|
|
|
_msg = msg.decode(salt_system_encoding, "replace")
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
@@ -367,9 +366,7 @@ class SaltLoggingClass(
|
|
|
|
|
|
|
|
_args = []
|
|
|
|
for item in args:
|
|
|
|
- if isinstance(item, six.string_types) and not isinstance(
|
|
|
|
- item, six.text_type
|
|
|
|
- ):
|
|
|
|
+ if isinstance(item, str) and not isinstance(item, str):
|
|
|
|
try:
|
|
|
|
_args.append(item.decode(salt_system_encoding, "replace"))
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
@@ -378,24 +375,9 @@ class SaltLoggingClass(
|
|
|
|
_args.append(item)
|
|
|
|
_args = tuple(_args)
|
|
|
|
|
|
|
|
- if six.PY2:
|
|
|
|
- # Recreate what's done for Py >= 3.5
|
|
|
|
- _log_record_factory = get_log_record_factory()
|
|
|
|
- logrecord = _log_record_factory(
|
|
|
|
- name, level, fn, lno, _msg, _args, exc_info, func
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if extra is not None:
|
|
|
|
- for key in extra:
|
|
|
|
- if (key in ["message", "asctime"]) or (key in logrecord.__dict__):
|
|
|
|
- raise KeyError(
|
|
|
|
- "Attempt to overwrite '{}' in LogRecord".format(key)
|
|
|
|
- )
|
|
|
|
- logrecord.__dict__[key] = extra[key]
|
|
|
|
- else:
|
|
|
|
- logrecord = LOGGING_LOGGER_CLASS.makeRecord(
|
|
|
|
- self, name, level, fn, lno, _msg, _args, exc_info, func, sinfo
|
|
|
|
- )
|
|
|
|
+ logrecord = LOGGING_LOGGER_CLASS.makeRecord(
|
|
|
|
+ self, name, level, fn, lno, _msg, _args, exc_info, func, sinfo
|
|
|
|
+ )
|
|
|
|
|
|
|
|
if exc_info_on_loglevel is not None:
|
|
|
|
# Let's add some custom attributes to the LogRecord class in order
|
|
|
|
@@ -419,6 +401,7 @@ if logging.getLoggerClass() is not SaltLoggingClass:
|
|
|
|
logging.addLevelName(PROFILE, "PROFILE")
|
|
|
|
logging.addLevelName(TRACE, "TRACE")
|
|
|
|
logging.addLevelName(GARBAGE, "GARBAGE")
|
|
|
|
+ logging.addLevelName(DEBUG, "DEBUG")
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
# ----- REMOVE ON REFACTORING COMPLETE -------------------------------------------------------------------------->
|
|
|
|
if not logging.root.handlers:
|
|
|
|
diff --git a/salt/client/ssh/__init__.py b/salt/client/ssh/__init__.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index ef9eb0c07e..6570fba5b1 100644
|
2020-05-08 17:22:25 +02:00
|
|
|
--- a/salt/client/ssh/__init__.py
|
|
|
|
+++ b/salt/client/ssh/__init__.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -532,7 +532,9 @@ class SSH:
|
|
|
|
**target
|
|
|
|
)
|
|
|
|
ret = {"id": single.id}
|
2020-05-08 17:22:25 +02:00
|
|
|
+ logging._acquireLock()
|
|
|
|
stdout, stderr, retcode = single.run()
|
|
|
|
+ logging._releaseLock()
|
|
|
|
# This job is done, yield
|
|
|
|
try:
|
|
|
|
data = salt.utils.json.find_json(stdout)
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -600,8 +602,14 @@ class SSH:
|
|
|
|
self.targets[host],
|
|
|
|
mine,
|
|
|
|
)
|
|
|
|
- routine = Process(target=self.handle_routine, args=args)
|
2020-05-08 17:22:25 +02:00
|
|
|
- routine.start()
|
|
|
|
+ try:
|
|
|
|
+ logging._acquireLock()
|
2021-01-08 13:41:50 +01:00
|
|
|
+ routine = Process(target=self.handle_routine, args=args)
|
2020-05-08 17:22:25 +02:00
|
|
|
+ routine.start()
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+ finally:
|
|
|
|
+ logging._releaseLock()
|
2021-01-08 13:41:50 +01:00
|
|
|
running[host] = {"thread": routine}
|
2020-05-08 17:22:25 +02:00
|
|
|
continue
|
|
|
|
ret = {}
|
|
|
|
diff --git a/salt/client/ssh/client.py b/salt/client/ssh/client.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 55436366cf..d2dbdeb00e 100644
|
2020-05-08 17:22:25 +02:00
|
|
|
--- a/salt/client/ssh/client.py
|
|
|
|
+++ b/salt/client/ssh/client.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1,14 +1,10 @@
|
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
|
-
|
|
|
|
-# Import Python libs
|
|
|
|
-from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
-
|
2020-05-08 17:22:25 +02:00
|
|
|
import copy
|
|
|
|
import logging
|
2021-01-08 13:41:50 +01:00
|
|
|
+import multiprocessing
|
|
|
|
import os
|
2020-05-08 17:22:25 +02:00
|
|
|
import random
|
|
|
|
+import time
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
-# Import Salt libs
|
2020-05-08 17:22:25 +02:00
|
|
|
import salt.config
|
2021-01-08 13:41:50 +01:00
|
|
|
import salt.syspaths as syspaths
|
|
|
|
import salt.utils.args
|
|
|
|
@@ -16,8 +12,10 @@ from salt.exceptions import SaltClientError # Temporary
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
+_LOCK = multiprocessing.Lock()
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
-class SSHClient(object):
|
|
|
|
+
|
|
|
|
+class SSHClient:
|
|
|
|
"""
|
|
|
|
Create a client object for executing routines via the salt-ssh backend
|
|
|
|
|
|
|
|
@@ -60,7 +58,11 @@ class SSHClient(object):
|
|
|
|
opts["selected_target_option"] = tgt_type
|
|
|
|
opts["tgt"] = tgt
|
|
|
|
opts["arg"] = arg
|
2020-05-08 17:22:25 +02:00
|
|
|
- return salt.client.ssh.SSH(opts)
|
|
|
|
+ _LOCK.acquire()
|
|
|
|
+ ret = salt.client.ssh.SSH(opts)
|
|
|
|
+ time.sleep(0.01)
|
|
|
|
+ _LOCK.release()
|
|
|
|
+ return ret
|
|
|
|
|
|
|
|
def cmd_iter(
|
2021-01-08 13:41:50 +01:00
|
|
|
self,
|
|
|
|
@@ -80,8 +82,7 @@ class SSHClient(object):
|
|
|
|
.. versionadded:: 2015.5.0
|
|
|
|
"""
|
|
|
|
ssh = self._prep_ssh(tgt, fun, arg, timeout, tgt_type, kwarg, **kwargs)
|
|
|
|
- for ret in ssh.run_iter(jid=kwargs.get("jid", None)):
|
|
|
|
- yield ret
|
|
|
|
+ yield from ssh.run_iter(jid=kwargs.get("jid", None))
|
|
|
|
|
|
|
|
def cmd(
|
|
|
|
self, tgt, fun, arg=(), timeout=None, tgt_type="glob", kwarg=None, **kwargs
|
2020-05-08 17:22:25 +02:00
|
|
|
diff --git a/salt/client/ssh/wrapper/cp.py b/salt/client/ssh/wrapper/cp.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index e369d8475f..eb37ae971b 100644
|
2020-05-08 17:22:25 +02:00
|
|
|
--- a/salt/client/ssh/wrapper/cp.py
|
|
|
|
+++ b/salt/client/ssh/wrapper/cp.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1,15 +1,11 @@
|
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Wrap the cp module allowing for managed ssh file transfers
|
|
|
|
"""
|
|
|
|
-# Import Python libs
|
|
|
|
-from __future__ import absolute_import, print_function
|
|
|
|
|
2020-05-08 17:22:25 +02:00
|
|
|
-import logging
|
|
|
|
import os
|
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
-# Import salt libs
|
|
|
|
import salt.client.ssh
|
|
|
|
+import salt.log.setup as logging
|
|
|
|
import salt.utils.files
|
|
|
|
import salt.utils.stringutils
|
|
|
|
import salt.utils.templates
|
|
|
|
@@ -107,7 +103,7 @@ def _render_filenames(path, dest, saltenv, template):
|
|
|
|
if template not in salt.utils.templates.TEMPLATE_REGISTRY:
|
|
|
|
raise CommandExecutionError(
|
|
|
|
"Attempted to render file paths with unavailable engine "
|
|
|
|
- "{0}".format(template)
|
|
|
|
+ "{}".format(template)
|
|
|
|
)
|
|
|
|
|
|
|
|
kwargs = {}
|
|
|
|
@@ -133,7 +129,7 @@ def _render_filenames(path, dest, saltenv, template):
|
|
|
|
if not data["result"]:
|
|
|
|
# Failed to render the template
|
|
|
|
raise CommandExecutionError(
|
|
|
|
- "Failed to render file path with error: {0}".format(data["data"])
|
|
|
|
+ "Failed to render file path with error: {}".format(data["data"])
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return data["data"]
|
2020-05-08 17:22:25 +02:00
|
|
|
diff --git a/salt/loader.py b/salt/loader.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 9a9c11b401..cfcd18f6f3 100644
|
2020-05-08 17:22:25 +02:00
|
|
|
--- a/salt/loader.py
|
|
|
|
+++ b/salt/loader.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -8,7 +8,6 @@ import functools
|
|
|
|
import importlib.machinery # pylint: disable=no-name-in-module,import-error
|
|
|
|
import importlib.util # pylint: disable=no-name-in-module,import-error
|
|
|
|
import inspect
|
|
|
|
-import logging
|
|
|
|
import os
|
2020-05-08 17:22:25 +02:00
|
|
|
import re
|
|
|
|
import sys
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -23,6 +22,7 @@ from zipimport import zipimporter
|
|
|
|
import salt.config
|
|
|
|
import salt.defaults.events
|
|
|
|
import salt.defaults.exitcodes
|
2020-05-08 17:22:25 +02:00
|
|
|
+import salt.log.setup as logging
|
2021-01-08 13:41:50 +01:00
|
|
|
import salt.syspaths
|
|
|
|
import salt.utils.args
|
|
|
|
import salt.utils.context
|
2020-05-08 17:22:25 +02:00
|
|
|
diff --git a/salt/utils/lazy.py b/salt/utils/lazy.py
|
2021-01-08 13:41:50 +01:00
|
|
|
index 8fc538164a..c828dd2c32 100644
|
2020-05-08 17:22:25 +02:00
|
|
|
--- a/salt/utils/lazy.py
|
|
|
|
+++ b/salt/utils/lazy.py
|
2021-01-08 13:41:50 +01:00
|
|
|
@@ -1,15 +1,13 @@
|
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Lazily-evaluated data structures, primarily used by Salt's loader
|
|
|
|
"""
|
|
|
|
|
|
|
|
-# Import Python Libs
|
|
|
|
-from __future__ import absolute_import, unicode_literals
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
-import logging
|
|
|
|
+import time
|
2021-01-08 13:41:50 +01:00
|
|
|
from collections.abc import MutableMapping
|
|
|
|
|
2020-05-08 17:22:25 +02:00
|
|
|
import salt.exceptions
|
2021-01-08 13:41:50 +01:00
|
|
|
+import salt.log.setup as logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
@@ -81,7 +79,7 @@ class LazyDict(MutableMapping):
|
|
|
|
|
|
|
|
Override this to return a more meaningfull error message if possible
|
|
|
|
"""
|
|
|
|
- return "'{0}' is not available.".format(function_name)
|
|
|
|
+ return "'{}' is not available.".format(function_name)
|
2020-05-08 17:22:25 +02:00
|
|
|
|
2021-01-08 13:41:50 +01:00
|
|
|
def __setitem__(self, key, val):
|
|
|
|
self._dict[key] = val
|
|
|
|
@@ -100,11 +98,13 @@ class LazyDict(MutableMapping):
|
2020-05-08 17:22:25 +02:00
|
|
|
# load the item
|
|
|
|
if self._load(key):
|
2021-01-08 13:41:50 +01:00
|
|
|
log.debug("LazyLoaded %s", key)
|
2020-05-08 17:22:25 +02:00
|
|
|
+ time.sleep(0.0001)
|
|
|
|
return self._dict[key]
|
|
|
|
else:
|
2021-01-08 13:41:50 +01:00
|
|
|
log.debug(
|
|
|
|
"Could not LazyLoad %s: %s", key, self.missing_fun_string(key)
|
|
|
|
)
|
2020-05-08 17:22:25 +02:00
|
|
|
+ time.sleep(0.0001)
|
|
|
|
raise KeyError(key)
|
|
|
|
else:
|
|
|
|
return self._dict[key]
|
|
|
|
--
|
2021-01-08 13:41:50 +01:00
|
|
|
2.29.2
|
2020-05-08 17:22:25 +02:00
|
|
|
|
|
|
|
|