Merge pull request #18263 from s0undt3ch/hotfix/rockin-salt

More Py3 and Lint Fixes
This commit is contained in:
Thomas S Hatch 2014-11-20 12:56:12 -07:00
commit d8e8d6007a
55 changed files with 616 additions and 518 deletions

View File

@ -2,11 +2,16 @@
'''
Salt compatibility code
'''
# pylint: disable=W0611
# pylint: disable=import-error,unused-import
# Import python libs
import sys
import types
# Import 3rd-party libs
from salt.ext.six import binary_type, string_types, text_type
from salt.ext.six.moves import cStringIO, StringIO
try:
import cPickle as pickle
except ImportError:
@ -33,31 +38,6 @@ except ImportError:
# True if we are running on Python 3.
PY3 = sys.version_info[0] == 3
if PY3:
MAX_SIZE = sys.maxsize
else:
MAX_SIZE = sys.maxint
if PY3:
xrange = range
else:
xrange = xrange
# pylint: disable=C0103
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
long = int
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = str
long = long
if PY3:
import builtins
@ -65,12 +45,6 @@ if PY3:
else:
import exceptions # pylint: disable=W0403
if PY3:
def callable(obj):
return any('__call__' in klass.__dict__ for klass in type(obj).__mro__)
else:
callable = callable
def text_(s, encoding='latin-1', errors='strict'):
'''
@ -103,31 +77,6 @@ else:
s = s.encode('ascii')
return str(s)
if PY3:
exec_ = getattr(builtins, 'exec') # pylint: disable=E0602
def reraise(tp, value, tb=None):
if value is None:
value = tp()
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
else:
def exec_(code_, globals_=None, locals_=None):
'''
Execute code directly in a passed namespace
'''
if globals_ is None:
frame = sys._getframe(1)
globals_ = frame.f_globals
if locals_ is None:
locals_ = frame.f_locals
del frame
elif locals_ is None:
locals_ = globals_
exec('''exec code_ in globals_, locals_''')
ascii_native_.__doc__ = '''
Python 3: If ``s`` is an instance of ``text_type``, return
``s.encode('ascii')``, otherwise return ``str(s, 'ascii', 'strict')``
@ -164,60 +113,6 @@ Python 2: If ``s`` is an instance of ``text_type``, return
``s.encode(encoding, errors)``, otherwise return ``str(s)``
'''
if PY3:
# pylint: disable=E0611
from urllib.parse import urlparse
from urllib.parse import urlunparse
from urllib.error import URLError
import http.server as BaseHTTPServer
from urllib.error import HTTPError
from urllib.parse import quote as url_quote
from urllib.parse import quote_plus as url_quote_plus
from urllib.parse import unquote as url_unquote
from urllib.parse import urlencode as url_encode
from urllib.request import urlopen as url_open
from urllib.request import HTTPPasswordMgrWithDefaultRealm as url_passwd_mgr
from urllib.request import HTTPBasicAuthHandler as url_auth_handler
from urllib.request import build_opener as url_build_opener
from urllib.request import install_opener as url_install_opener
url_unquote_text = url_unquote
url_unquote_native = url_unquote
import configparser
else:
from urlparse import urlparse
from urlparse import urlunparse
import BaseHTTPServer
from urllib2 import HTTPError, URLError
from urllib import quote as url_quote
from urllib import quote_plus as url_quote_plus
from urllib import unquote as url_unquote
from urllib import urlencode as url_encode
from urllib2 import urlopen as url_open
from urllib2 import HTTPPasswordMgrWithDefaultRealm as url_passwd_mgr
from urllib2 import HTTPBasicAuthHandler as url_auth_handler
from urllib2 import build_opener as url_build_opener
from urllib2 import install_opener as url_install_opener
import ConfigParser as configparser
def url_unquote_text(v, encoding='utf-8', errors='replace'):
v = url_unquote(v)
return v.decode(encoding, errors)
def url_unquote_native(v, encoding='utf-8', errors='replace'):
return native_(url_unquote_text(v, encoding, errors))
if PY3:
zip = zip
else:
from future_builtins import zip
if PY3:
from io import StringIO
from io import BytesIO as cStringIO
else:
from StringIO import StringIO
from cStringIO import StringIO as cStringIO
def string_io(data=None): # cStringIO can't handle unicode
'''
@ -227,10 +122,3 @@ def string_io(data=None): # cStringIO can't handle unicode
return cStringIO(bytes(data))
except (UnicodeEncodeError, TypeError):
return StringIO(data)
if PY3:
import queue as Queue
else:
import Queue
# pylint: enable=C0103

View File

@ -30,15 +30,17 @@ from __future__ import absolute_import
import time
import json
import pprint
import requests
import logging
import hmac
import urllib
import uuid
import sys
import base64
from hashlib import sha1
# Import 3rd-party libs
import requests
from salt.ext.six.moves.urllib.parse import quote as _quote # pylint: disable=import-error,no-name-in-module
# Import salt cloud libs
import salt.utils.cloud
import salt.config as config
@ -664,7 +666,7 @@ def _compute_signature(parameters, access_key_secret):
s = line.decode().encode('utf8')
else:
s = line.decode(sys.stdin.encoding).encode('utf8')
res = urllib.quote(s, '')
res = _quote(s, '')
res = res.replace('+', '%20')
res = res.replace('*', '%2A')
res = res.replace('%7E', '~')

View File

