Created
February 24, 2016 20:27
-
-
Save sivel/2e869ec470f7ee53eaf1 to your computer and use it in GitHub Desktop.
diff of changes made to inspect module arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/hacking/test-module b/hacking/test-module | |
index d9f19b7..511be8b 100755 | |
--- a/hacking/test-module | |
+++ b/hacking/test-module | |
@@ -138,8 +138,6 @@ def boilerplate_module(modfile, args, interpreter, check, destfile): | |
) | |
modfile2_path = os.path.expanduser(destfile) | |
- print("* including generated source, if any, saving to: %s" % modfile2_path) | |
- print("* this may offset any line numbers in tracebacks/debuggers!") | |
modfile2 = open(modfile2_path, 'w') | |
modfile2.write(module_data) | |
modfile2.close() | |
@@ -147,7 +145,7 @@ def boilerplate_module(modfile, args, interpreter, check, destfile): | |
return (modfile2_path, module_style) | |
-def runtest( modfile, argspath): | |
+def runtest( modfile, argspath, module): | |
"""Test run a module, piping it's output for reporting.""" | |
os.system("chmod +x %s" % modfile) | |
@@ -159,22 +157,8 @@ def runtest( modfile, argspath): | |
cmd = subprocess.Popen(invoke, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
(out, err) = cmd.communicate() | |
- try: | |
- print("***********************************") | |
- print("RAW OUTPUT") | |
- print(out) | |
- print(err) | |
- results = json.loads(out) | |
- except: | |
- print("***********************************") | |
- print("INVALID OUTPUT FORMAT") | |
- print(out) | |
- traceback.print_exc() | |
- sys.exit(1) | |
- | |
- print("***********************************") | |
- print("PARSED OUTPUT") | |
- print(jsonify(results,format=True)) | |
+ with open('modules/%s' % os.path.basename(module), 'w+') as f: | |
+ f.write(out) | |
def rundebug(debugger, modfile, argspath): | |
"""Run interactively with console debugger.""" | |
@@ -201,7 +185,7 @@ def main(): | |
if options.debugger: | |
rundebug(options.debugger, modfile, argspath) | |
else: | |
- runtest(modfile, argspath) | |
+ runtest(modfile, argspath, options.module_path) | |
if __name__ == "__main__": | |
main() | |
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py | |
index df59144..21fa78f 100644 | |
--- a/lib/ansible/module_utils/basic.py | |
+++ b/lib/ansible/module_utils/basic.py | |
@@ -577,7 +577,7 @@ class AnsibleModule(object): | |
'raw': self._check_type_raw, | |
} | |
if not bypass_checks: | |
- self._check_required_arguments() | |
+ #self._check_required_arguments() | |
self._check_argument_types() | |
self._check_argument_values() | |
self._check_required_together(required_together) | |
@@ -1368,6 +1368,11 @@ class AnsibleModule(object): | |
def _check_argument_types(self): | |
''' ensure all arguments have the requested type ''' | |
for (k, v) in self.argument_spec.items(): | |
+ default = v.get('default') | |
+ if not isinstance(default, basestring): | |
+ print('%s: type=%s' % (k, v.get('type', None))) | |
+ continue | |
+ | |
wanted = v.get('type', None) | |
if k not in self.params: | |
continue | |
@@ -1389,6 +1394,7 @@ class AnsibleModule(object): | |
self.params[k] = type_checker(value) | |
except (TypeError, ValueError): | |
self.fail_json(msg="argument %s is of type %s and we were unable to convert to %s" % (k, type(value), wanted)) | |
+ sys.exit() | |
def _set_defaults(self, pre=True): | |
for (k,v) in self.argument_spec.items(): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment