[PY3] Add unicode_literals to cache and cli modules

This commit is contained in:
Erik Johnson 2018-01-05 11:13:46 -06:00
parent dcac4d4ce9
commit 685bfbbd3e
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F
23 changed files with 85 additions and 94 deletions

View File

@ -6,7 +6,7 @@ Loader mechanism for caching data, with data expiration, etc.
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
import time
@ -323,10 +323,10 @@ class MemCache(Cache):
if record is not None and record[0] + self.expire >= now:
if self.debug:
self.hit += 1
log.debug('MemCache stats (call/hit/rate): '
'{0}/{1}/{2}'.format(self.call,
self.hit,
float(self.hit) / self.call))
log.debug(
'MemCache stats (call/hit/rate): %s/%s/%s',
self.call, self.hit, float(self.hit) / self.call
)
# update atime and return
record[0] = now
self.storage[(bank, key)] = record

View File

@ -46,7 +46,7 @@ value to ``consul``:
.. _`python-consul documentation`: https://python-consul.readthedocs.io/en/latest/#consul
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
try:
import consul

View File

@ -48,7 +48,7 @@ value to ``etcd``:
.. _`python-etcd documentation`: http://python-etcd.readthedocs.io/en/latest/
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
try:
import etcd

View File

@ -10,7 +10,7 @@ require any configuration.
Expiration values can be set in the relevant config file (``/etc/salt/master`` for
the master, ``/etc/salt/cloud`` for Salt Cloud, etc).
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
import os
import os.path

View File

@ -43,7 +43,7 @@ value to ``mysql``:
.. _`python-mysql documentation`: http://python-mysql.readthedocs.io/en/latest/
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
from time import sleep
import logging
try:

View File

@ -132,7 +132,7 @@ Cluster Configuration Example:
cache.redis.separator: '@'
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import stdlib
import logging
@ -297,7 +297,7 @@ def _build_bank_hier(bank, redis_pipe):
for bank_name in bank_list[1:]:
prev_bank_redis_key = _get_bank_redis_key(parent_bank_path)
redis_pipe.sadd(prev_bank_redis_key, bank_name)
log.debug('Adding {bname} to {bkey}'.format(bname=bank_name, bkey=prev_bank_redis_key))
log.debug('Adding %s to %s', bank_name, prev_bank_redis_key)
parent_bank_path = '{curr_path}/{bank_name}'.format(
curr_path=parent_bank_path,
bank_name=bank_name
@ -341,13 +341,12 @@ def store(bank, key, data):
_build_bank_hier(bank, redis_pipe)
value = __context__['serial'].dumps(data)
redis_pipe.set(redis_key, value)
log.debug('Setting the value for {key} under {bank} ({redis_key})'.format(
key=key,
bank=bank,
redis_key=redis_key
))
log.debug(
'Setting the value for %s under %s (%s)',
key=key, bank=bank, redis_key=redis_key
)
redis_pipe.sadd(redis_bank_keys, key)
log.debug('Adding {key} to {bkey}'.format(key=key, bkey=redis_bank_keys))
log.debug('Adding %s to %s', key, redis_bank_keys)
redis_pipe.execute()
except (RedisConnectionError, RedisResponseError) as rerr:
mesg = 'Cannot set the Redis cache key {rkey}: {rerr}'.format(rkey=redis_key,
@ -405,10 +404,10 @@ def flush(bank, key=None):
bank_keys_redis_key = _get_bank_keys_redis_key(bank_to_remove)
# Redis key of the SET that stores the bank keys
redis_pipe.smembers(bank_keys_redis_key) # fetch these keys
log.debug('Fetching the keys of the {bpath} bank ({bkey})'.format(
bpath=bank_to_remove,
bkey=bank_keys_redis_key
))
log.debug(
'Fetching the keys of the %s bank (%s)',
bank_to_remove, bank_keys_redis_key
)
try:
log.debug('Executing the pipe...')
subtree_keys = redis_pipe.execute() # here are the keys under these banks to be removed
@ -430,41 +429,35 @@ def flush(bank, key=None):
for key in bank_keys:
redis_key = _get_key_redis_key(bank_path, key)
redis_pipe.delete(redis_key) # kill 'em all!
log.debug('Removing the key {key} under the {bpath} bank ({bkey})'.format(
key=key,
bpath=bank_path,
bkey=redis_key
))
log.debug(
'Removing the key %s under the %s bank (%s)',
key, bank_path, redis_key
)
bank_keys_redis_key = _get_bank_keys_redis_key(bank_path)
redis_pipe.delete(bank_keys_redis_key)
log.debug('Removing the bank-keys key for the {bpath} bank ({bkey})'.format(
bpath=bank_path,
bkey=bank_keys_redis_key
))
log.debug(
'Removing the bank-keys key for the %s bank (%s)',
bank_path, bank_keys_redis_key
)
# delete the Redis key where are stored
# the list of keys under this bank
bank_key = _get_bank_redis_key(bank_path)
redis_pipe.delete(bank_key)
log.debug('Removing the {bpath} bank ({bkey})'.format(
bpath=bank_path,
bkey=bank_key
))
log.debug('Removing the %s bank (%s)', bank_path, bank_key)
# delete the bank key itself
else:
redis_key = _get_key_redis_key(bank, key)
redis_pipe.delete(redis_key) # delete the key cached
log.debug('Removing the key {key} under the {bank} bank ({bkey})'.format(
key=key,
bank=bank,
bkey=redis_key
))
log.debug(
'Removing the key %s under the %s bank (%s)',
key, bank, redis_key
)
bank_keys_redis_key = _get_bank_keys_redis_key(bank)
redis_pipe.srem(bank_keys_redis_key, key)
log.debug('De-referencing the key {key} from the bank-keys of the {bank} bank ({bkey})'.format(
key=key,
bank=bank,
bkey=bank_keys_redis_key
))
log.debug(
'De-referencing the key %s from the bank-keys of the %s bank (%s)',
key, bank, bank_keys_redis_key
)
# but also its reference from $BANKEYS list
try:
redis_pipe.execute() # Fluuuush

View File

@ -8,7 +8,7 @@
'''
# Import Python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
import logging

View File

@ -4,7 +4,7 @@ Execute batch runs
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import math
import time
import copy
@ -273,7 +273,10 @@ class Batch(object):
out,
self.opts)
if failhard:
log.error('ERROR: Minion {} returned with non-zero exit code. Batch run stopped due to failhard'.format(minion))
log.error(
'Minion %s returned with non-zero exit code. '
'Batch run stopped due to failhard', minion
)
raise StopIteration
# remove inactive iterators from the iters list

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
import salt.utils.parsers

View File

@ -5,7 +5,7 @@ minion modules.
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
import sys
@ -101,7 +101,7 @@ class BaseCaller(object):
try:
self.minion = salt.minion.SMinion(opts)
except SaltClientError as exc:
raise SystemExit(str(exc))
raise SystemExit(six.text_type(exc))
def print_docs(self):
'''
@ -230,11 +230,11 @@ class BaseCaller(object):
self.opts['log_level'].lower(), logging.ERROR)
if active_level <= logging.DEBUG:
sys.stderr.write(traceback.format_exc())
sys.stderr.write(msg.format(fun, str(exc)))
sys.stderr.write(msg.format(fun, exc))
sys.exit(salt.defaults.exitcodes.EX_GENERIC)
except CommandNotFoundError as exc:
msg = 'Command required for \'{0}\' not found: {1}\n'
sys.stderr.write(msg.format(fun, str(exc)))
sys.stderr.write(msg.format(fun, exc))
sys.exit(salt.defaults.exitcodes.EX_GENERIC)
try:
os.remove(proc_fn)
@ -420,7 +420,7 @@ class RAETCaller(BaseCaller):
name='manor',
lanename=lanename,
dirpath=sockdirpath))
log.debug("Created Caller Jobber Stack {0}\n".format(stack.name))
log.debug("Created Caller Jobber Stack %s\n", stack.name)
return stack

