Merge pull request #5461 from sivel/test-module-interpreter

Add -I/--interpreter argument to test-module
This commit is contained in:
jctanner 2014-01-29 16:24:37 -08:00
commit 7fa0d8bdd3

View file

@ -56,6 +56,9 @@ def parse():
help="module argument string") help="module argument string")
parser.add_option('-D', '--debugger', dest='debugger', parser.add_option('-D', '--debugger', dest='debugger',
help="path to python debugger (e.g. /usr/bin/pdb)") help="path to python debugger (e.g. /usr/bin/pdb)")
parser.add_option('-I', '--interpreter', dest='interpreter',
help="path to interpeter to use for this module (e.g. ansible_python_interpreter=/usr/bin/python)",
metavar='INTERPRETER_TYPE=INTERPRETER_PATH')
options, args = parser.parse_args() options, args = parser.parse_args()
if not options.module_path: if not options.module_path:
parser.print_help() parser.print_help()
@ -74,7 +77,7 @@ def write_argsfile(argstring, json=False):
argsfile.close() argsfile.close()
return argspath return argspath
def boilerplate_module(modfile, args): def boilerplate_module(modfile, args, interpreter):
""" simulate what ansible does with new style modules """ """ simulate what ansible does with new style modules """
#module_fh = open(modfile) #module_fh = open(modfile)
@ -87,6 +90,16 @@ def boilerplate_module(modfile, args):
complex_args = {} complex_args = {}
inject = {} inject = {}
if interpreter:
if '=' not in interpreter:
print 'interpeter must by in the form of ansible_python_interpreter=/usr/bin/python'
sys.exit(1)
interpreter_type, interpreter_path = interpreter.split('=')
if not interpreter_type.startswith('ansible_'):
interpreter_type = 'ansible_%s' % interpreter_type
if not interpreter_type.endswith('_interpreter'):
interpreter_type = '%s_interpreter' % interpreter_type
inject[interpreter_type] = interpreter_path
(module_data, module_style, shebang) = replacer.modify_module( (module_data, module_style, shebang) = replacer.modify_module(
modfile, modfile,
complex_args, complex_args,
@ -144,7 +157,7 @@ def rundebug(debugger, modfile, argspath):
def main(): def main():
options, args = parse() options, args = parse()
(modfile, module_style) = boilerplate_module(options.module_path, options.module_args) (modfile, module_style) = boilerplate_module(options.module_path, options.module_args, options.interpreter)
argspath=None argspath=None
if module_style != 'new': if module_style != 'new':