Add unicode_literals to runner modules

This commit is contained in:
Erik Johnson 2017-12-14 19:21:00 -06:00
parent 3ed7a29c56
commit 5adf852615
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F
57 changed files with 217 additions and 213 deletions

View file

@ -28,16 +28,17 @@ master configuration at ``/etc/salt/master`` or ``/etc/salt/master.d/asam.conf``
is not using the defaults. Default is ``protocol: https`` and ``port: 3451``.
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
# Import Python libs
import logging
# Import third party libs
# Import 3rd-party libs
import salt.ext.six as six
HAS_LIBS = False
try:
import requests
import salt.ext.six as six
from salt.ext.six.moves.html_parser import HTMLParser # pylint: disable=E0611
HAS_LIBS = True
@ -90,8 +91,8 @@ def _get_asam_configuration(driver_url=''):
if not username or not password:
log.error(
"Username or Password has not been specified in the master "
"configuration for {0}".format(asam_server)
'Username or Password has not been specified in the '
'master configuration for %s', asam_server
)
return False
@ -107,15 +108,13 @@ def _get_asam_configuration(driver_url=''):
if (not driver_url) or (driver_url == asam_server):
return ret
except Exception as exc:
log.error(
"Exception encountered: {0}".format(exc)
)
log.error('Exception encountered: %s', exc)
return False
if driver_url:
log.error(
"Configuration for {0} has not been specified in the master "
"configuration".format(driver_url)
'Configuration for %s has not been specified in the master '
'configuration', driver_url
)
return False
@ -205,7 +204,7 @@ def remove_platform(name, server_url):
html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc:
err_msg = "Failed to look up existing platforms on {0}".format(server_url)
log.error("{0}:\n{1}".format(err_msg, exc))
log.error('%s:\n%s', err_msg, exc)
return {name: err_msg}
parser = _parse_html_content(html_content)
@ -214,14 +213,14 @@ def remove_platform(name, server_url):
if platformset_name:
log.debug(platformset_name)
data['platformName'] = name
data['platformSetName'] = str(platformset_name)
data['platformSetName'] = six.text_type(platformset_name)
data['postType'] = 'platformRemove'
data['Submit'] = 'Yes'
try:
html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc:
err_msg = "Failed to delete platform from {1}".format(server_url)
log.error("{0}:\n{1}".format(err_msg, exc))
log.error('%s:\n%s', err_msg, exc)
return {name: err_msg}
parser = _parse_html_content(html_content)
@ -263,7 +262,7 @@ def list_platforms(server_url):
html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc:
err_msg = "Failed to look up existing platforms"
log.error("{0}:\n{1}".format(err_msg, exc))
log.error('%s:\n%s', err_msg, exc)
return {server_url: err_msg}
parser = _parse_html_content(html_content)
@ -304,7 +303,7 @@ def list_platform_sets(server_url):
html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc:
err_msg = "Failed to look up existing platform sets"
log.error("{0}:\n{1}".format(err_msg, exc))
log.error('%s:\n%s', err_msg, exc)
return {server_url: err_msg}
parser = _parse_html_content(html_content)
@ -359,7 +358,7 @@ def add_platform(name, platform_set, server_url):
html_content = _make_post_request(url, data, auth, verify=False)
except Exception as exc:
err_msg = "Failed to add platform on {0}".format(server_url)
log.error("{0}:\n{1}".format(err_msg, exc))
log.error('%s:\n%s', err_msg, exc)
return {name: err_msg}
platforms = list_platforms(server_url)

View file

@ -7,7 +7,7 @@ Authentication runner for creating, deleting, and managing eauth tokens.
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import os
# Import Salt libs

View file

@ -97,9 +97,7 @@ Configuration
- flap_count
outputter: yaml
'''
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import absolute_import, print_function, unicode_literals
# Import third party libs
try:
@ -335,7 +333,7 @@ def neighbors(*asns, **kwargs):
title_parts = []
if asns:
title_parts.append('BGP Neighbors for {asns}'.format(
asns=', '.join([str(asn) for asn in asns])
asns=', '.join([six.text_type(asn) for asn in asns])
))
if neighbor_ip:
title_parts.append('Selecting neighbors having the remote IP address: {ipaddr}'.format(ipaddr=neighbor_ip))

View file

@ -2,7 +2,7 @@
'''
Return cached data from minions
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import fnmatch
import logging

View file

@ -6,7 +6,7 @@ The Salt Cloud Runner
This runner wraps the functionality of salt cloud making salt cloud routines
available to all internal apis via the runner system
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import logging

View file

