Merge pull request #8214 from hacosta/checkmode
Add checkmode support for test-module script
This commit is contained in:
commit
571dbe09c3
1 changed files with 12 additions and 5 deletions
|
@ -23,9 +23,10 @@
|
||||||
# modules
|
# modules
|
||||||
#
|
#
|
||||||
# example:
|
# example:
|
||||||
# test-module -m ../library/command -a "/bin/sleep 3"
|
# test-module -m ../library/commands/command -a "/bin/sleep 3"
|
||||||
# test-module -m ../library/service -a "name=httpd ensure=restarted"
|
# test-module -m ../library/system/service -a "name=httpd ensure=restarted"
|
||||||
# test-module -m ../library/service -a "name=httpd ensure=restarted" --debugger /usr/bin/pdb
|
# test-module -m ../library/system/service -a "name=httpd ensure=restarted" --debugger /usr/bin/pdb
|
||||||
|
# test-modulr -m ../library/file/lineinfile -a "dest=/etc/exports line='/srv/home hostname1(rw,sync)'" --check
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import base64
|
import base64
|
||||||
|
@ -59,6 +60,8 @@ def parse():
|
||||||
parser.add_option('-I', '--interpreter', dest='interpreter',
|
parser.add_option('-I', '--interpreter', dest='interpreter',
|
||||||
help="path to interpeter to use for this module (e.g. ansible_python_interpreter=/usr/bin/python)",
|
help="path to interpeter to use for this module (e.g. ansible_python_interpreter=/usr/bin/python)",
|
||||||
metavar='INTERPRETER_TYPE=INTERPRETER_PATH')
|
metavar='INTERPRETER_TYPE=INTERPRETER_PATH')
|
||||||
|
parser.add_option('-c', '--check', dest='check', action='store_true',
|
||||||
|
help="run the module in check mode")
|
||||||
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()
|
||||||
|
@ -77,7 +80,7 @@ def write_argsfile(argstring, json=False):
|
||||||
argsfile.close()
|
argsfile.close()
|
||||||
return argspath
|
return argspath
|
||||||
|
|
||||||
def boilerplate_module(modfile, args, interpreter):
|
def boilerplate_module(modfile, args, interpreter, check):
|
||||||
""" simulate what ansible does with new style modules """
|
""" simulate what ansible does with new style modules """
|
||||||
|
|
||||||
#module_fh = open(modfile)
|
#module_fh = open(modfile)
|
||||||
|
@ -109,6 +112,10 @@ def boilerplate_module(modfile, args, interpreter):
|
||||||
if not interpreter_type.endswith('_interpreter'):
|
if not interpreter_type.endswith('_interpreter'):
|
||||||
interpreter_type = '%s_interpreter' % interpreter_type
|
interpreter_type = '%s_interpreter' % interpreter_type
|
||||||
inject[interpreter_type] = interpreter_path
|
inject[interpreter_type] = interpreter_path
|
||||||
|
|
||||||
|
if check:
|
||||||
|
complex_args['CHECKMODE'] = True
|
||||||
|
|
||||||
(module_data, module_style, shebang) = replacer.modify_module(
|
(module_data, module_style, shebang) = replacer.modify_module(
|
||||||
modfile,
|
modfile,
|
||||||
complex_args,
|
complex_args,
|
||||||
|
@ -166,7 +173,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, options.interpreter)
|
(modfile, module_style) = boilerplate_module(options.module_path, options.module_args, options.interpreter, options.check)
|
||||||
|
|
||||||
argspath=None
|
argspath=None
|
||||||
if module_style != 'new':
|
if module_style != 'new':
|
||||||
|
|
Loading…
Reference in a new issue