From d2e544386098e1d2d25cf2d14734b065a1726977 Mon Sep 17 00:00:00 2001 From: rallytime Date: Mon, 24 Nov 2014 11:58:24 -0700 Subject: [PATCH 1/7] Add parser to jenkins.py --- tests/jenkins.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/jenkins.py b/tests/jenkins.py index f71ddfe0ca..8ba6d764e3 100644 --- a/tests/jenkins.py +++ b/tests/jenkins.py @@ -19,6 +19,7 @@ import time import shutil import optparse import subprocess +import argparse # Import Salt libs try: @@ -117,7 +118,7 @@ def delete_vm(options): proc.communicate() -def echo_parseable_environment(options): +def echo_parseable_environment(options, parser): ''' Echo NAME=VAL parseable output ''' @@ -365,6 +366,10 @@ def run(opts): ''' RUN! ''' + + parser = argparse.ArgumentParser( + description='Jenkins execution helper' + ) vm_name = os.environ.get( 'JENKINS_SALTCLOUD_VM_NAME', generate_vm_name(opts) @@ -959,7 +964,7 @@ def parse(): parser.exit('--provider or --pull-request is required') if options.echo_parseable_environment: - echo_parseable_environment(options) + echo_parseable_environment(options, parser) parser.exit(0) if not options.test_git_commit and not options.pull_request: From 512f07303a9357c8aca6187b00a3634c34621790 Mon Sep 17 00:00:00 2001 From: rallytime Date: Mon, 24 Nov 2014 12:13:38 -0700 Subject: [PATCH 2/7] Put the parser variable in the correct place --- tests/jenkins.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/jenkins.py b/tests/jenkins.py index 8ba6d764e3..a7f74d1d2e 100644 --- a/tests/jenkins.py +++ b/tests/jenkins.py @@ -366,10 +366,6 @@ def run(opts): ''' RUN! ''' - - parser = argparse.ArgumentParser( - description='Jenkins execution helper' - ) vm_name = os.environ.get( 'JENKINS_SALTCLOUD_VM_NAME', generate_vm_name(opts) From 022d2dbbfbbacf0751a26b02998561e089e8c676 Mon Sep 17 00:00:00 2001 From: rallytime Date: Mon, 24 Nov 2014 13:02:08 -0700 Subject: [PATCH 3/7] Remove unused import --- tests/jenkins.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/jenkins.py b/tests/jenkins.py index a7f74d1d2e..5e31e1c524 100644 --- a/tests/jenkins.py +++ b/tests/jenkins.py @@ -19,7 +19,6 @@ import time import shutil import optparse import subprocess -import argparse # Import Salt libs try: From a9f5eeec4297d4ac4bf7d8208fbb7774741a4b93 Mon Sep 17 00:00:00 2001 From: Justin Findlay Date: Mon, 24 Nov 2014 14:22:51 -0700 Subject: [PATCH 4/7] quote input in rbenv mod --- salt/modules/rbenv.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/salt/modules/rbenv.py b/salt/modules/rbenv.py index fa2f108a25..5f47dbc8f9 100644 --- a/salt/modules/rbenv.py +++ b/salt/modules/rbenv.py @@ -9,6 +9,11 @@ Manage ruby installations with rbenv. import os import re import logging +try: + from shlex import quote as _cmd_quote # pylint: disable=E0611 +except ImportError: + from pipes import quote as _cmd_quote +from shlex import split as _cmd_split # Set up logger log = logging.getLogger(__name__) @@ -30,15 +35,21 @@ def _rbenv_exec(command, args='', env=None, runas=None, ret=None): binary = _rbenv_bin(runas) path = _rbenv_path(runas) - if env: - env = ' {0}'.format(env) - env = env or '' + environ = {} + for token in _cmd_split(env): + try: + var, val = token.split('=') + environ[var] = val + except: + pass # if token != var=val, it's not a proper env anyway + environ['RBENV_ROOT'] = path - binary = 'env RBENV_ROOT={0}{1} {2}'.format(path, env, binary) + args = ' '.join([_cmd_quote(arg) for arg in _cmd_split(args)]) result = __salt__['cmd.run_all']( - '{0} {1} {2}'.format(binary, command, args), - runas=runas + '{0} {1} {2}'.format(binary, _cmd_quote(command), args), + runas=runas, + env=environ ) if isinstance(ret, dict): @@ -61,7 +72,8 @@ def _rbenv_path(runas=None): if runas in (None, 'root'): path = __salt__['config.option']('rbenv.root') or '/usr/local/rbenv' else: - path = __salt__['config.option']('rbenv.root') or '~{0}/.rbenv'.format(runas) + path = _cmd_quote(__salt__['config.option']('rbenv.root') + or '~{0}/.rbenv'.format(runas)) return os.path.expanduser(path) @@ -71,7 +83,8 @@ def _install_rbenv(path, runas=None): return True return 0 == __salt__['cmd.retcode']( - 'git clone https://github.com/sstephenson/rbenv.git {0}'.format(path), runas=runas) + 'git clone https://github.com/sstephenson/rbenv.git {0}' + .format(_cmd_quote(path)), runas=runas) def _install_ruby_build(path, runas=None): @@ -80,7 +93,8 @@ def _install_ruby_build(path, runas=None): return True return 0 == __salt__['cmd.retcode']( - 'git clone https://github.com/sstephenson/ruby-build.git {0}'.format(path), runas=runas) + 'git clone https://github.com/sstephenson/ruby-build.git {0}' + .format(_cmd_quote(path)), runas=runas) def _update_rbenv(path, runas=None): @@ -88,7 +102,7 @@ def _update_rbenv(path, runas=None): return False return 0 == __salt__['cmd.retcode']( - 'cd {0} && git pull'.format(path), runas=runas) + 'git pull', runas=runas, cwd=path) def _update_ruby_build(path, runas=None): @@ -97,7 +111,7 @@ def _update_ruby_build(path, runas=None): return False return 0 == __salt__['cmd.retcode']( - 'cd {0} && git pull'.format(path), runas=runas) + 'git pull', runas=runas, cwd=path) def install(runas=None, path=None): @@ -298,9 +312,12 @@ def do(cmdline=None, runas=None): salt '*' rbenv.do 'gem list bundler' deploy ''' path = _rbenv_path(runas) + environ = {'PATH': '{0}/shims:{1}'.format(path, os.environ['PATH'])} + cmdline = ' '.join([_cmd_quote(cmd) for cmd in _cmd_split(cmdline)]) result = __salt__['cmd.run_all']( - 'env PATH={0}/shims:$PATH {1}'.format(path, cmdline), - runas=runas + cmdline, + runas=runas, + env=environ ) if result['retcode'] == 0: From 98c581385e72861abbc3e399238cd7ea46dc81be Mon Sep 17 00:00:00 2001 From: Justin Findlay Date: Mon, 24 Nov 2014 15:32:53 -0700 Subject: [PATCH 5/7] pylint fix for quote rbenv mod --- salt/modules/rbenv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/rbenv.py b/salt/modules/rbenv.py index 5f47dbc8f9..c977486409 100644 --- a/salt/modules/rbenv.py +++ b/salt/modules/rbenv.py @@ -40,7 +40,7 @@ def _rbenv_exec(command, args='', env=None, runas=None, ret=None): try: var, val = token.split('=') environ[var] = val - except: + except Exception: pass # if token != var=val, it's not a proper env anyway environ['RBENV_ROOT'] = path From 2402d1040748f5ca33806350d3a13a7a0ad78d3c Mon Sep 17 00:00:00 2001 From: Colton Myers Date: Mon, 24 Nov 2014 15:46:52 -0700 Subject: [PATCH 6/7] Force contents to a string in file.managed --- salt/states/file.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/salt/states/file.py b/salt/states/file.py index 04f96cf437..4005d9bdf0 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -1194,6 +1194,10 @@ def managed(name, If the command exits with a nonzero exit code, the command will not be run. ''' + # contents must be a string + if contents: + contents = str(contents) + # Make sure that leading zeros stripped by YAML loader are added back mode = __salt__['config.manage_mode'](mode) From 0909269c62fff4ec5247d1eb66be0fa6e67f6b81 Mon Sep 17 00:00:00 2001 From: rallytime Date: Mon, 24 Nov 2014 19:48:43 -0700 Subject: [PATCH 7/7] Fix OrderedDict import in runners/lxc.py --- salt/runners/lxc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/runners/lxc.py b/salt/runners/lxc.py index c80f389baf..a9592bb95d 100644 --- a/salt/runners/lxc.py +++ b/salt/runners/lxc.py @@ -13,7 +13,7 @@ import copy import logging # Import Salt libs -from salt.utils.odict import _OrderedDict +from salt.utils.odict import OrderedDict as _OrderedDict import salt.client import salt.output import salt.utils.virt