@ -3,7 +3,7 @@
This runner is designed to mirror the execution module config.py, but for
master settings
'''
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import salt.utils.data
import salt.utils.sdb

View file

@ -10,7 +10,7 @@ Runner to interact with DNS server and create/delete/update DNS records
:codeauthor: Nitin Madhok <nmadhok@clemson.edu>
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import os

View file

@ -35,7 +35,7 @@ This API currently only supports RSA key types. Support for other key types wil
if interest warrants.
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import os
import logging
import tempfile
@ -569,7 +569,7 @@ def gen_csr(
tmppriv = '{0}/priv'.format(tmpdir)
tmpcsr = '{0}/csr'.format(tmpdir)
with salt.utils.files.fopen(tmppriv, 'w') as if_:
if_.write(data['private_key'])
if_.write(salt.utils.stringutils.to_str(data['private_key']))
subject = '/C={0}/ST={1}/L={2}/O={3}'.format(
org_details['dict']['country'],
@ -597,7 +597,7 @@ def gen_csr(
)
with salt.utils.files.fopen(tmpcsr, 'r') as of_:
csr = of_.read()
csr = salt.utils.stringutils.to_unicode(of_.read())
data['minion_id'] = minion_id
data['csr'] = csr
@ -643,7 +643,7 @@ def show_organization(domain):
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -670,7 +670,7 @@ def show_csrs():
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)

View file

@ -4,7 +4,7 @@ A runner module to collect and display the inline documentation from the
various module types
'''
# Import Python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import itertools
# Import salt libs

View file

@ -14,7 +14,7 @@ configuration file.
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import logging
# Import 3rd-party libs
@ -60,7 +60,7 @@ def __connect(hostname, timeout=20, username=None, password=None):
try:
client.connect(hostname, username=username, password=password, timeout=timeout)
except Exception as e:
log.error('Unable to connect to {0}: {1}'.format(hostname, e))
log.error('Unable to connect to %s: %s', hostname, e)
return False
return client
@ -108,14 +108,14 @@ def pxe(hostname, timeout=20, username=None, password=None):
if isinstance(client, paramiko.SSHClient):
for i, cmd in enumerate(_cmds, 1):
log.info('Executing command {0}'.format(i))
log.info('Executing command %s', i)
(stdin, stdout, stderr) = client.exec_command(cmd)
if 'successful' in stdout.readline():
log.info('Executing command: {0}'.format(cmd))
log.info('Executing command: %s', cmd)
else:
log.error('Unable to execute: {0}'.format(cmd))
log.error('Unable to execute: %s', cmd)
return False
return True

View file

@ -3,7 +3,7 @@
Error generator to enable integration testing of salt runner error handling
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs

View file

@ -4,7 +4,7 @@ Module for sending events using the runner system.
.. versionadded:: 2016.11.0
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging

View file

@ -17,7 +17,7 @@ Runner to provide F5 Load Balancer functionality
username: admin
password: secret
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
from salt.exceptions import CommandExecutionError

View file

@ -2,7 +2,7 @@
'''
Directly manage the Salt fileserver plugins
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt libs
import salt.fileserver

View file

@ -2,7 +2,7 @@
'''
Runner module to directly manage the git external pillar
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import logging
@ -83,8 +83,8 @@ def update(branch=None, repo=None):
result = remote.fetch()
except Exception as exc:
log.error(
'Exception \'{0}\' caught while fetching git_pillar '
'remote \'{1}\''.format(exc, remote.id),
'Exception \'%s\' caught while fetching git_pillar '
'remote \'%s\'', exc, remote.id,
exc_info_on_loglevel=logging.DEBUG
)
result = False

View file

@ -5,7 +5,7 @@ like, but also useful for basic http testing.
.. versionadded:: 2015.5.0
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Python libs
import logging

View file

@ -4,7 +4,7 @@ A convenience system to manage jobs, both active and already run
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import fnmatch
import logging
import os

View file