@ -74,19 +74,21 @@ import uuid
import pprint
import logging
import yaml
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
import requests
import salt.ext.six as six
from salt.ext.six.moves import map
from salt.ext.six.moves import zip
from salt.ext.six.moves import range
from salt.ext.six.moves import map, range, zip
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse, urlencode as _urlencode
# pylint: enable=import-error,no-name-in-module
# Import libs for talking to the EC2 API
import hmac
import hashlib
import binascii
import datetime
import urllib
import urlparse
import requests
import base64
# Import salt libs
@ -312,11 +314,12 @@ def query(params=None, setname=None, requesturl=None, location=None,
requesturl = 'https://{0}/'.format(endpoint)
else:
endpoint = urlparse.urlparse(requesturl).netloc
endpoint = _urlparse(requesturl).netloc
if endpoint == '':
endpoint_err = 'Could not find a valid endpoint in the requesturl: {0}. Looking for something like https://some.ec2.endpoint/?args'.format(
requesturl
)
endpoint_err = (
'Could not find a valid endpoint in the '
'requesturl: {0}. Looking for something '
'like https://some.ec2.endpoint/?args').format(requesturl)
log.error(endpoint_err)
if return_url is True:
return {'error': endpoint_err}, requesturl
@ -337,7 +340,7 @@ def query(params=None, setname=None, requesturl=None, location=None,
params_with_headers['Version'] = ec2_api_version
keys = sorted(params_with_headers)
values = list(map(params_with_headers.get, keys))
querystring = urllib.urlencode(list(zip(keys, values)))
querystring = _urlencode(list(zip(keys, values)))
# AWS signature version 2 requires that spaces be encoded as
# %20, however urlencode uses '+'. So replace pluses with %20.
@ -1038,10 +1041,10 @@ def _request_eip(interface):
'''
params = {'Action': 'AllocateAddress'}
params['Domain'] = interface.setdefault('domain', 'vpc')
eip = query(params, return_root=True)
for e in eip:
if 'allocationId' in e:
return e['allocationId']
eips = query(params, return_root=True)
for eip in eips:
if 'allocationId' in eip:
return eip['allocationId']
return None

View File

@ -19,16 +19,27 @@ Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
provider: parallels
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import copy
import time
import pprint
import urllib
import urllib2
import logging
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module
from salt.ext.six.moves.urllib.error import URLError
from salt.ext.six.moves.urllib.parse import urlencode as _urlencode
from salt.ext.six.moves.urllib.request import (
HTTPBasicAuthHandler as _HTTPBasicAuthHandler,
Request as _Request,
urlopen as _urlopen,
build_opener as _build_opener,
install_opener as _install_opener
)
# pylint: enable=import-error,no-name-in-module
# Import salt libs
import salt.utils
from salt._compat import ElementTree as ET
@ -467,7 +478,7 @@ def query(action=None, command=None, args=None, method='GET', data=None):
path = config.get_cloud_config_value(
'url', get_configured_provider(), __opts__, search_global=False
)
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler = _HTTPBasicAuthHandler()
auth_handler.add_password(
realm='Parallels Instance Manager',
uri=path,
@ -479,8 +490,8 @@ def query(action=None, command=None, args=None, method='GET', data=None):
search_global=False
)
)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
opener = _build_opener(auth_handler)
_install_opener(opener)
if action:
path += action
@ -498,10 +509,10 @@ def query(action=None, command=None, args=None, method='GET', data=None):
}
if args:
params = urllib.urlencode(args)
req = urllib2.Request(url='{0}?{1}'.format(path, params), **kwargs)
params = _urlencode(args)
req = _Request(url='{0}?{1}'.format(path, params), **kwargs)
else:
req = urllib2.Request(url=path, **kwargs)
req = _Request(url=path, **kwargs)
req.get_method = lambda: method
@ -510,7 +521,7 @@ def query(action=None, command=None, args=None, method='GET', data=None):
log.debug(data)
try:
result = urllib2.urlopen(req)
result = _urlopen(req)
log.debug(
'PARALLELS Response Status Code: {0}'.format(
result.getcode()
@ -524,7 +535,7 @@ def query(action=None, command=None, args=None, method='GET', data=None):
return items
return {}
except urllib2.URLError as exc:
except URLError as exc:
log.error(
'PARALLELS Response Status Code: {0} {1}'.format(
exc.code,

View File

@ -14,9 +14,9 @@ import logging
from copy import deepcopy
import time
import codecs
# import third party libs
import yaml
import salt.ext.six as six
try:
yaml.Loader = yaml.CLoader
yaml.Dumper = yaml.CDumper
@ -31,8 +31,9 @@ import salt.syspaths
import salt.utils.validate.path
import salt.utils.xdg
import salt.exceptions
from salt._compat import urlparse
from salt.ext.six import string_types
from salt.ext.six import string_types, text_type
from salt.ext.six.moves.urllib.parse import urlparse # pylint: disable=import-error,no-name-in-module
import sys
@ -747,7 +748,7 @@ def _read_conf_file(path):
if 'id' in conf_opts:
conf_opts['id'] = str(conf_opts['id'])
for key, value in conf_opts.copy().items():
if isinstance(value, six.text_type):
if isinstance(value, text_type):
# We do not want unicode settings
conf_opts[key] = value.encode('utf-8')
return conf_opts

View File

@ -26,11 +26,20 @@ import salt.fileserver
import salt.utils
import salt.utils.templates
import salt.utils.gzip_util
from salt._compat import (
URLError, HTTPError, BaseHTTPServer, urlparse, urlunparse,
url_passwd_mgr, url_auth_handler, url_build_opener, url_install_opener)
from salt.utils.openstack.swift import SaltSwift
# pylint: disable=no-name-in-module,import-error
import salt.ext.six.moves.BaseHTTPServer as BaseHTTPServer
from salt.ext.six.moves.urllib.error import HTTPError, URLError
from salt.ext.six.moves.urllib.parse import urlparse, urlunparse
from salt.ext.six.moves.urllib.request import (
HTTPPasswordMgrWithDefaultRealm as url_passwd_mgr,
HTTPBasicAuthHandler as url_auth_handler,
build_opener as url_build_opener,
install_opener as url_install_opener
)
# pylint: enable=no-name-in-module,import-error
log = logging.getLogger(__name__)

View File

@ -69,7 +69,6 @@ import datetime
import os
import time
import pickle
import urllib
import logging
# Import salt libs
@ -77,8 +76,13 @@ import salt.fileserver as fs
import salt.modules
import salt.utils
import salt.utils.s3 as s3
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
import salt.ext.six as six
from salt.ext.six.moves import filter
from salt.ext.six.moves.urllib.parse import quote as _quote
# pylint: disable=import-error,no-name-in-module,redefined-builtin
log = logging.getLogger(__name__)
@ -572,7 +576,7 @@ def _get_file_from_s3(metadata, saltenv, bucket_name, path, cached_file_path):
bucket=bucket_name,
service_url=service_url,
verify_ssl=verify_ssl,
path=urllib.quote(path),
path=_quote(path),
local_file=cached_file_path
)
if ret is not None:
@ -600,7 +604,7 @@ def _get_file_from_s3(metadata, saltenv, bucket_name, path, cached_file_path):
bucket=bucket_name,
service_url=service_url,
verify_ssl=verify_ssl,
path=urllib.quote(path),
path=_quote(path),
local_file=cached_file_path
)

View File

@ -17,7 +17,6 @@ import threading
import logging.handlers
# Import salt libs
from salt._compat import Queue
from salt.log.mixins import NewStyleClassMixIn, ExcInfoOnLogLevelFormatMixIn
log = logging.getLogger(__name__)

View File

@ -24,7 +24,9 @@ import socket
import logging
import logging.handlers
import traceback
from salt.ext.six import PY3
from salt.ext.six import string_types, text_type, with_metaclass
from salt.ext.six.moves.urllib.parse import urlparse # pylint: disable=import-error,no-name-in-module
# Let's define these custom logging levels before importing the salt.log.mixins
# since they will be used there
@ -35,7 +37,6 @@ QUIET = logging.QUIET = 1000
# Import salt libs
from salt.log.handlers import TemporaryLoggingHandler, StreamHandler, SysLogHandler, WatchedFileHandler
from salt.log.mixins import LoggingMixInMeta, NewStyleClassMixIn
from salt._compat import PY3, urlparse
LOG_LEVELS = {
'all': logging.NOTSET,

View File

@ -16,8 +16,19 @@ from __future__ import absolute_import
# Import python libs
import re
import logging
import urllib2
import cStringIO
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module
from salt.ext.six.moves import cStringIO
from salt.ext.six.moves.urllib.error import URLError
from salt.ext.six.moves.urllib.request import (
HTTPBasicAuthHandler as _HTTPBasicAuthHandler,
HTTPDigestAuthHandler as _HTTPDigestAuthHandler,
urlopen as _urlopen,
build_opener as _build_opener,
install_opener as _install_opener
)
# pylint: enable=import-error,no-name-in-module
# Import salt libs
import salt.utils
@ -354,17 +365,17 @@ def server_status(profile='default'):
# create authentication handler if configuration exists
if user and passwd:
basic = urllib2.HTTPBasicAuthHandler()
basic = _HTTPBasicAuthHandler()
basic.add_password(realm=realm, uri=url, user=user, passwd=passwd)
digest = urllib2.HTTPDigestAuthHandler()
digest = _HTTPDigestAuthHandler()
digest.add_password(realm=realm, uri=url, user=user, passwd=passwd)
urllib2.install_opener(urllib2.build_opener(basic, digest))
_install_opener(_build_opener(basic, digest))
# get http data
url += '?auto'
try:
response = urllib2.urlopen(url, timeout=timeout).read().splitlines()
except urllib2.URLError:
response = _urlopen(url, timeout=timeout).read().splitlines()
except URLError:
return 'error'
# parse the data
@ -387,7 +398,7 @@ def server_status(profile='default'):
def _parse_config(conf, slot=None):
ret = cStringIO.StringIO()
ret = cStringIO()
if isinstance(conf, str):
if slot:
print('{0} {1}'.format(slot, conf), file=ret, end='')

View File

@ -16,29 +16,30 @@ import copy
import os
import re
import logging
import urllib2
import json
# Import third party libs
import yaml
# pylint: disable=no-name-in-module,import-error,redefined-builtin
import salt.ext.six as six
from salt.ext.six.moves import range
from salt.ext.six.moves.urllib.error import HTTPError
from salt.ext.six.moves.urllib.request import Request as _Request, urlopen as _urlopen
# pylint: enable=no-name-in-module,import-error,redefined-builtin
# Import salt libs
from salt.modules.cmdmod import _parse_env
import salt.utils
from salt.ext.six import string_types
from salt.exceptions import (
CommandExecutionError, MinionError, SaltInvocationError
)
import salt.ext.six as six
from salt.ext.six.moves import range
log = logging.getLogger(__name__)
# pylint: disable=import-error
try:
import apt.cache # pylint: disable=E0611
import apt.debfile # pylint: disable=E0611
import apt.cache
import apt.debfile
from aptsources import sourceslist
HAS_APT = True
except ImportError:
@ -49,6 +50,7 @@ try:
HAS_SOFTWAREPROPERTIES = True
except ImportError:
HAS_SOFTWAREPROPERTIES = False
# pylint: disable=import-error
# Source format for urllib fallback on PPA handling
LP_SRC_FORMAT = 'deb http://ppa.launchpad.net/{0}/{1}/ubuntu {2} main'
@ -102,8 +104,8 @@ def _get_ppa_info_from_launchpad(owner_name, ppa_name):
lp_url = 'https://launchpad.net/api/1.0/~{0}/+archive/{1}'.format(
owner_name, ppa_name)
request = urllib2.Request(lp_url, headers={'Accept': 'application/json'})
lp_page = urllib2.urlopen(request)
request = _Request(lp_url, headers={'Accept': 'application/json'})
lp_page = _urlopen(request)
return json.load(lp_page)
@ -1398,7 +1400,7 @@ def mod_repo(repo, saltenv='base', **kwargs):
raise CommandExecutionError(
error_str.format(owner_name, ppa_name)
)
except urllib2.HTTPError as exc:
except HTTPError as exc:
raise CommandExecutionError(
'Launchpad does not know about {0}/{1}: {2}'.format(
owner_name, ppa_name, exc)
@ -1671,7 +1673,7 @@ def _parse_selections(dpkgselection):
pkg.get_selections and pkg.set_selections work with.
'''
ret = {}
if isinstance(dpkgselection, string_types):
if isinstance(dpkgselection, six.string_types):
dpkgselection = dpkgselection.split('\n')
for line in dpkgselection:
if line:
@ -1776,7 +1778,7 @@ def set_selections(path=None, selection=None, clear=False, saltenv='base'):
'specified together')
raise SaltInvocationError(err)
if isinstance(selection, string_types):
if isinstance(selection, six.string_types):
try:
selection = yaml.safe_load(selection)
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as exc:

View File

@ -12,13 +12,14 @@ import re
import time
import datetime
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
# Import 3rd-party libs
# pylint: disable=import-error,redefined-builtin
from salt.ext.six.moves import map
from salt.ext.six.moves import shlex_quote as _cmd_quote
# pylint: enable=import-error,redefined-builtin
# Import salt libs
import salt.utils
from salt.ext.six.moves import map
# OS Families that should work (Ubuntu and Debian are the default)
# TODO: Refactor some of this module to remove the checks for binaries

View File

@ -14,20 +14,22 @@ from __future__ import absolute_import
# Import python libs
import logging
# Import 3rd-party libs
# pylint: disable=import-error
from salt.ext.six.moves import shlex_quote as _cmd_quote
# pylint: enable=import-error
# Import salt libs
import salt.utils.validate.net
from salt.exceptions import CommandExecutionError
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
log = logging.getLogger(__name__)
HAS_PYBLUEZ = False
try:
import bluetooth
import bluetooth # pylint: disable=import-error
HAS_PYBLUEZ = True
except Exception as exc:
except ImportError:
pass
__func_alias__ = {

View File

@ -32,12 +32,14 @@ from __future__ import absolute_import
# Import Python libs
import logging
import urllib
import json
log = logging.getLogger(__name__)
# Import third party libs
# pylint: disable=import-error
from salt.ext.six import string_types
from salt.ext.six.moves.urllib.parse import unquote as _unquote # pylint: disable=no-name-in-module
try:
import boto
import boto.iam
@ -45,9 +47,9 @@ try:
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
# pylint: enable=import-error
# Import salt libs
from salt.ext.six import string_types
import salt.utils.odict as odict
@ -342,7 +344,7 @@ def get_role_policy(role_name, policy_name, region=None, key=None,
# I _hate_ you for not giving me an object boto.
_policy = _policy.get_role_policy_response.policy_document
# Policy is url encoded
_policy = urllib.unquote(_policy)
_policy = _unquote(_policy)
_policy = json.loads(_policy, object_pairs_hook=odict.OrderedDict)
return _policy
except boto.exception.BotoServerError:

View File

@ -9,11 +9,6 @@ try:
except ImportError:
pass
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
# Define the module's virtual name
__virtualname__ = 'shadow'

View File

@ -11,10 +11,15 @@ import logging
import re
import os
import bz2
from urllib import urlopen
# Import 3rd-party libs
from salt.ext.six.moves.urllib.request import urlopen as _urlopen # pylint: disable=no-name-in-module,import-error
# Import Salt libs
import salt.utils
from salt.exceptions import SaltInvocationError
LOG = logging.getLogger(__name__)
DEFAULT_MIRROR = "ftp://mirrors.kernel.org/sourceware/cygwin/"
@ -73,7 +78,7 @@ def _get_all_packages(mirror=DEFAULT_MIRROR,
if not len(__context__['cyg.all_packages'][mirror]):
pkg_source = '/'.join([mirror, cyg_arch, 'setup.bz2'])
file_data = urlopen(pkg_source).read()
file_data = _urlopen(pkg_source).read()
file_lines = bz2.decompress(file_data).decode('utf_8',
errors='replace'
).splitlines()
@ -123,7 +128,7 @@ def _run_silent_cygwin(cyg_arch='x86_64',
elif os.path.exists(cyg_setup_path):
os.remove(cyg_setup_path)
file_data = urlopen(cyg_setup_source)
file_data = _urlopen(cyg_setup_source)
open(cyg_setup_path, "wb").write(file_data.read())
setup_command = cyg_setup_path

View File

@ -5,12 +5,14 @@ Service support for Debian systems (uses update-rc.d and /sbin/service)
from __future__ import absolute_import
# Import python libs
import logging
import glob
import re
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
# Import 3rd-party libs
# pylint: disable=import-error
from salt.ext.six.moves import shlex_quote as _cmd_quote
# pylint: enable=import-error
# Import salt libs
from .systemd import _sd_booted
@ -22,7 +24,6 @@ __func_alias__ = {
# Define the module's virtual name
__virtualname__ = 'service'
import logging
log = logging.getLogger(__name__)

View File

@ -30,11 +30,12 @@ import sys
import tempfile
import time
import glob
from functools import reduce
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six import string_types
from salt.ext.six.moves import range
from salt.ext.six.moves import zip
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse # pylint: disable=E0611
from salt.ext.six.moves import range, reduce, zip
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse
# pylint: enable=import-error,no-name-in-module,redefined-builtin
try:
import grp

View File

@ -8,14 +8,11 @@ from __future__ import absolute_import
import logging
# Import 3rd-party libs
# pylint: disable=import-error
from salt.ext.six.moves import shlex_quote as _cmd_quote
# pylint: enable=import-error
from salt.ext.six.moves import range, shlex_quote as _cmd_quote # pylint: disable=import-error,redefined-builtin
# Import salt libs
import salt.utils
import salt.utils.cloud as suc
from salt.ext.six.moves import range
log = logging.getLogger(__name__)

View File

@ -14,15 +14,21 @@ Module for sending messages to hipchat
api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15
api_version: v1
'''
# Import Python Libs
from __future__ import absolute_import
import json
import requests
import logging
from urlparse import urljoin as _urljoin
# Import 3rd-party Libs
import requests
from requests.exceptions import ConnectionError
# pylint: disable=import-error,no-name-in-module
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin
from salt.ext.six.moves import range
# pylint: enable=import-error,no-name-in-module
log = logging.getLogger(__name__)
__virtualname__ = 'hipchat'

View File

@ -7,6 +7,8 @@ from __future__ import absolute_import
# Import python libs
import logging
# Import 3rd-party libs
#from salt.ext.six.moves.urllib.parse import urlparse # pylint: disable=import-error,no-name-in-module
# Set up logging
log = logging.getLogger(__name__)
@ -33,7 +35,7 @@ def mount_image(location):
return first
return ''
#compatibility for api change
# compatibility for api change
mnt_image = mount_image
@ -60,7 +62,7 @@ def umount_image(mnt):
# system
# '''
# cache_dir = os.path.join(__salt__['config.option']('img.cache'), 'src')
# parse = urlparse.urlparse(name)
# parse = urlparse(name)
# if __salt__['config.valid_file_proto'](parse.scheme):
# # Valid scheme to download
# dest = os.path.join(cache_dir, parse.netloc)

View File

@ -32,9 +32,17 @@ this module.
'''
from __future__ import absolute_import
# Python libs
import urllib
import urllib2
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module
from salt.ext.six.moves.urllib.parse import urlencode as _urlencode
from salt.ext.six.moves.urllib.request import (
HTTPBasicAuthHandler as _HTTPBasicAuthHandler,
HTTPDigestAuthHandler as _HTTPDigestAuthHandler,
urlopen as _urlopen,
build_opener as _build_opener,
install_opener as _install_opener
)
# pylint: enable=import-error,no-name-in-module
def __virtual__():
@ -49,11 +57,11 @@ def _auth(url, user, passwd, realm):
returns a authentication handler.
'''
basic = urllib2.HTTPBasicAuthHandler()
basic = _HTTPBasicAuthHandler()
basic.add_password(realm=realm, uri=url, user=user, passwd=passwd)
digest = urllib2.HTTPDigestAuthHandler()
digest = _HTTPDigestAuthHandler()
digest.add_password(realm=realm, uri=url, user=user, passwd=passwd)
return urllib2.build_opener(basic, digest)
return _build_opener(basic, digest)
def _do_http(opts, profile='default'):
@ -74,11 +82,11 @@ def _do_http(opts, profile='default'):
if user and passwd:
auth = _auth(url, realm, user, passwd)
urllib2.install_opener(auth)
_install_opener(auth)
url += '?{0}'.format(urllib.urlencode(opts))
url += '?{0}'.format(_urlencode(opts))
for line in urllib2.urlopen(url, timeout=timeout).read().splitlines():
for line in _urlopen(url, timeout=timeout).read().splitlines():
splt = line.split('=', 1)
if splt[0] in ret:
ret[splt[0]] += ',{0}'.format(splt[1])

View File

@ -3,7 +3,10 @@
Support for nginx
'''
from __future__ import absolute_import
import urllib2
# Import 3rd-party libs
from salt.ext.six.moves.urllib.request import urlopen as _urlopen # pylint: disable=no-name-in-module,import-error
# Import salt libs
import salt.utils
import salt.utils.decorators as decorators
@ -110,7 +113,7 @@ def status(url="http://127.0.0.1/status"):
salt '*' nginx.status
"""
resp = urllib2.urlopen(url)
resp = _urlopen(url)
status_data = resp.read()
resp.close()

View File

@ -17,7 +17,19 @@ import fnmatch
import time
import sys
import copy
from urllib2 import URLError
# Import 3rd-party libs
# pylint: disable=import-error
try:
import esky
from esky import EskyVersionError
HAS_ESKY = True
except ImportError:
HAS_ESKY = False
# pylint: disable=no-name-in-module
from salt.ext.six import string_types
from salt.ext.six.moves.urllib.error import URLError
# pylint: enable=import-error,no-name-in-module
# Import salt libs
import salt
@ -33,18 +45,9 @@ import salt.wheel
from salt.exceptions import (
SaltReqTimeoutError, SaltRenderError, CommandExecutionError
)
from salt.ext.six import string_types
__proxyenabled__ = ['*']
# Import third party libs
try:
import esky
from esky import EskyVersionError
HAS_ESKY = True
except ImportError:
HAS_ESKY = False
log = logging.getLogger(__name__)

View File

@ -15,12 +15,18 @@ Module for sending messages to Slack
slack:
api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15
'''
# Import Python libs
from __future__ import absolute_import
import requests
import logging
from urlparse import urljoin as _urljoin
# Import 3rd-party libs
import requests
from requests.exceptions import ConnectionError
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin
from salt.ext.six.moves import range
# pylint: enable=import-error,no-name-in-module
log = logging.getLogger(__name__)
__virtualname__ = 'slack'

View File

@ -63,16 +63,25 @@ verbose : True
from __future__ import absolute_import
import json
import os
import urllib2
# Import 3rd-party libs
# pylint: disable=no-name-in-module,import-error
from salt.ext.six import string_types
from salt.ext.six.moves.urllib.request import (
urlopen as _urlopen,
HTTPBasicAuthHandler as _HTTPBasicAuthHandler,
HTTPDigestAuthHandler as _HTTPDigestAuthHandler,
build_opener as _build_opener,
install_opener as _install_opener
)
# pylint: enable=no-name-in-module,import-error
# Import salt libs
import salt.utils
from salt._compat import url_open
from salt.ext.six import string_types
########################## PRIVATE METHODS ##############################
def __virtual__():
'''
PRIVATE METHOD
@ -233,16 +242,16 @@ def _auth(url):
realm = __salt__['config.get']('solr.auth_realm', 'Solr')
if user and password:
basic = urllib2.HTTPBasicAuthHandler()
basic = _HTTPBasicAuthHandler()
basic.add_password(
realm=realm, uri=url, user=user, passwd=password
)
digest = urllib2.HTTPDigestAuthHandler()
digest = _HTTPDigestAuthHandler()
digest.add_password(
realm=realm, uri=url, user=user, passwd=password
)
urllib2.install_opener(
urllib2.build_opener(basic, digest)
_install_opener(
_build_opener(basic, digest)
)
@ -266,9 +275,9 @@ def _http_request(url, request_timeout=None):
request_timeout = __salt__['config.option']('solr.request_timeout')
if request_timeout is None:
data = json.load(url_open(url))
data = json.load(_urlopen(url))
else:
data = json.load(url_open(url, timeout=request_timeout))
data = json.load(_urlopen(url, timeout=request_timeout))
return _get_return_dict(True, data, [])
except Exception as err:
return _get_return_dict(False, {}, ["{0} : {1}".format(url, err)])
@ -384,18 +393,18 @@ def _pre_index_check(handler, host=None, core_name=None):
{'success':boolean, 'data':dict, 'errors':list, 'warnings':list}
'''
#make sure that it's a master minion
# make sure that it's a master minion
if _get_none_or_value(host) is None and not _is_master():
err = [
'solr.pre_indexing_check can only be called by "master" minions']
return _get_return_dict(False, err)
#solr can run out of memory quickly if the dih is processing multiple
#handlers at the same time, so if it's a multicore setup require a
#core_name param.
# solr can run out of memory quickly if the dih is processing multiple
# handlers at the same time, so if it's a multicore setup require a
# core_name param.
if _get_none_or_value(core_name) is None and _check_for_cores():
errors = ['solr.full_import is not safe to multiple handlers at once']
return _get_return_dict(False, errors=errors)
#check to make sure that we're not already indexing
# check to make sure that we're not already indexing
resp = import_status(handler, host, core_name)
if resp['success']:
status = resp['data']['status']
@ -472,7 +481,7 @@ def lucene_version(core_name=None):
salt '*' solr.lucene_version
'''
ret = _get_return_dict()
#do we want to check for all the cores?
# do we want to check for all the cores?
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
for name in __salt__['config.option']('solr.cores'):
@ -515,7 +524,7 @@ def version(core_name=None):
salt '*' solr.version
'''
ret = _get_return_dict()
#do we want to check for all the cores?
# do we want to check for all the cores?
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
for name in __opts__['solr.cores']:
@ -655,7 +664,7 @@ def is_replication_enabled(host=None, core_name=None):
errors = ['Only "slave" minions can run "is_replication_enabled"']
return ret.update({'success': False, 'errors': errors})
#define a convenience method so we don't duplicate code
# define a convenience method so we don't duplicate code
def _checks(ret, success, resp, core):
if response['success']:
slave = resp['data']['details']['slave']
@ -663,27 +672,27 @@ def is_replication_enabled(host=None, core_name=None):
# on the master and we can't get this info.
enabled = 'false'
master_url = slave['masterUrl']
#check for errors on the slave
# check for errors on the slave
if 'ERROR' in slave:
success = False
err = "{0}: {1} - {2}".format(core, slave['ERROR'], master_url)
resp['errors'].append(err)
#if there is an error return everything
# if there is an error return everything
data = slave if core is None else {core: {'data': slave}}
else:
enabled = slave['masterDetails']['master'][
'replicationEnabled']
#if replication is turned off on the master, or polling is
#disabled we need to return false. These may not be errors,
#but the purpose of this call is to check to see if the slaves
#can replicate.
# if replication is turned off on the master, or polling is
# disabled we need to return false. These may not be errors,
# but the purpose of this call is to check to see if the slaves
# can replicate.
if enabled == 'false':
resp['warnings'].append("Replication is disabled on master.")
success = False
if slave['isPollingDisabled'] == 'true':
success = False
resp['warning'].append("Polling is disabled")
#update the return
# update the return
ret = _update_return_dict(ret, success, data,
resp['errors'], resp['warnings'])
return (ret, success)
@ -748,8 +757,8 @@ def match_index_versions(host=None, core_name=None):
success = False
err = "{0}: {1} - {2}".format(core, error, master_url)
resp['errors'].append(err)
#if there was an error return the entire response so the
#alterer can get what it wants
# if there was an error return the entire response so the
# alterer can get what it wants
data = slave if core is None else {core: {'data': slave}}
else:
versions = {
@ -762,7 +771,7 @@ def match_index_versions(host=None, core_name=None):
if 'replicationFailedAtList' in slave:
versions.update({'failed_list': slave[
'replicationFailedAtList']})
#check the index versions
# check the index versions
if versions['master'] != versions['slave']:
success = False
resp['errors'].append(
@ -778,7 +787,7 @@ def match_index_versions(host=None, core_name=None):
ret = _update_return_dict(ret, success, data, errors=err)
return (ret, success)
#check all cores?
# check all cores?
if _get_none_or_value(core_name) is None and _check_for_cores():
success = True
for name in __opts__['solr.cores']:
@ -1130,7 +1139,7 @@ def reload_import_config(handler, host=None, core_name=None, verbose=False):
salt '*' solr.reload_import_config dataimport None music {'clean':True}
'''
#make sure that it's a master minion
# make sure that it's a master minion
if not _is_master() and _get_none_or_value(host) is None:
err = [
'solr.pre_indexing_check can only be called by "master" minions']
@ -1285,7 +1294,7 @@ def delta_import(handler, host=None, core_name=None, options=None, extra=None):
if not resp['success']:
return resp
options = _merge_options(options)
#if we're nuking data, and we're multi-core disable replication for safety
# if we're nuking data, and we're multi-core disable replication for safety
if options['clean'] and _check_for_cores():
resp = set_replication_enabled(False, host=host, core_name=core_name)
if not resp['success']:

View File

@ -3,15 +3,19 @@
Provide the service module for system supervisord or supervisord in a
virtualenv
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import os
# Import 3rd-party libs
from salt.ext.six import string_types
from salt.ext.six.moves import configparser # pylint: disable=import-error
# Import salt libs
import salt.utils
from salt.exceptions import CommandExecutionError, CommandNotFoundError
from salt._compat import configparser, string_types
def __virtual__():
@ -375,10 +379,12 @@ def options(name, conf_file=None):
ret = {}
for key, val in config.items(section_name):
val = salt.utils.str_to_num(val.split(';')[0].strip())
# pylint: disable=maybe-no-member
if isinstance(val, string_types):
if val.lower() == 'true':
val = True
elif val.lower() == 'false':
val = False
# pylint: enable=maybe-no-member
ret[key] = val
return ret

View File

@ -45,12 +45,22 @@ from __future__ import absolute_import
# Import python libs
import glob
import hashlib
import urllib
import urllib2
import tempfile
import os
import re
# Import 3rd-party libs
# pylint: disable=no-name-in-module,import-error
from salt.ext.six.moves.urllib.parse import urlencode as _urlencode
from salt.ext.six.moves.urllib.request import (
urlopen as _urlopen,
HTTPBasicAuthHandler as _HTTPBasicAuthHandler,
HTTPDigestAuthHandler as _HTTPDigestAuthHandler,
build_opener as _build_opener,
install_opener as _install_opener
)
# pylint: enable=no-name-in-module,import-error
# Import Salt libs
import salt.utils
@ -116,13 +126,13 @@ def _auth(uri):
if user is False or password is False:
return False
basic = urllib2.HTTPBasicAuthHandler()
basic = _HTTPBasicAuthHandler()
basic.add_password(realm='Tomcat Manager Application', uri=uri,
user=user, passwd=password)
digest = urllib2.HTTPDigestAuthHandler()
digest = _HTTPDigestAuthHandler()
digest.add_password(realm='Tomcat Manager Application', uri=uri,
user=user, passwd=password)
return urllib2.build_opener(basic, digest)
return _build_opener(basic, digest)
def _wget(cmd, opts=None, url='http://localhost:8080/manager', timeout=180):
@ -167,19 +177,19 @@ def _wget(cmd, opts=None, url='http://localhost:8080/manager', timeout=180):
url += 'text/{0}'.format(cmd)
url6 += '{0}'.format(cmd)
if opts:
url += '?{0}'.format(urllib.urlencode(opts))
url6 += '?{0}'.format(urllib.urlencode(opts))
url += '?{0}'.format(_urlencode(opts))
url6 += '?{0}'.format(_urlencode(opts))
# Make the HTTP request
urllib2.install_opener(auth)
_install_opener(auth)
try:
# Trying tomcat >= 7 url
ret['msg'] = urllib2.urlopen(url, timeout=timeout).read().splitlines()
ret['msg'] = _urlopen(url, timeout=timeout).read().splitlines()
except Exception:
try:
# Trying tomcat6 url
ret['msg'] = urllib2.urlopen(url6, timeout=timeout).read().splitlines()
ret['msg'] = _urlopen(url6, timeout=timeout).read().splitlines()
except Exception:
ret['msg'] = 'Failed to create HTTP request'

View File

@ -16,14 +16,15 @@ import shutil
import subprocess
import string # pylint: disable=deprecated-module
import logging
import salt.ext.six as six
# Import third party libs
import yaml
import jinja2
import jinja2.exceptions
import salt.ext.six as six
from salt.ext.six.moves import StringIO as _StringIO # pylint: disable=import-error
try:
import libvirt
import libvirt # pylint: disable=import-error
from xml.dom import minidom
HAS_ALL_IMPORTS = True
except ImportError:
@ -34,7 +35,6 @@ import salt.utils
import salt.utils.files
import salt.utils.templates
import salt.utils.validate.net
from salt._compat import StringIO as _StringIO
from salt.exceptions import CommandExecutionError, SaltInvocationError
log = logging.getLogger(__name__)
@ -1589,7 +1589,7 @@ def is_hyper():
salt '*' virt.is_hyper
'''
try:
import libvirt
import libvirt # pylint: disable=import-error
except ImportError:
# not a usable hypervisor without libvirt module
return False

View File

@ -30,7 +30,7 @@ import fileinput # do not remove, used in imported file.py functions
import fnmatch # do not remove, used in imported file.py functions
from salt.ext.six import string_types # do not remove, used in imported file.py functions
# do not remove, used in imported file.py functions
from salt.ext.six.moves.urllib.parse import urlparse # pylint: disable=E0611
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse # pylint: disable=import-error,no-name-in-module
import salt.utils.atomicfile # do not remove, used in imported file.py functions
from salt.exceptions import CommandExecutionError, SaltInvocationError
# pylint: enable=W0611

View File

@ -19,20 +19,17 @@ import copy
import logging
import os
import re
from distutils.version import LooseVersion as _LooseVersion
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote # pylint: disable=E0611
from distutils.version import LooseVersion as _LooseVersion # pylint: disable=no-name-in-module,import-error
# Import 3rd-party libs
# pylint: disable=import-error,redefined-builtin
import salt.ext.six as six
from distutils.version import LooseVersion as _LooseVersion
from salt.ext.six.moves import range
from salt.ext.six import string_types
from salt.ext.six.moves import shlex_quote as _cmd_quote, range
# pylint: enable=import-error
# Import salt libs
import salt.utils
import salt.ext.six as six
from salt.ext.six import string_types
from salt.exceptions import (
CommandExecutionError, MinionError, SaltInvocationError
)
@ -722,6 +719,7 @@ def group_install(name,
elif not isinstance(groups, list):
raise SaltInvocationError('\'groups\' must be a list')
# pylint: disable=maybe-no-member
if isinstance(skip, string_types):
skip = skip.split(',')
if not isinstance(skip, (list, tuple)):
@ -731,6 +729,7 @@ def group_install(name,
include = include.split(',')
if not isinstance(include, (list, tuple)):
raise SaltInvocationError('\'include\' must be a list')
# pylint: enable=maybe-no-member
targets = []
for group in groups:

View File

@ -22,34 +22,26 @@ You have those following methods:
* run_buildout
* buildout
'''
from __future__ import absolute_import
import salt.ext.six as six
from salt.ext.six.moves import range
# Define the module's virtual name
__virtualname__ = 'buildout'
def __virtual__():
'''
Only load if buildout libs are present
'''
if True:
return __virtualname__
return False
# Import python libs
from __future__ import absolute_import
import os
import re
import logging
import sys
import traceback
import copy
import urllib2
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six import string_types, text_type
from salt.ext.six.moves import range
from salt.ext.six.moves.urllib.request import urlopen as _urlopen
# pylint: enable=import-error,no-name-in-module,redefined-builtin
# Import salt libs
from salt.exceptions import CommandExecutionError
from salt.ext.six import string_types
INVALID_RESPONSE = 'We did not get any expectable answer from buildout'
@ -73,6 +65,18 @@ _URL_VERSIONS = {
DEFAULT_VER = 2
_logger = logging.getLogger(__name__)
# Define the module's virtual name
__virtualname__ = 'buildout'
def __virtual__():
'''
Only load if buildout libs are present
'''
if True:
return __virtualname__
return False
def _salt_callback(func, **kwargs):
LOG.clear()
@ -139,7 +143,7 @@ class _Logger(object):
self._by_level = {}
def _log(self, level, msg):
if not isinstance(msg, six.text_type):
if not isinstance(msg, text_type):
msg = msg.decode('utf-8')
if level not in self._by_level:
self._by_level[level] = []
@ -182,7 +186,7 @@ LOG = _Logger()
def _encode_string(string):
if isinstance(string, six.text_type):
if isinstance(string, text_type):
string = string.encode('utf-8')
return string
@ -522,7 +526,7 @@ def upgrade_bootstrap(directory='.',
'{0}.updated_bootstrap'.format(buildout_ver)))
except (OSError, IOError):
LOG.info('Bootstrap updated from repository')
data = urllib2.urlopen(booturl).read()
data = _urlopen(booturl).read()
updated = True
dled = True
if 'socket.setdefaulttimeout' not in data:

View File

@ -11,14 +11,15 @@ import copy
import logging
import re
import os
# Import 3rd-party libs
# pylint: disable=import-error,redefined-builtin,no-name-in-module
import salt.ext.six as six
import salt.ext.six.moves.configparser # pylint: disable=E0611
import urlparse
from salt.ext.six.moves import shlex_quote as _cmd_quote, configparser
from salt.ext.six.moves.urllib.parse import urlparse
# pylint: enable=import-error,redefined-builtin,no-name-in-module
from xml.dom import minidom as dom
try:
from shlex import quote as _cmd_quote # pylint: disable=E0611
except ImportError:
from pipes import quote as _cmd_quote
# Import salt libs
import salt.utils
@ -28,9 +29,9 @@ from salt.exceptions import (
log = logging.getLogger(__name__)
HAS_ZYPP = False
ZYPP_HOME = "/etc/zypp"
LOCKS = "{0}/locks".format(ZYPP_HOME)
REPOS = "{0}/repos.d".format(ZYPP_HOME)
ZYPP_HOME = '/etc/zypp'
LOCKS = '{0}/locks'.format(ZYPP_HOME)
REPOS = '{0}/repos.d'.format(ZYPP_HOME)
# Define the module's virtual name
__virtualname__ = 'pkg'
@ -245,8 +246,8 @@ def _get_configured_repos():
Get all the info about repositories from the configurations.
'''
repos_cfg = salt.ext.six.moves.configparser.ConfigParser()
repos_cfg.read([REPOS + "/" + fname for fname in os.listdir(REPOS)])
repos_cfg = configparser.ConfigParser()
repos_cfg.read([REPOS + '/' + fname for fname in os.listdir(REPOS)])
return repos_cfg
@ -314,14 +315,14 @@ def del_repo(repo):
if alias == repo:
cmd = ('zypper -x --non-interactive rr --loose-auth --loose-query {0}'.format(alias))
doc = dom.parseString(__salt__['cmd.run'](cmd, output_loglevel='trace'))
msg = doc.getElementsByTagName("message")
if doc.getElementsByTagName("progress") and msg:
msg = doc.getElementsByTagName('message')
if doc.getElementsByTagName('progress') and msg:
return {
repo: True,
'message': msg[0].childNodes[0].nodeValue,
}
raise CommandExecutionError('Repository "{0}" not found.'.format(repo))
raise CommandExecutionError('Repository \'{0}\' not found.'.format(repo))
def mod_repo(repo, **kwargs):
@ -365,21 +366,21 @@ def mod_repo(repo, **kwargs):
# An attempt to add new one?
if repo not in repos_cfg.sections():
url = kwargs.get("url", kwargs.get("mirrorlist"))
url = kwargs.get('url', kwargs.get('mirrorlist'))
if not url:
raise CommandExecutionError(
'Repository "{0}" not found and no URL passed to create one.'.format(repo))
'Repository \'{0}\' not found and no URL passed to create one.'.format(repo))
if not urlparse.urlparse(url).scheme:
if not urlparse(url).scheme:
raise CommandExecutionError(
'Repository "{0}" not found and passed URL looks wrong.'.format(repo))
'Repository \'{0}\' not found and passed URL looks wrong.'.format(repo))
# Is there already such repo under different alias?
for alias in repos_cfg.sections():
repo_meta = _get_repo_info(alias, repos_cfg=repos_cfg)
# Complete user URL, in case it is not
new_url = urlparse.urlparse(url)
new_url = urlparse(url)
if not new_url.path:
new_url = urlparse.ParseResult(scheme=new_url.scheme, # pylint: disable=E1123
netloc=new_url.netloc,
@ -387,59 +388,61 @@ def mod_repo(repo, **kwargs):
params=new_url.params,
query=new_url.query,
fragment=new_url.fragment)
base_url = urlparse.urlparse(repo_meta["baseurl"])
base_url = urlparse(repo_meta['baseurl'])
if new_url == base_url:
raise CommandExecutionError(
'Repository "{0}" already exists as "{1}".'.format(repo, alias))
'Repository \'{0}\' already exists as \'{1}\'.'.format(repo, alias))
# Add new repo
doc = None
try:
# Try to parse the output and find the error,
# but this not always working (depends on Zypper version)
doc = dom.parseString(__salt__['cmd.run'](("zypper -x ar {0} '{1}'".format(url, repo)),
doc = dom.parseString(__salt__['cmd.run'](('zypper -x ar {0} \'{1}\''.format(url, repo)),
output_loglevel='trace'))
except Exception:
# No XML out available, but it is still unknown the state of the result.
pass
if doc:
msg_nodes = doc.getElementsByTagName("message")
msg_nodes = doc.getElementsByTagName('message')
if msg_nodes:
msg_node = msg_nodes[0]
if msg_node.getAttribute("type") == "error":
if msg_node.getAttribute('type') == 'error':
raise CommandExecutionError(msg_node.childNodes[0].nodeValue)
# Verify the repository has been added
repos_cfg = _get_configured_repos()
if repo not in repos_cfg.sections():
raise CommandExecutionError(
'Failed add new repository "{0}" for unknown reason. Please look into Zypper logs.'.format(repo))
'Failed add new repository \'{0}\' for unknown reason. '
'Please look into Zypper logs.'.format(repo))
added = True
# Modify added or existing repo according to the options
cmd_opt = []
if "enabled" in kwargs:
cmd_opt.append(kwargs["enabled"] and "--enable" or "--disable")
if 'enabled' in kwargs:
cmd_opt.append(kwargs['enabled'] and '--enable' or '--disable')
if "refresh" in kwargs:
cmd_opt.append(kwargs["refresh"] and "--refresh" or "--no-refresh")
if 'refresh' in kwargs:
cmd_opt.append(kwargs['refresh'] and '--refresh' or '--no-refresh')
if "cache" in kwargs:
cmd_opt.append(kwargs["cache"] and "--keep-packages" or "--no-keep-packages")
if 'cache' in kwargs:
cmd_opt.append(kwargs['cache'] and '--keep-packages' or '--no-keep-packages')
if "gpgcheck" in kwargs:
cmd_opt.append(kwargs["gpgcheck"] and "--gpgcheck" or "--no-gpgcheck")
if 'gpgcheck' in kwargs:
cmd_opt.append(kwargs['gpgcheck'] and '--gpgcheck' or '--no-gpgcheck')
if cmd_opt:
__salt__['cmd.run'](("zypper -x mr {0} '{1}'".format(' '.join(cmd_opt), repo)),
__salt__['cmd.run'](('zypper -x mr {0} \'{1}\''.format(' '.join(cmd_opt), repo)),
output_loglevel='trace')
# If repo nor added neither modified, error should be thrown
if not added and not cmd_opt:
raise CommandExecutionError('Modification of the repository "{0}" was not specified.'.format(repo))
raise CommandExecutionError(
'Modification of the repository \'{0}\' was not specified.'.format(repo))
return {}
@ -474,11 +477,11 @@ def refresh_db():
if not line:
continue
if line.strip().startswith('Repository'):
key = line.split("'")[1].strip()
key = line.split('\'')[1].strip()
if 'is up to date' in line:
ret[key] = False
elif line.strip().startswith('Building'):
key = line.split("'")[1].strip()
key = line.split('\'')[1].strip()
if 'done' in line:
ret[key] = True
return ret
@ -572,7 +575,7 @@ def install(name=None,
# Allow "version" to work for single package target
pkg_params = {name: version_num}
else:
log.warning('"version" parameter will be ignored for multiple '
log.warning('\'version\' parameter will be ignored for multiple '
'package targets')
if pkg_type == 'repository':
@ -605,10 +608,10 @@ def install(name=None,
old = list_pkgs()
downgrades = []
if fromrepo:
fromrepoopt = "--force --force-resolution --from {0} ".format(fromrepo)
fromrepoopt = '--force --force-resolution --from {0} '.format(fromrepo)
log.info('Targeting repo {0!r}'.format(fromrepo))
else:
fromrepoopt = ""
fromrepoopt = ''
# Split the targets into batches of 500 packages each, so that
# the maximal length of the command line is not broken
while targets:
@ -793,11 +796,11 @@ def list_locks():
return False
locks = {}
for meta in [item.split("\n") for item in open(LOCKS).read().split("\n\n")]:
for meta in [item.split('\n') for item in open(LOCKS).read().split('\n\n')]:
lock = {}
for element in [el for el in meta if el]:
if ":" in element:
lock.update(dict([tuple([i.strip() for i in element.split(":", 1)]), ]))
if ':' in element:
lock.update(dict([tuple([i.strip() for i in element.split(':', 1)]), ]))
if lock.get('solvable_name'):
locks[lock.pop('solvable_name')] = lock
@ -969,12 +972,12 @@ def _get_patterns(installed_only=None):
patterns = {}
doc = dom.parseString(__salt__['cmd.run'](('zypper --xmlout se -t pattern'),
output_loglevel='trace'))
for element in doc.getElementsByTagName("solvable"):
installed = element.getAttribute("status") == "installed"
for element in doc.getElementsByTagName('solvable'):
installed = element.getAttribute('status') == 'installed'
if (installed_only and installed) or not installed_only:
patterns[element.getAttribute("name")] = {
patterns[element.getAttribute('name')] = {
'installed': installed,
'summary': element.getAttribute("summary"),
'summary': element.getAttribute('summary'),
}
return patterns
@ -1018,16 +1021,16 @@ def search(criteria):
'''
doc = dom.parseString(__salt__['cmd.run'](('zypper --xmlout se {0}'.format(criteria)),
output_loglevel='trace'))
solvables = doc.getElementsByTagName("solvable")
solvables = doc.getElementsByTagName('solvable')
if not solvables:
raise CommandExecutionError("No packages found by criteria \"{0}\".".format(criteria))
raise CommandExecutionError('No packages found by criteria "{0}".'.format(criteria))
out = {}
for solvable in [s for s in solvables
if s.getAttribute("status") == "not-installed" and
s.getAttribute("kind") == "package"]:
out[solvable.getAttribute("name")] = {
'summary': solvable.getAttribute("summary")
if s.getAttribute('status') == 'not-installed' and
s.getAttribute('kind') == 'package']:
out[solvable.getAttribute('name')] = {
'summary': solvable.getAttribute('summary')
}
return out
@ -1037,13 +1040,13 @@ def _get_first_aggregate_text(node_list):
Extract text from the first occurred DOM aggregate.
'''
if not node_list:
return ""
return ''
out = []
for node in node_list[0].childNodes:
if node.nodeType == dom.Document.TEXT_NODE:
out.append(node.nodeValue)
return "\n".join(out)
return '\n'.join(out)
def _parse_suse_product(path, *info):
@ -1072,12 +1075,12 @@ def list_products():
salt '*' pkg.list_products
'''
PRODUCTS = "/etc/products.d"
PRODUCTS = '/etc/products.d'
if not os.path.exists(PRODUCTS):
raise CommandExecutionError("Directory {0} does not exists.".format(PRODUCTS))
raise CommandExecutionError('Directory {0} does not exists.'.format(PRODUCTS))
products = {}
for fname in os.listdir("/etc/products.d"):
for fname in os.listdir('/etc/products.d'):
pth_name = os.path.join(PRODUCTS, fname)
r_pth_name = os.path.realpath(pth_name)
products[r_pth_name] = r_pth_name != pth_name and 'baseproduct' or None

View File

@ -63,15 +63,19 @@ import logging
import os
import time
import pickle
import urllib
from copy import deepcopy
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
import salt.ext.six as six
from salt.ext.six.moves import filter
from salt.ext.six.moves.urllib.parse import quote as _quote
# pylint: enable=import-error,no-name-in-module,redefined-builtin
# Import salt libs
from salt.pillar import Pillar
import salt.utils
import salt.utils.s3 as s3
import salt.ext.six as six
from salt.ext.six.moves import filter
# Set up logging
log = logging.getLogger(__name__)
@ -347,7 +351,7 @@ def _get_file_from_s3(creds, metadata, saltenv, bucket, path,
keyid=creds.keyid,
bucket=bucket,
service_url=creds.service_url,
path=urllib.quote(path),
path=_quote(path),
local_file=cached_file_path,
verify_ssl=creds.verify_ssl
)

View File

@ -41,13 +41,23 @@ otherwise multi-minion targetting can lead to losing output:
* the first returning minion is able to create a document in the database
* other minions fail with ``{'error': 'HTTP Error 409: Conflict'}``
'''
from __future__ import absolute_import
# Import Python libs
from __future__ import absolute_import
import logging
import time
import urllib2
import json
# Import 3rd-party libs
# pylint: disable=no-name-in-module,import-error
from salt.ext.six.moves.urllib.error import HTTPError
from salt.ext.six.moves.urllib.request import (
Request as _Request,
HTTPHandler as _HTTPHandler,
build_opener as _build_opener,
)
# pylint: enable=no-name-in-module,import-error
# Import Salt libs
import salt.utils
import salt.returners
@ -88,37 +98,37 @@ def _get_options(ret=None):
return {"url": server_url, "db": db_name}
def _generate_doc(ret, options):
def _generate_doc(ret):
'''
Create a object that will be saved into the database based on
options.
'''
# Create a copy of the object that we will return.
r = ret.copy()
retc = ret.copy()
# Set the ID of the document to be the JID.
r["_id"] = ret["jid"]
retc["_id"] = ret["jid"]
# Add a timestamp field to the document
r["timestamp"] = time.time()
retc["timestamp"] = time.time()
return r
return retc
def _request(method, url, content_type=None, _data=None):
'''
Makes a HTTP request. Returns the JSON parse, or an obj with an error.
'''
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(url, data=_data)
opener = _build_opener(_HTTPHandler)
request = _Request(url, data=_data)
if content_type:
request.add_header('Content-Type', content_type)
request.get_method = lambda: method
try:
handler = opener.open(request)
except urllib2.HTTPError as e:
return {'error': '{0}'.format(e)}
except HTTPError as exc:
return {'error': '{0}'.format(exc)}
return json.loads(handler.read())
@ -146,7 +156,7 @@ def returner(ret):
# Call _generate_doc to get a dict object of the document we're going to
# shove into the database.
doc = _generate_doc(ret, options)
doc = _generate_doc(ret)
# Make the actual HTTP PUT request to create the doc.
_response = _request("PUT",
@ -195,7 +205,7 @@ def get_jids():
# See if the identifier is an int..
try:
int(row['id'])
except Exception:
except ValueError:
continue
# Check the correct number of digits by simply casting to str and

View File

@ -60,14 +60,21 @@ Hipchat settings may also be configured as::
'''
from __future__ import absolute_import
import salt.returners
# Import Python libs
import json
import pprint
import requests
import logging
from urlparse import urljoin as _urljoin
# Import 3rd-party libs
import requests
from requests.exceptions import ConnectionError
# pylint: disable=import-error
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin # pylint: disable=import-error,no-name-in-module
# pylint: enable=import-error
# Import Salt Libs
import salt.returners
log = logging.getLogger(__name__)
__virtualname__ = 'hipchat'

View File

@ -55,15 +55,22 @@ Hipchat settings may also be configured as::
'''
from __future__ import absolute_import
# Import Python libs
import pprint
import logging
# Import 3rd-party libs
import requests
from requests.exceptions import ConnectionError
# pylint: disable=import-error
from salt.ext.six.moves.urllib.parse import urljoin as _urljoin # pylint: disable=import-error,no-name-in-module
# pylint: enable=import-error
# Import Salt Libs
import salt.returners
import pprint
import requests
import logging
from urlparse import urljoin as _urljoin
from requests.exceptions import ConnectionError
log = logging.getLogger(__name__)
__virtualname__ = 'slack'

View File

@ -5,15 +5,16 @@ and what hosts are down
'''
# Import python libs
from __future__ import print_function
from __future__ import absolute_import
from __future__ import absolute_import, print_function
import os
import operator
import re
import subprocess
import tempfile
import time
import urllib
# Import 3rd-party libs
from salt.ext.six.moves.urllib.request import urlopen as _urlopen # pylint: disable=no-name-in-module,import-error
# Import salt libs
import salt.key
@ -370,7 +371,7 @@ def bootstrap_psexec(hosts='', master=None, version=None, arch='win32',
if not installer_url:
base_url = 'http://docs.saltstack.com/downloads/'
source = urllib.urlopen(base_url).read()
source = _urlopen(base_url).read()
salty_rx = re.compile('>(Salt-Minion-(.+?)-(.+)-Setup.exe)</a></td><td align="right">(.*?)\\s*<')
source_list = sorted([[path, ver, plat, time.strptime(date, "%d-%b-%Y %H:%M")]
for path, ver, plat, date in salty_rx.findall(source)],

View File

@ -18,16 +18,17 @@ import datetime
import hashlib
import hmac
import logging
import urllib
import urlparse
import requests
# Import Salt libs
import salt.utils.xmlutil as xml
from salt._compat import ElementTree as ET
from salt.ext.six.moves import map
from salt.ext.six.moves import zip
from salt.ext.six.moves import range
# Import 3rd-party libs
import requests
# pylint: disable=import-error,redefined-builtin,no-name-in-module
from salt.ext.six.moves import map, range, zip
from salt.ext.six.moves.urllib.parse import urlencode, urlparse
# pylint: enable=import-error,redefined-builtin,no-name-in-module
LOG = logging.getLogger(__name__)
DEFAULT_LOCATION = 'us-east-1'
@ -60,7 +61,7 @@ def sig2(method, endpoint, params, provider, aws_api_version):
params_with_headers['Version'] = aws_api_version
keys = sorted(params_with_headers.keys())
values = list(list(map(params_with_headers.get, keys)))
querystring = urllib.urlencode(list(zip(keys, values)))
querystring = urlencode(list(zip(keys, values)))
canonical = '{0}\n{1}\n/\n{2}'.format(
method.encode('utf-8'),
@ -91,7 +92,7 @@ def sig4(method, endpoint, params, prov_dict, aws_api_version, location,
params_with_headers['Version'] = aws_api_version
keys = sorted(params_with_headers.keys())
values = list(map(params_with_headers.get, keys))
querystring = urllib.urlencode(list(zip(keys, values)))
querystring = urlencode(list(zip(keys, values)))
amzdate = timenow.strftime('%Y%m%dT%H%M%SZ')
datestamp = timenow.strftime('%Y%m%d')
@ -254,7 +255,7 @@ def query(params=None, setname=None, requesturl=None, location=None,
requesturl = 'https://{0}/'.format(endpoint)
else:
endpoint = urlparse.urlparse(requesturl).netloc
endpoint = urlparse(requesturl).netloc
if endpoint == '':
endpoint_err = ('Could not find a valid endpoint in the '
'requesturl: {0}. Looking for something '

View File

@ -104,9 +104,11 @@ try:
except ImportError:
pass
# Import 3rd-party libs
import salt.ext.six as six
# Import salt libs
import salt.utils
from salt._compat import MAX_SIZE
from salt.utils.filebuffer import BufferedReader
# Set up logger
@ -209,7 +211,7 @@ def _parse_size(value):
max_size = num
elif style == '+':
min_size = num
max_size = MAX_SIZE
max_size = six.MAXSIZE
else:
min_size = num
max_size = num + multiplier - 1

View File

@ -9,7 +9,9 @@ from __future__ import absolute_import
# Import python libs
import gzip
from salt._compat import StringIO
# Import 3rd-party libs
from salt.ext.six.moves import StringIO # pylint: disable=import-error
class GzipFile(gzip.GzipFile):

View File

@ -6,7 +6,10 @@ import os
import urlparse
# Import third party libs
from mako.lookup import TemplateCollection, TemplateLookup
# pylint: disable=import-error,no-name-in-module
from salt.ext.six.moves.urllib.parse import urlparse
# pylint: enable=import-error,no-name-in-module
from mako.lookup import TemplateCollection, TemplateLookup # pylint: disable=import-error
# Import salt libs
import salt.fileclient
@ -57,7 +60,7 @@ class SaltMakoTemplateLookup(TemplateCollection):
self.cache = {}
def adjust_uri(self, uri, filename):
scheme = urlparse.urlparse(uri).scheme
scheme = urlparse(uri).scheme
if scheme in ('salt', 'file'):
return uri
elif scheme:

View File

@ -21,6 +21,9 @@ import optparse
import traceback
from functools import partial
# Import 3rd-party libs
import salt.ext.six as six
# Import salt libs
import salt.config as config
import salt.exitcodes
@ -34,7 +37,6 @@ import salt.utils.xdg
from salt.utils import kinds
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.utils.validate.path import is_writeable
from salt._compat import MAX_SIZE
def _sorted(mixins_or_funcs):
@ -207,7 +209,7 @@ class MergeConfigMixIn(object):
This mix-in should run last.
'''
__metaclass__ = MixInMeta
_mixin_prio_ = MAX_SIZE
_mixin_prio_ = six.MAXSIZE
def _mixin_setup(self):
if not hasattr(self, 'setup_config') and not hasattr(self, 'config'):

View File

@ -12,8 +12,10 @@ import datetime
import hashlib
import hmac
import logging
import urllib
# Import 3rd-party libs
import requests
from salt.ext.six.moves.urllib.parse import urlencode # pylint: disable=no-name-in-module,import-error
# Import Salt libs
import salt.utils
@ -128,7 +130,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
sig = binascii.b2a_base64(hashed.digest())
headers['Authorization'] = 'AWS {0}:{1}'.format(keyid, sig.strip())
querystring = urllib.urlencode(params)
querystring = urlencode(params)
if action:
if querystring:
querystring = '{0}&{1}'.format(action, querystring)

View File

@ -2,9 +2,10 @@
'''
Generate the salt thin tarball from the installed python files
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import os
import shutil
import tarfile
@ -15,6 +16,9 @@ import tempfile
import jinja2
import yaml
import requests
import salt.ext.six as six
# pylint: disable=import-error,no-name-in-module
try:
import msgpack
HAS_MSGPACK = True
@ -26,27 +30,17 @@ try:
except ImportError:
# Import the bundled package
try:
from requests.packages import urllib3 # pylint: disable=E0611
from requests.packages import urllib3
HAS_URLLIB3 = True
except ImportError:
HAS_URLLIB3 = False
try:
import salt.ext.six as six
HAS_SIX = True
except ImportError:
# Import the bundled package
try:
from requests.packages.urllib3.packages import six # pylint: disable=E0611
HAS_SIX = True
except ImportError:
HAS_SIX = False
try:
import chardet
HAS_CHARDET = True
except ImportError:
# Import the bundled package
try:
from requests.packages.urllib3.packages import chardet # pylint: disable=E0611
from requests.packages.urllib3.packages import chardet
HAS_CHARDET = True
except ImportError:
HAS_CHARDET = False
@ -56,6 +50,7 @@ try:
except ImportError:
# Older jinja does not need markupsafe
HAS_MARKUPSAFE = False
# pylint: enable=import-error,no-name-in-module
# Import salt libs
import salt
@ -108,8 +103,7 @@ def gen_thin(cachedir, extra_mods='', overwrite=False, so_mods=''):
if HAS_URLLIB3:
tops.append(os.path.dirname(urllib3.__file__))
if HAS_SIX:
tops.append(six.__file__.replace('.pyc', '.py'))
tops.append(six.__file__.replace('.pyc', '.py'))
if HAS_CHARDET:
tops.append(os.path.dirname(chardet.__file__))

View File

@ -6,27 +6,15 @@ import subprocess
import tempfile
# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
from salttesting.helpers import ensure_in_syspath, skip_if_binaries_missing
ensure_in_syspath('../..')
# Import salt libs
import integration
@skip_if_binaries_missing('git')
class GitModuleTest(integration.ModuleCase):
'''
Integration tests for the git module
'''
@classmethod
def setUpClass(cls):
'''
Check if git is installed. If it isn't, skip everything in this class.
'''
from salt.utils import which
git = which('git')
if not git:
cls.skipTest('The git binary is not available')
def setUp(self):
self.repos = tempfile.mkdtemp(dir=integration.TMP)

View File

@ -1,24 +1,23 @@
# coding: utf-8
# Import python libs
import urllib
# Import salttesting libs
from salttesting import mock
from salttesting.unit import skipIf
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../../')
from salt.exceptions import EauthAuthenticationError
from tests.utils import BaseRestCherryPyTest
# Import 3rd-party libs
# pylint: disable=import-error,unused-import
from salt.ext.six.moves.urllib.parse import urlencode # pylint: disable=no-name-in-module
try:
import cherrypy # pylint: disable=W0611
import cherrypy
HAS_CHERRYPY = True
except ImportError:
HAS_CHERRYPY = False
# pylint: enable=import-error,unused-import
@skipIf(HAS_CHERRYPY is False, 'CherryPy not installed')
@ -78,7 +77,7 @@ class TestLogin(BaseRestCherryPyTest):
'eauth': 'auto',
}
body = urllib.urlencode(self.auth_creds)
body = urlencode(self.auth_creds)
request, response = self.request('/login', method='POST', body=body,
headers={
'content-type': 'application/x-www-form-urlencoded'
@ -93,7 +92,7 @@ class TestLogin(BaseRestCherryPyTest):
# Mock mk_token for a negative return
self.Resolver.return_value.mk_token.return_value = {}
body = urllib.urlencode({'totally': 'invalid_creds'})
body = urlencode({'totally': 'invalid_creds'})
request, response = self.request('/login', method='POST', body=body,
headers={
'content-type': 'application/x-www-form-urlencoded'
@ -104,7 +103,7 @@ class TestLogin(BaseRestCherryPyTest):
ret = self.test_good_login()
token = ret.headers['X-Auth-Token']
body = urllib.urlencode({})
body = urlencode({})
request, response = self.request('/logout', method='POST', body=body,
headers={
'content-type': 'application/x-www-form-urlencoded',
@ -130,7 +129,7 @@ class TestRun(BaseRestCherryPyTest):
Test the run URL with good auth credentials
'''
cmd = dict(self.low, **dict(self.auth_creds))
body = urllib.urlencode(cmd)
body = urlencode(cmd)
# Mock the interaction with Salt so we can focus on the API.
with mock.patch.object(self.app.salt.netapi.NetapiClient, 'run',
@ -147,7 +146,7 @@ class TestRun(BaseRestCherryPyTest):
Test the run URL with bad auth credentials
'''
cmd = dict(self.low, **{'totally': 'invalid_creds'})
body = urllib.urlencode(cmd)
body = urlencode(cmd)
# Mock the interaction with Salt so we can focus on the API.
with mock.patch.object(self.app.salt.netapi.NetapiClient, 'run',
@ -183,7 +182,7 @@ class TestWebhookDisableAuth(BaseRestCherryPyTest):
# Mock fire_event() since we're only testing auth here.
self.get_event.return_value.fire_event.return_value = True
body = urllib.urlencode({'foo': 'Foo!'})
body = urlencode({'foo': 'Foo!'})
request, response = self.request('/hook', method='POST', body=body,
headers={
'content-type': 'application/x-www-form-urlencoded'

View File

@ -1,18 +1,23 @@
# coding: utf-8
import json
from salt.netapi.rest_tornado import saltnado
import tornado.testing
import tornado.concurrent
import tornado.web
import tornado.ioloop
from unit.netapi.rest_tornado.test_handlers import SaltnadoTestCase
import json
import time
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../../')
try:
from salt.netapi.rest_tornado import saltnado
import tornado.testing
import tornado.concurrent
import tornado.web
import tornado.ioloop
except ImportError:
pass
from unit.netapi.rest_tornado.test_handlers import SaltnadoTestCase
class TestSaltAPIHandler(SaltnadoTestCase):
def get_app(self):
@ -492,3 +497,13 @@ class TestWebhookSaltAPIHandler(SaltnadoTestCase):
)
response_obj = json.loads(response.body)
assert response_obj['success'] is True
if __name__ == '__main__':
from integration import run_tests # pylint: disable=import-error
run_tests(TestEventsSaltAPIHandler,
TestJobsSaltAPIHandler,
TestMinionSaltAPIHandler,
TestRunSaltAPIHandler,
TestSaltAPIHandler,
TestWebhookSaltAPIHandler, needs_daemon=True)

View File

@ -1,7 +1,12 @@
# coding: utf-8
import salt.loader
from tests.integration import ModuleCase
# Import salt testing libs
from salttesting.case import ModuleCase
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Import Salt libs
import salt.loader
class HashutilTestCase(ModuleCase):

View File

@ -1,15 +1,14 @@
# -*- coding: utf-8 -*-
import urllib2
# Import Salt Testing libs
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, Mock, patch
from salt.modules import nginx
ensure_in_syspath('../../')
# Import Salt Module
from salt.modules import nginx
MOCK_STATUS_OUTPUT = """Active connections: 7
server accepts handled requests
46756 46756 89318
@ -29,10 +28,10 @@ class MockUrllibStatus(object):
@patch('salt.utils.which', Mock(return_value='/usr/bin/nginx'))
class NginxTestCase(TestCase):
@patch('urllib2.urlopen', Mock(return_value=MockUrllibStatus()))
@patch('salt.modules.nginx._urlopen', Mock(return_value=MockUrllibStatus()))
def test_nginx_status(self):
result = nginx.status()
urllib2.urlopen.assert_called_once_with('http://127.0.0.1/status')
nginx._urlopen.assert_called_once_with('http://127.0.0.1/status')
self.assertEqual(result, {
'active connections': 7,
'accepted': 46756,
@ -43,11 +42,11 @@ class NginxTestCase(TestCase):
'waiting': 0,
})
@patch('urllib2.urlopen', Mock(return_value=MockUrllibStatus()))
@patch('salt.modules.nginx._urlopen', Mock(return_value=MockUrllibStatus()))
def test_nginx_status_with_arg(self):
other_path = 'http://localhost/path'
result = nginx.status(other_path)
urllib2.urlopen.assert_called_once_with(other_path)
nginx._urlopen.assert_called_once_with(other_path)
if __name__ == '__main__':

View File

@ -3,10 +3,15 @@
# Import python libs
import os
import tempfile
import urllib2
import logging
import shutil
# Import 3rd-party libs
# pylint: disable=import-error,no-name-in-module,redefined-builtin
from salt.ext.six.moves.urllib.error import URLError
from salt.ext.six.moves.urllib.request import urlopen
# pylint: enable=import-error,no-name-in-module,redefined-builtin
# Import Salt Testing libs
from salttesting import TestCase, skipIf
from salttesting.helpers import (
@ -14,10 +19,10 @@ from salttesting.helpers import (
requires_network,
skip_if_binaries_missing
)
ensure_in_syspath('../../')
ensure_in_syspath('../..')
# Import Salt libs
import integration
import integration # pylint: disable=import-error
import salt.utils
from salt.modules import zcbuildout as buildout
from salt.modules import cmdmod as cmd
@ -51,9 +56,7 @@ log = logging.getLogger(__name__)
def download_to(url, dest):
with salt.utils.fopen(dest, 'w') as fic:
fic.write(
urllib2.urlopen(url, timeout=10).read()
)
fic.write(urlopen(url, timeout=10).read())
class Base(TestCase):
@ -70,7 +73,7 @@ class Base(TestCase):
)
try:
download_to(url, dest)
except urllib2.URLError:
except URLError:
log.debug('Failed to download {0}'.format(url))
# creating a new setuptools install
cls.ppy_st = os.path.join(cls.rdir, 'psetuptools')
@ -489,7 +492,7 @@ class BuildoutAPITestCase(TestCase):
if __name__ == '__main__':
from integration import run_tests
from integration import run_tests # pylint: disable=import-error
run_tests(
BuildoutAPITestCase,
BuildoutTestCase,

View File

@ -1,8 +1,11 @@
# coding: utf-8
import json
import urllib
# Import Python libs
import json
# Import 3rd-party libs
import yaml
from salt.ext.six.moves.urllib.parse import urlencode # pylint: disable=no-name-in-module,import-error
from tests.utils import BaseToolsTest
@ -43,7 +46,7 @@ class TestInFormats(BaseToolsTest):
def test_urlencoded_ctype(self):
data = {'valid': 'stuff'}
request, response = self.request('/', method='POST',
body=urllib.urlencode(data), headers=(
body=urlencode(data), headers=(
('Content-type', 'application/x-www-form-urlencoded'),
))
self.assertEqual(response.status, '200 OK')

View File

@ -1,18 +1,44 @@
# coding: utf-8
# Import Python libs
import json
import yaml
import urllib
from salt.netapi.rest_tornado import saltnado
# Import Salt Testing Libs
from salttesting.unit import skipIf
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../..')
import integration # pylint: disable=import-error
# Import Salt libs
try:
from salt.netapi.rest_tornado import saltnado
HAS_TORNADO = True
except ImportError:
HAS_TORNADO = False
import salt.auth
import integration
import tornado.testing
import tornado.concurrent
class SaltnadoTestCase(integration.ModuleCase, tornado.testing.AsyncHTTPTestCase):
# Import 3rd-party libs
# pylint: disable=import-error
try:
import tornado.testing
import tornado.concurrent
from tornado.testing import AsyncHTTPTestCase
HAS_TORNADO = True
except ImportError:
HAS_TORNADO = False
# Let's create a fake AsyncHTTPTestCase so we can properly skip the test case
class AsyncHTTPTestCase(object):
pass
from salt.ext.six.moves.urllib.parse import urlencode # pylint: disable=no-name-in-module
# pylint: enable=import-error
@skipIf(HAS_TORNADO is False, 'The tornado package needs to be installed')
class SaltnadoTestCase(integration.ModuleCase, AsyncHTTPTestCase):
'''
Mixin to hold some shared things
'''
@ -174,7 +200,7 @@ class TestBaseSaltAPIHandler(SaltnadoTestCase):
)
response = self.fetch('/',
method='POST',
body=urllib.urlencode(form_lowstate),
body=urlencode(form_lowstate),
headers={'Content-Type': self.content_type_map['form']})
returned_lowstate = json.loads(response.body)['lowstate']
assert len(returned_lowstate) == 1
@ -209,7 +235,7 @@ class TestSaltAuthHandler(SaltnadoTestCase):
'''
response = self.fetch('/login',
method='POST',
body=urllib.urlencode(self.auth_creds),
body=urlencode(self.auth_creds),
headers={'Content-Type': self.content_type_map['form']})
response_obj = json.loads(response.body)['return'][0]
@ -229,7 +255,7 @@ class TestSaltAuthHandler(SaltnadoTestCase):
bad_creds.append((key, val))
response = self.fetch('/login',
method='POST',
body=urllib.urlencode(bad_creds),
body=urlencode(bad_creds),
headers={'Content-Type': self.content_type_map['form']})
assert response.code == 400
@ -245,7 +271,12 @@ class TestSaltAuthHandler(SaltnadoTestCase):
bad_creds.append((key, val))
response = self.fetch('/login',
method='POST',
body=urllib.urlencode(bad_creds),
body=urlencode(bad_creds),
headers={'Content-Type': self.content_type_map['form']})
assert response.code == 401
if __name__ == '__main__':
from integration import run_tests # pylint: disable=import-error
run_tests(TestBaseSaltAPIHandler, TestSaltAuthHandler, needs_daemon=False)

View File

@ -1,15 +1,39 @@
# coding: utf-8
import os
from salt.netapi.rest_tornado import saltnado
# Import Salt Testing Libs
from salttesting.unit import skipIf
from salttesting.case import TestCase
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../..')
import tornado.testing
import tornado.concurrent
from salttesting import TestCase
# Import 3rd-party libs
# pylint: disable=import-error
try:
import tornado.testing
import tornado.concurrent
from tornado.testing import AsyncTestCase
HAS_TORNADO = True
except ImportError:
HAS_TORNADO = False
from unit.utils.event_test import eventpublisher_process, event, SOCK_DIR
# Let's create a fake AsyncHTTPTestCase so we can properly skip the test case
class AsyncTestCase(object):
pass
# pylint: enable=import-error
try:
from salt.netapi.rest_tornado import saltnado
HAS_TORNADO = True
except ImportError:
HAS_TORNADO = False
# Import utility lib from tests
from unit.utils.event_test import eventpublisher_process, event, SOCK_DIR # pylint: disable=import-error
@skipIf(HAS_TORNADO is False, 'The tornado package needs to be installed')
class TestUtils(TestCase):
def test_batching(self):
assert 1 == saltnado.get_batch_size('1', 10)
@ -20,7 +44,8 @@ class TestUtils(TestCase):
assert 11 == saltnado.get_batch_size('110%', 10)
class TestSaltnadoUtils(tornado.testing.AsyncTestCase):
@skipIf(HAS_TORNADO is False, 'The tornado package needs to be installed')
class TestSaltnadoUtils(AsyncTestCase):
def test_any_future(self):
'''
Test that the Any Future does what we think it does
@ -58,7 +83,8 @@ class TestSaltnadoUtils(tornado.testing.AsyncTestCase):
assert futures[1].done() is False
class TestEventListener(tornado.testing.AsyncTestCase):
@skipIf(HAS_TORNADO is False, 'The tornado package needs to be installed')
class TestEventListener(AsyncTestCase):
def setUp(self):
if not os.path.exists(SOCK_DIR):
os.makedirs(SOCK_DIR)
@ -85,5 +111,5 @@ class TestEventListener(tornado.testing.AsyncTestCase):
if __name__ == '__main__':
from integration import run_tests
from integration import run_tests # pylint: disable=import-error
run_tests(TestUtils, needs_daemon=False)

View File

@ -8,8 +8,8 @@ import datetime
import pprint
# Import Salt Testing libs
from tests.integration import ModuleCase
from salttesting import skipIf, TestCase
from salttesting.case import ModuleCase
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')