Merge pull request #11449 from msabramo/make_test-module_work_in_v2

Make test module work in v2
This commit is contained in:
Brian Coca 2015-07-03 22:58:13 -04:00
commit 9de6471867

View file

@ -35,6 +35,8 @@ import subprocess
import traceback import traceback
import optparse import optparse
import ansible.utils as utils import ansible.utils as utils
from ansible.parsing.utils.jsonify import jsonify
from ansible.parsing.splitter import parse_kv
import ansible.module_common as module_common import ansible.module_common as module_common
import ansible.constants as C import ansible.constants as C
@ -74,8 +76,8 @@ def write_argsfile(argstring, json=False):
argspath = os.path.expanduser("~/.ansible_test_module_arguments") argspath = os.path.expanduser("~/.ansible_test_module_arguments")
argsfile = open(argspath, 'w') argsfile = open(argspath, 'w')
if json: if json:
args = utils.parse_kv(argstring) args = parse_kv(argstring)
argstring = utils.jsonify(args) argstring = jsonify(args)
argsfile.write(argstring) argsfile.write(argstring)
argsfile.close() argsfile.close()
return argspath return argspath
@ -150,7 +152,7 @@ def runtest( modfile, argspath):
print "RAW OUTPUT" print "RAW OUTPUT"
print out print out
print err print err
results = utils.parse_json(out) results = json.loads(out)
except: except:
print "***********************************" print "***********************************"
print "INVALID OUTPUT FORMAT" print "INVALID OUTPUT FORMAT"
@ -160,7 +162,7 @@ def runtest( modfile, argspath):
print "***********************************" print "***********************************"
print "PARSED OUTPUT" print "PARSED OUTPUT"
print utils.jsonify(results,format=True) print jsonify(results,format=True)
def rundebug(debugger, modfile, argspath): def rundebug(debugger, modfile, argspath):
"""Run interactively with console debugger.""" """Run interactively with console debugger."""
@ -175,7 +177,7 @@ def main():
options, args = parse() options, args = parse()
(modfile, module_style) = boilerplate_module(options.module_path, options.module_args, options.interpreter, options.check) (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':
if module_style == 'non_native_want_json': if module_style == 'non_native_want_json':
argspath = write_argsfile(options.module_args, json=True) argspath = write_argsfile(options.module_args, json=True)