@ -2,7 +2,7 @@
'''
Manage launchd plist files
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import os

View file

@ -6,7 +6,7 @@ Control Linux Containers via Salt
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import time
import os
import copy
@ -17,6 +17,7 @@ import salt.client
import salt.utils.args
import salt.utils.cloud
import salt.utils.files
import salt.utils.stringutils
import salt.utils.virt
import salt.key
from salt.utils.odict import OrderedDict as _OrderedDict
@ -267,10 +268,10 @@ def init(names, host=None, saltcloud_mode=False, quiet=False, **kwargs):
for host, containers in six.iteritems(data):
for name in names:
if name in sum(six.itervalues(containers), []):
log.info('Container \'{0}\' already exists'
' on host \'{1}\','
' init can be a NO-OP'.format(
name, host))
log.info(
'Container \'%s\' already exists on host \'%s\', init '
'can be a NO-OP', name, host
)
if host not in data:
ret['comment'] = 'Host \'{0}\' was not found'.format(host)
ret['result'] = False
@ -303,8 +304,7 @@ def init(names, host=None, saltcloud_mode=False, quiet=False, **kwargs):
ret['result'] = False
return ret
log.info('Creating container(s) \'{0}\''
' on host \'{1}\''.format(names, host))
log.info('Creating container(s) \'%s\' on host \'%s\'', names, host)
cmds = []
for name in names:
@ -374,10 +374,11 @@ def init(names, host=None, saltcloud_mode=False, quiet=False, **kwargs):
fcontent = ''
if os.path.exists(key):
with salt.utils.files.fopen(key) as fic:
fcontent = fic.read().strip()
fcontent = salt.utils.stringutils.to_unicode(fic.read()).strip()
pub_key = salt.utils.stringutils.to_unicode(pub_key)
if pub_key.strip() != fcontent:
with salt.utils.files.fopen(key, 'w') as fic:
fic.write(pub_key)
fic.write(salt.utils.stringutils.to_str(pub_key))
fic.flush()
mid = j_ret.get('mid', None)
if not mid:

View file

@ -5,7 +5,7 @@ and what hosts are down
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
import operator
import re
@ -816,7 +816,7 @@ def bootstrap(version='develop',
client_opts['argv'] = ['file.remove', tmp_dir]
salt.client.ssh.SSH(client_opts).run()
except SaltSystemExit as exc:
log.error(str(exc))
log.error(six.text_type(exc))
def bootstrap_psexec(hosts='', master=None, version=None, arch='win32',

View file

@ -16,7 +16,7 @@ Module for sending messages to Mattermost
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import json
import logging
@ -128,7 +128,7 @@ def post_message(message,
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)))
@ -168,8 +168,8 @@ def post_event(event,
if not event:
log.error('message is a required option.')
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)

View file

@ -2,7 +2,7 @@
'''
A runner to access data from the salt mine
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Python Libs
import logging

View file

@ -151,7 +151,7 @@ Optional small program to encrypt data without needing salt modules.
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import base64
import os
@ -162,6 +162,8 @@ import salt.utils.win_functions
import salt.utils.win_dacl
import salt.syspaths
# Import 3rd-party libs
from salt.ext import six
REQ_ERROR = None
try:
@ -209,7 +211,7 @@ def _get_sk(**kwargs):
sk_file = config['sk_file']
if not key and sk_file:
with salt.utils.files.fopen(sk_file, 'rb') as keyf:
key = str(keyf.read()).rstrip('\n')
key = six.text_type(keyf.read()).rstrip('\n')
if key is None:
raise Exception('no key or sk_file found')
return base64.b64decode(key)
@ -224,10 +226,10 @@ def _get_pk(**kwargs):
pk_file = config['pk_file']
if not pubkey and pk_file:
with salt.utils.files.fopen(pk_file, 'rb') as keyf:
pubkey = str(keyf.read()).rstrip('\n')
pubkey = six.text_type(keyf.read()).rstrip('\n')
if pubkey is None:
raise Exception('no pubkey or pk_file found')
pubkey = str(pubkey)
pubkey = six.text_type(pubkey)
return base64.b64decode(pubkey)
@ -283,7 +285,7 @@ def keygen(sk_file=None, pk_file=None):
if os.path.isfile(sk_file) and not os.path.isfile(pk_file):
# generate pk using the sk
with salt.utils.files.fopen(sk_file, 'rb') as keyf:
sk = str(keyf.read()).rstrip('\n')
sk = six.text_type(keyf.read()).rstrip('\n')
sk = base64.b64decode(sk)
kp = libnacl.public.SecretKey(sk)
with salt.utils.files.fopen(pk_file, 'w') as keyf:

View file