View File

@ -7,8 +7,7 @@ Salt-cp can be used to distribute configuration files
'''
# Import python libs
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import base64
import errno
import logging
@ -272,7 +271,7 @@ class SaltCP(object):
log.debug(
'Creating empty dir %s on %starget \'%s\'',
dirname,
'{0} '.format(selected_target_option)
'{0} '.format(selected_target_option) # pylint: disable=str-format-in-logging
if selected_target_option
else '',
tgt,

View File

@ -4,7 +4,7 @@ Make me some salt!
'''
# Import python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import os
import warnings
from salt.utils.verify import verify_log
@ -69,9 +69,11 @@ class DaemonsMixin(object): # pylint: disable=no-init
:return:
'''
if self.config['hash_type'].lower() in ['md5', 'sha1']:
log.warning('IMPORTANT: Do not use {h_type} hashing algorithm! Please set "hash_type" to '
'sha256 in Salt {d_name} config!'.format(
h_type=self.config['hash_type'], d_name=self.__class__.__name__))
log.warning(
'IMPORTANT: Do not use %s hashing algorithm! Please set '
'"hash_type" to sha256 in Salt %s config!',
self.config['hash_type'], self.__class__.__name__
)
def action_log_info(self, action):
'''
@ -80,7 +82,7 @@ class DaemonsMixin(object): # pylint: disable=no-init
:param action
:return:
'''
log.info('{action} the Salt {d_name}'.format(d_name=self.__class__.__name__, action=action))
log.info('%s the Salt %s', self.__class__.__name__, action)
def start_log_info(self):
'''
@ -88,7 +90,7 @@ class DaemonsMixin(object): # pylint: disable=no-init
:return:
'''
log.info('The Salt {d_name} is starting up'.format(d_name=self.__class__.__name__))
log.info('The Salt %s is starting up', self.__class__.__name__)
def shutdown_log_info(self):
'''
@ -96,7 +98,7 @@ class DaemonsMixin(object): # pylint: disable=no-init
:return:
'''
log.info('The Salt {d_name} is shut down'.format(d_name=self.__class__.__name__))
log.info('The Salt %s is shut down', self.__class__.__name__)
def environment_failure(self, error):
'''
@ -105,8 +107,10 @@ class DaemonsMixin(object): # pylint: disable=no-init
:param error:
:return:
'''
log.exception('Failed to create environment for {d_name}: {reason}'.format(
d_name=self.__class__.__name__, reason=get_error_message(error)))
log.exception(
'Failed to create environment for %s: %s',
self.__class__.__name__, get_error_message(error)
)
self.shutdown(error)
@ -290,11 +294,7 @@ class Minion(salt.utils.parsers.MinionOptionParser, DaemonsMixin): # pylint: di
self.setup_logfile_logger()
verify_log(self.config)
log.info(
'Setting up the Salt Minion "{0}"'.format(
self.config['id']
)
)
log.info('Setting up the Salt Minion "%s"', self.config['id'])
migrations.migrate_paths(self.config)
# Bail out if we find a process running and it matches out pidfile
@ -324,10 +324,8 @@ class Minion(salt.utils.parsers.MinionOptionParser, DaemonsMixin): # pylint: di
self.minion = salt.daemons.flo.IofloMinion(self.config)
else:
log.error(
'The transport \'{0}\' is not supported. Please use one of the following: '
'tcp, '
'raet, '
'or zeromq.'.format(transport)
'The transport \'%s\' is not supported. Please use one of '
'the following: tcp, raet, or zeromq.', transport
)
self.shutdown(1)
@ -355,7 +353,7 @@ class Minion(salt.utils.parsers.MinionOptionParser, DaemonsMixin): # pylint: di
log.warning('Exiting on Ctrl-c')
self.shutdown()
else:
log.error(str(error))
log.error(error)
self.shutdown(error.code)
def call(self, cleanup_protecteds):
@ -383,7 +381,7 @@ class Minion(salt.utils.parsers.MinionOptionParser, DaemonsMixin): # pylint: di
log.warning('Exiting on Ctrl-c')
self.shutdown()
else:
log.error(str(exc))
log.error(exc)
self.shutdown(exc.code)
def shutdown(self, exitcode=0, exitmsg=None):
@ -531,7 +529,7 @@ class ProxyMinion(salt.utils.parsers.ProxyMinionOptionParser, DaemonsMixin): #
log.warning('Exiting on Ctrl-c')
self.shutdown()
else:
log.error(str(exc))
log.error(exc)
self.shutdown(exc.code)
# def call(self, cleanup_protecteds):

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import salt.utils.parsers

View File

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import salt.utils.parsers
import salt.utils.profile
from salt.utils.verify import check_user, verify_log
from salt.exceptions import SaltClientError
from salt.ext import six
import salt.defaults.exitcodes # pylint: disable=W0611
@ -55,4 +55,4 @@ class SaltRun(salt.utils.parsers.SaltRunOptionParser):
stop=True)
except SaltClientError as exc:
raise SystemExit(str(exc))
raise SystemExit(six.text_type(exc))

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import sys
sys.modules['pkg_resources'] = None
import os
@ -211,7 +211,7 @@ class SaltCMD(salt.utils.parsers.SaltCMDOptionParser):
sys.exit(11)
except (SaltInvocationError, EauthAuthenticationError, SaltClientError) as exc:
ret = str(exc)
ret = six.text_type(exc)
self._output_ret(ret, '', retcode=1)
def _preview_target(self):

View File

@ -9,7 +9,7 @@
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt libs
import salt.spm

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import sys
import salt.client.ssh
import salt.utils.parsers

View File

@ -3,7 +3,7 @@
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
'''
# 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

View File

@ -35,7 +35,7 @@
$ python tests/runtests.py -C --ssh
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import test Libs
from tests.support.case import SSHCase

View File

@ -13,7 +13,7 @@
localhost
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import os
# Import Salt Libs

View File

@ -4,7 +4,7 @@ unit tests for the localfs cache
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing libs
# import integration

View File

@ -4,7 +4,7 @@ unit tests for the localfs cache
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import shutil
import tempfile
@ -95,7 +95,7 @@ class LocalFSTest(TestCase, LoaderModuleMockMixin):
# Read in the contents of the key.p file and assert "payload data" was written
with salt.utils.files.fopen(tmp_dir + '/bank/key.p', 'rb') as fh_:
for line in fh_:
self.assertIn(six.b('payload data'), line)
self.assertIn(six.b(str('payload data')), line) # future lint: disable=blacklisted-function
# 'fetch' function tests: 3

View File

@ -4,7 +4,7 @@
'''
# Import python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Libs
from salt.cli.batch import Batch