mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #45032 from terminalmage/renderers-returners-unicode
[PY3] Add unicode_literals to renderers and returners
This commit is contained in:
commit
4e56835221
68 changed files with 378 additions and 340 deletions
|
@ -3,7 +3,7 @@
|
|||
Cheetah Renderer for Salt
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import 3rd party libs
|
||||
try:
|
||||
|
@ -13,7 +13,7 @@ except ImportError:
|
|||
HAS_LIBS = False
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
def render(cheetah_data, saltenv='base', sls='', method='xml', **kws):
|
||||
|
@ -25,7 +25,7 @@ def render(cheetah_data, saltenv='base', sls='', method='xml', **kws):
|
|||
if not HAS_LIBS:
|
||||
return {}
|
||||
|
||||
if not isinstance(cheetah_data, string_types):
|
||||
if not isinstance(cheetah_data, six.string_types):
|
||||
cheetah_data = cheetah_data.read()
|
||||
|
||||
if cheetah_data.startswith('#!'):
|
||||
|
@ -33,4 +33,4 @@ def render(cheetah_data, saltenv='base', sls='', method='xml', **kws):
|
|||
if not cheetah_data.strip():
|
||||
return {}
|
||||
|
||||
return str(Template(cheetah_data, searchList=[kws]))
|
||||
return six.text_type(Template(cheetah_data, searchList=[kws]))
|
||||
|
|
|
@ -12,7 +12,7 @@ This renderer requires `Dogeon`__ (installable via pip)
|
|||
.. __: https://github.com/soasme/dogeon
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Genshi Renderer for Salt
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import 3rd party libs
|
||||
try:
|
||||
|
@ -15,7 +15,7 @@ except ImportError:
|
|||
HAS_LIBS = False
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
def render(genshi_data, saltenv='base', sls='', method='xml', **kws):
|
||||
|
@ -40,7 +40,7 @@ def render(genshi_data, saltenv='base', sls='', method='xml', **kws):
|
|||
if not HAS_LIBS:
|
||||
return {}
|
||||
|
||||
if not isinstance(genshi_data, string_types):
|
||||
if not isinstance(genshi_data, six.string_types):
|
||||
genshi_data = genshi_data.read()
|
||||
|
||||
if genshi_data.startswith('#!'):
|
||||
|
|
|
@ -209,7 +209,7 @@ pillar data like so:
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
|
@ -288,7 +288,7 @@ def _decrypt_ciphertext(cipher, translate_newlines=False):
|
|||
else:
|
||||
if six.PY3 and isinstance(decrypted_data, bytes):
|
||||
decrypted_data = decrypted_data.decode(__salt_system_encoding__)
|
||||
return str(decrypted_data)
|
||||
return six.text_type(decrypted_data)
|
||||
|
||||
|
||||
def _decrypt_object(obj, translate_newlines=False):
|
||||
|
|
|
@ -4,7 +4,7 @@ Hjson Renderer for Salt
|
|||
http://laktak.github.io/hjson/
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import 3rd party libs
|
||||
try:
|
||||
|
@ -14,7 +14,7 @@ except ImportError:
|
|||
HAS_LIBS = False
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
def render(hjson_data, saltenv='base', sls='', **kws):
|
||||
|
@ -24,7 +24,7 @@ def render(hjson_data, saltenv='base', sls='', **kws):
|
|||
|
||||
:rtype: A Python data structure
|
||||
'''
|
||||
if not isinstance(hjson_data, string_types):
|
||||
if not isinstance(hjson_data, six.string_types):
|
||||
hjson_data = hjson_data.read()
|
||||
|
||||
if hjson_data.startswith('#!'):
|
||||
|
|
|
@ -6,7 +6,7 @@ For Jinja usage information see :ref:`Understanding Jinja <understanding-jinja>`
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
|
@ -53,7 +53,7 @@ def render(template_file, saltenv='base', sls='', argline='',
|
|||
from_str = argline == '-s'
|
||||
if not from_str and argline:
|
||||
raise SaltRenderError(
|
||||
'Unknown renderer option: {opt}'.format(opt=argline)
|
||||
'Unknown renderer option: {opt}'.format(opt=argline)
|
||||
)
|
||||
|
||||
tmp_data = salt.utils.templates.JINJA(template_file,
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
JSON Renderer for Salt
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import salt.utils.json
|
||||
json = salt.utils.json.import_json()
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
def render(json_data, saltenv='base', sls='', **kws):
|
||||
|
@ -20,7 +20,7 @@ def render(json_data, saltenv='base', sls='', **kws):
|
|||
|
||||
:rtype: A Python data structure
|
||||
'''
|
||||
if not isinstance(json_data, string_types):
|
||||
if not isinstance(json_data, six.string_types):
|
||||
json_data = json_data.read()
|
||||
|
||||
if json_data.startswith('#!'):
|
||||
|
|
|
@ -12,7 +12,7 @@ This renderer requires the `json5 python bindings`__, installable via pip.
|
|||
.. __: https://pypi.python.org/pypi/json5
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
@ -23,7 +23,7 @@ except ImportError:
|
|||
HAS_JSON5 = False
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -44,7 +44,7 @@ def render(json_data, saltenv='base', sls='', **kws):
|
|||
|
||||
:rtype: A Python data structure
|
||||
'''
|
||||
if not isinstance(json_data, string_types):
|
||||
if not isinstance(json_data, six.string_types):
|
||||
json_data = json_data.read()
|
||||
|
||||
if json_data.startswith('#!'):
|
||||
|
|
|
@ -4,7 +4,7 @@ Mako Renderer for Salt
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext import six
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import third party libs
|
||||
import msgpack
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
def render(msgpack_data, saltenv='base', sls='', **kws):
|
||||
|
@ -21,7 +21,7 @@ def render(msgpack_data, saltenv='base', sls='', **kws):
|
|||
|
||||
:rtype: A Python data structure
|
||||
'''
|
||||
if not isinstance(msgpack_data, string_types):
|
||||
if not isinstance(msgpack_data, six.string_types):
|
||||
msgpack_data = msgpack_data.read()
|
||||
|
||||
if msgpack_data.startswith('#!'):
|
||||
|
|
|
@ -53,7 +53,7 @@ data like so:
|
|||
'''
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import re
|
||||
import logging
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
'''
|
||||
Pass Renderer for Salt
|
||||
|
||||
[pass](https://www.passwordstore.org/)
|
||||
|
@ -38,10 +38,10 @@ entries that are of interest for pillar data
|
|||
pass:
|
||||
pkg.installed
|
||||
```
|
||||
"""
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
from os.path import expanduser
|
||||
|
@ -58,9 +58,9 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def _get_pass_exec():
|
||||
"""
|
||||
'''
|
||||
Return the pass executable or raise an error
|
||||
"""
|
||||
'''
|
||||
pass_exec = salt.utils.path.which('pass')
|
||||
if pass_exec:
|
||||
return pass_exec
|
||||
|
@ -69,12 +69,12 @@ def _get_pass_exec():
|
|||
|
||||
|
||||
def _fetch_secret(pass_path):
|
||||
"""
|
||||
'''
|
||||
Fetch secret from pass based on pass_path. If there is
|
||||
any error, return back the original pass_path value
|
||||
"""
|
||||
'''
|
||||
cmd = "pass show {0}".format(pass_path.strip())
|
||||
log.debug('Fetching secret: {0}'.format(cmd))
|
||||
log.debug('Fetching secret: %s', cmd)
|
||||
|
||||
proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE)
|
||||
pass_data, pass_error = proc.communicate()
|
||||
|
@ -88,9 +88,9 @@ def _fetch_secret(pass_path):
|
|||
|
||||
|
||||
def _decrypt_object(obj):
|
||||
"""
|
||||
'''
|
||||
Recursively try to find a pass path (string) that can be handed off to pass
|
||||
"""
|
||||
'''
|
||||
if isinstance(obj, six.string_types):
|
||||
return _fetch_secret(obj)
|
||||
elif isinstance(obj, dict):
|
||||
|
@ -103,9 +103,9 @@ def _decrypt_object(obj):
|
|||
|
||||
|
||||
def render(pass_info, saltenv='base', sls='', argline='', **kwargs):
|
||||
"""
|
||||
'''
|
||||
Fetch secret from pass based on pass_path
|
||||
"""
|
||||
'''
|
||||
try:
|
||||
_get_pass_exec()
|
||||
except SaltRenderError:
|
||||
|
|
|
@ -97,7 +97,7 @@ Translate to::
|
|||
return config
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
|
|
|
@ -230,7 +230,7 @@ is enabled by setting the ``ordered`` option on ``__pydsl__``.
|
|||
__pydsl__.set(ordered=True)
|
||||
|
||||
for i in range(10):
|
||||
i = str(i)
|
||||
i = six.text_type(i)
|
||||
state(i).cmd.run('echo '+i, cwd='/')
|
||||
state('1').cmd.run('echo one')
|
||||
state('2').cmd.run(name='echo two')
|
||||
|
@ -334,7 +334,7 @@ For example:
|
|||
my_mod = sys.modules['salt.loaded.ext.module.my_mod']
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import types
|
||||
import salt.utils.pydsl as pydsl
|
||||
|
|
|
@ -295,13 +295,13 @@ TODO
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.ext.six import exec_
|
||||
from salt.ext import six
|
||||
import salt.utils.files
|
||||
import salt.loader
|
||||
from salt.fileclient import get_file_client
|
||||
|
@ -384,7 +384,7 @@ def render(template, saltenv='base', sls='', salt_data=True, **kwargs):
|
|||
mod,
|
||||
valid_funcs
|
||||
)
|
||||
exec_(mod_cmd, mod_globals, mod_locals)
|
||||
six.exec_(mod_cmd, mod_globals, mod_locals)
|
||||
|
||||
_globals[mod_camel] = mod_locals[mod_camel]
|
||||
|
||||
|
@ -459,7 +459,7 @@ def render(template, saltenv='base', sls='', salt_data=True, **kwargs):
|
|||
|
||||
with salt.utils.files.fopen(state_file) as state_fh:
|
||||
state_contents, state_globals = process_template(state_fh)
|
||||
exec_(state_contents, state_globals)
|
||||
six.exec_(state_contents, state_globals)
|
||||
|
||||
# if no imports have been specified then we are being imported as: import salt://foo.sls
|
||||
# so we want to stick all of the locals from our state file into the template globals
|
||||
|
@ -501,6 +501,6 @@ def render(template, saltenv='base', sls='', salt_data=True, **kwargs):
|
|||
Registry.enabled = True
|
||||
|
||||
# now exec our template using our created scopes
|
||||
exec_(final_template, _globals)
|
||||
six.exec_(final_template, _globals)
|
||||
|
||||
return Registry.salt_data()
|
||||
|
|
|
@ -27,15 +27,16 @@ A flexible renderer that takes a templating engine and a data format
|
|||
#
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import getopt
|
||||
import copy
|
||||
from os import path as ospath
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.files
|
||||
import salt.utils.stringutils
|
||||
from salt.exceptions import SaltRenderError
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -75,7 +76,7 @@ def __init__(opts):
|
|||
STATE_NAME = STATE_FUNC.split('.')[0]
|
||||
|
||||
|
||||
MOD_BASENAME = ospath.basename(__file__)
|
||||
MOD_BASENAME = os.path.basename(__file__)
|
||||
INVALID_USAGE_ERROR = SaltRenderError(
|
||||
'Invalid use of {0} renderer!\n'
|
||||
'''Usage: #!{1} [-GoSp] [<data_renderer> [options] . <template_renderer> [options]]
|
||||
|
@ -108,7 +109,7 @@ def render(input, saltenv='base', sls='', argline='', **kws):
|
|||
implicit_require = False
|
||||
|
||||
def process_sls_data(data, context=None, extract=False):
|
||||
sls_dir = ospath.dirname(sls.replace('.', ospath.sep)) if '.' in sls else sls
|
||||
sls_dir = os.path.dirname(sls.replace('.', os.path.sep)) if '.' in sls else sls
|
||||
ctx = dict(sls_dir=sls_dir if sls_dir else '.')
|
||||
|
||||
if context:
|
||||
|
@ -156,8 +157,8 @@ def render(input, saltenv='base', sls='', argline='', **kws):
|
|||
raise
|
||||
except Exception as err:
|
||||
log.exception(
|
||||
'Error found while pre-processing the salt file '
|
||||
'{0}:\n{1}'.format(sls, err)
|
||||
'Error found while pre-processing the salt file %s:\n%s',
|
||||
sls, err
|
||||
)
|
||||
from salt.state import State
|
||||
state = State(__opts__)
|
||||
|
@ -207,9 +208,9 @@ def render(input, saltenv='base', sls='', argline='', **kws):
|
|||
|
||||
if isinstance(input, six.string_types):
|
||||
with salt.utils.files.fopen(input, 'r') as ifile:
|
||||
sls_templ = ifile.read()
|
||||
sls_templ = salt.utils.stringutils.to_unicode(ifile.read())
|
||||
else: # assume file-like
|
||||
sls_templ = input.read()
|
||||
sls_templ = salt.utils.stringutils.to_unicode(input.read())
|
||||
|
||||
# first pass to extract the state configuration
|
||||
match = re.search(__opts__['stateconf_end_marker'], sls_templ)
|
||||
|
@ -235,7 +236,7 @@ def render(input, saltenv='base', sls='', argline='', **kws):
|
|||
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
import pprint # FIXME: pprint OrderedDict
|
||||
log.debug('Rendered sls: {0}'.format(pprint.pformat(data)))
|
||||
log.debug('Rendered sls: %s', pprint.pformat(data))
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import salt libs
|
||||
from salt.ext import six
|
||||
|
|
|
@ -5,7 +5,7 @@ YAML Renderer for Salt
|
|||
For YAML usage information see :ref:`Understanding YAML <yaml>`.
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
@ -60,13 +60,12 @@ def render(yaml_data, saltenv='base', sls='', argline='', **kws):
|
|||
if len(warn_list) > 0:
|
||||
for item in warn_list:
|
||||
log.warning(
|
||||
'{warn} found in {sls} saltenv={env}'.format(
|
||||
warn=item.message, sls=salt.utils.url.create(sls), env=saltenv
|
||||
)
|
||||
'%s found in %s saltenv=%s',
|
||||
item.message, salt.utils.url.create(sls), saltenv
|
||||
)
|
||||
if not data:
|
||||
data = {}
|
||||
log.debug('Results of YAML rendering: \n{0}'.format(data))
|
||||
log.debug('Results of YAML rendering: \n%s', data)
|
||||
|
||||
def _validate_data(data):
|
||||
'''
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
@ -24,11 +24,10 @@ def render(sls_data, saltenv='base', sls='', **kws):
|
|||
|
||||
for item in warn_list:
|
||||
log.warning(
|
||||
'{warn} found in {sls} saltenv={env}'.format(
|
||||
warn=item.message, sls=salt.utils.url.create(sls), env=saltenv
|
||||
)
|
||||
'%s found in %s saltenv=%s',
|
||||
item.message, salt.utils.url.create(sls), saltenv
|
||||
)
|
||||
|
||||
log.debug('Results of SLS rendering: \n{0}'.format(data))
|
||||
log.debug('Results of SLS rendering: \n%s', data)
|
||||
|
||||
return data
|
||||
|
|
|
@ -5,9 +5,10 @@ Returners Directory
|
|||
:func:`get_returner_options` is a general purpose function that returners may
|
||||
use to fetch their configuration options.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -116,7 +117,7 @@ def _fetch_ret_config(ret):
|
|||
return None
|
||||
if 'ret_config' not in ret:
|
||||
return ''
|
||||
return str(ret['ret_config'])
|
||||
return six.text_type(ret['ret_config'])
|
||||
|
||||
|
||||
def _fetch_option(cfg, ret_config, virtualname, attr_name):
|
||||
|
|
|
@ -82,7 +82,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import collections
|
||||
import logging
|
||||
import socket
|
||||
|
@ -143,7 +143,7 @@ def _carbon(host, port):
|
|||
|
||||
carbon_sock.connect((host, port))
|
||||
except socket.error as err:
|
||||
log.error('Error connecting to {0}:{1}, {2}'.format(host, port, err))
|
||||
log.error('Error connecting to %s:%s, %s', host, port, err)
|
||||
raise
|
||||
else:
|
||||
log.debug('Connected to carbon')
|
||||
|
@ -176,7 +176,7 @@ def _send_textmetrics(metrics):
|
|||
Format metrics for the carbon plaintext protocol
|
||||
'''
|
||||
|
||||
data = [' '.join(map(str, metric)) for metric in metrics] + ['']
|
||||
data = [' '.join(map(six.text_type, metric)) for metric in metrics] + ['']
|
||||
|
||||
return '\n'.join(data)
|
||||
|
||||
|
@ -199,7 +199,10 @@ def _walk(path, value, metrics, timestamp, skip):
|
|||
Whether or not to skip metrics when there's an error casting the value
|
||||
to a float. Defaults to `False`.
|
||||
'''
|
||||
log.trace('Carbon return walking path: {0}, value: {1}, metrics: {2}, timestamp: {3}'.format(path, value, metrics, timestamp))
|
||||
log.trace(
|
||||
'Carbon return walking path: %s, value: %s, metrics: %s, ',
|
||||
'timestamp: %s', path, value, metrics, timestamp
|
||||
)
|
||||
if isinstance(value, collections.Mapping):
|
||||
for key, val in six.iteritems(value):
|
||||
_walk('{0}.{1}'.format(path, key), val, metrics, timestamp, skip)
|
||||
|
@ -232,8 +235,8 @@ def _send(saltdata, metric_base, opts):
|
|||
metric_base_pattern = opts.get('carbon.metric_base_pattern')
|
||||
mode = opts.get('mode').lower() if 'mode' in opts else 'text'
|
||||
|
||||
log.debug('Carbon minion configured with host: {0}:{1}'.format(host, port))
|
||||
log.debug('Using carbon protocol: {0}'.format(mode))
|
||||
log.debug('Carbon minion configured with host: %s:%s', host, port)
|
||||
log.debug('Using carbon protocol: %s', mode)
|
||||
|
||||
if not (host and port):
|
||||
log.error('Host or port not defined')
|
||||
|
@ -246,10 +249,10 @@ def _send(saltdata, metric_base, opts):
|
|||
|
||||
handler = _send_picklemetrics if mode == 'pickle' else _send_textmetrics
|
||||
metrics = []
|
||||
log.trace('Carbon returning walking data: {0}'.format(saltdata))
|
||||
log.trace('Carbon returning walking data: %s', saltdata)
|
||||
_walk(metric_base, saltdata, metrics, timestamp, skip)
|
||||
data = handler(metrics)
|
||||
log.trace('Carbon inserting data: {0}'.format(data))
|
||||
log.trace('Carbon inserting data: %s', data)
|
||||
|
||||
with _carbon(host, port) as sock:
|
||||
total_sent_bytes = 0
|
||||
|
@ -259,7 +262,7 @@ def _send(saltdata, metric_base, opts):
|
|||
log.error('Bytes sent 0, Connection reset?')
|
||||
return
|
||||
|
||||
log.debug('Sent {0} bytes to carbon'.format(sent_bytes))
|
||||
log.debug('Sent %s bytes to carbon', sent_bytes)
|
||||
total_sent_bytes += sent_bytes
|
||||
|
||||
|
||||
|
@ -272,7 +275,7 @@ def event_return(events):
|
|||
opts = _get_options({}) # Pass in empty ret, since this is a list of events
|
||||
opts['skip'] = True
|
||||
for event in events:
|
||||
log.trace('Carbon returner received event: {0}'.format(event))
|
||||
log.trace('Carbon returner received event: %s', event)
|
||||
metric_base = event['tag']
|
||||
saltdata = event['data'].get('data')
|
||||
_send(saltdata, metric_base, opts)
|
||||
|
|
|
@ -117,9 +117,7 @@ needs. SaltStack has seen situations where these timeouts can resolve
|
|||
some stacktraces that appear to come from the Datastax Python driver.
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
# Let's not allow PyLint complain about string substitution
|
||||
# pylint: disable=W1321,E1321
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
|
@ -132,6 +130,7 @@ import salt.returners
|
|||
import salt.utils.jid
|
||||
import salt.exceptions
|
||||
from salt.exceptions import CommandExecutionError
|
||||
from salt.ext import six
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
|
@ -210,7 +209,7 @@ def returner(ret):
|
|||
log.critical('Could not insert into salt_returns with Cassandra returner.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while inserting into salt_returns: {0}'.format(str(e)))
|
||||
log.critical('Unexpected error while inserting into salt_returns: %s', e)
|
||||
raise
|
||||
|
||||
# Store the last function called by the minion
|
||||
|
@ -234,7 +233,10 @@ def returner(ret):
|
|||
log.critical('Could not store minion ID with Cassandra returner.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while inserting minion ID into the minions table: {0}'.format(str(e)))
|
||||
log.critical(
|
||||
'Unexpected error while inserting minion ID into the minions '
|
||||
'table: %s', e
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
|
@ -258,7 +260,7 @@ def event_return(events):
|
|||
) VALUES (
|
||||
?, ?, ?, ?, ?)
|
||||
'''
|
||||
statement_arguments = [str(uuid.uuid1()),
|
||||
statement_arguments = [six.text_type(uuid.uuid1()),
|
||||
int(time.time() * 1000),
|
||||
json.dumps(data).replace("'", "''"),
|
||||
__opts__['id'],
|
||||
|
@ -273,7 +275,8 @@ def event_return(events):
|
|||
log.critical('Could not store events with Cassandra returner.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while inserting into salt_events: {0}'.format(str(e)))
|
||||
log.critical(
|
||||
'Unexpected error while inserting into salt_events: %s', e)
|
||||
raise
|
||||
|
||||
|
||||
|
@ -302,7 +305,7 @@ def save_load(jid, load, minions=None):
|
|||
log.critical('Could not save load in jids table.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while inserting into jids: {0}'.format(str(e)))
|
||||
log.critical('Unexpected error while inserting into jids: %s', e)
|
||||
raise
|
||||
|
||||
|
||||
|
@ -333,7 +336,7 @@ def get_load(jid):
|
|||
log.critical('Could not get load from jids table.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while getting load from jids: {0}'.format(str(e)))
|
||||
log.critical('Unexpected error while getting load from jids: %s', e)
|
||||
raise
|
||||
|
||||
return ret
|
||||
|
@ -361,7 +364,8 @@ def get_jid(jid):
|
|||
log.critical('Could not select job specific information.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while getting job specific information: {0}'.format(str(e)))
|
||||
log.critical(
|
||||
'Unexpected error while getting job specific information: %s', e)
|
||||
raise
|
||||
|
||||
return ret
|
||||
|
@ -389,7 +393,8 @@ def get_fun(fun):
|
|||
log.critical('Could not get the list of minions.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while getting list of minions: {0}'.format(str(e)))
|
||||
log.critical(
|
||||
'Unexpected error while getting list of minions: %s', e)
|
||||
raise
|
||||
|
||||
return ret
|
||||
|
@ -417,7 +422,8 @@ def get_jids():
|
|||
log.critical('Could not get a list of all job ids.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while getting list of all job ids: {0}'.format(str(e)))
|
||||
log.critical(
|
||||
'Unexpected error while getting list of all job ids: %s', e)
|
||||
raise
|
||||
|
||||
return ret
|
||||
|
@ -444,7 +450,8 @@ def get_minions():
|
|||
log.critical('Could not get the list of minions.')
|
||||
raise
|
||||
except Exception as e:
|
||||
log.critical('Unexpected error while getting list of minions: {0}'.format(str(e)))
|
||||
log.critical(
|
||||
'Unexpected error while getting list of minions: %s', e)
|
||||
raise
|
||||
|
||||
return ret
|
||||
|
|
|
@ -20,7 +20,7 @@ Required python modules: pycassa
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
|
@ -68,9 +68,9 @@ def returner(ret):
|
|||
'id': ret['id']}
|
||||
if isinstance(ret['return'], dict):
|
||||
for key, value in six.iteritems(ret['return']):
|
||||
columns['return.{0}'.format(key)] = str(value)
|
||||
columns['return.{0}'.format(key)] = six.text_type(value)
|
||||
else:
|
||||
columns['return'] = str(ret['return'])
|
||||
columns['return'] = six.text_type(ret['return'])
|
||||
|
||||
log.debug(columns)
|
||||
ccf.insert(ret['jid'], columns)
|
||||
|
|
|
@ -48,7 +48,7 @@ JID/MINION_ID
|
|||
return: return_data
|
||||
full_ret: full load of job return
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
@ -59,11 +59,14 @@ try:
|
|||
except ImportError:
|
||||
HAS_DEPS = False
|
||||
|
||||
# Import salt libs
|
||||
# Import Salt libs
|
||||
import salt.utils.jid
|
||||
import salt.utils.json
|
||||
import salt.utils.minions
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -168,7 +171,7 @@ def prep_jid(nocache=False, passed_jid=None):
|
|||
cb_ = _get_connection()
|
||||
|
||||
try:
|
||||
cb_.add(str(jid),
|
||||
cb_.add(six.text_type(jid),
|
||||
{'nocache': nocache},
|
||||
ttl=_get_ttl(),
|
||||
)
|
||||
|
@ -197,10 +200,8 @@ def returner(load):
|
|||
)
|
||||
except couchbase.exceptions.KeyExistsError:
|
||||
log.error(
|
||||
'An extra return was detected from minion {0}, please verify '
|
||||
'the minion, this could be a replay attack'.format(
|
||||
load['id']
|
||||
)
|
||||
'An extra return was detected from minion %s, please verify '
|
||||
'the minion, this could be a replay attack', load['id']
|
||||
)
|
||||
return False
|
||||
|
||||
|
@ -212,13 +213,13 @@ def save_load(jid, clear_load, minion=None):
|
|||
cb_ = _get_connection()
|
||||
|
||||
try:
|
||||
jid_doc = cb_.get(str(jid))
|
||||
jid_doc = cb_.get(six.text_type(jid))
|
||||
except couchbase.exceptions.NotFoundError:
|
||||
cb_.add(str(jid), {}, ttl=_get_ttl())
|
||||
jid_doc = cb_.get(str(jid))
|
||||
cb_.add(six.text_type(jid), {}, ttl=_get_ttl())
|
||||
jid_doc = cb_.get(six.text_type(jid))
|
||||
|
||||
jid_doc.value['load'] = clear_load
|
||||
cb_.replace(str(jid), jid_doc.value, cas=jid_doc.cas, ttl=_get_ttl())
|
||||
cb_.replace(six.text_type(jid), jid_doc.value, cas=jid_doc.cas, ttl=_get_ttl())
|
||||
|
||||
# if you have a tgt, save that for the UI etc
|
||||
if 'tgt' in clear_load and clear_load['tgt'] != '':
|
||||
|
@ -240,9 +241,9 @@ def save_minions(jid, minions, syndic_id=None): # pylint: disable=unused-argume
|
|||
cb_ = _get_connection()
|
||||
|
||||
try:
|
||||
jid_doc = cb_.get(str(jid))
|
||||
jid_doc = cb_.get(six.text_type(jid))
|
||||
except couchbase.exceptions.NotFoundError:
|
||||
log.warning('Could not write job cache file for jid: {0}'.format(jid))
|
||||
log.warning('Could not write job cache file for jid: %s', jid)
|
||||
return False
|
||||
|
||||
# save the minions to a cache so we can see in the UI
|
||||
|
@ -252,7 +253,7 @@ def save_minions(jid, minions, syndic_id=None): # pylint: disable=unused-argume
|
|||
)
|
||||
else:
|
||||
jid_doc.value['minions'] = minions
|
||||
cb_.replace(str(jid), jid_doc.value, cas=jid_doc.cas, ttl=_get_ttl())
|
||||
cb_.replace(six.text_type(jid), jid_doc.value, cas=jid_doc.cas, ttl=_get_ttl())
|
||||
|
||||
|
||||
def get_load(jid):
|
||||
|
@ -262,7 +263,7 @@ def get_load(jid):
|
|||
cb_ = _get_connection()
|
||||
|
||||
try:
|
||||
jid_doc = cb_.get(str(jid))
|
||||
jid_doc = cb_.get(six.text_type(jid))
|
||||
except couchbase.exceptions.NotFoundError:
|
||||
return {}
|
||||
|
||||
|
@ -285,7 +286,7 @@ def get_jid(jid):
|
|||
|
||||
ret = {}
|
||||
|
||||
for result in cb_.query(DESIGN_NAME, 'jid_returns', key=str(jid), include_docs=True):
|
||||
for result in cb_.query(DESIGN_NAME, 'jid_returns', key=six.text_type(jid), include_docs=True):
|
||||
ret[result.value] = result.doc.value
|
||||
|
||||
return ret
|
||||
|
|
|
@ -53,7 +53,7 @@ otherwise multi-minion targeting can lead to losing output:
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import time
|
||||
import json
|
||||
|
@ -155,11 +155,10 @@ def returner(ret):
|
|||
|
||||
# Confirm that the response back was simple 'ok': true.
|
||||
if 'ok' not in _response or _response['ok'] is not True:
|
||||
log.error('Unable to create database "{0}"'
|
||||
.format(options['db']))
|
||||
log.error('Unable to create database \'%s\'', options['db'])
|
||||
log.error('Nothing logged! Lost data.')
|
||||
return
|
||||
log.info('Created database "{0}"'.format(options['db']))
|
||||
log.info('Created database \'%s\'', options['db'])
|
||||
|
||||
# Call _generate_doc to get a dict object of the document we're going to
|
||||
# shove into the database.
|
||||
|
@ -173,7 +172,7 @@ def returner(ret):
|
|||
|
||||
# Sanity check regarding the response..
|
||||
if 'ok' not in _response or _response['ok'] is not True:
|
||||
log.error('Unable to create document: "{0}"'.format(_response))
|
||||
log.error('Unable to create document: \'%s\'', _response)
|
||||
log.error('Nothing logged! Lost data.')
|
||||
|
||||
|
||||
|
@ -184,7 +183,7 @@ def get_jid(jid):
|
|||
options = _get_options(ret=None)
|
||||
_response = _request("GET", options['url'] + options['db'] + '/' + jid)
|
||||
if 'error' in _response:
|
||||
log.error('Unable to get JID "{0}" : "{1}"'.format(jid, _response))
|
||||
log.error('Unable to get JID \'%s\' : \'%s\'', jid, _response)
|
||||
return {}
|
||||
return {_response['id']: _response}
|
||||
|
||||
|
@ -198,8 +197,10 @@ def get_jids():
|
|||
|
||||
# Make sure the 'total_rows' is returned.. if not error out.
|
||||
if 'total_rows' not in _response:
|
||||
log.error('Didn\'t get valid response from requesting all docs: {0}'
|
||||
.format(_response))
|
||||
log.error(
|
||||
'Didn\'t get valid response from requesting all docs: %s',
|
||||
_response
|
||||
)
|
||||
return {}
|
||||
|
||||
# Return the rows.
|
||||
|
@ -246,8 +247,10 @@ def get_fun(fun):
|
|||
fun))
|
||||
# Skip the minion if we got an error..
|
||||
if 'error' in _response:
|
||||
log.warning('Got an error when querying for last command by a '
|
||||
'minion: {0}'.format(_response['error']))
|
||||
log.warning(
|
||||
'Got an error when querying for last command by a minion: %s',
|
||||
_response['error']
|
||||
)
|
||||
continue
|
||||
|
||||
# Skip the minion if we didn't get any rows back. ( IE function that
|
||||
|
@ -279,7 +282,7 @@ def get_minions():
|
|||
|
||||
# Verify that we got a response back.
|
||||
if 'rows' not in _response:
|
||||
log.error('Unable to get available minions: {0}'.format(_response))
|
||||
log.error('Unable to get available minions: %s', _response)
|
||||
return []
|
||||
|
||||
# Iterate over the rows to build up a list return it.
|
||||
|
@ -354,8 +357,10 @@ def set_salt_view():
|
|||
options['url'] + options['db'] + "/_design/salt",
|
||||
"application/json", json.dumps(new_doc))
|
||||
if 'error' in _response:
|
||||
log.warning("Unable to set the salt design document: {0}"
|
||||
.format(_response['error']))
|
||||
log.warning(
|
||||
'Unable to set the salt design document: %s',
|
||||
_response['error']
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ An example Django module that registers a function called
|
|||
|
||||
'''
|
||||
# Import Python libraries
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import Salt libraries
|
||||
|
@ -61,8 +61,10 @@ def returner(ret):
|
|||
signaled = dispatch.Signal(providing_args=['ret']).send(sender='returner', ret=ret)
|
||||
|
||||
for signal in signaled:
|
||||
log.debug('Django returner function \'returner\' signaled {0} '
|
||||
'which responded with {1}'.format(signal[0], signal[1]))
|
||||
log.debug(
|
||||
'Django returner function \'returner\' signaled %s '
|
||||
'which responded with %s', signal[0], signal[1]
|
||||
)
|
||||
|
||||
|
||||
def save_load(jid, load, minions=None):
|
||||
|
@ -74,8 +76,10 @@ def save_load(jid, load, minions=None):
|
|||
sender='save_load', jid=jid, load=load)
|
||||
|
||||
for signal in signaled:
|
||||
log.debug('Django returner function \'save_load\' signaled {0} '
|
||||
'which responded with {1}'.format(signal[0], signal[1]))
|
||||
log.debug(
|
||||
'Django returner function \'save_load\' signaled %s '
|
||||
'which responded with %s', signal[0], signal[1]
|
||||
)
|
||||
|
||||
|
||||
def prep_jid(nocache=False, passed_jid=None):
|
||||
|
|
|
@ -95,7 +95,7 @@ Minion configuration:
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import datetime
|
||||
from datetime import tzinfo, timedelta
|
||||
import uuid
|
||||
|
@ -220,14 +220,17 @@ def returner(ret):
|
|||
|
||||
if job_fun in options['functions_blacklist']:
|
||||
log.info(
|
||||
'Won\'t push new data to Elasticsearch, job with jid={0} and '
|
||||
'function={1} which is in the user-defined list of ignored '
|
||||
'functions'.format(job_id, job_fun))
|
||||
'Won\'t push new data to Elasticsearch, job with jid=%s and '
|
||||
'function=%s which is in the user-defined list of ignored '
|
||||
'functions', job_id, job_fun
|
||||
)
|
||||
return
|
||||
|
||||
if ret.get('return', None) is None:
|
||||
log.info('Won\'t push new data to Elasticsearch, job with jid={0} was '
|
||||
'not succesful'.format(job_id))
|
||||
log.info(
|
||||
'Won\'t push new data to Elasticsearch, job with jid=%s was '
|
||||
'not succesful', job_id
|
||||
)
|
||||
return
|
||||
|
||||
# Build the index name
|
||||
|
@ -258,7 +261,7 @@ def returner(ret):
|
|||
# index data format
|
||||
if options['states_order_output'] and isinstance(ret['return'], dict):
|
||||
index = '{0}-ordered'.format(index)
|
||||
max_chars = len(str(len(ret['return'])))
|
||||
max_chars = len(six.text_type(len(ret['return'])))
|
||||
|
||||
for uid, data in six.iteritems(ret['return']):
|
||||
# Skip keys we've already prefixed
|
||||
|
@ -274,7 +277,7 @@ def returner(ret):
|
|||
|
||||
# Prefix the key with the run order so it can be sorted
|
||||
new_uid = '{0}_|-{1}'.format(
|
||||
str(data['__run_num__']).zfill(max_chars),
|
||||
six.text_type(data['__run_num__']).zfill(max_chars),
|
||||
uid,
|
||||
)
|
||||
|
||||
|
@ -321,7 +324,7 @@ def returner(ret):
|
|||
}
|
||||
|
||||
if options['debug_returner_payload']:
|
||||
log.debug('Payload: {0}'.format(data))
|
||||
log.debug('elasicsearch payload: %s', data)
|
||||
|
||||
# Post the payload
|
||||
ret = __salt__['elasticsearch.document_create'](index=index,
|
||||
|
|
|
@ -64,20 +64,22 @@ create the profiles as specified above. Then add:
|
|||
etcd.returner_read_profile: my_etcd_read
|
||||
etcd.returner_write_profile: my_etcd_write
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.jid
|
||||
try:
|
||||
import salt.utils.etcd_util
|
||||
HAS_LIBS = True
|
||||
except ImportError:
|
||||
HAS_LIBS = False
|
||||
|
||||
import salt.utils.jid
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -185,7 +187,7 @@ def get_fun():
|
|||
client, path = _get_conn(__opts__)
|
||||
items = client.get('/'.join((path, 'minions')))
|
||||
for item in items.children:
|
||||
comps = str(item.key).split('/')
|
||||
comps = six.text_type(item.key).split('/')
|
||||
ret[comps[-1]] = item.value
|
||||
return ret
|
||||
|
||||
|
@ -199,7 +201,7 @@ def get_jids():
|
|||
items = client.get('/'.join((path, 'jobs')))
|
||||
for item in items.children:
|
||||
if item.dir is True:
|
||||
jid = str(item.key).split('/')[-1]
|
||||
jid = six.text_type(item.key).split('/')[-1]
|
||||
load = client.get('/'.join((item.key, '.load.p'))).value
|
||||
ret[jid] = salt.utils.jid.format_jid_instance(jid, json.loads(load))
|
||||
return ret
|
||||
|
@ -213,7 +215,7 @@ def get_minions():
|
|||
client, path = _get_conn(__opts__)
|
||||
items = client.get('/'.join((path, 'minions')))
|
||||
for item in items.children:
|
||||
comps = str(item.key).split('/')
|
||||
comps = six.text_type(item.key).split('/')
|
||||
ret.append(comps[-1])
|
||||
return ret
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ values at the time of pillar generation, these will contain minion values at
|
|||
the time of execution.
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
import json
|
||||
|
@ -88,8 +88,10 @@ from email.mime.text import MIMEText
|
|||
import yaml
|
||||
from salt.ext.six.moves import range
|
||||
from salt.ext.six.moves import StringIO
|
||||
from salt.ext import six
|
||||
|
||||
import salt.utils.files
|
||||
import salt.utils.stringutils
|
||||
import salt.returners
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -167,12 +169,12 @@ def _generate_html_table(data, out, level=0, extra_style=''):
|
|||
Generate a single table of data
|
||||
'''
|
||||
print('<table style="{0}">'.format(
|
||||
_lookup_style('table', ['table' + str(level)])), file=out)
|
||||
_lookup_style('table', ['table' + six.text_type(level)])), file=out)
|
||||
|
||||
firstone = True
|
||||
|
||||
row_style = 'row' + str(level)
|
||||
cell_style = 'cell' + str(level)
|
||||
row_style = 'row' + six.text_type(level)
|
||||
cell_style = 'cell' + six.text_type(level)
|
||||
|
||||
for subdata in data:
|
||||
first_style = 'first_first' if firstone else 'notfirst_first'
|
||||
|
@ -227,7 +229,7 @@ def _generate_html_table(data, out, level=0, extra_style=''):
|
|||
new_extra_style
|
||||
]
|
||||
),
|
||||
cgi.escape(str(value))
|
||||
cgi.escape(six.text_type(value))
|
||||
), file=out)
|
||||
print('</tr>', file=out)
|
||||
elif isinstance(subdata, list):
|
||||
|
@ -252,7 +254,7 @@ def _generate_html_table(data, out, level=0, extra_style=''):
|
|||
'td',
|
||||
[cell_style, first_style, 'value', extra_style]
|
||||
),
|
||||
cgi.escape(str(subdata))
|
||||
cgi.escape(six.text_type(subdata))
|
||||
), file=out)
|
||||
print('</tr>', file=out)
|
||||
firstone = False
|
||||
|
@ -356,10 +358,10 @@ def _generate_report(ret, setup):
|
|||
|
||||
unchanged = total - failed - changed
|
||||
|
||||
log.debug('highstate total: {0}'.format(total))
|
||||
log.debug('highstate failed: {0}'.format(failed))
|
||||
log.debug('highstate unchanged: {0}'.format(unchanged))
|
||||
log.debug('highstate changed: {0}'.format(changed))
|
||||
log.debug('highstate total: %s', total)
|
||||
log.debug('highstate failed: %s', failed)
|
||||
log.debug('highstate unchanged: %s', unchanged)
|
||||
log.debug('highstate changed: %s', changed)
|
||||
|
||||
# generate report if required
|
||||
if setup.get('report_everything', False) or \
|
||||
|
@ -409,7 +411,7 @@ def _sprinkle(config_str):
|
|||
'''
|
||||
parts = [x for sub in config_str.split('{') for x in sub.split('}')]
|
||||
for i in range(1, len(parts), 2):
|
||||
parts[i] = str(__grains__.get(parts[i], ''))
|
||||
parts[i] = six.text_type(__grains__.get(parts[i], ''))
|
||||
return ''.join(parts)
|
||||
|
||||
|
||||
|
@ -419,7 +421,7 @@ def _produce_output(report, failed, setup):
|
|||
'''
|
||||
report_format = setup.get('report_format', 'yaml')
|
||||
|
||||
log.debug('highstate output format: {0}'.format(report_format))
|
||||
log.debug('highstate output format: %s', report_format)
|
||||
|
||||
if report_format == 'json':
|
||||
report_text = json.dumps(report)
|
||||
|
@ -436,12 +438,12 @@ def _produce_output(report, failed, setup):
|
|||
|
||||
report_delivery = setup.get('report_delivery', 'file')
|
||||
|
||||
log.debug('highstate report_delivery: {0}'.format(report_delivery))
|
||||
log.debug('highstate report_delivery: %s', report_delivery)
|
||||
|
||||
if report_delivery == 'file':
|
||||
output_file = _sprinkle(setup.get('file_output', '/tmp/test.rpt'))
|
||||
with salt.utils.files.fopen(output_file, 'w') as out:
|
||||
out.write(report_text)
|
||||
out.write(salt.utils.stringutils.to_str(report_text))
|
||||
else:
|
||||
msg = MIMEText(report_text, report_format)
|
||||
|
||||
|
@ -473,7 +475,7 @@ def returner(ret):
|
|||
'''
|
||||
setup = _get_options(ret)
|
||||
|
||||
log.debug('highstate setup {0}'.format(setup))
|
||||
log.debug('highstate setup %s', setup)
|
||||
|
||||
report, failed = _generate_report(ret, setup)
|
||||
if report:
|
||||
|
@ -491,7 +493,7 @@ def __test_html():
|
|||
file_output: '/srv/salt/_returners/test.rpt'
|
||||
'''
|
||||
with salt.utils.files.fopen('test.rpt', 'r') as input_file:
|
||||
data_text = input_file.read()
|
||||
data_text = salt.utils.stringutils.to_unicode(input_file.read())
|
||||
data = yaml.safe_load(data_text)
|
||||
|
||||
string_file = StringIO()
|
||||
|
@ -500,7 +502,7 @@ def __test_html():
|
|||
result = string_file.read()
|
||||
|
||||
with salt.utils.files.fopen('test.html', 'w') as output:
|
||||
output.write(result)
|
||||
output.write(salt.utils.stringutils.to_str(result))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -93,7 +93,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return hipchat --return_kwargs '{"room_id": "another-room"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import json
|
||||
|
@ -101,6 +101,7 @@ import pprint
|
|||
import logging
|
||||
|
||||
# pylint: disable=import-error,no-name-in-module
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin
|
||||
from salt.ext.six.moves.urllib.parse import urlencode as _urlencode
|
||||
import salt.ext.six.moves.http_client
|
||||
|
@ -183,7 +184,7 @@ def _query(function,
|
|||
query_params = {}
|
||||
|
||||
if room_id:
|
||||
room_id = 'room/{0}/notification'.format(str(room_id))
|
||||
room_id = 'room/{0}/notification'.format(six.text_type(room_id))
|
||||
else:
|
||||
room_id = 'room/0/notification'
|
||||
|
||||
|
@ -388,7 +389,7 @@ def event_return(events):
|
|||
# TODO:
|
||||
# Pre-process messages to apply individualized colors for various
|
||||
# event types.
|
||||
log.trace('Hipchat returner received event: {0}'.format(event))
|
||||
log.trace('Hipchat returner received event: %s', event)
|
||||
_send_message(_options.get('room_id'), # room_id
|
||||
event['data'], # message
|
||||
_options.get('from_name'), # from_name
|
||||
|
|
|
@ -50,7 +50,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return influxdb --return_kwargs '{"db": "another-salt"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
|
@ -113,7 +113,10 @@ def _get_version(host, port, user, password):
|
|||
if influxDBVersionHeader in result.headers:
|
||||
version = result.headers[influxDBVersionHeader]
|
||||
except Exception as ex:
|
||||
log.critical('Failed to query InfluxDB version from HTTP API within InfluxDB returner: {0}'.format(ex))
|
||||
log.critical(
|
||||
'Failed to query InfluxDB version from HTTP API within InfluxDB '
|
||||
'returner: %s', ex
|
||||
)
|
||||
return version
|
||||
|
||||
|
||||
|
@ -187,7 +190,7 @@ def returner(ret):
|
|||
try:
|
||||
serv.write_points(req)
|
||||
except Exception as ex:
|
||||
log.critical('Failed to store return with InfluxDB returner: {0}'.format(ex))
|
||||
log.critical('Failed to store return with InfluxDB returner: %s', ex)
|
||||
|
||||
|
||||
def save_load(jid, load, minions=None):
|
||||
|
@ -224,7 +227,7 @@ def save_load(jid, load, minions=None):
|
|||
try:
|
||||
serv.write_points(req)
|
||||
except Exception as ex:
|
||||
log.critical('Failed to store load with InfluxDB returner: {0}'.format(ex))
|
||||
log.critical('Failed to store load with InfluxDB returner: %s', ex)
|
||||
|
||||
|
||||
def save_minions(jid, minions, syndic_id=None): # pylint: disable=unused-argument
|
||||
|
@ -241,9 +244,9 @@ def get_load(jid):
|
|||
serv = _get_serv(ret=None)
|
||||
sql = "select load from jids where jid = '{0}'".format(jid)
|
||||
|
||||
log.debug(">> Now in get_load {0}".format(jid))
|
||||
log.debug(">> Now in get_load %s", jid)
|
||||
data = serv.query(sql)
|
||||
log.debug(">> Now Data: {0}".format(data))
|
||||
log.debug(">> Now Data: %s", data)
|
||||
if data:
|
||||
return data
|
||||
return {}
|
||||
|
|
|
@ -25,7 +25,7 @@ To use the kafka returner, append '--return kafka' to the Salt command, eg;
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import json
|
||||
import logging
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ by adding more tags to the submission.
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import Salt libs
|
||||
|
@ -75,7 +75,7 @@ def _get_options(ret=None):
|
|||
|
||||
_options['api_url'] = _options.get('api_url', 'metrics-api.librato.com')
|
||||
|
||||
log.debug("Retrieved Librato options: {0}".format(_options))
|
||||
log.debug('Retrieved Librato options: %s', _options)
|
||||
return _options
|
||||
|
||||
|
||||
|
@ -112,7 +112,7 @@ def _calculate_runtimes(states):
|
|||
# Count durations
|
||||
results['runtime'] += resultset['duration']
|
||||
|
||||
log.debug("Parsed state metrics: {0}".format(results))
|
||||
log.debug('Parsed state metrics: %s', results)
|
||||
return results
|
||||
|
||||
|
||||
|
@ -125,31 +125,37 @@ def returner(ret):
|
|||
q = librato_conn.new_queue()
|
||||
|
||||
if ret['fun'] == 'state.highstate':
|
||||
log.debug("Found returned Highstate data.")
|
||||
log.debug('Found returned Highstate data.')
|
||||
# Calculate the runtimes and number of failed states.
|
||||
stats = _calculate_runtimes(ret['return'])
|
||||
log.debug("Batching Metric retcode with {0}".format(ret['retcode']))
|
||||
q.add("saltstack.highstate.retcode", ret[
|
||||
'retcode'], tags={'Name': ret['id']})
|
||||
log.debug('Batching Metric retcode with %s', ret['retcode'])
|
||||
q.add('saltstack.highstate.retcode',
|
||||
ret['retcode'], tags={'Name': ret['id']})
|
||||
|
||||
log.debug("Batching Metric num_failed_jobs with {0}".format(
|
||||
stats['num_failed_states']))
|
||||
q.add("saltstack.highstate.failed_states",
|
||||
log.debug(
|
||||
'Batching Metric num_failed_jobs with %s',
|
||||
stats['num_failed_states']
|
||||
)
|
||||
q.add('saltstack.highstate.failed_states',
|
||||
stats['num_failed_states'], tags={'Name': ret['id']})
|
||||
|
||||
log.debug("Batching Metric num_passed_states with {0}".format(
|
||||
stats['num_passed_states']))
|
||||
q.add("saltstack.highstate.passed_states",
|
||||
log.debug(
|
||||
'Batching Metric num_passed_states with %s',
|
||||
stats['num_passed_states']
|
||||
)
|
||||
q.add('saltstack.highstate.passed_states',
|
||||
stats['num_passed_states'], tags={'Name': ret['id']})
|
||||
|
||||
log.debug("Batching Metric runtime with {0}".format(stats['runtime']))
|
||||
q.add("saltstack.highstate.runtime",
|
||||
log.debug('Batching Metric runtime with %s', stats['runtime'])
|
||||
q.add('saltstack.highstate.runtime',
|
||||
stats['runtime'], tags={'Name': ret['id']})
|
||||
|
||||
log.debug("Batching Metric runtime with {0}".format(
|
||||
stats['num_failed_states'] + stats['num_passed_states']))
|
||||
q.add("saltstack.highstate.total_states", stats[
|
||||
log.debug(
|
||||
'Batching Metric runtime with %s',
|
||||
stats['num_failed_states'] + stats['num_passed_states']
|
||||
)
|
||||
q.add('saltstack.highstate.total_states', stats[
|
||||
'num_failed_states'] + stats['num_passed_states'], tags={'Name': ret['id']})
|
||||
|
||||
log.info("Sending metrics to Librato.")
|
||||
log.info('Sending metrics to Librato.')
|
||||
q.submit()
|
||||
|
|
|
@ -11,7 +11,7 @@ To use the local returner, append '--return local' to the salt command. ex:
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
|
||||
def returner(ret):
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Return data to local job cache
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import errno
|
||||
|
@ -20,6 +20,7 @@ import salt.utils.atomicfile
|
|||
import salt.utils.files
|
||||
import salt.utils.jid
|
||||
import salt.utils.minions
|
||||
import salt.utils.stringutils
|
||||
import salt.exceptions
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -108,15 +109,13 @@ def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
|
|||
|
||||
try:
|
||||
with salt.utils.files.fopen(os.path.join(jid_dir, 'jid'), 'wb+') as fn_:
|
||||
if six.PY2:
|
||||
fn_.write(jid)
|
||||
else:
|
||||
fn_.write(bytes(jid, 'utf-8'))
|
||||
fn_.write(salt.utils.stringutils.to_bytes(jid))
|
||||
if nocache:
|
||||
with salt.utils.files.fopen(os.path.join(jid_dir, 'nocache'), 'wb+') as fn_:
|
||||
fn_.write(b'')
|
||||
with salt.utils.files.fopen(os.path.join(jid_dir, 'nocache'), 'wb+'):
|
||||
pass
|
||||
except IOError:
|
||||
log.warning('Could not write out jid file for job {0}. Retrying.'.format(jid))
|
||||
log.warning(
|
||||
'Could not write out jid file for job %s. Retrying.', jid)
|
||||
time.sleep(0.1)
|
||||
return prep_jid(passed_jid=jid, nocache=nocache,
|
||||
recurse_count=recurse_count+1)
|
||||
|
@ -146,16 +145,14 @@ def returner(load):
|
|||
if err.errno == errno.EEXIST:
|
||||
# Minion has already returned this jid and it should be dropped
|
||||
log.error(
|
||||
'An extra return was detected from minion {0}, please verify '
|
||||
'the minion, this could be a replay attack'.format(
|
||||
load['id']
|
||||
)
|
||||
'An extra return was detected from minion %s, please verify '
|
||||
'the minion, this could be a replay attack', load['id']
|
||||
)
|
||||
return False
|
||||
elif err.errno == errno.ENOENT:
|
||||
log.error(
|
||||
'An inconsistency occurred, a job was received with a job id '
|
||||
'that is not present in the local cache: {jid}'.format(**load)
|
||||
'(%s) that is not present in the local cache', load['jid']
|
||||
)
|
||||
return False
|
||||
raise
|
||||
|
@ -280,8 +277,8 @@ def save_minions(jid, minions, syndic_id=None):
|
|||
serial.dump(minions, wfh)
|
||||
except IOError as exc:
|
||||
log.error(
|
||||
'Failed to write minion list {0} to job cache file {1}: {2}'
|
||||
.format(minions, minions_path, exc)
|
||||
'Failed to write minion list %s to job cache file %s: %s',
|
||||
minions, minions_path, exc
|
||||
)
|
||||
|
||||
|
||||
|
@ -351,7 +348,7 @@ def get_jid(jid):
|
|||
with salt.utils.files.fopen(outp, 'rb') as rfh:
|
||||
ret[fn_]['out'] = serial.load(rfh)
|
||||
except Exception as exc:
|
||||
if 'Permission denied:' in str(exc):
|
||||
if 'Permission denied:' in six.text_type(exc):
|
||||
raise
|
||||
return ret
|
||||
|
||||
|
@ -459,9 +456,9 @@ def update_endtime(jid, time):
|
|||
if not os.path.exists(jid_dir):
|
||||
os.makedirs(jid_dir)
|
||||
with salt.utils.files.fopen(os.path.join(jid_dir, ENDTIME), 'w') as etfile:
|
||||
etfile.write(time)
|
||||
etfile.write(salt.utils.stringutils.to_str(time))
|
||||
except IOError as exc:
|
||||
log.warning('Could not write job invocation cache file: {0}'.format(exc))
|
||||
log.warning('Could not write job invocation cache file: %s', exc)
|
||||
|
||||
|
||||
def get_endtime(jid):
|
||||
|
@ -475,7 +472,7 @@ def get_endtime(jid):
|
|||
if not os.path.exists(etpath):
|
||||
return False
|
||||
with salt.utils.files.fopen(etpath, 'r') as etfile:
|
||||
endtime = etfile.read().strip('\n')
|
||||
endtime = salt.utils.stringutils.to_unicode(etfile.read()).strip('\n')
|
||||
return endtime
|
||||
|
||||
|
||||
|
@ -504,7 +501,7 @@ def save_reg(data):
|
|||
with salt.utils.files.fopen(regfile, 'a') as fh_:
|
||||
msgpack.dump(data, fh_)
|
||||
except:
|
||||
log.error('Could not write to msgpack file {0}'.format(__opts__['outdir']))
|
||||
log.error('Could not write to msgpack file %s', __opts__['outdir'])
|
||||
raise
|
||||
|
||||
|
||||
|
@ -518,5 +515,5 @@ def load_reg():
|
|||
with salt.utils.files.fopen(regfile, 'r') as fh_:
|
||||
return msgpack.load(fh_)
|
||||
except:
|
||||
log.error('Could not write to msgpack file {0}'.format(__opts__['outdir']))
|
||||
log.error('Could not write to msgpack file %s', __opts__['outdir'])
|
||||
raise
|
||||
|
|
|
@ -43,7 +43,7 @@ To override individual configuration items, append --return_kwargs '{'key:': 'va
|
|||
|
||||
salt '*' test.ping --return mattermost --return_kwargs '{'channel': '#random'}'
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import logging
|
||||
|
@ -89,7 +89,7 @@ def _get_options(ret=None):
|
|||
attrs,
|
||||
__salt__=__salt__,
|
||||
__opts__=__opts__)
|
||||
log.debug('Options: {0}'.format(_options))
|
||||
log.debug('Options: %s', _options)
|
||||
return _options
|
||||
|
||||
|
||||
|
@ -146,8 +146,8 @@ def event_return(events):
|
|||
|
||||
is_ok = True
|
||||
for event in events:
|
||||
log.debug('Event: {0}'.format(str(event)))
|
||||
log.debug('Event data: {0}'.format(str(event['data'])))
|
||||
log.debug('Event: %s', event)
|
||||
log.debug('Event data: %s', event['data'])
|
||||
message = 'tag: {0}\r\n'.format(event['tag'])
|
||||
for key, value in six.iteritems(event['data']):
|
||||
message += '{0}: {1}\r\n'.format(key, value)
|
||||
|
@ -183,10 +183,10 @@ def post_message(channel,
|
|||
if username:
|
||||
parameters['username'] = username
|
||||
parameters['text'] = '```' + message + '```' # pre-formatted, fixed-width text
|
||||
log.debug('Parameters: {0}'.format(parameters))
|
||||
log.debug('Parameters: %s', parameters)
|
||||
result = salt.utils.mattermost.query(api_url=api_url,
|
||||
hook=hook,
|
||||
data='payload={0}'.format(json.dumps(parameters)))
|
||||
|
||||
log.debug('result {0}'.format(result))
|
||||
log.debug('result %s', result)
|
||||
return bool(result)
|
||||
|
|
|
@ -45,7 +45,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return memcache --return_kwargs '{"host": "hostname.domain.com"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
|
@ -99,7 +99,7 @@ def _get_serv(ret):
|
|||
host = _options.get('host')
|
||||
port = _options.get('port')
|
||||
|
||||
log.debug('memcache server: {0}:{1}'.format(host, port))
|
||||
log.debug('memcache server: %s:%s', host, port)
|
||||
if not host or not port:
|
||||
log.error('Host or port not defined in salt config')
|
||||
return
|
||||
|
|
|
@ -63,7 +63,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return mongo --return_kwargs '{"db": "another-salt"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
@ -226,7 +226,7 @@ def _safe_copy(dat):
|
|||
for k in dat:
|
||||
r = k.replace('%', '%25').replace('\\', '%5c').replace('$', '%24').replace('.', '%2e')
|
||||
if r != k:
|
||||
log.debug('converting dict key from {0} to {1} for mongodb'.format(k, r))
|
||||
log.debug('converting dict key from %s to %s for mongodb', k, r)
|
||||
ret[r] = _safe_copy(dat[k])
|
||||
return ret
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return mongo --return_kwargs '{"db": "another-salt"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -5,7 +5,7 @@ Read/Write multiple returners
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
|
|
|
@ -138,7 +138,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return mysql --return_kwargs '{"db": "another-salt"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# Let's not allow PyLint complain about string substitution
|
||||
# pylint: disable=W1321,E1321
|
||||
|
||||
|
@ -229,7 +229,7 @@ def _get_serv(ret=None, commit=False):
|
|||
conn.ping()
|
||||
connect = False
|
||||
except MySQLdb.connections.OperationalError as exc:
|
||||
log.debug('OperationalError on ping: {0}'.format(exc))
|
||||
log.debug('OperationalError on ping: %s', exc)
|
||||
|
||||
if connect:
|
||||
log.debug('Generating new MySQL connection pool')
|
||||
|
@ -263,7 +263,7 @@ def _get_serv(ret=None, commit=False):
|
|||
yield cursor
|
||||
except MySQLdb.DatabaseError as err:
|
||||
error = err.args
|
||||
sys.stderr.write(str(error))
|
||||
sys.stderr.write(six.text_type(error))
|
||||
cursor.execute("ROLLBACK")
|
||||
raise err
|
||||
else:
|
||||
|
@ -476,8 +476,8 @@ def _purge_jobs(timestamp):
|
|||
cur.execute('COMMIT')
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to delete contents of table \'jids\'')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.Salt(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
||||
try:
|
||||
sql = 'delete from `salt_returns` where alter_time < %s'
|
||||
|
@ -485,8 +485,8 @@ def _purge_jobs(timestamp):
|
|||
cur.execute('COMMIT')
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to delete contents of table \'salt_returns\'')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.Salt(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
||||
try:
|
||||
sql = 'delete from `salt_events` where alter_time < %s'
|
||||
|
@ -494,8 +494,8 @@ def _purge_jobs(timestamp):
|
|||
cur.execute('COMMIT')
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to delete contents of table \'salt_events\'')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.Salt(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
||||
return True
|
||||
|
||||
|
@ -521,8 +521,8 @@ def _archive_jobs(timestamp):
|
|||
target_tables[table_name] = tmp_table_name
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to create the archive tables.')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.SaltRunnerError(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
||||
try:
|
||||
sql = 'insert into `{0}` select * from `{1}` where jid in (select distinct jid from salt_returns where alter_time < %s)'.format(target_tables['jids'], 'jids')
|
||||
|
@ -530,8 +530,8 @@ def _archive_jobs(timestamp):
|
|||
cur.execute('COMMIT')
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to copy contents of table \'jids\'')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.SaltRunnerError(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
except Exception as e:
|
||||
log.error(e)
|
||||
raise
|
||||
|
@ -542,8 +542,8 @@ def _archive_jobs(timestamp):
|
|||
cur.execute('COMMIT')
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to copy contents of table \'salt_returns\'')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.SaltRunnerError(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
||||
try:
|
||||
sql = 'insert into `{0}` select * from `{1}` where alter_time < %s'.format(target_tables['salt_events'], 'salt_events')
|
||||
|
@ -551,8 +551,8 @@ def _archive_jobs(timestamp):
|
|||
cur.execute('COMMIT')
|
||||
except MySQLdb.Error as e:
|
||||
log.error('mysql returner archiver was unable to copy contents of table \'salt_events\'')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.SaltRunnerError(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
||||
return _purge_jobs(timestamp)
|
||||
|
||||
|
@ -577,5 +577,5 @@ def clean_old_jobs():
|
|||
_purge_jobs(stamp)
|
||||
except MySQLdb.Error as e:
|
||||
log.error('Mysql returner was unable to get timestamp for purge/archive of jobs')
|
||||
log.error(str(e))
|
||||
raise salt.exceptions.Salt(str(e))
|
||||
log.error(six.text_type(e))
|
||||
raise salt.exceptions.SaltRunnerError(six.text_type(e))
|
||||
|
|
|
@ -48,7 +48,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return nagios --return_kwargs '{"service": "service-name"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import cgi
|
||||
|
@ -56,6 +56,7 @@ import logging
|
|||
|
||||
import salt.returners
|
||||
# pylint: disable=import-error,no-name-in-module,redefined-builtin
|
||||
from salt.ext import six
|
||||
import salt.ext.six.moves.http_client
|
||||
# pylint: enable=import-error,no-name-in-module,redefined-builtin
|
||||
|
||||
|
@ -64,6 +65,13 @@ log = logging.getLogger(__name__)
|
|||
__virtualname__ = 'nagios_nrdp'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Return virtualname
|
||||
'''
|
||||
return 'nagios.list_plugins' in __salt__
|
||||
|
||||
|
||||
def _get_options(ret=None):
|
||||
'''
|
||||
Get the requests options from salt.
|
||||
|
@ -80,7 +88,7 @@ def _get_options(ret=None):
|
|||
__salt__=__salt__,
|
||||
__opts__=__opts__)
|
||||
|
||||
log.debug('attrs {0}'.format(attrs))
|
||||
log.debug('attrs %s', attrs)
|
||||
if 'checktype' not in _options or _options['checktype'] == '':
|
||||
# default to passive check type
|
||||
_options['checktype'] = '1'
|
||||
|
@ -92,7 +100,7 @@ def _get_options(ret=None):
|
|||
_options['checktype'] = '1'
|
||||
|
||||
# checktype should be a string
|
||||
_options['checktype'] = str(_options['checktype'])
|
||||
_options['checktype'] = six.text_type(_options['checktype'])
|
||||
|
||||
return _options
|
||||
|
||||
|
@ -111,11 +119,11 @@ def _prepare_xml(options=None, state=None):
|
|||
|
||||
# No service defined then we set the status of the hostname
|
||||
if 'service' in options and options['service'] != '':
|
||||
xml += "<checkresult type='service' checktype='"+str(options['checktype'])+"'>"
|
||||
xml += "<checkresult type='service' checktype='" + six.text_type(options['checktype'])+"'>"
|
||||
xml += "<hostname>"+cgi.escape(options['hostname'], True)+"</hostname>"
|
||||
xml += "<servicename>"+cgi.escape(options['service'], True)+"</servicename>"
|
||||
else:
|
||||
xml += "<checkresult type='host' checktype='"+str(options['checktype'])+"'>"
|
||||
xml += "<checkresult type='host' checktype='" + six.text_type(options['checktype'])+"'>"
|
||||
xml += "<hostname>"+cgi.escape(options['hostname'], True)+"</hostname>"
|
||||
|
||||
xml += "<state>"+_state+"</state>"
|
||||
|
@ -169,24 +177,20 @@ def _post_data(options=None, xml=None):
|
|||
log.error('No content returned from Nagios NRDP.')
|
||||
return False
|
||||
else:
|
||||
log.error('Error returned from Nagios NRDP. Status code: {0}.'.format(res.status_code))
|
||||
log.error(
|
||||
'Error returned from Nagios NRDP. Status code: %s.',
|
||||
res.status_code
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Return virtualname
|
||||
'''
|
||||
return 'nagios.list_plugins' in __salt__
|
||||
|
||||
|
||||
def returner(ret):
|
||||
'''
|
||||
Send a message to Nagios with the data
|
||||
'''
|
||||
|
||||
_options = _get_options(ret)
|
||||
log.debug('_options {0}'.format(_options))
|
||||
log.debug('_options %s', _options)
|
||||
_options['hostname'] = ret.get('id')
|
||||
|
||||
if 'url' not in _options or _options['url'] == '':
|
||||
|
|
|
@ -123,7 +123,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return odbc --return_kwargs '{"dsn": "dsn-name"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# Let's not allow PyLint complain about string substitution
|
||||
# pylint: disable=W1321,E1321
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return pgjsonb --return_kwargs '{"db": "another-salt"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# Let's not allow PyLint complain about string substitution
|
||||
# pylint: disable=W1321,E1321
|
||||
|
||||
|
@ -247,7 +247,7 @@ def _get_serv(ret=None, commit=False):
|
|||
yield cursor
|
||||
except psycopg2.DatabaseError as err:
|
||||
error = err.args
|
||||
sys.stderr.write(str(error))
|
||||
sys.stderr.write(six.text_type(error))
|
||||
cursor.execute("ROLLBACK")
|
||||
raise err
|
||||
else:
|
||||
|
|
|
@ -126,7 +126,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return postgres --return_kwargs '{"db": "another-salt"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# Let's not allow PyLint complain about string substitution
|
||||
# pylint: disable=W1321,E1321
|
||||
|
||||
|
@ -142,6 +142,7 @@ import salt.returners
|
|||
import salt.exceptions
|
||||
|
||||
# Import third party libs
|
||||
from salt.ext import six
|
||||
try:
|
||||
import psycopg2
|
||||
HAS_POSTGRES = True
|
||||
|
@ -209,7 +210,7 @@ def _get_serv(ret=None, commit=False):
|
|||
yield cursor
|
||||
except psycopg2.DatabaseError as err:
|
||||
error = err.args
|
||||
sys.stderr.write(str(error))
|
||||
sys.stderr.write(six.text_type(error))
|
||||
cursor.execute("ROLLBACK")
|
||||
raise err
|
||||
else:
|
||||
|
|
|
@ -108,7 +108,7 @@ Required python modules: psycopg2
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
|
@ -148,7 +148,7 @@ def _get_conn():
|
|||
database=__opts__['master_job_cache.postgres.db'],
|
||||
port=__opts__['master_job_cache.postgres.port'])
|
||||
except psycopg2.OperationalError:
|
||||
log.error("Could not connect to SQL server: " + str(sys.exc_info()[0]))
|
||||
log.error('Could not connect to SQL server: %s', sys.exc_info()[0])
|
||||
return None
|
||||
return conn
|
||||
|
||||
|
@ -232,7 +232,7 @@ def returner(load):
|
|||
sql = '''INSERT INTO salt_returns
|
||||
(fun, jid, return, id, success)
|
||||
VALUES (%s, %s, %s, %s, %s)'''
|
||||
job_ret = {'return': six.text_type(str(load['return']), 'utf-8', 'replace')}
|
||||
job_ret = {'return': six.text_type(six.text_type(load['return']), 'utf-8', 'replace')}
|
||||
if 'retcode' in load:
|
||||
job_ret['retcode'] = load['retcode']
|
||||
if 'success' in load:
|
||||
|
@ -288,14 +288,14 @@ def save_load(jid, clear_load, minions=None):
|
|||
sql, (
|
||||
jid,
|
||||
salt.utils.jid.jid_to_time(jid),
|
||||
str(clear_load.get("tgt_type")),
|
||||
str(clear_load.get("cmd")),
|
||||
str(clear_load.get("tgt")),
|
||||
str(clear_load.get("kwargs")),
|
||||
str(clear_load.get("ret")),
|
||||
str(clear_load.get("user")),
|
||||
str(json.dumps(clear_load.get("arg"))),
|
||||
str(clear_load.get("fun")),
|
||||
six.text_type(clear_load.get("tgt_type")),
|
||||
six.text_type(clear_load.get("cmd")),
|
||||
six.text_type(clear_load.get("tgt")),
|
||||
six.text_type(clear_load.get("kwargs")),
|
||||
six.text_type(clear_load.get("ret")),
|
||||
six.text_type(clear_load.get("user")),
|
||||
six.text_type(json.dumps(clear_load.get("arg"))),
|
||||
six.text_type(clear_load.get("fun")),
|
||||
)
|
||||
)
|
||||
# TODO: Add Metadata support when it is merged from develop
|
||||
|
@ -313,7 +313,7 @@ def _escape_jid(jid):
|
|||
'''
|
||||
Do proper formatting of the jid
|
||||
'''
|
||||
jid = str(jid)
|
||||
jid = six.text_type(jid)
|
||||
jid = re.sub(r"'*", "", jid)
|
||||
return jid
|
||||
|
||||
|
@ -393,7 +393,7 @@ def get_jids():
|
|||
'''FROM jids'''
|
||||
if __opts__['keep_jobs'] != 0:
|
||||
sql = sql + " WHERE started > NOW() - INTERVAL '" \
|
||||
+ str(__opts__['keep_jobs']) + "' HOUR"
|
||||
+ six.text_type(__opts__['keep_jobs']) + "' HOUR"
|
||||
|
||||
cur.execute(sql)
|
||||
ret = {}
|
||||
|
|
|
@ -75,7 +75,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return pushover --return_kwargs '{"title": "Salt is awesome!"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import pprint
|
||||
|
@ -245,7 +245,7 @@ def returner(ret):
|
|||
sound=sound,
|
||||
token=token)
|
||||
|
||||
log.debug('result {0}'.format(result))
|
||||
log.debug('pushover result %s', result)
|
||||
if not result['res']:
|
||||
log.info('Error: {0}'.format(result['message']))
|
||||
log.info('Error: %s', result['message'])
|
||||
return
|
||||
|
|
|
@ -18,7 +18,7 @@ to restrict the events that are written.
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, with_statement
|
||||
from __future__ import absolute_import, print_function, with_statement, unicode_literals
|
||||
import logging
|
||||
import json
|
||||
|
||||
|
@ -60,7 +60,7 @@ def returner(ret):
|
|||
with salt.utils.files.flopen(opts['filename'], 'a') as logfile:
|
||||
logfile.write(json.dumps(ret)+'\n')
|
||||
except:
|
||||
log.error('Could not write to rawdata_json file {0}'.format(opts['filename']))
|
||||
log.error('Could not write to rawdata_json file %s', opts['filename'])
|
||||
raise
|
||||
|
||||
|
||||
|
@ -79,5 +79,5 @@ def event_return(events):
|
|||
json.dump(event, logfile)
|
||||
logfile.write('\n')
|
||||
except:
|
||||
log.error('Could not write to rawdata_json file {0}'.format(opts['filename']))
|
||||
log.error('Could not write to rawdata_json file %s', opts['filename'])
|
||||
raise
|
||||
|
|
|
@ -86,7 +86,7 @@ cluster.skip_full_coverage_check: ``False``
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import json
|
||||
import logging
|
||||
|
||||
|
@ -305,7 +305,7 @@ def clean_old_jobs():
|
|||
to_remove.append(ret_key)
|
||||
if len(to_remove) != 0:
|
||||
serv.delete(*to_remove)
|
||||
log.debug('clean old jobs: {0}'.format(to_remove))
|
||||
log.debug('clean old jobs: %s', to_remove)
|
||||
|
||||
|
||||
def prep_jid(nocache=False, passed_jid=None): # pylint: disable=unused-argument
|
||||
|
|
|
@ -41,7 +41,7 @@ tags, allowing tagging of events in the sentry ui.
|
|||
|
||||
To report only errors to sentry, set report_errors_only: true.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import logging
|
||||
|
@ -58,7 +58,7 @@ try:
|
|||
except ImportError:
|
||||
has_raven = False
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'sentry'
|
||||
|
@ -81,10 +81,7 @@ def returner(ret):
|
|||
try:
|
||||
_connect_sentry(_get_message(ret), ret)
|
||||
except Exception as err:
|
||||
logger.error(
|
||||
'Can\'t run connect_sentry: {0}'.format(err),
|
||||
exc_info=True
|
||||
)
|
||||
log.error('Can\'t run connect_sentry: %s', err, exc_info=True)
|
||||
|
||||
|
||||
def _ret_is_not_error(result):
|
||||
|
@ -164,7 +161,7 @@ def _connect_sentry(message, result):
|
|||
transport=HTTPTransport
|
||||
)
|
||||
except KeyError as missing_key:
|
||||
logger.error(
|
||||
log.error(
|
||||
'Sentry returner needs key \'%s\' in pillar',
|
||||
missing_key
|
||||
)
|
||||
|
@ -178,12 +175,9 @@ def _connect_sentry(message, result):
|
|||
extra=sentry_data,
|
||||
tags=tags
|
||||
)
|
||||
logger.info('Message id {} written to sentry'.format(msgid))
|
||||
log.info('Message id %s written to sentry', msgid)
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
'Can\'t send message to sentry: {0}'.format(exc),
|
||||
exc_info=True
|
||||
)
|
||||
log.error('Can\'t send message to sentry: %s', exc, exc_info=True)
|
||||
|
||||
|
||||
def prep_jid(nocache=False, passed_jid=None): # pylint: disable=unused-argument
|
||||
|
|
|
@ -76,7 +76,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return slack --return_kwargs '{"channel": "#random"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import yaml
|
||||
|
@ -170,7 +170,7 @@ def _post_message(channel,
|
|||
header_dict={'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
data=_urlencode(parameters))
|
||||
|
||||
log.debug('result {0}'.format(result))
|
||||
log.debug('Slack message post result: %s', result)
|
||||
if result:
|
||||
return True
|
||||
else:
|
||||
|
|
|
@ -28,7 +28,7 @@ To use the sms returner, append '--return sms' to the salt command.
|
|||
salt '*' test.ping --return sms
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
import salt.returners
|
||||
|
@ -96,8 +96,10 @@ def returner(ret):
|
|||
ret['id'], ret['fun'], ret['success'], ret['jid']
|
||||
), to=receiver, from_=sender)
|
||||
except TwilioRestException as e:
|
||||
log.error('Twilio [https://www.twilio.com/docs/errors/{0}]'.format(
|
||||
e.code))
|
||||
log.error(
|
||||
'Twilio [https://www.twilio.com/docs/errors/%s]',
|
||||
e.code
|
||||
)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
@ -106,7 +106,7 @@ This configuration enables Salt Master to send an email when accepting or reject
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import logging
|
||||
import smtplib
|
||||
|
@ -184,7 +184,7 @@ def returner(ret):
|
|||
|
||||
if not port:
|
||||
port = 25
|
||||
log.debug('SMTP port has been set to {0}'.format(port))
|
||||
log.debug('SMTP port has been set to %s', port)
|
||||
|
||||
for field in fields:
|
||||
if field in ret:
|
||||
|
@ -198,7 +198,7 @@ def returner(ret):
|
|||
**ret)
|
||||
if isinstance(subject, six.moves.StringIO):
|
||||
subject = subject.read()
|
||||
log.debug("smtp_return: Subject is '{0}'".format(subject))
|
||||
log.debug("smtp_return: Subject is '%s'", subject)
|
||||
|
||||
template = _options.get('template')
|
||||
if template:
|
||||
|
@ -224,7 +224,7 @@ def returner(ret):
|
|||
encrypted_data = gpg.encrypt(content, to_addrs)
|
||||
if encrypted_data.ok:
|
||||
log.debug('smtp_return: Encryption successful')
|
||||
content = str(encrypted_data)
|
||||
content = six.text_type(encrypted_data)
|
||||
else:
|
||||
log.error('smtp_return: Encryption failed, only an error message will be sent')
|
||||
content = 'Encryption failed, the return data was not sent.\r\n\r\n{0}\r\n{1}'.format(
|
||||
|
|
|
@ -17,7 +17,7 @@ Run a test by using ``salt-call test.ping --return splunk``
|
|||
Written by Scott Pack (github.com/scottjpack)
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
|
||||
import socket
|
||||
|
@ -28,6 +28,8 @@ import json
|
|||
import time
|
||||
import logging
|
||||
|
||||
from salt.ext import six
|
||||
|
||||
_max_content_bytes = 100000
|
||||
http_event_collector_SSL_verify = False
|
||||
http_event_collector_debug = False
|
||||
|
@ -74,7 +76,7 @@ def _send_splunk(event, index_override=None, sourcetype_override=None):
|
|||
'''
|
||||
#Get Splunk Options
|
||||
opts = _get_options()
|
||||
logging.info('Options: {0}'.format(json.dumps(opts)))
|
||||
logging.info('Options: %s', json.dumps(opts))
|
||||
http_event_collector_key = opts['token']
|
||||
http_event_collector_host = opts['indexer']
|
||||
#Set up the collector
|
||||
|
@ -94,7 +96,7 @@ def _send_splunk(event, index_override=None, sourcetype_override=None):
|
|||
|
||||
#Add the event
|
||||
payload.update({"event": event})
|
||||
logging.info('Payload: {0}'.format(json.dumps(payload)))
|
||||
logging.info('Payload: %s', json.dumps(payload))
|
||||
#fire it off
|
||||
splunk_event.sendEvent(payload)
|
||||
return True
|
||||
|
@ -145,7 +147,7 @@ class http_event_collector(object):
|
|||
|
||||
# If eventtime in epoch not passed as optional argument use current system time in epoch
|
||||
if not eventtime:
|
||||
eventtime = str(int(time.time()))
|
||||
eventtime = six.text_type(int(time.time()))
|
||||
|
||||
# Fill in local hostname if not manually populated
|
||||
if 'host' not in payload:
|
||||
|
@ -182,7 +184,7 @@ class http_event_collector(object):
|
|||
|
||||
# If eventtime in epoch not passed as optional argument use current system time in epoch
|
||||
if not eventtime:
|
||||
eventtime = str(int(time.time()))
|
||||
eventtime = six.text_type(int(time.time()))
|
||||
|
||||
# Update time value on payload if need to use system time
|
||||
data = {"time": eventtime}
|
||||
|
|
|
@ -80,7 +80,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return sqlite3 --return_kwargs '{"db": "/var/lib/salt/another-salt.db"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
@ -91,6 +91,9 @@ import datetime
|
|||
import salt.utils.jid
|
||||
import salt.returners
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
# Better safe than sorry here. Even though sqlite3 is included in python
|
||||
try:
|
||||
import sqlite3
|
||||
|
@ -141,9 +144,7 @@ def _get_conn(ret=None):
|
|||
if not timeout:
|
||||
raise Exception(
|
||||
'sqlite3 config option "sqlite3.timeout" is missing')
|
||||
log.debug('Connecting the sqlite3 database: {0} timeout: {1}'.format(
|
||||
database,
|
||||
timeout))
|
||||
log.debug('Connecting the sqlite3 database: %s timeout: %s', database, timeout)
|
||||
conn = sqlite3.connect(database, timeout=float(timeout))
|
||||
return conn
|
||||
|
||||
|
@ -161,7 +162,7 @@ def returner(ret):
|
|||
'''
|
||||
Insert minion return data into the sqlite3 database
|
||||
'''
|
||||
log.debug('sqlite3 returner <returner> called with data: {0}'.format(ret))
|
||||
log.debug('sqlite3 returner <returner> called with data: %s', ret)
|
||||
conn = _get_conn(ret)
|
||||
cur = conn.cursor()
|
||||
sql = '''INSERT INTO salt_returns
|
||||
|
@ -171,8 +172,8 @@ def returner(ret):
|
|||
{'fun': ret['fun'],
|
||||
'jid': ret['jid'],
|
||||
'id': ret['id'],
|
||||
'fun_args': str(ret['fun_args']) if ret.get('fun_args') else None,
|
||||
'date': str(datetime.datetime.now()),
|
||||
'fun_args': six.text_type(ret['fun_args']) if ret.get('fun_args') else None,
|
||||
'date': six.text_type(datetime.datetime.now()),
|
||||
'full_ret': json.dumps(ret['return']),
|
||||
'success': ret.get('success', '')})
|
||||
_close_conn(conn)
|
||||
|
@ -182,8 +183,7 @@ def save_load(jid, load, minions=None):
|
|||
'''
|
||||
Save the load to the specified jid
|
||||
'''
|
||||
log.debug('sqlite3 returner <save_load> called jid:{0} load:{1}'
|
||||
.format(jid, load))
|
||||
log.debug('sqlite3 returner <save_load> called jid: %s load: %s', jid, load)
|
||||
conn = _get_conn(ret=None)
|
||||
cur = conn.cursor()
|
||||
sql = '''INSERT INTO jids (jid, load) VALUES (:jid, :load)'''
|
||||
|
@ -204,7 +204,7 @@ def get_load(jid):
|
|||
'''
|
||||
Return the load from a specified jid
|
||||
'''
|
||||
log.debug('sqlite3 returner <get_load> called jid: {0}'.format(jid))
|
||||
log.debug('sqlite3 returner <get_load> called jid: %s', jid)
|
||||
conn = _get_conn(ret=None)
|
||||
cur = conn.cursor()
|
||||
sql = '''SELECT load FROM jids WHERE jid = :jid'''
|
||||
|
@ -221,18 +221,18 @@ def get_jid(jid):
|
|||
'''
|
||||
Return the information returned from a specified jid
|
||||
'''
|
||||
log.debug('sqlite3 returner <get_jid> called jid: {0}'.format(jid))
|
||||
log.debug('sqlite3 returner <get_jid> called jid: %s', jid)
|
||||
conn = _get_conn(ret=None)
|
||||
cur = conn.cursor()
|
||||
sql = '''SELECT id, full_ret FROM salt_returns WHERE jid = :jid'''
|
||||
cur.execute(sql,
|
||||
{'jid': jid})
|
||||
data = cur.fetchone()
|
||||
log.debug('query result: {0}'.format(data))
|
||||
log.debug('query result: %s', data)
|
||||
ret = {}
|
||||
if data and len(data) > 1:
|
||||
ret = {str(data[0]): {u'return': json.loads(data[1])}}
|
||||
log.debug("ret: {0}".format(ret))
|
||||
ret = {six.text_type(data[0]): {u'return': json.loads(data[1])}}
|
||||
log.debug('ret: %s', ret)
|
||||
_close_conn(conn)
|
||||
return ret
|
||||
|
||||
|
@ -241,7 +241,7 @@ def get_fun(fun):
|
|||
'''
|
||||
Return a dict of the last function called for all minions
|
||||
'''
|
||||
log.debug('sqlite3 returner <get_fun> called fun: {0}'.format(fun))
|
||||
log.debug('sqlite3 returner <get_fun> called fun: %s', fun)
|
||||
conn = _get_conn(ret=None)
|
||||
cur = conn.cursor()
|
||||
sql = '''SELECT s.id, s.full_ret, s.jid
|
||||
|
|
|
@ -86,7 +86,7 @@ To override individual configuration items, append
|
|||
implmentation's documentation to determine how to adjust this limit.
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import python libs
|
||||
|
@ -148,10 +148,10 @@ def _verify_options(options):
|
|||
|
||||
for opt_name, opt in bitwise_args:
|
||||
if not hasattr(syslog, opt):
|
||||
log.error('syslog has no attribute {0}'.format(opt))
|
||||
log.error('syslog has no attribute %s', opt)
|
||||
return False
|
||||
if not isinstance(getattr(syslog, opt), int):
|
||||
log.error('{0} is not a valid syslog {1}'.format(opt, opt_name))
|
||||
log.error('%s is not a valid syslog %s', opt, opt_name)
|
||||
return False
|
||||
|
||||
# Sanity check tag
|
||||
|
|
|
@ -22,7 +22,7 @@ To use the Telegram return, append '--return telegram' to the salt command.
|
|||
salt '*' test.ping --return telegram
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python libs
|
||||
import logging
|
||||
|
@ -60,7 +60,7 @@ def _get_options(ret=None):
|
|||
attrs,
|
||||
__salt__=__salt__,
|
||||
__opts__=__opts__)
|
||||
log.debug('Options: {0}'.format(_options))
|
||||
log.debug('Options: %s', _options)
|
||||
return _options
|
||||
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ To override individual configuration items, append --return_kwargs '{"key:": "va
|
|||
salt '*' test.ping --return xmpp --return_kwargs '{"recipient": "someone-else@xmpp.example.com"}'
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -20,7 +20,7 @@ To use the Zabbix returner, append '--return zabbix' to the salt command. ex:
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import textwrap
|
||||
|
||||
|
@ -11,6 +11,7 @@ from tests.support.case import ModuleCase
|
|||
# Import Salt libs
|
||||
import salt.utils.files
|
||||
import salt.utils.platform
|
||||
import salt.utils.stringutils
|
||||
|
||||
|
||||
class PyDSLRendererIncludeTestCase(ModuleCase):
|
||||
|
@ -49,7 +50,7 @@ class PyDSLRendererIncludeTestCase(ModuleCase):
|
|||
'hello blue 3 \r\n'
|
||||
|
||||
with salt.utils.files.fopen('/tmp/output', 'r') as f:
|
||||
ret = f.read()
|
||||
ret = salt.utils.stringutils.to_unicode(f.read())
|
||||
|
||||
os.remove('/tmp/output')
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the librato returner
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import Salt Testing libs
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
|
|
@ -7,7 +7,7 @@ Unit tests for the Default Job Cache (local_cache).
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
import logging
|
||||
|
@ -217,7 +217,7 @@ class Local_CacheTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleM
|
|||
are either present or removed
|
||||
'''
|
||||
for content in contents:
|
||||
log.debug('CONTENT {0}'.format(content))
|
||||
log.debug('CONTENT %s', content)
|
||||
if status == 'present':
|
||||
check_job_dir = os.path.exists(content)
|
||||
elif status == 'removed':
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.unit import TestCase
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
|
Loading…
Add table
Reference in a new issue