@ -68,10 +68,7 @@ Configuration
- fxp0
outputter: yaml
'''
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import absolute_import, print_function, unicode_literals
# Import salt lib
import salt.output
@ -340,7 +337,7 @@ def interfaces(device=None,
if device:
title += ' on device {0}'.format(device)
if ipnet:
title += ' that include network {net}'.format(net=str(ipnet))
title += ' that include network {net}'.format(net=six.text_type(ipnet))
if best:
title += ' - only best match returned'
@ -403,7 +400,7 @@ def interfaces(device=None,
interf_entry['ips'] = '\n'.join(interf_entry['ips'])
if ipnet:
inet_ips = [
str(ip) for ip in ips if _ipnet_belongs(ip)
six.text_type(ip) for ip in ips if _ipnet_belongs(ip)
] # filter and get only IP include ipnet
if inet_ips: # if any
if best:
@ -600,7 +597,7 @@ def findmac(device=None, mac=None, interface=None, vlan=None, display=_DEFAULT_D
napalm_helpers.convert(napalm_helpers.mac, mac_entry.get('mac', '')) ==
napalm_helpers.convert(napalm_helpers.mac, mac)) or
(interface and interface in mac_entry.get('interface', '')) or
(vlan and str(mac_entry.get('vlan', '')) == str(vlan))):
(vlan and six.text_type(mac_entry.get('vlan', '')) == six.text_type(vlan))):
rows.append({
'device': device,
'interface': mac_entry.get('interface'),

View file

@ -4,14 +4,14 @@ Network tools to run from the Master
'''
# Import python libs
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
import socket
# Import salt libs
import salt.utils.files
import salt.utils.network
import salt.utils.stringutils
log = logging.getLogger(__name__)
@ -33,8 +33,9 @@ def wollist(maclist, bcast='255.255.255.255', destport=9):
try:
with salt.utils.files.fopen(maclist, 'r') as ifile:
for mac in ifile:
wol(mac.strip(), bcast, destport)
print('Waking up {0}'.format(mac.strip()))
mac = salt.utils.stringutils.to_unicode(mac).strip()
wol(mac, bcast, destport)
print('Waking up {0}'.format(mac))
ret.append(mac)
except Exception as err:
__jid_event__.fire_event({'error': 'Failed to open the MAC file. Error: {0}'.format(err)}, 'progress')
@ -78,7 +79,8 @@ def wolmatch(tgt, tgt_type='glob', bcast='255.255.255.255', destport=9):
for iface, mac in minion['hwaddr_interfaces'].items():
if iface == 'lo':
continue
mac = mac.strip()
wol(mac, bcast, destport)
log.info('Waking up {0}'.format(mac.strip()))
log.info('Waking up %s', mac)
ret.append(mac)
return ret

View file

@ -15,7 +15,7 @@ Runner Module for Firing Events via PagerDuty
pagerduty.api_key: F3Rbyjbve43rfFWf2214
pagerduty.subdomain: mysubdomain
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import yaml
@ -24,7 +24,7 @@ import json
# Import salt libs
import salt.utils.functools
import salt.utils.pagerduty
from salt.ext.six import string_types
from salt.ext import six
def __virtual__():
@ -175,9 +175,9 @@ def create_event(service_key=None, description=None, details=None,
'''
trigger_url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json'
if isinstance(details, string_types):
if isinstance(details, six.string_types):
details = yaml.safe_load(details)
if isinstance(details, string_types):
if isinstance(details, six.string_types):
details = {'details': details}
ret = json.loads(salt.utils.pagerduty.query(

View file

@ -2,7 +2,7 @@
'''
Functions to interact with the pillar compiler on the master
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
import salt.pillar

View file

@ -6,7 +6,7 @@ Package helper functions using ``salt.modules.pkg``
'''
# Import python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
import salt.output

View file

@ -63,8 +63,7 @@ still running from the last time the process_runner task was executed.
'''
# Import python libs
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
import salt.loader

View file

@ -3,7 +3,7 @@
A convenience system to manage reactors
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import logging
# Import salt libs

View file

@ -30,8 +30,7 @@ Execution modules are also available to salt runners:
'''
# import python libs
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, print_function, unicode_literals
import logging
# import salt libs
@ -121,9 +120,7 @@ def execute(tgt,
kwarg=kwarg,
**kwargs)
except SaltClientError as client_error:
log.error('Error while executing {fun} on {tgt} ({tgt_type})'.format(fun=fun,
tgt=tgt,
tgt_type=tgt_type))
log.error('Error while executing %s on %s (%s)', fun, tgt, tgt_type)
log.error(client_error)
return {}
return ret

View file

@ -6,7 +6,7 @@ managing updates to minions.
.. versionadded:: 2016.3.0
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import logging

View file

@ -2,7 +2,7 @@
'''
Runner for setting and querying data via the sdb API on the master
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
import salt.utils.sdb

View file

@ -3,8 +3,7 @@
Runner for SmartOS minions control vmadm
'''
# Import python libs
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
import salt.client

View file

@ -29,7 +29,7 @@ master configuration at ``/etc/salt/master`` or ``/etc/salt/master.d/spacewalk.c
not using the defaults. Default is ``protocol: https``.
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import atexit
@ -70,7 +70,7 @@ def _get_spacewalk_configuration(spacewalk_url=''):
if not username or not password:
log.error(
'Username or Password has not been specified in the master '
'configuration for {0}'.format(spacewalk_server)
'configuration for %s', spacewalk_server
)
return False
@ -83,15 +83,13 @@ def _get_spacewalk_configuration(spacewalk_url=''):
if (not spacewalk_url) or (spacewalk_url == spacewalk_server):
return ret
except Exception as exc:
log.error(
'Exception encountered: {0}'.format(exc)
)
log.error('Exception encountered: %s', exc)
return False
if spacewalk_url:
log.error(
'Configuration for {0} has not been specified in the master '
'configuration'.format(spacewalk_url)
'Configuration for %s has not been specified in the master '
'configuration', spacewalk_url
)
return False

View file

@ -6,7 +6,7 @@ This allows for programmatic use from salt-api, the Reactor, Orchestrate, etc.
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Libs
import salt.client.ssh.client

View file

@ -3,7 +3,7 @@
Execute orchestration functions
'''
# Import pytohn libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import logging
# Import salt libs

View file

@ -13,7 +13,7 @@ when identifying discrepancies in a large infrastructure managed by salt.
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
import salt.client
@ -101,7 +101,7 @@ def diff(*args, **kwargs):
print(k['pool'])
print('pool size :\n'
'----------')
print(' ' + str(len(k['pool'])))
print(' ' + six.text_type(len(k['pool'])))
if is_first_time:
is_first_time = False
print('pool result :\n'
@ -171,11 +171,11 @@ def _get_pool_results(*args, **kwargs):
# hash minion return values as a string
for minion in sorted(minions):
digest = hashlib.sha256(str(minions[minion]).encode(__salt_system_encoding__)).hexdigest()
digest = hashlib.sha256(six.text_type(minions[minion]).encode(__salt_system_encoding__)).hexdigest()
if digest not in ret:
ret[digest] = {}
ret[digest]['pool'] = []
ret[digest]['result'] = str(minions[minion])
ret[digest]['result'] = six.text_type(minions[minion])
ret[digest]['pool'].append(minion)

View file

@ -2,8 +2,7 @@
'''
This runner is used only for test purposes and servers no production purpose
'''
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, print_function, unicode_literals
# Import python libs
import time
from salt.ext import six

View file

@ -8,8 +8,7 @@ system for easy consumption.
'''
# Import python libs
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt libs
import salt.utils.thin

View file

@ -7,16 +7,19 @@
Runner functions supporting the Vault modules. Configuration instructions are
documented in the execution module docs.
'''
from __future__ import absolute_import
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import base64
import logging
import string
import requests
# Import Salt libs
import salt.crypt
import salt.exceptions
# Import 3rd-party libs
from salt.ext import six
log = logging.getLogger(__name__)
@ -36,8 +39,10 @@ def generate_token(minion_id, signature, impersonated_by_master=False):
If the master needs to create a token on behalf of the minion, this is
True. This happens when the master generates minion pillars.
'''
log.debug('Token generation request for {0} (impersonated by master: {1})'.
format(minion_id, impersonated_by_master))
log.debug(
'Token generation request for %s (impersonated by master: %s)'.
minion_id, impersonated_by_master
)
_validate_signature(minion_id, signature, impersonated_by_master)
try:
@ -83,7 +88,7 @@ def generate_token(minion_id, signature, impersonated_by_master=False):
'verify': verify,
}
except Exception as e:
return {'error': str(e)}
return {'error': six.text_type(e)}
def show_policies(minion_id):
@ -114,7 +119,7 @@ def _validate_signature(minion_id, signature, impersonated_by_master):
else:
public_key = '{0}/minions/{1}'.format(pki_dir, minion_id)
log.trace('Validating signature for {0}'.format(minion_id))
log.trace('Validating signature for %s', minion_id)
signature = base64.b64decode(signature)
if not salt.crypt.verify_signature(public_key, minion_id, signature):
raise salt.exceptions.AuthenticationError(
@ -143,9 +148,9 @@ def _get_policies(minion_id, config):
.lower() # Vault requirement
)
except KeyError:
log.warning('Could not resolve policy pattern {0}'.format(pattern))
log.warning('Could not resolve policy pattern %s', pattern)
log.debug('{0} policies: {1}'.format(minion_id, policies))
log.debug('%s policies: %s', minion_id, policies)
return policies
@ -191,7 +196,7 @@ def _expand_pattern_lists(pattern, **mappings):
(value, _) = f.get_field(field_name, None, mappings)
if isinstance(value, list):
token = '{{{0}}}'.format(field_name)
expanded = [pattern.replace(token, str(elem)) for elem in value]
expanded = [pattern.replace(token, six.text_type(elem)) for elem in value]
for expanded_item in expanded:
result = _expand_pattern_lists(expanded_item, **mappings)
expanded_patterns += result
@ -215,5 +220,5 @@ def _selftoken_expired():
return False
except Exception as e:
raise salt.exceptions.CommandExecutionError(
'Error while looking up self token : {0}'.format(str(e))
'Error while looking up self token : {0}'.format(six.text_type(e))
)

View file

@ -29,18 +29,23 @@ file and set the ``api_key`` to it:
venafi:
api_key: abcdef01-2345-6789-abcd-ef0123456789
'''
from __future__ import absolute_import
import os
from __future__ import absolute_import, print_function, unicode_literals
import json
import logging
import os
import tempfile
from Crypto.PublicKey import RSA
import json
import salt.syspaths as syspaths
# Import Salt libs
import salt.cache
import salt.syspaths as syspaths
import salt.utils.files
from salt.ext import six
import salt.utils.stringutils
from salt.exceptions import CommandExecutionError
# Import 3rd-party libs
from salt.ext import six
__virtualname__ = 'venafi'
log = logging.getLogger(__name__)
@ -189,7 +194,7 @@ def gen_csr(
tmppriv = '{0}/priv'.format(tmpdir)
tmpcsr = '{0}/csr'.format(tmpdir)
with salt.utils.files.fopen(tmppriv, 'w') as if_:
if_.write(data['private_key'])
if_.write(salt.utils.stringutils.to_str(data['private_key']))
if country is None:
country = __opts__.get('venafi', {}).get('country')
@ -233,7 +238,7 @@ def gen_csr(
)
with salt.utils.files.fopen(tmpcsr, 'r') as of_:
csr = of_.read()
csr = salt.utils.stringutils.to_unicode(of_.read())
data['minion_id'] = minion_id
data['csr'] = csr
@ -386,7 +391,7 @@ def register(email):
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -413,7 +418,7 @@ def show_company(domain):
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -440,7 +445,7 @@ def show_csrs():
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -468,7 +473,7 @@ def get_zone_id(zone_name):
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -495,7 +500,7 @@ def show_policies():
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -522,7 +527,7 @@ def show_zones():
},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -550,7 +555,7 @@ def show_cert(id_):
header_dict={'tppl-api-key': _api_key()},
)
status = data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(data['error'])
)
@ -563,7 +568,7 @@ def show_cert(id_):
header_dict={'tppl-api-key': _api_key()},
)
status = csr_data['status']
if str(status).startswith('4') or str(status).startswith('5'):
if six.text_type(status).startswith('4') or six.text_type(status).startswith('5'):
raise CommandExecutionError(
'There was an API error: {0}'.format(csr_data['error'])
)

