From ab7fd7041cfe52cee94402cf0a887c7af26302fb Mon Sep 17 00:00:00 2001 From: Kent Tenney Date: Thu, 19 Sep 2013 20:44:55 -0500 Subject: [PATCH 01/23] added -Contents-, removed inline markup from section headings --- doc/faq.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/faq.rst b/doc/faq.rst index 916af3a1ca..aefc03ec36 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -1,6 +1,8 @@ Frequently Asked Questions ========================== +.. contents:: FAQ + Is Salt open-core? ------------------ @@ -19,8 +21,8 @@ Minions need to be able to connect to the Master on TCP ports 4505 and 4506. Minions do not need any inbound ports open. More detailed information on firewall settings can be found :doc:`here `. -My script runs every time I run a :mod:`state.highstate `. Why? ---------------------------------------------------------------------------------------------- +My script runs every time I run a *state.highstate*. Why? +--------------------------------------------------------- You are probably using :mod:`cmd.run ` rather than :mod:`cmd.wait `. A :mod:`cmd.wait @@ -34,13 +36,13 @@ arguments). More details can be found in the docmentation for the :mod:`cmd ` states. -When I run :mod:`test.ping `, why do the Minions that aren't responding return anything? Returning ``False`` would be helpful. ------------------------------------------------------------------------------------------------------------------------------------------------------- +When I run *test.ping* why do the Minions that aren't responding return anything? Returning ``False`` would be helpful. +------------------------------------------------------------------------------------------------------------------------------------------------------ -The reason for this is because the Master tells Minions to run -commands/functions, and listens for the return data, printing it to the screen -when it is received. If it doesn't receive anything back, it doesn't have -anything to display for that Minion. +When you run :mod:`test.ping ` the Master tells Minions +to run commands/functions, and listens for the return data, printing it to the +screen when it is received. If it doesn't receive anything back, it doesn't +have anything to display for that Minion. There are a couple options for getting information on Minions that are not responding. One is to use the verbose (``-v``) option when you run salt From 712d3e2ae0039e818666828224390c7f0f476c4e Mon Sep 17 00:00:00 2001 From: Adam Bolte Date: Fri, 20 Sep 2013 18:51:53 +1000 Subject: [PATCH 02/23] Add git.current_branch. --- salt/modules/git.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/salt/modules/git.py b/salt/modules/git.py index 83b999aeea..778c4543b1 100644 --- a/salt/modules/git.py +++ b/salt/modules/git.py @@ -110,6 +110,16 @@ def _check_git(): utils.check_or_die('git') +def current_branch(cwd, user=None): + ''' + Returns the current branch name, if on a branch. + ''' + cmd = 'git branch --list | grep "^*\ " | cut -d " " -f 2 | ' + \ + 'grep -v "(detached"' + + return __salt__['cmd.run_stdout'](cmd, cwd=cwd, runas=user) + + def revision(cwd, rev='HEAD', short=False, user=None): ''' Returns the long hash of a given identifier (hash, branch, tag, HEAD, etc) From 9f6ce692a7b4547212ef50a0e5e64eef67f0d875 Mon Sep 17 00:00:00 2001 From: Adam Bolte Date: Fri, 20 Sep 2013 18:54:16 +1000 Subject: [PATCH 03/23] Support branch matching in git.latest. --- salt/states/git.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/salt/states/git.py b/salt/states/git.py index 86909a3c6f..7fa0f14118 100644 --- a/salt/states/git.py +++ b/salt/states/git.py @@ -113,6 +113,10 @@ def latest(name, try: current_rev = __salt__['git.revision'](target, user=runas) + branch = __salt__['git.current_branch'](target, user=runas) + if len(branch) > 0: + current_rev = branch + #only do something, if the specified rev differs from the #current_rev if rev == current_rev: From 5d81966e5f035a21d4d9466a425a127dceea7f52 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:56:21 +0100 Subject: [PATCH 04/23] Enable PEP263 pylint plugin. Fixes #7294. --- .pylintrc | 2 +- .travis.pylintrc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 484abe4a0a..b739b50d8e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -27,7 +27,7 @@ persistent=yes # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=salttesting.pylintplugins.pep263 [MESSAGES CONTROL] diff --git a/.travis.pylintrc b/.travis.pylintrc index 129c367b1d..f2cb14de15 100644 --- a/.travis.pylintrc +++ b/.travis.pylintrc @@ -14,6 +14,8 @@ init-hook=" # Pickle collected data for later comparisons. persistent=no +load-plugins=salttesting.pylintplugins.pep263 + [MESSAGES CONTROL] From 9991ea9916c848d2201980db8b6109f367a72068 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 12:42:06 +0100 Subject: [PATCH 05/23] Fix all `E3` `pep8` issues. * E301: expected 1 blank line, found 0 * E302: expected 2 blank lines, found 0 * E303: too many blank lines (3) * E304: blank lines found after function decorator --- salt/_compat.py | 2 + salt/auth/stormpath_mod.py | 1 + salt/client/api.py | 1 + salt/client/ssh/wrapper/__init__.py | 1 + salt/exceptions.py | 2 + salt/fileserver/__init__.py | 5 ++- salt/fileserver/roots.py | 1 + salt/grains/opts.py | 1 + salt/key.py | 1 + salt/modules/file.py | 8 ++++ salt/modules/git.py | 1 + salt/modules/mine.py | 2 + salt/modules/modjk.py | 1 + salt/modules/moosefs.py | 1 + salt/modules/nzbget.py | 1 + salt/modules/rdp.py | 1 + salt/modules/svn.py | 1 + salt/modules/win_disk.py | 1 + salt/output/nested.py | 2 + salt/output/no_out.py | 2 + salt/output/no_return.py | 3 ++ salt/output/virt_query.py | 1 + salt/pillar/git_pillar.py | 1 + salt/pillar/puppet.py | 1 + salt/pillar/reclass_adapter.py | 3 +- salt/renderers/pydsl.py | 1 + salt/returners/carbon_return.py | 5 ++- salt/returners/mysql.py | 6 ++- salt/returners/sqlite3_return.py | 13 ++++++- salt/roster/flat.py | 1 + salt/runners/cache.py | 5 +++ salt/states/file.py | 58 ++++++++++++++--------------- salt/states/grains.py | 1 + salt/states/layman.py | 3 ++ salt/states/makeconf.py | 4 ++ salt/states/mdadm.py | 2 + salt/states/mongodb_database.py | 2 + salt/states/mongodb_user.py | 1 + salt/states/pkgng.py | 5 ++- salt/states/portage_config.py | 5 +++ salt/states/rbenv.py | 6 +++ salt/states/rdp.py | 1 + salt/states/selinux.py | 1 + salt/states/tomcat.py | 4 ++ salt/states/win_path.py | 3 ++ salt/utils/ipaddr.py | 8 +++- salt/utils/mako.py | 1 + salt/utils/master.py | 1 + salt/utils/nb_popen.py | 1 - salt/utils/reclass.py | 5 +++ salt/utils/verify.py | 2 + salt/utils/winapi.py | 8 ++-- salt/utils/xmlutil.py | 1 + salt/wheel/key.py | 1 + 54 files changed, 156 insertions(+), 44 deletions(-) diff --git a/salt/_compat.py b/salt/_compat.py index d84e07c312..5a04a8834b 100644 --- a/salt/_compat.py +++ b/salt/_compat.py @@ -143,9 +143,11 @@ else: 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 + 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)) diff --git a/salt/auth/stormpath_mod.py b/salt/auth/stormpath_mod.py index 74d068fd33..ade18c2117 100644 --- a/salt/auth/stormpath_mod.py +++ b/salt/auth/stormpath_mod.py @@ -33,6 +33,7 @@ def __virtual__(): else: return False + def auth(username, password): ''' Try and authenticate diff --git a/salt/client/api.py b/salt/client/api.py index f41b165c48..0e391224d9 100644 --- a/salt/client/api.py +++ b/salt/client/api.py @@ -18,6 +18,7 @@ import salt.syspaths as syspaths from salt.exceptions import SaltException, EauthAuthenticationError from salt.utils.event import tagify + def tokenify(cmd, token=None): ''' If token is not None Then assign token to 'token' key of cmd dict diff --git a/salt/client/ssh/wrapper/__init__.py b/salt/client/ssh/wrapper/__init__.py index c11eb9be8f..9d90837d89 100644 --- a/salt/client/ssh/wrapper/__init__.py +++ b/salt/client/ssh/wrapper/__init__.py @@ -39,6 +39,7 @@ class FunctionWrapper(object): ''' if cmd in self.wfuncs: return self.wfuncs[cmd] + def caller(*args, **kwargs): ''' The remote execution function diff --git a/salt/exceptions.py b/salt/exceptions.py index 872b674a3a..1823398775 100644 --- a/salt/exceptions.py +++ b/salt/exceptions.py @@ -84,12 +84,14 @@ class SaltReqTimeoutError(SaltException): Thrown when a salt master request call fails to return within the timeout ''' + class TimedProcTimeoutError(SaltException): ''' Thrown when a timed subprocess does not terminate within the timeout, or if the specified timeout is not an int or a float ''' + class EauthAuthenticationError(SaltException): ''' Thrown when eauth authentication fails diff --git a/salt/fileserver/__init__.py b/salt/fileserver/__init__.py index 71558e4040..e1f70646ba 100644 --- a/salt/fileserver/__init__.py +++ b/salt/fileserver/__init__.py @@ -12,9 +12,9 @@ import logging # Import salt libs import salt.loader - log = logging.getLogger(__name__) + def generate_mtime_map(path_map): ''' Generate a dict of filename -> mtime @@ -28,6 +28,7 @@ def generate_mtime_map(path_map): file_map[file_path] = os.path.getmtime(file_path) return file_map + def diff_mtime_map(map1, map2): ''' Is there a change to the mtime map? return a boolean @@ -46,6 +47,7 @@ def diff_mtime_map(map1, map2): log.debug('diff_mtime_map: the maps are the same') return False + def reap_fileserver_cache_dir(cache_base, find_func): ''' Remove unused cache items assuming the cache directory follows a directory convention: @@ -71,6 +73,7 @@ def reap_fileserver_cache_dir(cache_base, find_func): if ret['path'] == '': os.unlink(file_path) + def is_file_ignored(opts, fname): ''' If file_ignore_regex or file_ignore_glob were given in config, diff --git a/salt/fileserver/roots.py b/salt/fileserver/roots.py index 895fdbc6a3..ae884b003d 100644 --- a/salt/fileserver/roots.py +++ b/salt/fileserver/roots.py @@ -14,6 +14,7 @@ import salt.fileserver import salt.utils from salt.utils.event import tagify + def find_file(path, env='base', **kwargs): ''' Search the environment for the relative path diff --git a/salt/grains/opts.py b/salt/grains/opts.py index 483bc1df3d..963cf8326b 100644 --- a/salt/grains/opts.py +++ b/salt/grains/opts.py @@ -4,6 +4,7 @@ Simple grain to merge the opts into the grains directly if the grain_opts configuration value is set ''' + def opts(): ''' Return the minion configuration settings diff --git a/salt/key.py b/salt/key.py index 350e94c8d6..3d49b1f027 100644 --- a/salt/key.py +++ b/salt/key.py @@ -15,6 +15,7 @@ import salt.utils import salt.utils.event from salt.utils.event import tagify + class KeyCLI(object): ''' Manage key CLI operations diff --git a/salt/modules/file.py b/salt/modules/file.py index 4617c5446c..097e63bf2e 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -2227,6 +2227,7 @@ def makedirs_perms(name, group, int('{0}'.format(mode)) if mode else None) + def get_devmm(name): ''' Get major/minor info from a device @@ -2267,6 +2268,7 @@ def is_chrdev(name): raise return stat.S_ISCHR(stat_structure.st_mode) + def mknod_chrdev(name, major, minor, @@ -2315,6 +2317,7 @@ def mknod_chrdev(name, int('{0}'.format(mode)) if mode else None) return ret + def is_blkdev(name): ''' Check if a file exists and is a block device. @@ -2336,6 +2339,7 @@ def is_blkdev(name): raise return stat.S_ISBLK(stat_structure.st_mode) + def mknod_blkdev(name, major, minor, @@ -2384,6 +2388,7 @@ def mknod_blkdev(name, int('{0}'.format(mode)) if mode else None) return ret + def is_fifo(name): ''' Check if a file exists and is a FIFO. @@ -2405,6 +2410,7 @@ def is_fifo(name): raise return stat.S_ISFIFO(stat_structure.st_mode) + def mknod_fifo(name, user=None, group=None, @@ -2445,6 +2451,7 @@ def mknod_fifo(name, int('{0}'.format(mode)) if mode else None) return ret + def mknod(name, ntype, major=0, @@ -2491,6 +2498,7 @@ def mknod(name, raise Exception("Node type unavailable: '{0}'. Available node types are character ('c'), block ('b'), and pipe ('p').".format(ntype)) return ret + def list_backups(path, limit=None): ''' .. note:: diff --git a/salt/modules/git.py b/salt/modules/git.py index 83b999aeea..5b67a4d486 100644 --- a/salt/modules/git.py +++ b/salt/modules/git.py @@ -24,6 +24,7 @@ def __virtual__(): return False return 'git' + def _git_ssh_helper(identity): ''' Returns the path to a helper script which can be used in the GIT_SSH env diff --git a/salt/modules/mine.py b/salt/modules/mine.py index 2130b9d0eb..c0a78d379c 100644 --- a/salt/modules/mine.py +++ b/salt/modules/mine.py @@ -156,6 +156,7 @@ def get(tgt, fun, expr_form='glob'): ret = sreq.send('aes', auth.crypticle.dumps(load)) return auth.crypticle.loads(ret) + def delete(fun): ''' Remove specific function contents of minion. Returns True on success. @@ -176,6 +177,7 @@ def delete(fun): ret = sreq.send('aes', auth.crypticle.dumps(load)) return auth.crypticle.loads(ret) + def flush(): ''' Remove all mine contents of minion. Returns True on success. diff --git a/salt/modules/modjk.py b/salt/modules/modjk.py index 5f1d79eaf8..6ad51e4b8f 100644 --- a/salt/modules/modjk.py +++ b/salt/modules/modjk.py @@ -227,6 +227,7 @@ def workers(profile='default'): return ret + def recover_all(lbn, profile='default'): ''' Set the all the workers in lbn to recover and activate them if they are not diff --git a/salt/modules/moosefs.py b/salt/modules/moosefs.py index 379f5ec54b..71ac11ef5a 100644 --- a/salt/modules/moosefs.py +++ b/salt/modules/moosefs.py @@ -6,6 +6,7 @@ Module for gathering and managing information about MooseFS # Import salt libs import salt.utils + def __virtual__(): ''' Only load if the mfs commands are installed diff --git a/salt/modules/nzbget.py b/salt/modules/nzbget.py index 376a8a7ff5..dc8a6f7592 100644 --- a/salt/modules/nzbget.py +++ b/salt/modules/nzbget.py @@ -10,6 +10,7 @@ __func_alias__ = { 'list_': 'list' } + def __virtual__(): ''' Only load the module if apache is installed diff --git a/salt/modules/rdp.py b/salt/modules/rdp.py index b5b115f363..29b7dc4f8e 100644 --- a/salt/modules/rdp.py +++ b/salt/modules/rdp.py @@ -9,6 +9,7 @@ import re # Import salt libs import salt.utils + def __virtual__(): ''' Only works on Windows systems diff --git a/salt/modules/svn.py b/salt/modules/svn.py index cef56e10ce..062477640a 100644 --- a/salt/modules/svn.py +++ b/salt/modules/svn.py @@ -397,6 +397,7 @@ def status(cwd, targets=None, user=None, username=None, password=None, *opts): opts += tuple(shlex.split(targets)) return _run_svn('status', cwd, user, username, password, opts) + def export(cwd, remote, target=None, diff --git a/salt/modules/win_disk.py b/salt/modules/win_disk.py index 9e86032489..63beca001b 100644 --- a/salt/modules/win_disk.py +++ b/salt/modules/win_disk.py @@ -17,6 +17,7 @@ try: except ImportError: pass + def __virtual__(): ''' Only works on Windows systems diff --git a/salt/output/nested.py b/salt/output/nested.py index f755d46946..7ef7fa7846 100644 --- a/salt/output/nested.py +++ b/salt/output/nested.py @@ -8,6 +8,7 @@ from numbers import Number # Import salt libs import salt.utils + class NestDisplay(object): ''' Manage the nested display contents @@ -71,6 +72,7 @@ class NestDisplay(object): out = self.display(val, indent + 4, '', out) return out + def output(ret): ''' Display ret data diff --git a/salt/output/no_out.py b/salt/output/no_out.py index 5014f85e35..9576eb5ae7 100644 --- a/salt/output/no_out.py +++ b/salt/output/no_out.py @@ -3,9 +3,11 @@ Display no output. ''' + def __virtual__(): return 'quiet' + def output(ret): ''' Don't display data. Used when you only are interested in the diff --git a/salt/output/no_return.py b/salt/output/no_return.py index 012251a3a7..1591d57aec 100644 --- a/salt/output/no_return.py +++ b/salt/output/no_return.py @@ -3,8 +3,10 @@ Display output for minions that did not return ''' +# Import salt libs import salt.utils + class NestDisplay(object): ''' Create generator for nested output @@ -37,6 +39,7 @@ class NestDisplay(object): out = self.display(val, indent + 4, '', out) return out + def output(ret): ''' Display ret data diff --git a/salt/output/virt_query.py b/salt/output/virt_query.py index 22dd5f2655..956f2df4a9 100644 --- a/salt/output/virt_query.py +++ b/salt/output/virt_query.py @@ -3,6 +3,7 @@ virt.query outputter ''' + def output(data): ''' Display output for the salt-run virt.query function diff --git a/salt/pillar/git_pillar.py b/salt/pillar/git_pillar.py index 906e95984c..52bb1ffe8c 100644 --- a/salt/pillar/git_pillar.py +++ b/salt/pillar/git_pillar.py @@ -57,6 +57,7 @@ def _get_ref(repo, short): return ref return False + def init(branch, repo_location): ''' Return the git repo object for this session diff --git a/salt/pillar/puppet.py b/salt/pillar/puppet.py index 0bffd8d6b9..2a8299f955 100644 --- a/salt/pillar/puppet.py +++ b/salt/pillar/puppet.py @@ -13,6 +13,7 @@ import yaml # Set up logging log = logging.getLogger(__name__) + def ext_pillar(minion_id, pillar, command): ''' Execute an unmodified puppet_node_classifier and read the output as YAML diff --git a/salt/pillar/reclass_adapter.py b/salt/pillar/reclass_adapter.py index 98a2da617d..eeb58f1ecc 100644 --- a/salt/pillar/reclass_adapter.py +++ b/salt/pillar/reclass_adapter.py @@ -48,6 +48,7 @@ setting the configuration option, like in the example above. # not work. Thanks to the __virtual__ function, however, the plugin still # responds to the name 'reclass'. +from salt.exceptions import SaltInvocationError from salt.utils.reclass import ( prepend_reclass_source_path, filter_out_source_path_option, @@ -76,8 +77,6 @@ def __virtual__(retry=False): return __virtual__(retry=True) -from salt.exceptions import SaltInvocationError - def ext_pillar(minion_id, pillar, **kwargs): ''' Obtain the Pillar data from **reclass** for the given ``minion_id``. diff --git a/salt/renderers/pydsl.py b/salt/renderers/pydsl.py index 8ad92d667d..4b8d349865 100755 --- a/salt/renderers/pydsl.py +++ b/salt/renderers/pydsl.py @@ -316,6 +316,7 @@ from salt.utils import pydsl __all__ = ['render'] + def render(template, env='', sls='', tmplpath=None, rendered_sls=None, **kws): mod = imp.new_module(sls) # Note: mod object is transient. It's existence only lasts as long as diff --git a/salt/returners/carbon_return.py b/salt/returners/carbon_return.py index ba7d74e3ae..98fb712751 100644 --- a/salt/returners/carbon_return.py +++ b/salt/returners/carbon_return.py @@ -9,22 +9,25 @@ Add the following configuration to your minion configuration files:: ''' +# Import python libs import pickle import socket import logging import time import struct - log = logging.getLogger(__name__) + def __virtual__(): return 'carbon' + def _formatHostname(hostname, separator='_'): ''' carbon uses . as separator, so replace this in the hostname ''' return hostname.replace('.', separator) + def _send_picklemetrics(metrics, carbon_sock): ''' Uses pickle protocol to send data ''' metrics = [(metric_name, (timestamp, value)) for (metric_name, timestamp, value) in metrics] diff --git a/salt/returners/mysql.py b/salt/returners/mysql.py index b462edfc70..63369d0545 100644 --- a/salt/returners/mysql.py +++ b/salt/returners/mysql.py @@ -62,8 +62,6 @@ import sys import json import logging -log = logging.getLogger( __name__ ) - # Import third party libs try: import MySQLdb @@ -71,12 +69,15 @@ try: except ImportError: HAS_MYSQL = False +log = logging.getLogger(__name__) + def __virtual__(): if not HAS_MYSQL: return False return 'mysql' + def _get_options(): ''' Returns options used for the MySQL connection. @@ -97,6 +98,7 @@ def _get_options(): return _options + @contextmanager def _get_serv(commit=False): ''' diff --git a/salt/returners/sqlite3_return.py b/salt/returners/sqlite3_return.py index ce5d8ac8e6..a3951415b6 100644 --- a/salt/returners/sqlite3_return.py +++ b/salt/returners/sqlite3_return.py @@ -48,7 +48,6 @@ Use the commands to create the sqlite3 database and tables:: import logging import json import datetime -log = logging.getLogger(__name__) # Better safe than sorry here. Even though sqlite3 is included in python try: @@ -57,11 +56,15 @@ try: except ImportError: HAS_SQLITE3 = False +log = logging.getLogger(__name__) + + def __virtual__(): if not HAS_SQLITE3: return False return 'sqlite3' + def _get_conn(): ''' Return a sqlite3 database connection @@ -82,6 +85,7 @@ def _get_conn(): timeout = float(__salt__['config.option']('returner.sqlite3.timeout'))) return conn + def _close_conn(conn): ''' Close the sqlite3 database connection @@ -90,6 +94,7 @@ def _close_conn(conn): conn.commit() conn.close() + def returner(ret): ''' Insert minion return data into the sqlite3 database @@ -109,6 +114,7 @@ def returner(ret): 'success':ret['success']}) _close_conn(conn) + def save_load(jid, load): ''' Save the load to the specified jid @@ -123,6 +129,7 @@ def save_load(jid, load): 'load':json.dumps(load)}) _close_conn(conn) + def get_load(jid): ''' Return the load from a specified jid @@ -139,6 +146,7 @@ def get_load(jid): _close_conn(conn) return {} + def get_jid(jid): ''' Return the information returned from a specified jid @@ -158,6 +166,7 @@ def get_jid(jid): _close_conn(conn) return ret + def get_fun(fun): ''' Return a dict of the last function called for all minions @@ -185,6 +194,7 @@ def get_fun(fun): _close_conn(conn) return ret + def get_jids(): ''' Return a list of all job ids @@ -201,6 +211,7 @@ def get_jids(): _close_conn(conn) return ret + def get_minions(): ''' Return a list of minions diff --git a/salt/roster/flat.py b/salt/roster/flat.py index 0b2d354603..a04dae4e2b 100644 --- a/salt/roster/flat.py +++ b/salt/roster/flat.py @@ -12,6 +12,7 @@ import re import salt.loader from salt.template import compile_template + def targets(tgt, tgt_type='glob', **kwargs): ''' Return the targets from the flat yaml file, checks opts for location but diff --git a/salt/runners/cache.py b/salt/runners/cache.py index aa508ce6a0..9a2d984e9c 100644 --- a/salt/runners/cache.py +++ b/salt/runners/cache.py @@ -98,6 +98,7 @@ def _clear_cache(tgt=None, clear_mine=clear_mine, clear_mine_func=clear_mine_func) + def clear_pillar(tgt, expr_form='glob'): ''' Clear the cached pillar data of the targeted minions @@ -110,6 +111,7 @@ def clear_pillar(tgt, expr_form='glob'): ''' return _clear_cache(tgt, expr_form, clear_pillar=True) + def clear_grains(tgt=None, expr_form='glob'): ''' Clear the cached grains data of the targeted minions @@ -122,6 +124,7 @@ def clear_grains(tgt=None, expr_form='glob'): ''' return _clear_cache(tgt, expr_form, clear_grains=True) + def clear_mine(tgt=None, expr_form='glob'): ''' Clear the cached mine data of the targeted minions @@ -134,6 +137,7 @@ def clear_mine(tgt=None, expr_form='glob'): ''' return _clear_cache(tgt, expr_form, clear_mine=True) + def clear_mine_func(tgt=None, expr_form='glob', clear_mine_func=None): ''' Clear the cached mine function data of the targeted minions @@ -146,6 +150,7 @@ def clear_mine_func(tgt=None, expr_form='glob', clear_mine_func=None): ''' return _clear_cache(tgt, expr_form, clear_mine_func=clear_mine_func) + def clear_all(tgt=None, expr_form='glob'): ''' Clear the cached pillar, grains, and mine data of the targeted minions diff --git a/salt/states/file.py b/salt/states/file.py index 6a9ffac57b..732a7693a4 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -581,55 +581,56 @@ def _test_owner(kwargs, user=None): return user -def _unify_sources_and_hashes(source=None, source_hash=None, +def _unify_sources_and_hashes(source=None, source_hash=None, sources=None, source_hashes=None): ''' - Silly lil function to give us a standard tuple list for sources and + Silly lil function to give us a standard tuple list for sources and source_hashes ''' if sources is None: sources = [] - + if source_hashes is None: source_hashes = [] - + if ( source and sources ): - return (False, + return (False, "source and sources are mutally exclusive", [] ) if ( source_hash and source_hashes ): - return (False, + return (False, "source_hash and source_hashes are mutally exclusive", [] ) - if ( source ): + if ( source ): return (True, '', [ (source, source_hash) ] ) # Make a nice neat list of tuples exactly len(sources) long.. return (True, '', map(None, sources, source_hashes[:len(sources)]) ) -def _get_template_texts(source_list = None, template='jinja', defaults = None, + +def _get_template_texts(source_list = None, template='jinja', defaults = None, context = None, env = 'base', **kwargs): ''' Iterate a list of sources and process them as templates. Returns a list of 'chunks' containing the rendered templates. ''' - ret = {'name': '_get_template_texts', 'changes': {}, + ret = {'name': '_get_template_texts', 'changes': {}, 'result': True, 'comment': '', 'data': []} - + if source_list is None: - return _error(ret, + return _error(ret, '_get_template_texts called with empty source_list') - + txtl = [] - + for (source, source_hash) in source_list: tmpctx = defaults if defaults else {} if context: tmpctx.update(context) - rndrd_templ_fn = __salt__['cp.get_template'](source, '', - template=template, env=env, + rndrd_templ_fn = __salt__['cp.get_template'](source, '', + template=template, env=env, context = tmpctx, **kwargs ) msg = 'cp.get_template returned {0} (Called with: {1})' log.debug(msg.format(rndrd_templ_fn, source)) @@ -993,7 +994,7 @@ def managed(name, contents_pillar .. versionadded:: 0.17 - + Operates like ``contents``, but draws from a value stored in pillar, using the pillar path syntax used in :mod:`pillar.get `. This is useful when the pillar value @@ -2025,7 +2026,7 @@ def append(name, - "Salt is born of the purest of parents: the sun and the sea." Gather text from multiple template files:: - + /etc/motd: file: - append @@ -2034,28 +2035,27 @@ def append(name, - salt://motd/devops-messages.tmpl - salt://motd/hr-messages.tmpl - salt://motd/general-messages.tmpl - + .. versionadded:: 0.9.5 ''' ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} if sources is None: sources = [] - + if source_hashes is None: source_hashes = [] - + # Add sources and source_hashes with template support - # NOTE: FIX 'text' and any 'source' are mutally exclusive as 'text' + # NOTE: FIX 'text' and any 'source' are mutally exclusive as 'text' # is re-assigned in the original code. (ok, err, sl) = _unify_sources_and_hashes(source = source, - source_hash = source_hash, - sources = sources, + source_hash = source_hash, + sources = sources, source_hashes = source_hashes ) if not ok: return _error(ret, err) - if makedirs is True: dirname = os.path.dirname(name) if not __salt__['file.directory_exists'](dirname): @@ -2075,10 +2075,10 @@ def append(name, #Follow the original logic and re-assign 'text' if using source(s)... if sl: - tmpret = _get_template_texts(source_list = sl, - template = template, - defaults = defaults, - context = context, + tmpret = _get_template_texts(source_list = sl, + template = template, + defaults = defaults, + context = context, env = __env__) if not tmpret['result']: return tmpret @@ -2092,7 +2092,6 @@ def append(name, count = 0 - for chunk in text: if __salt__['file.contains_regex_multiline']( @@ -2619,6 +2618,7 @@ def serialize(name, show_diff=show_diff, contents=contents) + def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'): ''' Create a special file similar to the 'nix mknod command. The supported device types are diff --git a/salt/states/grains.py b/salt/states/grains.py index 982c54d980..715fd98adf 100644 --- a/salt/states/grains.py +++ b/salt/states/grains.py @@ -18,6 +18,7 @@ Note: This does NOT override any grains set in the minion file. - value: edam ''' + def present(name, value): ''' Ensure that a grain is set diff --git a/salt/states/layman.py b/salt/states/layman.py index c114ef0e3d..82d736843a 100644 --- a/salt/states/layman.py +++ b/salt/states/layman.py @@ -11,12 +11,14 @@ A state module to manage Gentoo package overlays via layman layman.present ''' + def __virtual__(): ''' Only load if the layman module is available in __salt__ ''' return 'layman' if 'layman.add' in __salt__ else False + def present(name): ''' Verify that the overlay is present @@ -51,6 +53,7 @@ def present(name): return ret + def absent(name): ''' Verify that the overlay is absent diff --git a/salt/states/makeconf.py b/salt/states/makeconf.py index 0c15f31433..0f3e30dfd6 100644 --- a/salt/states/makeconf.py +++ b/salt/states/makeconf.py @@ -12,12 +12,14 @@ A state module to manage Gentoo's make.conf file - value: '-j3' ''' + def __virtual__(): ''' Only load if the makeconf module is available in __salt__ ''' return 'makeconf' if 'makeconf.get_var' in __salt__ else False + def _make_set(var): ''' Force var to be a set @@ -31,6 +33,7 @@ def _make_set(var): var = list(var) return set(var) + def present(name, value=None, contains=None, excludes=None): ''' Verify that the variable is in the make.conf and has the provided @@ -154,6 +157,7 @@ def present(name, value=None, contains=None, excludes=None): # Now finally return return ret + def absent(name): ''' Verify that the variable is not in the make.conf. diff --git a/salt/states/mdadm.py b/salt/states/mdadm.py index 04bbc98623..f869b8d7b6 100644 --- a/salt/states/mdadm.py +++ b/salt/states/mdadm.py @@ -21,6 +21,7 @@ import salt.utils # Set up logger log = logging.getLogger(__name__) + def __virtual__(): ''' mdadm provides raid functions for Linux @@ -31,6 +32,7 @@ def __virtual__(): return False return 'raid' + def present(name, opts=None): ''' Verify that the raid is present diff --git a/salt/states/mongodb_database.py b/salt/states/mongodb_database.py index 274ab71933..e2400ad391 100644 --- a/salt/states/mongodb_database.py +++ b/salt/states/mongodb_database.py @@ -5,6 +5,8 @@ Management of Mongodb databases Only deletion is supported, creation doesn't make sense and can be done using mongodb_user.present ''' + + def absent(name, user=None, password=None, diff --git a/salt/states/mongodb_user.py b/salt/states/mongodb_user.py index c1781eee68..381d8ebbfb 100644 --- a/salt/states/mongodb_user.py +++ b/salt/states/mongodb_user.py @@ -4,6 +4,7 @@ Management of Mongodb users =========================== ''' + def present(name, passwd, database="admin", diff --git a/salt/states/pkgng.py b/salt/states/pkgng.py index 81818a2a58..15d7f54dcd 100644 --- a/salt/states/pkgng.py +++ b/salt/states/pkgng.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ''' -Manage package remote repo using FreeBSD pkgng. -========================================================================== +Manage package remote repo using FreeBSD pkgng +============================================== Salt can manage the URL pkgng pulls packages from. ATM the state and module are small so use cases are @@ -15,6 +15,7 @@ typically rather simple: - name: "http://192.168.0.2" ''' + def update_packaging_site(name): ret = { 'name': name, diff --git a/salt/states/portage_config.py b/salt/states/portage_config.py index 9684eeb737..3bd4a881c9 100644 --- a/salt/states/portage_config.py +++ b/salt/states/portage_config.py @@ -13,12 +13,14 @@ A state module to manage Portage configuration on Gentoo - openssl ''' + def __virtual__(): ''' Only load if the portage_config module is available in __salt__ ''' return 'portage_config' if 'portage_config.get_missing_flags' in __salt__ else False + def mod_init(low): ''' Enforce a nice structure on the configuration files. @@ -29,6 +31,7 @@ def mod_init(low): return False return True + def _flags_helper(conf, atom, new_flags, test=False): try: new_flags = __salt__['portage_config.get_missing_flags'](conf, atom, new_flags) @@ -42,6 +45,7 @@ def _flags_helper(conf, atom, new_flags, test=False): return {'result': True, 'changes': {'old': old_flags, 'new': new_flags}} return {'result': None} + def _mask_helper(conf, atom, test=False): try: is_present = __salt__['portage_config.is_present'](conf, atom) @@ -54,6 +58,7 @@ def _mask_helper(conf, atom, test=False): return {'result': True} return {'result': None} + def flags(name, use=None, accept_keywords=None, diff --git a/salt/states/rbenv.py b/salt/states/rbenv.py index 47baa9464f..e0947b9c1c 100644 --- a/salt/states/rbenv.py +++ b/salt/states/rbenv.py @@ -44,6 +44,7 @@ This is how a state configuration could look like: # Import python libs import re + def _check_rbenv(ret, runas=None): ''' Check to see if rbenv is installed. @@ -53,6 +54,7 @@ def _check_rbenv(ret, runas=None): ret['comment'] = 'Rbenv is not installed.' return ret + def _ruby_installed(ret, ruby, runas=None): ''' Check to see if given ruby is installed. @@ -67,6 +69,7 @@ def _ruby_installed(ret, ruby, runas=None): return ret + def _check_and_install_ruby(ret, ruby, default=False, runas=None): ''' Verify that ruby is installed, install if unavailable @@ -88,6 +91,7 @@ def _check_and_install_ruby(ret, ruby, default=False, runas=None): return ret + def installed(name, default=False, runas=None): ''' Verify that the specified ruby is installed with rbenv. Rbenv is @@ -121,6 +125,7 @@ def installed(name, default=False, runas=None): else: return _check_and_install_ruby(ret, name, default, runas=runas) + def _check_and_uninstall_ruby(ret, ruby, runas=None): ''' Verify that ruby is uninstalled @@ -145,6 +150,7 @@ def _check_and_uninstall_ruby(ret, ruby, runas=None): return ret + def absent(name, runas=None): ''' Verify that the specified ruby is not installed with rbenv. Rbenv diff --git a/salt/states/rdp.py b/salt/states/rdp.py index e5aac19c58..9653eb185b 100644 --- a/salt/states/rdp.py +++ b/salt/states/rdp.py @@ -3,6 +3,7 @@ Manage RDP Service on Windows servers ''' + def __virtual__(): ''' Load only if network_win is loaded diff --git a/salt/states/selinux.py b/salt/states/selinux.py index 12015324e6..3a3d6a6d88 100644 --- a/salt/states/selinux.py +++ b/salt/states/selinux.py @@ -21,6 +21,7 @@ booleans can be set. execution module is available. ''' + def __virtual__(): ''' Only make this state available if the selinux module is available. diff --git a/salt/states/tomcat.py b/salt/states/tomcat.py index b6bd79c1cc..7e7d2d8b0b 100644 --- a/salt/states/tomcat.py +++ b/salt/states/tomcat.py @@ -40,6 +40,7 @@ Notes: Apache Tomcat/7.0.37 ''' + # Private def __virtual__(): ''' @@ -48,6 +49,7 @@ def __virtual__(): return 'tomcat' if 'tomcat.status' in __salt__ else False + # Functions def war_deployed(name, war, url='http://localhost:8080/manager', __env__='base', timeout=180): @@ -150,6 +152,7 @@ def war_deployed(name, war, url='http://localhost:8080/manager', ret['changes'].pop('deploy') return ret + def wait(name, url='http://localhost:8080/manager', timeout=180): ''' Wait for the tomcat manager to load @@ -198,6 +201,7 @@ def wait(name, url='http://localhost:8080/manager', timeout=180): return ret + def mod_watch(name, url='http://localhost:8080/manager', timeout=180): ''' The tomcat watcher function. diff --git a/salt/states/win_path.py b/salt/states/win_path.py index 483f5eabed..ab6b8de215 100644 --- a/salt/states/win_path.py +++ b/salt/states/win_path.py @@ -6,12 +6,14 @@ Manage the Windows System PATH # Python Libs import re + def __virtual__(): ''' Load this state if the win_path module exists ''' return 'win_path' if 'win_path.rehash' in __salt__ else False + def _normalize_dir(string): ''' Normalize the directory to make comparison possible @@ -49,6 +51,7 @@ def absent(name): ret['comment'] = 'could not remove {0} from the PATH'.format(name) return ret + def exists(name, index=0): ''' Add the directory to the system PATH at index location diff --git a/salt/utils/ipaddr.py b/salt/utils/ipaddr.py index 6b031527f8..d6ca6480a8 100644 --- a/salt/utils/ipaddr.py +++ b/salt/utils/ipaddr.py @@ -168,6 +168,7 @@ def _find_address_range(addresses): break return (first, last) + def _get_prefix_length(number1, number2, bits): """Get the number of leading bits that are same for two numbers. @@ -185,6 +186,7 @@ def _get_prefix_length(number1, number2, bits): return bits - i return 0 + def _count_righthand_zero_bits(number, bits): """Count the number of zero bits on the right hand side. @@ -202,6 +204,7 @@ def _count_righthand_zero_bits(number, bits): if (number >> i) % 2: return i + def summarize_address_range(first, last): """Summarize a network range given the first and last IP addresses. @@ -266,6 +269,7 @@ def summarize_address_range(first, last): first = IPAddress(first_int, version=first._version) return networks + def _collapse_address_list_recursive(addresses): """Loops through the addresses, collapsing concurrent netblocks. @@ -391,6 +395,7 @@ except (NameError, TypeError): def __repr__(self): return 'Bytes(%s)' % str.__repr__(self) + def get_mixed_type_key(obj): """Return a key suitable for sorting between networks and addresses. @@ -415,6 +420,7 @@ def get_mixed_type_key(obj): return obj._get_address_key() return NotImplemented + class _IPAddrBase(object): """The mother class.""" @@ -989,7 +995,6 @@ class _BaseNet(_IPAddrBase): raise ValueError('cannot set prefixlen_diff and new_prefix') prefixlen_diff = self._prefixlen - new_prefix - if self.prefixlen - prefixlen_diff < 0: raise ValueError( 'current prefixlen is %d, cannot have a prefixlen_diff of %d' % @@ -1807,7 +1812,6 @@ class IPv6Network(_BaseV6, _BaseNet): """ - def __init__(self, address, strict=False): """Instantiate a new IPv6 Network object. diff --git a/salt/utils/mako.py b/salt/utils/mako.py index c27c33c1f6..7cd00d3a57 100644 --- a/salt/utils/mako.py +++ b/salt/utils/mako.py @@ -11,6 +11,7 @@ from mako.lookup import TemplateCollection, TemplateLookup # Import salt libs import salt.fileclient + class SaltMakoTemplateLookup(TemplateCollection): """ Look up Mako template files on Salt master via salt://... URLs. diff --git a/salt/utils/master.py b/salt/utils/master.py index 05352243fd..1d845d87df 100755 --- a/salt/utils/master.py +++ b/salt/utils/master.py @@ -21,6 +21,7 @@ from salt.exceptions import SaltException log = logging.getLogger(__name__) + class MasterPillarUtil(object): ''' Helper utility for easy access to targeted minion grain and diff --git a/salt/utils/nb_popen.py b/salt/utils/nb_popen.py index 3b49df2db5..15515cdeee 100644 --- a/salt/utils/nb_popen.py +++ b/salt/utils/nb_popen.py @@ -84,7 +84,6 @@ class NonBlockingPopen(subprocess.Popen): self._stderr_logger_name_.format(pid=self.pid) ) - self._stderr_logger = logging.getLogger( self._stderr_logger_name_.format(pid=self.pid) ) diff --git a/salt/utils/reclass.py b/salt/utils/reclass.py index 3ca330bf5c..a8253aa8cb 100644 --- a/salt/utils/reclass.py +++ b/salt/utils/reclass.py @@ -3,20 +3,25 @@ Common utility functions for the reclass adapters http://reclass.pantsfullofunix.net ''' + +# Import python libs import sys import os + def prepend_reclass_source_path(opts): source_path = opts.get('reclass_source_path') if source_path: source_path = os.path.abspath(os.path.expanduser(source_path)) sys.path.insert(0, source_path) + def filter_out_source_path_option(opts): if 'reclass_source_path' in opts: del opts['reclass_source_path'] # no return required, object was passed by reference + def set_inventory_base_uri_default(config, opts): if 'inventory_base_uri' in opts: return diff --git a/salt/utils/verify.py b/salt/utils/verify.py index 17061368f0..9b77250ffc 100644 --- a/salt/utils/verify.py +++ b/salt/utils/verify.py @@ -88,6 +88,7 @@ def zmq_version(): sys.stderr.write('CRITICAL {0}\n'.format(msg)) return False + def lookup_family(hostname): ''' Lookup a hostname and determine its address family. The first address returned @@ -106,6 +107,7 @@ def lookup_family(hostname): except socket.gaierror: return fallback + def verify_socket(interface, pub_port, ret_port): ''' Attempt to bind to the sockets to verify that they are available diff --git a/salt/utils/winapi.py b/salt/utils/winapi.py index 8e7790e714..f9553e7311 100644 --- a/salt/utils/winapi.py +++ b/salt/utils/winapi.py @@ -1,11 +1,13 @@ # -*- coding: utf-8 -*- + +# Import python libs import logging import pythoncom import threading - log = logging.getLogger(__name__) + class Com(object): def __init__(self): self.need_com_init = not self._is_main_thread() @@ -15,10 +17,10 @@ class Com(object): def __enter__(self): if self.need_com_init: - log.debug("Initializing COM library") + log.debug('Initializing COM library') pythoncom.CoInitialize() def __exit__(self, exc_type, exc_value, traceback): if self.need_com_init: - log.debug("Uninitializing COM library") + log.debug('Uninitializing COM library') pythoncom.CoUninitialize() diff --git a/salt/utils/xmlutil.py b/salt/utils/xmlutil.py index 7839cac62b..0b7045c2c9 100644 --- a/salt/utils/xmlutil.py +++ b/salt/utils/xmlutil.py @@ -3,6 +3,7 @@ Various XML utilities ''' + def to_dict(xmltree): ''' Convert an XML tree into a dict. The tree that is passed in must be an diff --git a/salt/wheel/key.py b/salt/wheel/key.py index 46f0ea3c8f..058f0b3764 100644 --- a/salt/wheel/key.py +++ b/salt/wheel/key.py @@ -10,6 +10,7 @@ __func_alias__ = { 'list_': 'list' } + def list_(match): ''' List all the keys under a named status From 4dbc9e9aa899b4b1fe95b75012290e8b4bbc8029 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 12:51:00 +0100 Subject: [PATCH 06/23] Fix `pep8` `E251` issues. --- salt/master.py | 18 ++++++++--------- salt/returners/sqlite3_return.py | 2 +- salt/states/apt.py | 2 +- salt/states/file.py | 34 ++++++++++++++++++-------------- salt/utils/master.py | 8 ++++---- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/salt/master.py b/salt/master.py index a061a13232..06f031e1a9 100644 --- a/salt/master.py +++ b/salt/master.py @@ -1682,7 +1682,7 @@ class ClearFuncs(object): eload = {'result': False, 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return ret elif os.path.isfile(pubfn): # The key has been accepted check it @@ -1697,7 +1697,7 @@ class ClearFuncs(object): eload = {'result': False, 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return ret elif not os.path.isfile(pubfn_pend)\ and not self._check_autosign(load['id']): @@ -1711,7 +1711,7 @@ class ClearFuncs(object): eload = {'result': False, 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return ret # This is a new key, stick it in pre log.info( @@ -1725,7 +1725,7 @@ class ClearFuncs(object): 'act': 'pend', 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return ret elif os.path.isfile(pubfn_pend)\ and not self._check_autosign(load['id']): @@ -1740,7 +1740,7 @@ class ClearFuncs(object): eload = {'result': False, 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return {'enc': 'clear', 'load': {'ret': False}} else: @@ -1753,7 +1753,7 @@ class ClearFuncs(object): 'act': 'pend', 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return {'enc': 'clear', 'load': {'ret': True}} elif os.path.isfile(pubfn_pend)\ @@ -1768,7 +1768,7 @@ class ClearFuncs(object): eload = {'result': False, 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return {'enc': 'clear', 'load': {'ret': False}} else: @@ -1783,7 +1783,7 @@ class ClearFuncs(object): eload = {'result': False, 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return {'enc': 'clear', 'load': {'ret': False}} @@ -1841,7 +1841,7 @@ class ClearFuncs(object): 'act': 'accept', 'id': load['id'], 'pub': load['pub']} - self.event.fire_event(eload, tagify(prefix = 'auth')) + self.event.fire_event(eload, tagify(prefix='auth')) return ret def runner(self, clear_load): diff --git a/salt/returners/sqlite3_return.py b/salt/returners/sqlite3_return.py index a3951415b6..687b6fbc3c 100644 --- a/salt/returners/sqlite3_return.py +++ b/salt/returners/sqlite3_return.py @@ -82,7 +82,7 @@ def _get_conn(): __salt__['config.option']('returner.sqlite3.timeout'))) conn = sqlite3.connect( __salt__['config.option']('returner.sqlite3.database'), - timeout = float(__salt__['config.option']('returner.sqlite3.timeout'))) + timeout=float(__salt__['config.option']('returner.sqlite3.timeout'))) return conn diff --git a/salt/states/apt.py b/salt/states/apt.py index c8e18e4595..ff767be91b 100644 --- a/salt/states/apt.py +++ b/salt/states/apt.py @@ -45,7 +45,7 @@ def held(name): ret.update(result=None, comment='Package {0} is set to be held'.format(name)) else: - ret.update(result= True, + ret.update(result=True, comment='Package {0} is already held'.format(name)) return ret diff --git a/salt/states/file.py b/salt/states/file.py index 732a7693a4..7f2afb3031 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -608,8 +608,12 @@ def _unify_sources_and_hashes(source=None, source_hash=None, return (True, '', map(None, sources, source_hashes[:len(sources)]) ) -def _get_template_texts(source_list = None, template='jinja', defaults = None, - context = None, env = 'base', **kwargs): +def _get_template_texts(source_list=None, + template='jinja', + defaults=None, + context=None, + env='base', + **kwargs): ''' Iterate a list of sources and process them as templates. Returns a list of 'chunks' containing the rendered templates. @@ -631,7 +635,7 @@ def _get_template_texts(source_list = None, template='jinja', defaults = None, tmpctx.update(context) rndrd_templ_fn = __salt__['cp.get_template'](source, '', template=template, env=env, - context = tmpctx, **kwargs ) + context=tmpctx, **kwargs ) msg = 'cp.get_template returned {0} (Called with: {1})' log.debug(msg.format(rndrd_templ_fn, source)) if rndrd_templ_fn: @@ -1997,11 +2001,11 @@ def append(name, source=None, source_hash=None, __env__='base', - template = 'jinja', + template='jinja', sources=None, source_hashes=None, - defaults = None, - context = None): + defaults=None, + context=None): ''' Ensure that some text appears at the end of a file @@ -2049,10 +2053,10 @@ def append(name, # Add sources and source_hashes with template support # NOTE: FIX 'text' and any 'source' are mutally exclusive as 'text' # is re-assigned in the original code. - (ok, err, sl) = _unify_sources_and_hashes(source = source, - source_hash = source_hash, - sources = sources, - source_hashes = source_hashes ) + (ok, err, sl) = _unify_sources_and_hashes(source=source, + source_hash=source_hash, + sources=sources, + source_hashes=source_hashes ) if not ok: return _error(ret, err) @@ -2075,11 +2079,11 @@ def append(name, #Follow the original logic and re-assign 'text' if using source(s)... if sl: - tmpret = _get_template_texts(source_list = sl, - template = template, - defaults = defaults, - context = context, - env = __env__) + tmpret = _get_template_texts(source_list=sl, + template=template, + defaults=defaults, + context=context, + env=__env__) if not tmpret['result']: return tmpret text = tmpret['data'] diff --git a/salt/utils/master.py b/salt/utils/master.py index 1d845d87df..0844169b3f 100755 --- a/salt/utils/master.py +++ b/salt/utils/master.py @@ -219,12 +219,12 @@ class MasterPillarUtil(object): log.debug('Getting minion grain data for: {0}'.format(minion_ids)) minion_grains = self._get_minion_grains( *minion_ids, - cached_grains = cached_minion_grains) + cached_grains=cached_minion_grains) log.debug('Getting minion pillar data for: {0}'.format(minion_ids)) minion_pillars = self._get_minion_pillar( *minion_ids, - grains = minion_grains, - cached_pillar = cached_minion_pillars) + grains=minion_grains, + cached_pillar=cached_minion_pillars) return minion_pillars def get_minion_grains(self): @@ -250,7 +250,7 @@ class MasterPillarUtil(object): log.debug('Getting minion grain data for: {0}'.format(minion_ids)) minion_grains = self._get_minion_grains( *minion_ids, - cached_grains = cached_minion_grains) + cached_grains=cached_minion_grains) return minion_grains def clear_cached_minion_data(self, From e313cb418d6e537a8fd0540b40549be5e9908717 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 12:54:52 +0100 Subject: [PATCH 07/23] Fix `pep8` `E271` issues. --- salt/client/api.py | 2 +- salt/modules/solr.py | 4 ++-- salt/modules/win_path.py | 2 +- salt/modules/win_service.py | 2 +- salt/pillar/__init__.py | 2 +- salt/utils/ipaddr.py | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/salt/client/api.py b/salt/client/api.py index 0e391224d9..3f0b26f955 100644 --- a/salt/client/api.py +++ b/salt/client/api.py @@ -202,7 +202,7 @@ class APIClient(object): module = '.'.join(parts[1:]) #strip prefix if client == 'wheel': functions = self.wheelClient.w_funcs - elif client == 'runner': + elif client == 'runner': functions = self.runnerClient.functions result = salt.utils.argspec_report(functions, module) return result diff --git a/salt/modules/solr.py b/salt/modules/solr.py index 389955c98b..56f69e7304 100644 --- a/salt/modules/solr.py +++ b/salt/modules/solr.py @@ -956,9 +956,9 @@ def set_replication_enabled(status, host=None, core_name=None): return ret else: if status: - return _replication_request(cmd, host=host, core_name=core_name) + return _replication_request(cmd, host=host, core_name=core_name) else: - return _replication_request(cmd, host=host, core_name=core_name) + return _replication_request(cmd, host=host, core_name=core_name) def signal(signal=None): diff --git a/salt/modules/win_path.py b/salt/modules/win_path.py index 82aa5ed541..c68f038f7b 100644 --- a/salt/modules/win_path.py +++ b/salt/modules/win_path.py @@ -39,7 +39,7 @@ def _normalize_dir(string): ''' Normalize the directory to make comparison possible ''' - return re.sub(r'\\$', '', string.lower()) + return re.sub(r'\\$', '', string.lower()) def rehash(): diff --git a/salt/modules/win_service.py b/salt/modules/win_service.py index 1094473e0e..e97cc6a867 100644 --- a/salt/modules/win_service.py +++ b/salt/modules/win_service.py @@ -72,7 +72,7 @@ def get_disabled(): for line in lines: if 'DEMAND_START' in line: ret.add(service) - elif 'DISABLED' in line: + elif 'DISABLED' in line: ret.add(service) return sorted(ret) diff --git a/salt/pillar/__init__.py b/salt/pillar/__init__.py index 951527cc5b..1326511954 100644 --- a/salt/pillar/__init__.py +++ b/salt/pillar/__init__.py @@ -385,7 +385,7 @@ class Pillar(object): Render the external pillar data ''' if not 'ext_pillar' in self.opts: - return {} + return {} if not isinstance(self.opts['ext_pillar'], list): log.critical('The "ext_pillar" option is malformed') return {} diff --git a/salt/utils/ipaddr.py b/salt/utils/ipaddr.py index d6ca6480a8..f42fc31e6e 100644 --- a/salt/utils/ipaddr.py +++ b/salt/utils/ipaddr.py @@ -517,7 +517,7 @@ class _BaseIP(_IPAddrBase): return '%s(%r)' % (self.__class__.__name__, str(self)) def __str__(self): - return '%s' % self._string_from_ip_int(self._ip) + return '%s' % self._string_from_ip_int(self._ip) def __hash__(self): return hash(hex(long(self._ip))) @@ -633,8 +633,8 @@ class _BaseNet(_IPAddrBase): return not eq def __str__(self): - return '%s/%s' % (str(self.ip), - str(self._prefixlen)) + return '%s/%s' % (str(self.ip), + str(self._prefixlen)) def __hash__(self): return hash(int(self.network) ^ int(self.netmask)) From c337fd3ac6db99ca5a253eaacccebb0ab9fa8ebd Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:03:31 +0100 Subject: [PATCH 08/23] Fix `pep8` `E201,E202` issues. --- salt/client/api.py | 2 +- salt/master.py | 2 +- salt/states/file.py | 26 +++++++++++++------------- salt/utils/master.py | 8 ++++---- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/salt/client/api.py b/salt/client/api.py index 3f0b26f955..8cbfbe32e9 100644 --- a/salt/client/api.py +++ b/salt/client/api.py @@ -113,7 +113,7 @@ class APIClient(object): cmd['fun'] = '.'.join(funparts[1:]) #strip prefix if not ('token' in cmd or - ('eauth' in cmd and 'password' in cmd and 'username' in cmd) ): + ('eauth' in cmd and 'password' in cmd and 'username' in cmd)): raise EauthAuthenticationError('No authentication credentials given') executor = getattr(self, '{0}_{1}'.format(client, mode)) diff --git a/salt/master.py b/salt/master.py index 06f031e1a9..c959f0d063 100644 --- a/salt/master.py +++ b/salt/master.py @@ -2120,7 +2120,7 @@ class ClearFuncs(object): for module_re in self.opts['client_acl_blacklist'].get('modules', []): # if this is a regular command, its a single function if type(clear_load['fun']) == str: - funs_to_check = [ clear_load['fun'] ] + funs_to_check = [clear_load['fun']] # if this a compound function else: funs_to_check = clear_load['fun'] diff --git a/salt/states/file.py b/salt/states/file.py index 7f2afb3031..2af7245fc2 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -593,19 +593,19 @@ def _unify_sources_and_hashes(source=None, source_hash=None, if source_hashes is None: source_hashes = [] - if ( source and sources ): + if (source and sources): return (False, - "source and sources are mutally exclusive", [] ) + "source and sources are mutally exclusive", []) - if ( source_hash and source_hashes ): + if (source_hash and source_hashes): return (False, - "source_hash and source_hashes are mutally exclusive", [] ) + "source_hash and source_hashes are mutally exclusive", []) - if ( source ): - return (True, '', [ (source, source_hash) ] ) + if (source): + return (True, '', [(source, source_hash)]) # Make a nice neat list of tuples exactly len(sources) long.. - return (True, '', map(None, sources, source_hashes[:len(sources)]) ) + return (True, '', map(None, sources, source_hashes[:len(sources)])) def _get_template_texts(source_list=None, @@ -635,7 +635,7 @@ def _get_template_texts(source_list=None, tmpctx.update(context) rndrd_templ_fn = __salt__['cp.get_template'](source, '', template=template, env=env, - context=tmpctx, **kwargs ) + context=tmpctx, **kwargs) msg = 'cp.get_template returned {0} (Called with: {1})' log.debug(msg.format(rndrd_templ_fn, source)) if rndrd_templ_fn: @@ -644,15 +644,15 @@ def _get_template_texts(source_list=None, tmplines = fp_.readlines() if not tmplines: msg = 'Failed to read rendered template file {0} ({1})' - log.debug( msg.format(rndrd_templ_fn, source)) + log.debug(msg.format(rndrd_templ_fn, source)) ret['name'] = source - return _error(ret, msg.format( rndrd_templ_fn, source) ) - txtl.append( ''.join(tmplines)) + return _error(ret, msg.format(rndrd_templ_fn, source)) + txtl.append(''.join(tmplines)) else: msg = 'Failed to load template file {0}'.format(source) log.debug(msg) ret['name'] = source - return _error(ret, msg ) + return _error(ret, msg) ret['data'] = txtl return ret @@ -2056,7 +2056,7 @@ def append(name, (ok, err, sl) = _unify_sources_and_hashes(source=source, source_hash=source_hash, sources=sources, - source_hashes=source_hashes ) + source_hashes=source_hashes) if not ok: return _error(ret, err) diff --git a/salt/utils/master.py b/salt/utils/master.py index 0844169b3f..15c8021ad6 100755 --- a/salt/utils/master.py +++ b/salt/utils/master.py @@ -138,14 +138,14 @@ class MasterPillarUtil(object): lret = {} if self.use_cached_grains: cret = dict([(minion_id, mcache) for (minion_id, mcache) in cached_grains.iteritems() if mcache]) - missed_minions = [ minion_id for minion_id in minion_ids if minion_id not in cret ] + missed_minions = [minion_id for minion_id in minion_ids if minion_id not in cret] log.debug('Missed cached minion grains for: {0}'.format(missed_minions)) if self.grains_fallback: lret = self._get_live_minion_grains(missed_minions) ret = dict(dict([(minion_id, {}) for minion_id in minion_ids]).items() + lret.items() + cret.items()) else: lret = self._get_live_minion_grains(minion_ids) - missed_minions = [ minion_id for minion_id in minion_ids if minion_id not in lret ] + missed_minions = [minion_id for minion_id in minion_ids if minion_id not in lret] log.debug('Missed live minion grains for: {0}'.format(missed_minions)) if self.grains_fallback: cret = dict([(minion_id, mcache) for (minion_id, mcache) in cached_grains.iteritems() if mcache]) @@ -163,14 +163,14 @@ class MasterPillarUtil(object): lret = {} if self.use_cached_pillar: cret = dict([(minion_id, mcache) for (minion_id, mcache) in cached_pillar.iteritems() if mcache]) - missed_minions = [ minion_id for minion_id in minion_ids if minion_id not in cret ] + missed_minions = [minion_id for minion_id in minion_ids if minion_id not in cret] log.debug('Missed cached minion pillars for: {0}'.format(missed_minions)) if self.pillar_fallback: lret = dict([(minion_id, self._get_live_minion_pillar(minion_id, grains.get(minion_id, {}))) for minion_id in missed_minions]) ret = dict(dict([(minion_id, {}) for minion_id in minion_ids]).items() + lret.items() + cret.items()) else: lret = dict([(minion_id, self._get_live_minion_pillar(minion_id, grains.get(minion_id, {}))) for minion_id in minion_ids]) - missed_minions = [ minion_id for minion_id in minion_ids if minion_id not in lret ] + missed_minions = [minion_id for minion_id in minion_ids if minion_id not in lret] log.debug('Missed live minion pillars for: {0}'.format(missed_minions)) if self.pillar_fallback: cret = dict([(minion_id, mcache) for (minion_id, mcache) in cached_pillar.iteritems() if mcache]) From 796c75f11d8ca105fba7a8fe8d0793c6bd1985d1 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:07:21 +0100 Subject: [PATCH 09/23] Fix `pep8` `E231` issues. --- salt/master.py | 2 +- salt/modules/file.py | 8 ++++---- salt/modules/ssh.py | 4 ++-- salt/returners/sqlite3_return.py | 24 ++++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/salt/master.py b/salt/master.py index c959f0d063..190421c53d 100644 --- a/salt/master.py +++ b/salt/master.py @@ -2319,7 +2319,7 @@ class ClearFuncs(object): new_job_load = { 'jid': clear_load['jid'], - 'tgt_type':clear_load['tgt_type'], + 'tgt_type': clear_load['tgt_type'], 'tgt': clear_load['tgt'], 'user': clear_load['user'], 'fun': clear_load['fun'], diff --git a/salt/modules/file.py b/salt/modules/file.py index 097e63bf2e..801e138da0 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -2298,8 +2298,8 @@ def mknod_chrdev(name, ret['result'] = None else: if os.mknod(name, - int(str(mode).lstrip('0'),8)|stat.S_IFCHR, - os.makedev(major,minor)) is None: + int(str(mode).lstrip('0'), 8)|stat.S_IFCHR, + os.makedev(major, minor)) is None: ret['changes'] = {'new' : 'Character device {0} created.'.format(name)} ret['result'] = True except OSError as exc: @@ -2369,8 +2369,8 @@ def mknod_blkdev(name, ret['result'] = None else: if os.mknod(name, - int(str(mode).lstrip('0'),8)|stat.S_IFBLK, - os.makedev(major,minor)) is None: + int(str(mode).lstrip('0'), 8)|stat.S_IFBLK, + os.makedev(major, minor)) is None: ret['changes'] = {'new' : 'Block device {0} created.'.format(name)} ret['result'] = True except OSError as exc: diff --git a/salt/modules/ssh.py b/salt/modules/ssh.py index 394d23d7ed..fd4a43670e 100644 --- a/salt/modules/ssh.py +++ b/salt/modules/ssh.py @@ -529,9 +529,9 @@ def recv_known_host(hostname, enc=None, port=None, hash_hostname=False): ''' # The following list of OSes have an old version of openssh-clients # and thus require the '-t' option for ssh-keyscan - need_dash_t = ['CentOS-5',] + need_dash_t = ['CentOS-5'] - chunks = ['ssh-keyscan', ] + chunks = ['ssh-keyscan'] if port: chunks += ['-p', str(port)] if enc: diff --git a/salt/returners/sqlite3_return.py b/salt/returners/sqlite3_return.py index 687b6fbc3c..3299ac0940 100644 --- a/salt/returners/sqlite3_return.py +++ b/salt/returners/sqlite3_return.py @@ -106,12 +106,12 @@ def returner(ret): (fun, jid, id, date, full_ret, success) VALUES (:fun, :jid, :id, :date, :full_ret, :success)''' cur.execute(sql, - {'fun':ret['fun'], - 'jid':ret['jid'], - 'id':ret['id'], - 'date':str(datetime.datetime.now()), - 'full_ret':json.dumps(ret['return']), - 'success':ret['success']}) + {'fun': ret['fun'], + 'jid': ret['jid'], + 'id': ret['id'], + 'date': str(datetime.datetime.now()), + 'full_ret': json.dumps(ret['return']), + 'success': ret['success']}) _close_conn(conn) @@ -125,8 +125,8 @@ def save_load(jid, load): cur = conn.cursor() sql = '''INSERT INTO jids (jid, load) VALUES (:jid, :load)''' cur.execute(sql, - {'jid':jid, - 'load':json.dumps(load)}) + {'jid': jid, + 'load': json.dumps(load)}) _close_conn(conn) @@ -139,7 +139,7 @@ def get_load(jid): cur = conn.cursor() sql = '''SELECT load FROM jids WHERE jid = :jid''' cur.execute(sql, - {'jid':jid}) + {'jid': jid}) data = cur.fetchone() if data: return json.loads(data) @@ -156,12 +156,12 @@ def get_jid(jid): cur = conn.cursor() sql = '''SELECT id, full_ret FROM salt_returns WHERE jid = :jid''' cur.execute(sql, - {'jid':jid}) + {'jid': jid}) data = cur.fetchone() log.debug('query result: {0}'.format(data)) ret = {} if data and len(data) > 1: - ret = {str(data[0]):{u'return':json.loads(data[1])}} + ret = {str(data[0]): {u'return': json.loads(data[1])}} log.debug("ret: {0}".format(ret)) _close_conn(conn) return ret @@ -181,7 +181,7 @@ def get_fun(fun): WHERE s.fun = :fun ''' cur.execute(sql, - {'fun':fun}) + {'fun': fun}) data = cur.fetchall() ret = {} if data: From 26347a5e03259c255c7ea44b2642d663112a6204 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:08:17 +0100 Subject: [PATCH 10/23] Fix `pep8` `E211` issues. --- salt/fileserver/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/fileserver/__init__.py b/salt/fileserver/__init__.py index e1f70646ba..41c5b50ffd 100644 --- a/salt/fileserver/__init__.py +++ b/salt/fileserver/__init__.py @@ -59,7 +59,7 @@ def reap_fileserver_cache_dir(cache_base, find_func): for root, dirs, files in os.walk(env_base): # if we have an empty directory, lets cleanup # This will only remove the directory on the second time "_reap_cache" is called (which is intentional) - if len(dirs) == 0 and len (files) == 0: + if len(dirs) == 0 and len(files) == 0: os.rmdir(root) continue # if not, lets check the files in the directory From 843f1e412d491d436ccf8e9451163d7cabf7372a Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:09:19 +0100 Subject: [PATCH 11/23] Fix `pep8` `E203` issues. --- salt/modules/file.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/salt/modules/file.py b/salt/modules/file.py index 801e138da0..9f1409fc08 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -2294,13 +2294,13 @@ def mknod_chrdev(name, mode)) try: if __opts__['test']: - ret['changes'] = {'new' : 'Character device {0} created.'.format(name)} + ret['changes'] = {'new': 'Character device {0} created.'.format(name)} ret['result'] = None else: if os.mknod(name, int(str(mode).lstrip('0'), 8)|stat.S_IFCHR, os.makedev(major, minor)) is None: - ret['changes'] = {'new' : 'Character device {0} created.'.format(name)} + ret['changes'] = {'new': 'Character device {0} created.'.format(name)} ret['result'] = True except OSError as exc: # be happy it is already there....however, if you are trying to change the @@ -2365,13 +2365,13 @@ def mknod_blkdev(name, mode)) try: if __opts__['test']: - ret['changes'] = {'new' : 'Block device {0} created.'.format(name)} + ret['changes'] = {'new': 'Block device {0} created.'.format(name)} ret['result'] = None else: if os.mknod(name, int(str(mode).lstrip('0'), 8)|stat.S_IFBLK, os.makedev(major, minor)) is None: - ret['changes'] = {'new' : 'Block device {0} created.'.format(name)} + ret['changes'] = {'new': 'Block device {0} created.'.format(name)} ret['result'] = True except OSError as exc: # be happy it is already there....however, if you are trying to change the @@ -2431,11 +2431,11 @@ def mknod_fifo(name, log.debug("Creating FIFO name:{0}".format(name)) try: if __opts__['test']: - ret['changes'] = {'new' : 'Fifo pipe {0} created.'.format(name)} + ret['changes'] = {'new': 'Fifo pipe {0} created.'.format(name)} ret['result'] = None else: if os.mkfifo(name, int(str(mode).lstrip('0'), 8)) is None: - ret['changes'] = {'new' : 'Fifo pipe {0} created.'.format(name)} + ret['changes'] = {'new': 'Fifo pipe {0} created.'.format(name)} ret['result'] = True except OSError as exc: #be happy it is already there From 18cc1e86aa859e99d745e8c14332cfe145d5048a Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:12:06 +0100 Subject: [PATCH 12/23] Fix `pep8` `E711,E712` comparison to `None`, `True` and `False` issues. --- salt/master.py | 2 +- salt/utils/ipaddr.py | 4 ++-- salt/utils/master.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/salt/master.py b/salt/master.py index 190421c53d..12ce9e079c 100644 --- a/salt/master.py +++ b/salt/master.py @@ -1083,7 +1083,7 @@ class AESFuncs(object): if 'events' in load: for event in load['events']: self.event.fire_event(event, event['tag']) # old dup event - if load.get('pretag') != None: + if load.get('pretag') is not None: self.event.fire_event(event, tagify(event['tag'], base=load['pretag'])) else: tag = load['tag'] diff --git a/salt/utils/ipaddr.py b/salt/utils/ipaddr.py index f42fc31e6e..a860c9c3cb 100644 --- a/salt/utils/ipaddr.py +++ b/salt/utils/ipaddr.py @@ -770,7 +770,7 @@ class _BaseNet(_IPAddrBase): s1, s2 = s2.subnet() else: # If we got here, there's a bug somewhere. - assert True == False, ('Error performing exclusion: ' + assert True is False, ('Error performing exclusion: ' 's1: %s s2: %s other: %s' % (str(s1), str(s2), str(other))) if s1 == other: @@ -779,7 +779,7 @@ class _BaseNet(_IPAddrBase): ret_addrs.append(s1) else: # If we got here, there's a bug somewhere. - assert True == False, ('Error performing exclusion: ' + assert True is False, ('Error performing exclusion: ' 's1: %s s2: %s other: %s' % (str(s1), str(s2), str(other))) diff --git a/salt/utils/master.py b/salt/utils/master.py index 15c8021ad6..9bb1789fcd 100755 --- a/salt/utils/master.py +++ b/salt/utils/master.py @@ -112,7 +112,7 @@ class MasterPillarUtil(object): def _get_live_minion_pillar(self, minion_id=None, minion_grains=None): # Returns a dict of pillar data for one minion - if minion_id == None: + if minion_id is None: return {} if not minion_grains: log.warn('Cannot get pillar data for {0}: no grains supplied.'.format(minion_id)) From 7e14c2a606bf9c1a869bf2393e4f9ad4980364e8 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:16:20 +0100 Subject: [PATCH 13/23] Fix `pep8` `E226,E227` missing whitespace around bitwise, shift or arithmetic operator issues. --- salt/modules/file.py | 4 ++-- salt/utils/ipaddr.py | 10 +++++----- salt/utils/templates.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/salt/modules/file.py b/salt/modules/file.py index 9f1409fc08..6ad4ffa039 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -2298,7 +2298,7 @@ def mknod_chrdev(name, ret['result'] = None else: if os.mknod(name, - int(str(mode).lstrip('0'), 8)|stat.S_IFCHR, + int(str(mode).lstrip('0'), 8) | stat.S_IFCHR, os.makedev(major, minor)) is None: ret['changes'] = {'new': 'Character device {0} created.'.format(name)} ret['result'] = True @@ -2369,7 +2369,7 @@ def mknod_blkdev(name, ret['result'] = None else: if os.mknod(name, - int(str(mode).lstrip('0'), 8)|stat.S_IFBLK, + int(str(mode).lstrip('0'), 8) | stat.S_IFBLK, os.makedev(major, minor)) is None: ret['changes'] = {'new': 'Block device {0} created.'.format(name)} ret['result'] = True diff --git a/salt/utils/ipaddr.py b/salt/utils/ipaddr.py index a860c9c3cb..d3774e0e25 100644 --- a/salt/utils/ipaddr.py +++ b/salt/utils/ipaddr.py @@ -147,7 +147,7 @@ def v6_int_to_packed(address): Returns: The binary representation of this address. """ - return Bytes(struct.pack('!QQ', address >> 64, address & (2**64 - 1))) + return Bytes(struct.pack('!QQ', address >> 64, address & (2 ** 64 - 1))) def _find_address_range(addresses): @@ -255,7 +255,7 @@ def summarize_address_range(first, last): nbits = _count_righthand_zero_bits(first_int, ip_bits) current = None while nbits >= 0: - addend = 2**nbits - 1 + addend = 2 ** nbits - 1 current = first_int + addend nbits -= 1 if current <= last_int: @@ -1021,7 +1021,7 @@ class _BaseV4(object): """ # Equivalent to 255.255.255.255 or 32 bits of 1's. - _ALL_ONES = (2**IPV4LENGTH) - 1 + _ALL_ONES = (2 ** IPV4LENGTH) - 1 _DECIMAL_DIGITS = frozenset('0123456789') def __init__(self, address): @@ -1393,7 +1393,7 @@ class _BaseV6(object): """ - _ALL_ONES = (2**IPV6LENGTH) - 1 + _ALL_ONES = (2 ** IPV6LENGTH) - 1 _HEXTET_COUNT = 8 _HEX_DIGITS = frozenset('0123456789ABCDEFabcdef') @@ -1572,7 +1572,7 @@ class _BaseV6(object): hex_str = '%032x' % ip_int hextets = [] for x in range(0, 32, 4): - hextets.append('%x' % int(hex_str[x:x+4], 16)) + hextets.append('%x' % int(hex_str[x:x + 4], 16)) hextets = self._compress_hextets(hextets) return ':'.join(hextets) diff --git a/salt/utils/templates.py b/salt/utils/templates.py index 95206b5211..c379ffc95c 100644 --- a/salt/utils/templates.py +++ b/salt/utils/templates.py @@ -245,8 +245,8 @@ def get_template_context(template, line, num_lines=5, marker=None): if line > num_template_lines: return template - context_start = max(0, line-num_lines-1) # subtract 1 for 0-based indexing - context_end = min(num_template_lines, line+num_lines) + context_start = max(0, line - num_lines - 1) # subtract 1 for 0-based indexing + context_end = min(num_template_lines, line + num_lines) error_line_in_context = line - context_start - 1 # subtract 1 for 0-based indexing buf = [] From 7ea0fd0b386a12d18b942c033631c031965d03a7 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:20:08 +0100 Subject: [PATCH 14/23] Fix `pep8` `E261,E262` issues. --- salt/client/api.py | 14 +++++++------- salt/master.py | 6 +++--- salt/utils/event.py | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/salt/client/api.py b/salt/client/api.py index 8cbfbe32e9..2cd3234250 100644 --- a/salt/client/api.py +++ b/salt/client/api.py @@ -103,14 +103,14 @@ class APIClient(object): eauth: the authentication type such as 'pam' or 'ldap'. Required if token is missing ''' - client = 'minion' #default to local minion client - mode = cmd.get('mode', 'async') #default to 'async' + client = 'minion' # default to local minion client + mode = cmd.get('mode', 'async') # default to 'async' # check for wheel or runner prefix to fun name to use wheel or runner client funparts = cmd.get('fun', '').split('.') - if len(funparts) > 2 and funparts[0] in ['wheel', 'runner']: #master + if len(funparts) > 2 and funparts[0] in ['wheel', 'runner']: # master client = funparts[0] - cmd['fun'] = '.'.join(funparts[1:]) #strip prefix + cmd['fun'] = '.'.join(funparts[1:]) # strip prefix if not ('token' in cmd or ('eauth' in cmd and 'password' in cmd and 'username' in cmd)): @@ -146,7 +146,7 @@ class APIClient(object): ''' return self.runnerClient.master_call(**kwargs) - runner_sync = runner_async # always runner async, so works in either mode + runner_sync = runner_async # always runner async, so works in either mode def wheel_sync(self, **kwargs): ''' @@ -156,7 +156,7 @@ class APIClient(object): ''' return self.wheelClient.master_call(**kwargs) - wheel_async = wheel_sync # always wheel_sync, so it works either mode + wheel_async = wheel_sync # always wheel_sync, so it works either mode def signature(self, cmd): ''' @@ -199,7 +199,7 @@ class APIClient(object): elif client == 'master': parts = cmd['module'].split('.') client = parts[0] - module = '.'.join(parts[1:]) #strip prefix + module = '.'.join(parts[1:]) # strip prefix if client == 'wheel': functions = self.wheelClient.w_funcs elif client == 'runner': diff --git a/salt/master.py b/salt/master.py index 12ce9e079c..d8ddf9fcee 100644 --- a/salt/master.py +++ b/salt/master.py @@ -1082,7 +1082,7 @@ class AESFuncs(object): return False if 'events' in load: for event in load['events']: - self.event.fire_event(event, event['tag']) # old dup event + self.event.fire_event(event, event['tag']) # old dup event if load.get('pretag') is not None: self.event.fire_event(event, tagify(event['tag'], base=load['pretag'])) else: @@ -1106,7 +1106,7 @@ class AESFuncs(object): self.opts['hash_type'], load.get('nocache', False)) log.info('Got return from {id} for job {jid}'.format(**load)) - self.event.fire_event(load, load['jid']) # old dup event + self.event.fire_event(load, load['jid']) # old dup event self.event.fire_event(load, tagify([load['jid'], 'ret', load['id']], 'job')) self.event.fire_ret_load(load) if self.opts['master_ext_job_cache']: @@ -2328,7 +2328,7 @@ class ClearFuncs(object): } # Announce the job on the event bus - self.event.fire_event(new_job_load, 'new_job') # old dup event + self.event.fire_event(new_job_load, 'new_job') # old dup event self.event.fire_event(new_job_load, tagify([clear_load['jid'], 'new'], 'job')) # Verify the jid dir diff --git a/salt/utils/event.py b/salt/utils/event.py index f9ebb86c0e..552a814240 100644 --- a/salt/utils/event.py +++ b/salt/utils/event.py @@ -93,9 +93,9 @@ TAGS = { 'minion': 'minion', # prefix for all salt/minion events (minion sourced events) 'syndic': 'syndic', # prefix for all salt/syndic events (syndic minion sourced events) 'run': 'run', # prefix for all salt/run events (salt runners) - 'wheel': 'wheel', # prefix for all salt/wheel events - 'cloud': 'cloud', # prefix for all salt/cloud events - 'fileserver': 'fileserver', #prefix for all salt/fileserver events + 'wheel': 'wheel', # prefix for all salt/wheel events + 'cloud': 'cloud', # prefix for all salt/cloud events + 'fileserver': 'fileserver', # prefix for all salt/fileserver events } From a8bc999afcf8247c6a61670379b1bebac4da4cab Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:24:29 +0100 Subject: [PATCH 15/23] Fix `pep8` `E502`, redundant backslash between brackets issues. --- salt/master.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/salt/master.py b/salt/master.py index d8ddf9fcee..2e2738f812 100644 --- a/salt/master.py +++ b/salt/master.py @@ -537,7 +537,7 @@ class ReqServer(object): else: log.info('Halite: Not starting. ' 'Package available is {0}. ' - 'Opts for "halite" exists is {1}.'\ + 'Opts for "halite" exists is {1}.' .format(HAS_HALITE, 'halite' in self.opts)) def run(self): @@ -1964,8 +1964,8 @@ class ClearFuncs(object): log.warning('Authentication failure of type "token" occurred.') return '' good = self.ckminions.wheel_check( - self.opts['external_auth'][token['eauth']][token['name']] \ - if token['name'] in self.opts['external_auth'][token['eauth']] \ + self.opts['external_auth'][token['eauth']][token['name']] + if token['name'] in self.opts['external_auth'][token['eauth']] else self.opts['external_auth'][token['eauth']]['*'], clear_load['fun']) if not good: @@ -2025,8 +2025,8 @@ class ClearFuncs(object): log.warning(msg) return '' good = self.ckminions.wheel_check( - self.opts['external_auth'][clear_load['eauth']][name] \ - if name in self.opts['external_auth'][clear_load['eauth']] \ + self.opts['external_auth'][clear_load['eauth']][name] + if name in self.opts['external_auth'][clear_load['eauth']] else self.opts['external_auth'][token['eauth']]['*'], clear_load['fun']) if not good: @@ -2165,8 +2165,8 @@ class ClearFuncs(object): log.warning('Authentication failure of type "token" occurred.') return '' good = self.ckminions.auth_check( - self.opts['external_auth'][token['eauth']][token['name']] \ - if token['name'] in self.opts['external_auth'][token['eauth']] \ + self.opts['external_auth'][token['eauth']][token['name']] + if token['name'] in self.opts['external_auth'][token['eauth']] else self.opts['external_auth'][token['eauth']]['*'], clear_load['fun'], clear_load['tgt'], @@ -2206,8 +2206,8 @@ class ClearFuncs(object): ) return '' good = self.ckminions.auth_check( - self.opts['external_auth'][extra['eauth']][name] \ - if name in self.opts['external_auth'][extra['eauth']] \ + self.opts['external_auth'][extra['eauth']][name] + if name in self.opts['external_auth'][extra['eauth']] else self.opts['external_auth'][extra['eauth']]['*'], clear_load['fun'], clear_load['tgt'], From 3b95c2e853f25f7c13df2dfbe2b6634dc4489990 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:25:53 +0100 Subject: [PATCH 16/23] Fix `pep8` `E222` issues. --- salt/client/api.py | 4 ++-- salt/master.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/client/api.py b/salt/client/api.py index 2cd3234250..9c8671a113 100644 --- a/salt/client/api.py +++ b/salt/client/api.py @@ -189,7 +189,7 @@ class APIClient(object): eauth: the authentication type such as 'pam' or 'ldap'. Required if token is missing ''' - result = {} + result = {} client = cmd.get('client', 'minion') if client == 'minion': @@ -204,7 +204,7 @@ class APIClient(object): functions = self.wheelClient.w_funcs elif client == 'runner': functions = self.runnerClient.functions - result = salt.utils.argspec_report(functions, module) + result = salt.utils.argspec_report(functions, module) return result def create_token(self, creds): diff --git a/salt/master.py b/salt/master.py index 2e2738f812..8a69af8c2a 100644 --- a/salt/master.py +++ b/salt/master.py @@ -2317,7 +2317,7 @@ class ClearFuncs(object): self.opts['hash_type'] ) - new_job_load = { + new_job_load = { 'jid': clear_load['jid'], 'tgt_type': clear_load['tgt_type'], 'tgt': clear_load['tgt'], From eed0a5feacda56e05692a935f2336044a470b92c Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:29:24 +0100 Subject: [PATCH 17/23] Fix `pep8` `E272` issues. --- salt/client/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/client/api.py b/salt/client/api.py index 9c8671a113..8875b2de52 100644 --- a/salt/client/api.py +++ b/salt/client/api.py @@ -112,7 +112,7 @@ class APIClient(object): client = funparts[0] cmd['fun'] = '.'.join(funparts[1:]) # strip prefix - if not ('token' in cmd or + if not ('token' in cmd or ('eauth' in cmd and 'password' in cmd and 'username' in cmd)): raise EauthAuthenticationError('No authentication credentials given') From bc2d8b9da1df04be4a1a284069292bb95d692b77 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 13:32:23 +0100 Subject: [PATCH 18/23] Fix `pep8` `W391`, blank line at end of file warning. --- salt/client/ssh/wrapper/pillar.py | 1 - salt/modules/alternatives.py | 1 - salt/states/file.py | 1 - salt/states/rabbitmq_policy.py | 1 - 4 files changed, 4 deletions(-) diff --git a/salt/client/ssh/wrapper/pillar.py b/salt/client/ssh/wrapper/pillar.py index 55021524a2..8592fcb6a8 100644 --- a/salt/client/ssh/wrapper/pillar.py +++ b/salt/client/ssh/wrapper/pillar.py @@ -82,4 +82,3 @@ def raw(key=None): # Allow pillar.data to also be used to return pillar data items = raw data = items - diff --git a/salt/modules/alternatives.py b/salt/modules/alternatives.py index 80a5319ce2..6200554104 100644 --- a/salt/modules/alternatives.py +++ b/salt/modules/alternatives.py @@ -168,4 +168,3 @@ def set_(name, path): if out['retcode'] > 0: return out['stderr'] return out['stdout'] - diff --git a/salt/states/file.py b/salt/states/file.py index 2af7245fc2..cfd4eb52ea 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -2752,4 +2752,3 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'): ret['comment'] = "Node type unavailable: '{0}. Available node types are character ('c'), block ('b'), and pipe ('p')".format(ntype) return ret - diff --git a/salt/states/rabbitmq_policy.py b/salt/states/rabbitmq_policy.py index 7912327056..958bfb347e 100644 --- a/salt/states/rabbitmq_policy.py +++ b/salt/states/rabbitmq_policy.py @@ -140,4 +140,3 @@ def absent(name, ret['comment'] = 'Policy {0} {1} is not present'.format(vhost, name) return ret - From 835ad6ba6fe06baf0c29eb75417dabc27e84fd82 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 17:56:44 +0100 Subject: [PATCH 19/23] Fix `pep8` `E261` issues. --- salt/modules/file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/modules/file.py b/salt/modules/file.py index 6ad4ffa039..cbc3b1f5cf 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -957,8 +957,8 @@ def replace(path, # Search the file; track if any changes have been made for the return val has_changes = False - orig_file = [] # used if show_changes - new_file = [] # used if show_changes + orig_file = [] # used if show_changes + new_file = [] # used if show_changes for line in fileinput.input(path, inplace=not dry_run, backup=False if dry_run else backup, bufsize=bufsize, mode='rb'): From 8dff16f2b636b024712cde1762a253cd0af6f72a Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 17:57:39 +0100 Subject: [PATCH 20/23] Fix `pep8` `E712` issues. --- salt/modules/file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/file.py b/salt/modules/file.py index cbc3b1f5cf..c9afd1790c 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -973,7 +973,7 @@ def replace(path, result = re.sub(cpattern, repl, line, count) # Identity check each potential change until one change is made - if has_changes == False and not result is line: + if has_changes is False and not result is line: has_changes = True if show_changes: From db1fdd17385ac32df80446ecdda1b713af8d8738 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 20 Sep 2013 17:58:22 +0100 Subject: [PATCH 21/23] Fix `pep8` `E302` issues. --- salt/states/file.py | 1 + 1 file changed, 1 insertion(+) diff --git a/salt/states/file.py b/salt/states/file.py index cfd4eb52ea..77266edb65 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -1701,6 +1701,7 @@ def replace(name, ret['result'] = True return ret + def sed(name, before, after, From 02122c3fa588f2371fc9902527c040f34f922d6f Mon Sep 17 00:00:00 2001 From: micahhausler Date: Fri, 20 Sep 2013 13:03:02 -0400 Subject: [PATCH 22/23] Added ext_pillar Django model field access through the ORM This external pillar will load django model fields into pillar data. --- doc/ref/pillar/all/index.rst | 1 + doc/ref/pillar/all/salt.pillar.django_orm.rst | 6 + salt/pillar/django_orm.py | 186 ++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 doc/ref/pillar/all/salt.pillar.django_orm.rst create mode 100644 salt/pillar/django_orm.py diff --git a/doc/ref/pillar/all/index.rst b/doc/ref/pillar/all/index.rst index a4e9d74a5c..a667efeca4 100644 --- a/doc/ref/pillar/all/index.rst +++ b/doc/ref/pillar/all/index.rst @@ -13,6 +13,7 @@ Full list of builtin pillar modules cmd_json cmd_yaml cobbler + django_orm git_pillar hiera libvirt diff --git a/doc/ref/pillar/all/salt.pillar.django_orm.rst b/doc/ref/pillar/all/salt.pillar.django_orm.rst new file mode 100644 index 0000000000..367cb4f9c2 --- /dev/null +++ b/doc/ref/pillar/all/salt.pillar.django_orm.rst @@ -0,0 +1,6 @@ +====================== +salt.pillar.django_orm +====================== + +.. automodule:: salt.pillar.django_orm + :members: diff --git a/salt/pillar/django_orm.py b/salt/pillar/django_orm.py new file mode 100644 index 0000000000..fe3ff52d4f --- /dev/null +++ b/salt/pillar/django_orm.py @@ -0,0 +1,186 @@ +# -*- coding: utf-8 -*- +''' +Generate pillar data from Django models through the Django ORM + +:maintainer: Micah Hausler +:maturity: new + + +Configuring the django_orm ext_pillar +================================ + +To use this module, your Django project must be on the saltmaster server with +databse access. This assumes you are using virtualenv with all the project's +requirements installed. + +.. code-block:: yaml + + ext_pillar: + - django_orm: + pillar_name: my_application + env: /path/to/virtualenv/ + project_path: /path/to/project/ + env_file: /path/to/env/file.sh + settings_module: my_application.settings + + django_app: + + # Required: the app that is included in INSTALLED_APPS + my_application.clients: + + # Required: the model name + Client: + + # Required: model field to use as a name in the + # rendered pillar, should be unique + name: shortname + + # Optional: + # See the Django QuerySet docuemntation for how to use .filter() + filter: {'kw': 'args'} + + # Required: a list of field names + fields: + - field_1 + - field_2 + + +This would return pillar data that would look like + +.. code-block:: yaml + + my_application: + my_application.clients: + Client: + client_1: + field_1: data_from_field_1 + field_2: data_from_field_2 + client_2: + field_1: data_from_field_1 + field_2: data_from_field_2 + + +Module Documentation +==================== +''' + +import logging +import os +import sys + + +HAS_VIRTUALENV = False + +try: + import virtualenv + HAS_VIRTUALENV = True +except ImportError: + pass + +log = logging.getLogger(__name__) + + +def __virtual__(): + if not HAS_VIRTUALENV: + log.warn('virtualenv not installed, please install first') + return False + return 'django_orm' + + +def ext_pillar(minion_id, + pillar, + pillar_name, + env, + project_path, + settings_module, + django_app, + env_file=None, + *args, + **kwargs): + ''' + Connect to a django database through the ORM and retrieve model fields + + Parameters: + * `pillar_name`: The name of the pillar to be returned + * `env`: The full path to the virtualenv for your django project + * `project_path`: The full path to your django project (the directory + manage.py is in.) + * `settings_module`: The settings module for your project. This can be + found in your manage.py file. + * `django_app`: A dictionary containing your apps, models, and fields + * `env_file`: A bash file that sets up your environment. The file is + run in a subprocess and the changed variables are then added. + ''' + + if not os.path.isdir(project_path): + log.error('Django project dir: \'{}\' not a directory!'.format(env)) + return {} + for path in virtualenv.path_locations(env): + if not os.path.isdir(path): + log.error('Virtualenv {} not a directory!'.format(path)) + return {} + + # load the virtualenv + sys.path.append(virtualenv.path_locations(env)[1] + '/site-packages/') + # load the django project + sys.path.append(project_path) + + os.environ['DJANGO_SETTINGS_MODULE'] = settings_module + + if env_file is not None: + import subprocess + + base_env = {} + proc = subprocess.Popen(['bash', '-c', 'env'], stdout=subprocess.PIPE) + for line in proc.stdout: + (key, _, value) = line.partition('=') + base_env[key] = value + + command = ['bash', '-c', 'source {0} && env'.format(env_file)] + proc = subprocess.Popen(command, stdout=subprocess.PIPE) + + for line in proc.stdout: + (key, _, value) = line.partition('=') + # only add a key if it is different or doesn't already exist + if key not in base_env or base_env[key] != value: + os.environ[key] = value.rstrip('\n') + log.debug('Adding {} = {} to django environment'.format( + key, + value.rstrip('\n'))) + + try: + import importlib + + django_pillar = {} + + for app, models in django_app.iteritems(): + django_pillar[app] = {} + model_file = importlib.import_module(app + '.models') + for model_name, model_meta in models.iteritems(): + model_orm = model_file.__dict__[model_name] + django_pillar[app][model_orm.__name__] = {} + + fields = model_meta['fields'] + + if 'filter' in model_meta.keys(): + qs = model_orm.objects.filter(**model_meta['filter']) + else: + qs = model_orm.objects.all() + + # Loop through records for the queryset + for model in qs: + django_pillar[app][model_orm.__name__][ + model.__dict__[ + model_meta['name'] + ]] = {} + + for field in fields: + django_pillar[app][model_orm.__name__][ + model.__dict__[ + model_meta['name'] + ]][field] = model.__dict__[field] + + return {pillar_name: django_pillar} + except ImportError, e: + log.error('Failed to import library: {}'.format(e.message)) + return {} From 8ac983d1656ed7a842042d7ecfb4adb7ae464f2d Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 20 Sep 2013 12:14:09 -0700 Subject: [PATCH 23/23] various style, spacing, spelling fixes to the file state --- salt/states/file.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/salt/states/file.py b/salt/states/file.py index 77266edb65..48f6ca6af2 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -584,7 +584,7 @@ def _test_owner(kwargs, user=None): def _unify_sources_and_hashes(source=None, source_hash=None, sources=None, source_hashes=None): ''' - Silly lil function to give us a standard tuple list for sources and + Silly little function to give us a standard tuple list for sources and source_hashes ''' if sources is None: @@ -593,21 +593,20 @@ def _unify_sources_and_hashes(source=None, source_hash=None, if source_hashes is None: source_hashes = [] - if (source and sources): + if source and sources: return (False, - "source and sources are mutally exclusive", []) + "source and sources are mutually exclusive", []) - if (source_hash and source_hashes): + if source_hash and source_hashes: return (False, - "source_hash and source_hashes are mutally exclusive", []) + "source_hash and source_hashes are mutually exclusive", []) - if (source): + if source: return (True, '', [(source, source_hash)]) # Make a nice neat list of tuples exactly len(sources) long.. return (True, '', map(None, sources, source_hashes[:len(sources)])) - def _get_template_texts(source_list=None, template='jinja', defaults=None, @@ -619,8 +618,11 @@ def _get_template_texts(source_list=None, Returns a list of 'chunks' containing the rendered templates. ''' - ret = {'name': '_get_template_texts', 'changes': {}, - 'result': True, 'comment': '', 'data': []} + ret = {'name': '_get_template_texts', + 'changes': {}, + 'result': True, + 'comment': '', + 'data': []} if source_list is None: return _error(ret, @@ -2052,7 +2054,7 @@ def append(name, source_hashes = [] # Add sources and source_hashes with template support - # NOTE: FIX 'text' and any 'source' are mutally exclusive as 'text' + # NOTE: FIX 'text' and any 'source' are mutually exclusive as 'text' # is re-assigned in the original code. (ok, err, sl) = _unify_sources_and_hashes(source=source, source_hash=source_hash,