mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add unicode_literals to tops, thorium, proxy, tokens
This commit is contained in:
parent
653ad2a224
commit
7147ac69ac
46 changed files with 131 additions and 125 deletions
|
@ -2,12 +2,13 @@
|
|||
'''
|
||||
Package support for the dummy proxy used by the test suite
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
import salt.utils.data
|
||||
import salt.utils.platform
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -96,9 +97,9 @@ def installed(name,
|
|||
p = __proxy__['dummy.package_status'](name)
|
||||
if version is None:
|
||||
if 'ret' in p:
|
||||
return str(p['ret'])
|
||||
return six.text_type(p['ret'])
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
if p is not None:
|
||||
return version == str(p)
|
||||
return version == six.text_type(p)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
Provide the service module for the dummy proxy used in integration tests
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import Salt libs
|
||||
|
|
|
@ -24,7 +24,7 @@ the chronos endpoint:
|
|||
|
||||
.. versionadded:: 2015.8.2
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
import salt.utils.http
|
||||
|
|
|
@ -60,7 +60,7 @@ The password used to login to the cimc host. Required.
|
|||
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python Libs
|
||||
import logging
|
||||
|
|
|
@ -173,7 +173,7 @@ responding:
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import Salt Libs
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
'''
|
||||
This is a dummy proxy-minion designed for testing the proxy minion subsystem.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
|
@ -194,7 +194,7 @@ def uptodate():
|
|||
for p in DETAILS['packages']:
|
||||
version_float = float(DETAILS['packages'][p])
|
||||
version_float = version_float + 1.0
|
||||
DETAILS['packages'][p] = str(version_float)
|
||||
DETAILS['packages'][p] = six.text_type(version_float)
|
||||
return DETAILS['packages']
|
||||
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ Look there to find an example structure for Pillar as well as an example
|
|||
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -200,13 +200,12 @@ def init(opts):
|
|||
login
|
||||
the protocol and port are cached.
|
||||
'''
|
||||
log.debug('Initting esxcluster proxy module in process '
|
||||
'{}'.format(os.getpid()))
|
||||
log.debug('Initting esxcluster proxy module in process %s', os.getpid())
|
||||
log.debug('Validating esxcluster proxy input')
|
||||
schema = EsxclusterProxySchema.serialize()
|
||||
log.trace('schema = {}'.format(schema))
|
||||
log.trace('schema = %s', schema)
|
||||
proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
|
||||
log.trace('proxy_conf = {0}'.format(proxy_conf))
|
||||
log.trace('proxy_conf = %s', proxy_conf)
|
||||
try:
|
||||
jsonschema.validate(proxy_conf, schema)
|
||||
except jsonschema.exceptions.ValidationError as exc:
|
||||
|
@ -253,7 +252,7 @@ def init(opts):
|
|||
username, password = find_credentials()
|
||||
DETAILS['password'] = password
|
||||
except salt.exceptions.SaltSystemExit as err:
|
||||
log.critical('Error: {0}'.format(err))
|
||||
log.critical('Error: %s', err)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ Look there to find an example structure for Pillar as well as an example
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -191,13 +191,12 @@ def init(opts):
|
|||
This function gets called when the proxy starts up.
|
||||
All login details are cached.
|
||||
'''
|
||||
log.debug('Initting esxdatacenter proxy module in process '
|
||||
'{}'.format(os.getpid()))
|
||||
log.debug('Initting esxdatacenter proxy module in process %s', os.getpid())
|
||||
log.trace('Validating esxdatacenter proxy input')
|
||||
schema = EsxdatacenterProxySchema.serialize()
|
||||
log.trace('schema = {}'.format(schema))
|
||||
log.trace('schema = %s', schema)
|
||||
proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
|
||||
log.trace('proxy_conf = {0}'.format(proxy_conf))
|
||||
log.trace('proxy_conf = %s', proxy_conf)
|
||||
try:
|
||||
jsonschema.validate(proxy_conf, schema)
|
||||
except jsonschema.exceptions.ValidationError as exc:
|
||||
|
@ -244,7 +243,7 @@ def init(opts):
|
|||
username, password = find_credentials()
|
||||
DETAILS['password'] = password
|
||||
except salt.exceptions.SaltSystemExit as err:
|
||||
log.critical('Error: {0}'.format(err))
|
||||
log.critical('Error: %s', err)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ for standing up an ESXi host from scratch.
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -317,13 +317,12 @@ def init(opts):
|
|||
ESXi devices, the host, login credentials, and, if configured,
|
||||
the protocol and port are cached.
|
||||
'''
|
||||
log.debug('Initting esxi proxy module in process \'{}\''
|
||||
''.format(os.getpid()))
|
||||
log.debug('Initting esxi proxy module in process %s', os.getpid())
|
||||
log.debug('Validating esxi proxy input')
|
||||
schema = EsxiProxySchema.serialize()
|
||||
log.trace('esxi_proxy_schema = {}'.format(schema))
|
||||
log.trace('esxi_proxy_schema = %s', schema)
|
||||
proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
|
||||
log.trace('proxy_conf = {0}'.format(proxy_conf))
|
||||
log.trace('proxy_conf = %s', proxy_conf)
|
||||
try:
|
||||
jsonschema.validate(proxy_conf, schema)
|
||||
except jsonschema.exceptions.ValidationError as exc:
|
||||
|
@ -348,7 +347,7 @@ def init(opts):
|
|||
try:
|
||||
username, password = find_credentials(host)
|
||||
except SaltSystemExit as err:
|
||||
log.critical('Error: {0}'.format(err))
|
||||
log.critical('Error: %s', err)
|
||||
return False
|
||||
|
||||
# Set configuration details
|
||||
|
@ -408,7 +407,7 @@ def init(opts):
|
|||
username, password = find_credentials(DETAILS['vcenter'])
|
||||
DETAILS['password'] = password
|
||||
except SaltSystemExit as err:
|
||||
log.critical('Error: {0}'.format(err))
|
||||
log.critical('Error: %s', err)
|
||||
return False
|
||||
|
||||
# Save optional
|
||||
|
|
|
@ -146,7 +146,7 @@ Look there to find an example structure for Pillar as well as an example
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -182,11 +182,10 @@ def init(opts):
|
|||
This function gets called when the proxy starts up. For
|
||||
login the protocol and port are cached.
|
||||
'''
|
||||
log.debug('Initting esxvm proxy module in process '
|
||||
'{}'.format(os.getpid()))
|
||||
log.debug('Initting esxvm proxy module in process %s', os.getpid())
|
||||
log.debug('Validating esxvm proxy input')
|
||||
proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
|
||||
log.trace('proxy_conf = {0}'.format(proxy_conf))
|
||||
log.trace('proxy_conf = %s', proxy_conf)
|
||||
# TODO json schema validation
|
||||
|
||||
# Save mandatory fields in cache
|
||||
|
@ -230,7 +229,7 @@ def init(opts):
|
|||
username, password = find_credentials()
|
||||
DETAILS['password'] = password
|
||||
except excs.SaltSystemExit as err:
|
||||
log.critical('Error: {0}'.format(err))
|
||||
log.critical('Error: %s', err)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ Look there to find an example structure for pillar as well as an example
|
|||
``.sls`` file for standing up a Dell Chassis from scratch.
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -35,7 +35,7 @@ Run the salt proxy via the following command:
|
|||
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
|
@ -191,7 +191,7 @@ def shutdown(opts):
|
|||
This is called when the proxy-minion is exiting to make sure the
|
||||
connection to the device is closed cleanly.
|
||||
'''
|
||||
log.debug('Proxy module {0} shutting down!!'.format(opts['id']))
|
||||
log.debug('Proxy module %s shutting down!!', opts['id'])
|
||||
try:
|
||||
thisproxy['conn'].close()
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ the marathon endpoint:
|
|||
|
||||
.. versionadded:: 2015.8.2
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import logging
|
||||
import salt.utils.http
|
||||
|
|
|
@ -135,7 +135,7 @@ Example using a user-specific library, extending NAPALM's capabilities, e.g. ``c
|
|||
.. versionadded:: 2016.11.0
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python lib
|
||||
import logging
|
||||
|
@ -196,10 +196,10 @@ def alive(opts):
|
|||
# or regular minion
|
||||
is_alive_ret = call('is_alive', **{})
|
||||
if not is_alive_ret.get('result', False):
|
||||
log.debug('[{proxyid}] Unable to execute `is_alive`: {comment}'.format(
|
||||
proxyid=opts.get('id'),
|
||||
comment=is_alive_ret.get('comment')
|
||||
))
|
||||
log.debug(
|
||||
'[%s] Unable to execute `is_alive`: %s',
|
||||
opts.get('id'), is_alive_ret.get('comment')
|
||||
)
|
||||
# if `is_alive` is not implemented by the underneath driver,
|
||||
# will consider the connection to be still alive
|
||||
# we don't want overly request connection reestablishment
|
||||
|
@ -207,10 +207,7 @@ def alive(opts):
|
|||
# and return False to force reconnection
|
||||
return True
|
||||
flag = is_alive_ret.get('out', {}).get('is_alive', False)
|
||||
log.debug('Is {proxyid} still alive? {answ}'.format(
|
||||
proxyid=opts.get('id'),
|
||||
answ='Yes.' if flag else 'No.'
|
||||
))
|
||||
log.debug('Is %s still alive? %s', opts.get('id'), 'Yes.' if flag else 'No.')
|
||||
return flag
|
||||
|
||||
|
||||
|
@ -277,13 +274,12 @@ def shutdown(opts):
|
|||
raise Exception('not connected!')
|
||||
NETWORK_DEVICE.get('DRIVER').close()
|
||||
except Exception as error:
|
||||
port = NETWORK_DEVICE.get('OPTIONAL_ARGS', {}).get('port')
|
||||
log.error(
|
||||
'Cannot close connection with {hostname}{port}! Please check error: {error}'.format(
|
||||
hostname=NETWORK_DEVICE.get('HOSTNAME', '[unknown hostname]'),
|
||||
port=(':{port}'.format(port=NETWORK_DEVICE.get('OPTIONAL_ARGS', {}).get('port'))
|
||||
if NETWORK_DEVICE.get('OPTIONAL_ARGS', {}).get('port') else ''),
|
||||
error=error
|
||||
)
|
||||
'Cannot close connection with %s%s! Please check error: %s',
|
||||
NETWORK_DEVICE.get('HOSTNAME', '[unknown hostname]'),
|
||||
':{0}'.format(port) if port else '',
|
||||
error
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
@ -55,7 +55,7 @@ the :mod:`salt.modules.nxos<salt.modules.nxos>` execution module.
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import multiprocessing
|
||||
import re
|
||||
|
|
|
@ -185,7 +185,7 @@ The generated XML API key for the Panorama server. Required.
|
|||
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Python Libs
|
||||
import logging
|
||||
|
|
|
@ -21,7 +21,7 @@ Philips HUE lamps module for proxy.
|
|||
'''
|
||||
|
||||
# pylint: disable=import-error,no-name-in-module,redefined-builtin
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import salt.ext.six.moves.http_client as http_client
|
||||
|
||||
# Import python libs
|
||||
|
@ -29,6 +29,7 @@ import logging
|
|||
import time
|
||||
import json
|
||||
from salt.exceptions import (CommandExecutionError, MinionError)
|
||||
from salt.ext import six
|
||||
|
||||
|
||||
__proxyenabled__ = ['philips_hue']
|
||||
|
@ -188,8 +189,8 @@ def call_lights(*args, **kwargs):
|
|||
res = dict()
|
||||
lights = _get_lights()
|
||||
for dev_id in 'id' in kwargs and _get_devices(kwargs) or sorted(lights.keys()):
|
||||
if lights.get(str(dev_id)):
|
||||
res[dev_id] = lights[str(dev_id)]
|
||||
if lights.get(six.text_type(dev_id)):
|
||||
res[dev_id] = lights[six.text_type(dev_id)]
|
||||
|
||||
return res or False
|
||||
|
||||
|
@ -221,7 +222,7 @@ def call_switch(*args, **kwargs):
|
|||
state = kwargs['on'] and Const.LAMP_ON or Const.LAMP_OFF
|
||||
else:
|
||||
# Invert the current state
|
||||
state = devices[str(dev_id)]['state']['on'] and Const.LAMP_OFF or Const.LAMP_ON
|
||||
state = devices[six.text_type(dev_id)]['state']['on'] and Const.LAMP_OFF or Const.LAMP_ON
|
||||
out[dev_id] = _set(dev_id, state)
|
||||
|
||||
return out
|
||||
|
@ -247,7 +248,7 @@ def call_blink(*args, **kwargs):
|
|||
pause = kwargs.get('pause', 0)
|
||||
res = dict()
|
||||
for dev_id in 'id' not in kwargs and sorted(devices.keys()) or _get_devices(kwargs):
|
||||
state = devices[str(dev_id)]['state']['on']
|
||||
state = devices[six.text_type(dev_id)]['state']['on']
|
||||
_set(dev_id, state and Const.LAMP_OFF or Const.LAMP_ON)
|
||||
if pause:
|
||||
time.sleep(pause)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This is a simple proxy-minion designed to connect to and communicate with
|
||||
the bottle-based web service contained in https://github.com/saltstack/salt-contrib/tree/master/proxyminion_rest_example
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
This can be used as an option when the device does not provide
|
||||
an api over HTTP and doesn't have the python stack to run a minion.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
|
|
|
@ -183,7 +183,7 @@ and communicate with the ESXi host.
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -228,13 +228,12 @@ def init(opts):
|
|||
This function gets called when the proxy starts up.
|
||||
For login the protocol and port are cached.
|
||||
'''
|
||||
log.info('Initting vcenter proxy module in process {0}'
|
||||
''.format(os.getpid()))
|
||||
log.info('Initting vcenter proxy module in process %s', os.getpid())
|
||||
log.trace('VCenter Proxy Validating vcenter proxy input')
|
||||
schema = VCenterProxySchema.serialize()
|
||||
log.trace('schema = {}'.format(schema))
|
||||
log.trace('schema = %s', schema)
|
||||
proxy_conf = merge(opts.get('proxy', {}), __pillar__.get('proxy', {}))
|
||||
log.trace('proxy_conf = {0}'.format(proxy_conf))
|
||||
log.trace('proxy_conf = %s', proxy_conf)
|
||||
try:
|
||||
jsonschema.validate(proxy_conf, schema)
|
||||
except jsonschema.exceptions.ValidationError as exc:
|
||||
|
@ -281,7 +280,7 @@ def init(opts):
|
|||
username, password = find_credentials()
|
||||
DETAILS['password'] = password
|
||||
except salt.exceptions.SaltSystemExit as err:
|
||||
log.critical('Error: {0}'.format(err))
|
||||
log.critical('Error: %s', err)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ The thorium system allows for advanced event tracking and reactions
|
|||
# Add dynamic recompile of thorium ruleset on given interval
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
|
|
|
@ -9,7 +9,7 @@ values are stored and computed, such as averages etc.
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
try:
|
||||
import statistics
|
||||
|
|
|
@ -6,7 +6,7 @@ succeed or fail based on the state of the register, this creates the pattern
|
|||
of having a command execution get gated by a check state via a requisite.
|
||||
'''
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
import salt.utils.stringutils
|
||||
|
@ -252,7 +252,7 @@ def contains(name,
|
|||
count_gte or count_gt or count_ne
|
||||
if count_compare:
|
||||
occurrences = __reg__[name]['val'].count(value)
|
||||
log.debug('{} appears {} times'.format(value, occurrences))
|
||||
log.debug('%s appears %s times', value, occurrences)
|
||||
ret['result'] = True
|
||||
if count_lt:
|
||||
ret['result'] &= occurrences < count_lt
|
||||
|
|
|
@ -39,7 +39,7 @@ that can be re-imported into Python.
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import json
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ The key Thorium State is used to apply changes to the accepted/rejected/pending
|
|||
.. versionadded:: 2016.11.0
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import time
|
||||
|
||||
# Import salt libs
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Run remote execution commands via the local client
|
||||
'''
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import salt libs
|
||||
import salt.client
|
||||
|
|
|
@ -5,7 +5,7 @@ values are stored and computed, such as averages etc.
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import, division
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
import salt.utils.stringutils
|
||||
|
||||
__func_alias__ = {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
React by calling async runners
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# import salt libs
|
||||
import salt.runner
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ the active status of minions
|
|||
.. versionadded:: 2016.11.0
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import time
|
||||
import fnmatch
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ Allow for flow based timers. These timers allow for a sleep to exist across
|
|||
multiple runs of the flow
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import time
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
React by calling async runners
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
# import salt libs
|
||||
import salt.wheel
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
Stores eauth tokens in the filesystem of the master. Location is configured by the master config option 'token_dir'
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
|
@ -14,6 +14,8 @@ import salt.utils.files
|
|||
import salt.utils.path
|
||||
import salt.payload
|
||||
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__virtualname__ = 'localfs'
|
||||
|
@ -30,10 +32,10 @@ def mk_token(opts, tdata):
|
|||
:returns: tdata with token if successful. Empty dict if failed.
|
||||
'''
|
||||
hash_type = getattr(hashlib, opts.get('hash_type', 'md5'))
|
||||
tok = str(hash_type(os.urandom(512)).hexdigest())
|
||||
tok = six.text_type(hash_type(os.urandom(512)).hexdigest())
|
||||
t_path = os.path.join(opts['token_dir'], tok)
|
||||
while os.path.isfile(t_path):
|
||||
tok = str(hash_type(os.urandom(512)).hexdigest())
|
||||
tok = six.text_type(hash_type(os.urandom(512)).hexdigest())
|
||||
t_path = os.path.join(opts['token_dir'], tok)
|
||||
tdata['token'] = tok
|
||||
serial = salt.payload.Serial(opts)
|
||||
|
@ -42,7 +44,8 @@ def mk_token(opts, tdata):
|
|||
with salt.utils.files.fopen(t_path, 'w+b') as fp_:
|
||||
fp_.write(serial.dumps(tdata))
|
||||
except (IOError, OSError):
|
||||
log.warning('Authentication failure: can not write token file "{0}".'.format(t_path))
|
||||
log.warning(
|
||||
'Authentication failure: can not write token file "%s".', t_path)
|
||||
return {}
|
||||
return tdata
|
||||
|
||||
|
@ -64,7 +67,8 @@ def get_token(opts, tok):
|
|||
tdata = serial.loads(fp_.read())
|
||||
return tdata
|
||||
except (IOError, OSError):
|
||||
log.warning('Authentication failure: can not read token file "{0}".'.format(t_path))
|
||||
log.warning(
|
||||
'Authentication failure: can not read token file "%s".', t_path)
|
||||
return {}
|
||||
|
||||
|
||||
|
@ -81,7 +85,7 @@ def rm_token(opts, tok):
|
|||
os.remove(t_path)
|
||||
return {}
|
||||
except (IOError, OSError):
|
||||
log.warning('Could not remove token {0}'.format(tok))
|
||||
log.warning('Could not remove token %s', tok)
|
||||
|
||||
|
||||
def list_tokens(opts):
|
||||
|
|
|
@ -15,7 +15,7 @@ Default values for these configs are as follow:
|
|||
:depends: - redis-py-cluster Python package
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
|
||||
try:
|
||||
|
@ -31,6 +31,8 @@ import hashlib
|
|||
|
||||
import salt.payload
|
||||
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
__virtualname__ = 'rediscluster'
|
||||
|
@ -53,7 +55,10 @@ def _redis_client(opts):
|
|||
try:
|
||||
return rediscluster.StrictRedisCluster(host=redis_host, port=redis_port)
|
||||
except rediscluster.exceptions.RedisClusterException as err:
|
||||
log.warning("Failed to connect to redis at {0}:{1} - {2}".format(redis_host, redis_port, err))
|
||||
log.warning(
|
||||
'Failed to connect to redis at %s:%s - %s',
|
||||
redis_host, redis_port, err
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -71,19 +76,25 @@ def mk_token(opts, tdata):
|
|||
if not redis_client:
|
||||
return {}
|
||||
hash_type = getattr(hashlib, opts.get('hash_type', 'md5'))
|
||||
tok = str(hash_type(os.urandom(512)).hexdigest())
|
||||
tok = six.text_type(hash_type(os.urandom(512)).hexdigest())
|
||||
try:
|
||||
while redis_client.get(tok) is not None:
|
||||
tok = str(hash_type(os.urandom(512)).hexdigest())
|
||||
tok = six.text_type(hash_type(os.urandom(512)).hexdigest())
|
||||
except Exception as err:
|
||||
log.warning("Authentication failure: cannot get token {0} from redis: {1}".format(tok, err))
|
||||
log.warning(
|
||||
'Authentication failure: cannot get token %s from redis: %s',
|
||||
tok, err
|
||||
)
|
||||
return {}
|
||||
tdata['token'] = tok
|
||||
serial = salt.payload.Serial(opts)
|
||||
try:
|
||||
redis_client.set(tok, serial.dumps(tdata))
|
||||
except Exception as err:
|
||||
log.warning("Authentication failure: cannot save token {0} to redis: {1}".format(tok, err))
|
||||
log.warning(
|
||||
'Authentication failure: cannot save token %s to redis: %s',
|
||||
tok, err
|
||||
)
|
||||
return {}
|
||||
return tdata
|
||||
|
||||
|
@ -104,7 +115,10 @@ def get_token(opts, tok):
|
|||
tdata = serial.loads(redis_client.get(tok))
|
||||
return tdata
|
||||
except Exception as err:
|
||||
log.warning("Authentication failure: cannot get token {0} from redis: {1}".format(tok, err))
|
||||
log.warning(
|
||||
'Authentication failure: cannot get token %s from redis: %s',
|
||||
tok, err
|
||||
)
|
||||
return {}
|
||||
|
||||
|
||||
|
@ -123,7 +137,7 @@ def rm_token(opts, tok):
|
|||
redis_client.delete(tok)
|
||||
return {}
|
||||
except Exception as err:
|
||||
log.warning("Could not remove token {0}: {1}".format(tok, err))
|
||||
log.warning('Could not remove token %s: %s', tok, err)
|
||||
|
||||
|
||||
def list_tokens(opts):
|
||||
|
@ -141,5 +155,5 @@ def list_tokens(opts):
|
|||
try:
|
||||
return [k.decode('utf8') for k in redis_client.keys()]
|
||||
except Exception as err:
|
||||
log.warning("Failed to list keys: {0}".format(err))
|
||||
log.warning('Failed to list keys: %s', err)
|
||||
return []
|
||||
|
|
|
@ -19,7 +19,7 @@ the Cobbler tops and Cobbler pillar modules.
|
|||
Module Documentation
|
||||
====================
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -45,7 +45,7 @@ The above essentially is the same as a top.sls containing the following:
|
|||
- basepackages
|
||||
- database
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -41,7 +41,7 @@ Configuring the Mongo Tops Subsystem
|
|||
Module Documentation
|
||||
====================
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
@ -102,17 +102,17 @@ def top(**kwargs):
|
|||
states_field = __opts__['master_tops']['mongo'].get('states_field', 'states')
|
||||
environment_field = __opts__['master_tops']['mongo'].get('environment_field', 'environment')
|
||||
|
||||
log.info('connecting to {0}:{1} for mongo ext_tops'.format(host, port))
|
||||
log.info('connecting to %s:%s for mongo ext_tops', host, port)
|
||||
conn = pymongo.MongoClient(host, port)
|
||||
|
||||
log.debug('using database \'{0}\''.format(__opts__['mongo.db']))
|
||||
log.debug('using database \'%s\'', __opts__['mongo.db'])
|
||||
mdb = conn[__opts__['mongo.db']]
|
||||
|
||||
user = __opts__.get('mongo.user')
|
||||
password = __opts__.get('mongo.password')
|
||||
|
||||
if user and password:
|
||||
log.debug('authenticating as \'{0}\''.format(user))
|
||||
log.debug('authenticating as \'%s\'', user)
|
||||
mdb.authenticate(user, password)
|
||||
|
||||
# Do the regex string replacement on the minion id
|
||||
|
@ -121,10 +121,8 @@ def top(**kwargs):
|
|||
minion_id = re.sub(re_pattern, re_replace, minion_id)
|
||||
|
||||
log.info(
|
||||
'ext_tops.mongo: looking up tops def for {{\'{0}\': \'{1}\'}} '
|
||||
'in mongo'.format(
|
||||
id_field, minion_id
|
||||
)
|
||||
'ext_tops.mongo: looking up tops def for {\'%s\': \'%s\'} in mongo',
|
||||
id_field, minion_id
|
||||
)
|
||||
|
||||
result = mdb[collection].find_one({id_field: minion_id}, projection=[states_field, environment_field])
|
||||
|
@ -138,9 +136,5 @@ def top(**kwargs):
|
|||
else:
|
||||
# If we can't find the minion the database it's not necessarily an
|
||||
# error.
|
||||
log.debug(
|
||||
'ext_tops.mongo: no document found in collection {0}'.format(
|
||||
collection
|
||||
)
|
||||
)
|
||||
log.debug('ext_tops.mongo: no document found in collection %s', collection)
|
||||
return {}
|
||||
|
|
|
@ -46,7 +46,7 @@ If you want to run reclass from source, rather than installing it, you can
|
|||
either let the master know via the ``PYTHONPATH`` environment variable, or by
|
||||
setting the configuration option, like in the example above.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# This file cannot be called reclass.py, because then the module import would
|
||||
# not work. Thanks to the __virtual__ function, however, the plugin still
|
||||
|
@ -60,6 +60,7 @@ from salt.utils.reclass import (
|
|||
)
|
||||
|
||||
from salt.exceptions import SaltInvocationError
|
||||
from salt.ext import six
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'reclass'
|
||||
|
@ -117,7 +118,7 @@ def top(**kwargs):
|
|||
return reclass_top(minion_id, **reclass_opts)
|
||||
|
||||
except ImportError as e:
|
||||
if 'reclass' in str(e):
|
||||
if 'reclass' in six.text_type(e):
|
||||
raise SaltInvocationError(
|
||||
'master_tops.reclass: cannot find reclass module '
|
||||
'in {0}'.format(sys.path)
|
||||
|
@ -126,8 +127,8 @@ def top(**kwargs):
|
|||
raise
|
||||
|
||||
except TypeError as e:
|
||||
if 'unexpected keyword argument' in str(e):
|
||||
arg = str(e).split()[-1]
|
||||
if 'unexpected keyword argument' in six.text_type(e):
|
||||
arg = six.text_type(e).split()[-1]
|
||||
raise SaltInvocationError(
|
||||
'master_tops.reclass: unexpected option: {0}'.format(arg)
|
||||
)
|
||||
|
@ -135,11 +136,11 @@ def top(**kwargs):
|
|||
raise
|
||||
|
||||
except KeyError as e:
|
||||
if 'reclass' in str(e):
|
||||
if 'reclass' in six.text_type(e):
|
||||
raise SaltInvocationError('master_tops.reclass: no configuration '
|
||||
'found in master config')
|
||||
else:
|
||||
raise
|
||||
|
||||
except ReclassException as e:
|
||||
raise SaltInvocationError('master_tops.reclass: {0}'.format(str(e)))
|
||||
raise SaltInvocationError('master_tops.reclass: {0}'.format(six.text_type(e)))
|
||||
|
|
|
@ -9,7 +9,7 @@ SaltClass master_tops Module
|
|||
'''
|
||||
|
||||
# import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
import salt.utils.saltclass as sc
|
||||
|
@ -45,7 +45,7 @@ def top(**kwargs):
|
|||
_opts = __opts__['master_tops']['saltclass']
|
||||
if 'path' not in _opts:
|
||||
path = '/srv/saltclass'
|
||||
log.warning('path variable unset, using default: {0}'.format(path))
|
||||
log.warning('path variable unset, using default: %s', path)
|
||||
else:
|
||||
path = _opts['path']
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ managed by salt as if given from a top.sls file.
|
|||
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ Simple Smoke Tests for Connected Proxy Minion
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ModuleCase
|
||||
|
|
|
@ -5,7 +5,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.case import ShellCase
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import logging
|
||||
|
||||
# Import salt tests libs
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import external libs
|
||||
try:
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import external libs
|
||||
try:
|
||||
|
|
|
@ -4,7 +4,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