View file

@ -4,15 +4,16 @@ Control virtual machines via Salt
'''
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os.path
import logging
# Import Salt libs
import salt.client
import salt.utils.files
import salt.utils.cloud
import salt.key
import salt.utils.cloud
import salt.utils.files
import salt.utils.stringutils
from salt.exceptions import SaltClientError
# Import 3rd-party libs
@ -246,7 +247,7 @@ def init(
priv_key, pub_key = salt.utils.cloud.gen_keys()
accepted_key = os.path.join(__opts__['pki_dir'], 'minions', name)
with salt.utils.files.fopen(accepted_key, 'w') as fp_:
fp_.write(pub_key)
fp_.write(salt.utils.stringutils.to_str(pub_key))
client = salt.client.get_local_client(__opts__['conf_file'])
@ -405,7 +406,7 @@ def purge(name, delete_key=True):
ret.update(comp)
if delete_key:
log.debug('Deleting key {0}'.format(name))
log.debug('Deleting key %s', name)
skey = salt.key.Key(__opts__)
skey.delete_key(name)
__jid_event__.fire_event({'message': 'Purged VM {0}'.format(name)}, 'progress')

View file

@ -20,7 +20,7 @@ For example ``/etc/salt/master.d/_vistara.conf``:
'''
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
# Import Python libs
import json

View file

@ -7,7 +7,7 @@ Runner to manage Windows software repo
# salt/modules/win_repo.py
# Import python libs
from __future__ import absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals
import os
# Import third party libs
@ -79,37 +79,32 @@ def genrepo(opts=None, fire_event=True):
)
except SaltRenderError as exc:
log.debug(
'Failed to render {0}.'.format(
os.path.join(root, name)
)
'Failed to render %s.',
os.path.join(root, name)
)
log.debug('Error: {0}.'.format(exc))
log.debug('Error: %s.', exc)
continue
if config:
revmap = {}
for pkgname, versions in six.iteritems(config):
log.debug(
'Compiling winrepo data for package \'{0}\''
.format(pkgname)
'Compiling winrepo data for package \'%s\'',
pkgname
)
for version, repodata in six.iteritems(versions):
log.debug(
'Compiling winrepo data for {0} version {1}'
.format(pkgname, version)
'Compiling winrepo data for %s version %s',
pkgname, version
)
if not isinstance(version, six.string_types):
config[pkgname][str(version)] = \
config[pkgname][six.text_type(version)] = \
config[pkgname].pop(version)
if not isinstance(repodata, dict):
log.debug(
'Failed to compile {0}.'.format(
os.path.join(root, name)
)
msg = 'Failed to compile {0}.'.format(
os.path.join(root, name)
)
log.debug(msg)
if fire_event:
msg = 'Failed to compile {0}.'.format(
os.path.join(root, name)
)
try:
__jid_event__.fire_event(
{'error': msg},
@ -119,8 +114,8 @@ def genrepo(opts=None, fire_event=True):
log.error(
'Attempted to fire the an event '
'with the following error, but '
'event firing is not supported: '
'{0}'.format(msg)
'event firing is not supported: %s',
msg
)
continue
revmap[repodata['full_name']] = pkgname

View file

@ -3,7 +3,7 @@
Tests for the salt-run command
'''
# 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

@ -3,7 +3,7 @@
Tests for the fileserver runner
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import contextlib
# Import Salt Testing libs

View file

@ -3,7 +3,7 @@
Tests for the salt-run command
'''
# 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

@ -3,7 +3,7 @@
Tests for the salt-run command
'''
# 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

@ -3,7 +3,7 @@
Tests for runner_returns
'''
# Import Python libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import errno
import os
import tempfile

View file

@ -5,7 +5,7 @@ Tests for the salt runner
.. versionadded:: 2016.11.0
'''
# 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

@ -4,7 +4,7 @@ Tests for the state runner
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import errno
import json
import os
@ -25,6 +25,10 @@ from tests.support.paths import TMP
import salt.utils.platform
import salt.utils.event
import salt.utils.files
import salt.utils.stringutils
# Import 3rd-party libs
from salt.ext import six
class StateRunnerTest(ShellCase):
@ -92,12 +96,12 @@ class StateRunnerTest(ShellCase):
self.run_run('saltutil.sync_modules')
ret = json.loads(
'\n'.join(
self.run_run(u'state.orchestrate orch.issue43204 --out=json')
self.run_run('state.orchestrate orch.issue43204 --out=json')
)
)
# Drill down to the changes dict
state_ret = ret[u'data'][u'master'][u'salt_|-Step01_|-Step01_|-state'][u'changes']
func_ret = ret[u'data'][u'master'][u'salt_|-Step02_|-runtests_helpers.nonzero_retcode_return_false_|-function'][u'changes']
state_ret = ret['data']['master']['salt_|-Step01_|-Step01_|-state']['changes']
func_ret = ret['data']['master']['salt_|-Step02_|-runtests_helpers.nonzero_retcode_return_false_|-function']['changes']
# Remove duration and start time from the results, since they would
# vary with each run and that would make it impossible to test.
@ -107,22 +111,22 @@ class StateRunnerTest(ShellCase):
self.assertEqual(
state_ret,
{
u'out': u'highstate',
u'ret': {
u'minion': {
u'test_|-test fail with changes_|-test fail with changes_|-fail_with_changes': {
u'__id__': u'test fail with changes',
u'__run_num__': 0,
u'__sls__': u'orch.issue43204.fail_with_changes',
u'changes': {
u'testing': {
u'new': u'Something pretended to change',
u'old': u'Unchanged'
'out': 'highstate',
'ret': {
'minion': {
'test_|-test fail with changes_|-test fail with changes_|-fail_with_changes': {
'__id__': 'test fail with changes',
'__run_num__': 0,
'__sls__': 'orch.issue43204.fail_with_changes',
'changes': {
'testing': {
'new': 'Something pretended to change',
'old': 'Unchanged'
}
},
u'comment': u'Failure!',
u'name': u'test fail with changes',
u'result': False,
'comment': 'Failure!',
'name': 'test fail with changes',
'result': False,
}
}
}
@ -131,7 +135,7 @@ class StateRunnerTest(ShellCase):
self.assertEqual(
func_ret,
{u'out': u'highstate', u'ret': {u'minion': False}}
{'out': 'highstate', 'ret': {'minion': False}}
)
def test_orchestrate_target_exists(self):
@ -230,7 +234,7 @@ class StateRunnerTest(ShellCase):
while q.empty():
self.run_salt('minion test.ping --static')
out = q.get()
self.assertIn(expect, str(out))
self.assertIn(expect, six.text_type(out))
server_thread.join()
@ -288,14 +292,14 @@ class OrchEventTest(ShellCase):
state_sls = os.path.join(self.base_env, 'test_state.sls')
with salt.utils.files.fopen(state_sls, 'w') as fp_:
fp_.write(textwrap.dedent('''
fp_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
date:
cmd.run
'''))
''')))
orch_sls = os.path.join(self.base_env, 'test_orch.sls')
with salt.utils.files.fopen(orch_sls, 'w') as fp_:
fp_.write(textwrap.dedent('''
fp_.write(salt.utils.stringutils.to_str(textwrap.dedent('''
date_cmd:
salt.state:
- tgt: minion
@ -311,7 +315,7 @@ class OrchEventTest(ShellCase):
config.values:
salt.wheel
'''))
''')))
listener = salt.utils.event.get_event(
'master',

View file

@ -4,7 +4,7 @@ unit tests for the cache runner
'''
# 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

View file

@ -4,7 +4,7 @@ unit tests for the jobs runner
'''
# 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

View file

@ -4,7 +4,7 @@ unit tests for the cache runner
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import os
# Import Salt Testing Libs

View file

@ -4,7 +4,7 @@ Unit tests for the Vault runner
'''
# Import Python Libs
from __future__ import absolute_import
from __future__ import absolute_import, print_function, unicode_literals
import logging
# Import Salt Testing Libs
@ -85,9 +85,9 @@ class VaultTest(TestCase, LoaderModuleMockMixin):
output = vault._expand_pattern_lists(case, **mappings) # pylint: disable=protected-access
diff = set(output).symmetric_difference(set(correct_output))
if len(diff) != 0:
log.debug('Test {0} failed'.format(case))
log.debug('Expected:\n\t{0}\nGot\n\t{1}'.format(output, correct_output))
log.debug('Difference:\n\t{0}'.format(diff))
log.debug('Test %s failed', case)
log.debug('Expected:\n\t%s\nGot\n\t%s', output, correct_output)
log.debug('Difference:\n\t%s', diff)
self.assertEqual(output, correct_output)
def test_get_policies_for_nonexisting_minions(self):
@ -105,9 +105,9 @@ class VaultTest(TestCase, LoaderModuleMockMixin):
output = vault._get_policies(minion_id, test_config) # pylint: disable=protected-access
diff = set(output).symmetric_difference(set(correct_output))
if len(diff) != 0:
log.debug('Test {0} failed'.format(case))
log.debug('Expected:\n\t{0}\nGot\n\t{1}'.format(output, correct_output))
log.debug('Difference:\n\t{0}'.format(diff))
log.debug('Test %s failed', case)
log.debug('Expected:\n\t%s\nGot\n\t%s', output, correct_output)
log.debug('Difference:\n\t%s', diff)
self.assertEqual(output, correct_output)
@skipIf(NO_MOCK, NO_MOCK_REASON)
@ -146,7 +146,7 @@ class VaultTest(TestCase, LoaderModuleMockMixin):
output = vault._get_policies('test-minion', test_config) # pylint: disable=protected-access
diff = set(output).symmetric_difference(set(correct_output))
if len(diff) != 0:
log.debug('Test {0} failed'.format(case))
log.debug('Expected:\n\t{0}\nGot\n\t{1}'.format(output, correct_output))
log.debug('Difference:\n\t{0}'.format(diff))
log.debug('Test %s failed', case)
log.debug('Expected:\n\t%s\nGot\n\t%s', output, correct_output)
log.debug('Difference:\n\t%s', diff)
self.assertEqual(output, correct_output)

View file

@ -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 shutil
import tempfile
@ -14,15 +14,19 @@ from tests.support.mock import NO_MOCK, NO_MOCK_REASON
# Import salt libs
import salt.utils.files
import salt.utils.stringutils
import salt.runners.winrepo as winrepo
_WINREPO_SLS = r'''
# Can't use raw string with unicode_literals, since the \u in the uninstaller
# will be interpreted as a unicode code point and the interpreter will raise a
# SyntaxError.
_WINREPO_SLS = '''
winscp_x86:
5.7.5:
full_name: 'WinSCP 5.7.5'
installer: 'http://heanet.dl.sourceforge.net/project/winscp/WinSCP/5.7.5/winscp575setup.exe'
install_flags: '/SP- /verysilent /norestart'
uninstaller: '%PROGRAMFILES%\WinSCP\unins000.exe'
uninstaller: '%PROGRAMFILES%\\WinSCP\\unins000.exe'
uninstall_flags: '/verysilent'
msiexec: False
locale: en_US
@ -31,7 +35,7 @@ winscp_x86:
full_name: 'WinSCP 5.7.4'
installer: 'http://cznic.dl.sourceforge.net/project/winscp/WinSCP/5.7.4/winscp574setup.exe'
install_flags: '/SP- /verysilent /norestart'
uninstaller: '%PROGRAMFILES%\WinSCP\unins000.exe'
uninstaller: '%PROGRAMFILES%\\WinSCP\\unins000.exe'
uninstall_flags: '/verysilent'
msiexec: False
locale: en_US
@ -103,5 +107,5 @@ class WinrepoTest(TestCase, LoaderModuleMockMixin):
sls_file = os.path.join(self.winrepo_sls_dir, 'wireshark.sls')
# Add a winrepo SLS file
with salt.utils.files.fopen(sls_file, 'w') as fp_:
fp_.write(_WINREPO_SLS)
fp_.write(salt.utils.stringutils.to_str(_WINREPO_SLS))
self.assertEqual(winrepo.genrepo(), _WINREPO_GENREPO_DATA)