summaryrefslogtreecommitdiff
path: root/hacking/test-module
Commit message (Collapse)AuthorAgeFilesLines
* Rename python files in hacking/ directory to have .py suffixToshio Kuratomi2019-07-101-274/+1
| | | | | | | | | | | | | ansible-test only passes files which have the .py suffix for sanity tests on python files. This change will allow sanity tests to run on the Python files in hacking/ * Rename test-module to test-module.py * Symlink test-module for backwards compat since end users may be using test-module * Fix test-module sanity errors that are now triggered * Rename ansible_profile to ansible-profile.py * Rename build-ansible
* Make test-module use default value for interpreter (#54053)Karolis Tamutis2019-04-101-1/+2
| | | | | | | | * Make test-module use default value for interpreter * Changing from static interpreter path to sys.executable as per #54053 * A little ntegration test for #54053
* Update bare exceptions to specify Exception.Toshio Kuratomi2018-12-161-1/+1
| | | | | This will keep us from accidentally catching program-exiting exceptions like KeyboardInterupt and SystemExit.
* test-module: define ansible_version attributePierre-Louis Bonicoli2018-10-181-0/+2
| | | | | | | | | | | | | | | | | | | | | Executed command: ./hacking/test-module -m lib/ansible/modules/cloud/scaleway/scaleway_security_group.py -a ... Fix this exception found while testing scaleway_security_group module: Traceback (most recent call last): File "~/debug_dir/__main__.py", line 240, in <module> main() File "~/debug_dir/__main__.py", line 236, in main core(module) File "~/debug_dir/__main__.py", line 209, in core api = Scaleway(module=module) File "~/debug_dir/ansible/module_utils/scaleway.py", line 58, in __init__ 'User-Agent': self.get_user_agent_string(module), File "~/debug_dir/ansible/module_utils/scaleway.py", line 99, in get_user_agent_string return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0]) AttributeError: 'AnsibleModule' object has no attribute 'ansible_version'
* Remove use of simplejson throughout code base (#43548)Matt Martz2018-08-101-4/+1
| | | | | | | | | | * Remove use of simplejson throughout code base. Fixes #42761 * Address failing tests * Remove simplejson from contrib and other outlying files * Add changelog fragment for simplejson removal
* AnsiballZ improvementsToshio Kuratomi2018-07-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now that we don't need to worry about python-2.4 and 2.5, we can make some improvements to the way AnsiballZ handles modules. * Change AnsiballZ wrapper to use import to invoke the module We need the module to think of itself as a script because it could be coded as: main() or as: if __name__ == '__main__': main() Or even as: if __name__ == '__main__': random_function_name() A script will invoke all of those. Prior to this change, we invoked a second Python interpreter on the module so that it really was a script. However, this means that we have to run python twice (once for the AnsiballZ wrapper and once for the module). This change makes the module think that it is a script (because __name__ in the module == '__main__') but it's actually being invoked by us importing the module code. There's three ways we've come up to do this. * The most elegant is to use zipimporter and tell the import mechanism that the module being loaded is __main__: * https://github.com/abadger/ansible/blob/5959f11c9ddb7b6eaa9c3214560bd85e631d4055/lib/ansible/executor/module_common.py#L175 * zipimporter is nice because we do not have to extract the module from the zip file and save it to the disk when we do that. The import machinery does it all for us. * The drawback is that modules do not have a __file__ which points to a real file when they do this. Modules could be using __file__ to for a variety of reasons, most of those probably have replacements (the most common one is to find a writable directory for temporary files. AnsibleModule.tmpdir should be used instead) We can monkeypatch __file__ in fom AnsibleModule initialization but that's kind of gross. There's no way I can see to do this from the wrapper. * Next, there's imp.load_module(): * https://github.com/abadger/ansible/blob/340edf7489/lib/ansible/executor/module_common.py#L151 * imp has the nice property of allowing us to set __name__ to __main__ without changing the name of the file itself * We also don't have to do anything special to set __file__ for backwards compatibility (although the reason for that is the drawback): * Its drawback is that it requires the file to exist on disk so we have to explicitly extract it from the zipfile and save it to a temporary file * The last choice is to use exec to execute the module: * https://github.com/abadger/ansible/blob/f47a4ccc76/lib/ansible/executor/module_common.py#L175 * The code we would have to maintain for this looks pretty clean. In the wrapper we create a ModuleType, set __file__ on it, read the module's contents in from the zip file and then exec it. * Drawbacks: We still have to explicitly extract the file's contents from the zip archive instead of letting python's import mechanism handle it. * Exec also has hidden performance issues and breaks certain assumptions that modules could be making about their own code: http://lucumr.pocoo.org/2011/2/1/exec-in-python/ Our plan is to use imp.load_module() for now, deprecate the use of __file__ in modules, and switch to zipimport once the deprecation period for __file__ is over (without monkeypatching a fake __file__ in via AnsibleModule). * Rename the name of the AnsiBallZ wrapped module This makes it obvious that the wrapped module isn't the module file that we distribute. It's part of trying to mitigate the fact that the module is now named __main)).py in tracebacks. * Shield all wrapper symbols inside of a function With the new import code, all symbols in the wrapper become visible in the module. To mitigate the chance of collisions, move most symbols into a toplevel function. The only symbols left in the global namespace are now _ANSIBALLZ_WRAPPER and _ansiballz_main. revised porting guide entry Integrate code coverage collection into AnsiballZ. ci_coverage ci_complete
* Fix test-module failing to validate args (#41004)Zhikang Zhang2018-06-011-1/+1
| | | | | | | | | | | | * Fix test-module failing to validate args The test-module pass a wrong argument _ansible_tmp cause the validation failed. Change the argument _ansible_tmp to _ansible_tmpdir to fix this. * Add a integration test for test-module. Prior to this change, we don't have a test for test-module. This change ensure the correctness of test-module script.
* Fixes incorrect variable name (#40274)Tim Rupp2018-05-161-1/+1
| | | | | Incorrect variable name was causing a NameError NameError: name 'comlpex_args' is not defined
* create module tmpdir based on remote_tmp (#39833)Jordan Borean2018-05-151-1/+2
| | | | | | | | | | | | | | | | * create module tmpdir based on remote_tmp * Source remote_tmp from controller if possible * Fixed sanity test and not use lambda * Added expansion of env vars to the remote tmp * Fixed sanity issues * Added note around shell remote_tmp option * Changed fallback tmp dir to ~/.ansible/tmp to make shell defaults
* Update test-module (#39331)mwpeterson2018-04-261-0/+1
| | | | Update test-module To use C.DEFAULT_LOCAL_TMP
* module_common: handle None value for templar (#36651)Pilou2018-03-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | * module_common: set required parameter templar Fix the following error (related to b455901): $ ./hacking/test-module -m ./lib/ansible/modules/system/ping.py -I ansible_python_interpreter=/usr/bin/python Traceback (most recent call last): File "./hacking/test-module", line 268, in <module> main() File "./hacking/test-module", line 249, in main (modfile, modname, module_style) = boilerplate_module(options.module_path, options.module_args, interpreters, options.check, options.filename) File "./hacking/test-module", line 152, in boilerplate_module task_vars=task_vars File "ansible/lib/ansible/executor/module_common.py", line 910, in modify_module environment=environment) File "ansible/lib/ansible/executor/module_common.py", line 736, in _find_module_utils shebang, interpreter = _get_shebang(u'/usr/bin/python', task_vars, templar) File "ansible/lib/ansible/executor/module_common.py", line 452, in _get_shebang interpreter = templar.template(task_vars[interpreter_config].strip()) AttributeError: 'NoneType' object has no attribute 'template' * module_common.modify_module: templar is required
* hacking/test-module: fix Python 3 compatibility (#33069)Pilou2017-11-201-2/+2
| | | | | | | | | | | Exception was: Traceback (most recent call last): File "./hacking/test-module", line 268, in <module> main() File "./hacking/test-module", line 249, in main (modfile, modname, module_style) = boilerplate_module(options.module_path, options.module_args, interpreters, options.check, options.filename) File "./hacking/test-module", line 155, in boilerplate_module if module_style == 'new' and 'ANSIBALLZ_WRAPPER = True' in module_data: TypeError: a bytes-like object is required, not 'str'
* bring comments and docs up-to-date for invoking hacking/test-module (#20940)welchwilmerck2017-08-181-5/+4
| | | inside test-module, rundebug also needs to know interpreters
* hacking/test-module: fix for python3 (#26194)Sloane Hertel2017-07-111-1/+4
| | | * make hacking/test-module compatible with python3
* Fix hacking/test-module to allow running modules with pdb (#23339)Michael De La Rue2017-06-281-3/+3
| | | | | | * Fix hacking/test-module to allow running modules with pdb * add emacs autosave files to gitignore
* Include error message when ansiballz_setup fails (#26127)Yujun Zhang2017-06-281-1/+1
| | | It is quite difficult to pinpoint what is wrong without it
* Allows for testing binary modules (#24857)Martyn Ranyard2017-05-221-1/+1
|
* Update test-module (#20737)Allan2017-01-311-2/+1
| | | | | | | | | | | | | | | | | | * Update test-module Ensuring invoke is assigned Traceback (most recent call last): File "ansible/hacking/test-module", line 267, in <module> main() File "ansible/hacking/test-module", line 263, in main runtest(modfile, argspath, modname, module_style, interpreters) File "ansible/hacking/test-module", line 207, in runtest invoke = "%s%s" % (invoke, modfile) UnboundLocalError: local variable 'invoke' referenced before assignment * Update test-module Made the change to only require a single if, making the function more 'DRY'.
* Use the python used with test-module to run modules (#19591)Will Thames2017-01-171-31/+52
| | | | | | | | | | | * Use ansible_python_interpreter to run modules Use ansible_python_interpreter to run modules if `-I ansible_python_interpreter` is set. Remove unused default from `-I` help text. * Update test-module to pep8 standards
* test-module _ansible_selinux_special_fs arg addedAdrian Likins2016-10-231-0/+4
| | | | | modules need to have _ansible_selinux_special_fs passed in as an arg, so add the default to the args.
* Find places where ziploader is used and change them to ansiballz so that ↵Toshio Kuratomi2016-07-211-11/+11
| | | | people aren't confused when they google for information.information (#16715)
* Remove the duplicate modstyle parameterToshio Kuratomi2016-04-271-1/+1
|
* Have test-module clean up the local temp dir when it exitsToshio Kuratomi2016-04-241-12/+44
| | | | Get test-module's debugger switch to do something useful with ziploader modules
* Cleanup. Since we no longer pass a lock, we no longer need to create itToshio Kuratomi2016-04-141-2/+0
|
* We switched away from passing the lock via the arguments to modify_moduleToshio Kuratomi2016-04-131-1/+0
| | | | Need to fix test-module to not pass the lock either
* Controller-side module caching.Toshio Kuratomi2016-04-121-2/+6
| | | | | | | | | This makes our recursive, ast.parse performance measures as fast as pre-ziploader baseline. Since this unittest isn't testing that the returned module data is correct we don't need to worry about os.rename not having any module data. Should devise a separate test for the module and caching code
* Python2.6 fix for test-moduleToshio Kuratomi2016-04-111-1/+1
|
* ZiploaderToshio Kuratomi2016-04-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Ziploader proof of concept (jimi-c) * Cleanups to proof of concept ziploader branch: * python3 compatible base64 encoding * zipfile compression (still need to enable toggling this off for systems without zlib support in python) * Allow non-wildcard imports (still need to make this recusrsive so that we can have module_utils code that imports other module_utils code.) * Better tracebacks: module filename is kept and module_utils directory is kept so that tracebacks show the real filenames that the errors appear in. * Make sure we import modules that are used into the module_utils files that they are used in. * Set ansible version in a more pythonic way for ziploader than we were doing in module replacer * Make it possible to set the module compression as an inventory var This may be necessary on systems where python has been compiled without zlib compression. * Refactoring of module_common code: * module replacer only replaces values that make sense for that type of file (example: don't attempt to replace python imports if we're in a powershell module). * Implement configurable shebang support for ziploader wrapper * Implement client-side constants (for SELINUX_SPECIAL_FS and SYSLOG) via environment variable. * Remove strip_comments param as we're never going to use it (ruins line numbering) * Don't repeat ourselves about detecting REPLACER * Add an easy way to debug * Port test-module to the ziploader-aware modify_module() * strip comments and blank lines from the wrapper so we send less over the wire. * Comments cleanup * Remember to output write the module line itself in powershell modules * for line in lines strips the newlines so we have to add them back in
* Update check mode argumentAlberto Gireud2015-11-081-1/+1
|
* Break apart a looped dependency to show a warning when parsing playbooksToshio Kuratomi2015-10-271-1/+1
| | | | | Display a warning when a dict key is overwritten by pyyaml Fixes #12888
* Change to python3 syntaxKevin Houdebert2015-08-311-16/+16
|
* Port some things in test-module to v2.Toshio Kuratomi2015-07-311-5/+8
| | | | | | In particular, fix arg parsing Fixes #11820
* Fix existing typo, remove trailing space added by PR commitAbhijit Menon-Sen2015-07-221-3/+3
|
* Add options to control output and execution of test-moduleWill Thames2015-07-221-7/+14
| | | | | | | | test-module is useful but sometimes you want to edit the result before running it to e.g. set a debug point. Added a noexecute option (i.e. just create the module script, don't run it) and an output option to choose the filename of the result.
* updated to use new loaderGerard Lynch2015-07-171-3/+5
|
* Merge pull request #11618 from halberom/test-moduleBrian Coca2015-07-161-3/+3
|\ | | | | hacking/test-module, updated to new location and non-classness of module_common
| * updated to new location and non-classness of module_commonGerard Lynch2015-07-161-3/+3
| |
* | Merge pull request #10928 from gimoh/test-module-default-pythonBrian Coca2015-07-161-1/+2
|\ \ | |/ |/| Use same interpreter for test-module and module it runs
| * Use same interpreter for test-module and module it runsgimoh2015-05-061-1/+2
| | | | | | | | | | | | | | Default python interpreter to the same interpreter the test-module script is executed with. This is so that the interpreter doesn't have to be specified twice in the command when using non-default python (e.g. ``/path/to/python ./hacking/test-module -I python=/path/to/python ...``)
* | hacking/test-module: Style nitMarc Abramowitz2015-07-021-1/+1
| |
* | hacking/test-module: Deal with move of parse_kvMarc Abramowitz2015-07-021-1/+2
| |
* | Make test-module work in v2Marc Abramowitz2015-07-021-3/+4
|/ | | | | - `jsonify` moved from `ansible.utils` to `ansible.parsing.utils.jsonify` - I don't see `ansible.utils.parse_json` anymore so I used `json.loads`.
* typofixes - https://github.com/vlajos/misspell_fixerVeres Lajos2014-12-041-2/+2
|
* Add checkmode support for test-module scriptHector Acosta2014-07-201-5/+12
| | | | Signed-off-by: Hector Acosta <hector.acosta@gmail.com>
* Make test-module interpret --args='{...' as yamlFelix Kaiser2014-04-101-0/+4
|
* Support for -a to accept a file with test-moduleMatt Martz2014-02-071-0/+5
| | | | | | If the CLI value for -a starts with an @, treat it like a file, and dump the contents into complex_args This supports yaml or json.
* Add -I/--interpreter argument to test-moduleMatt Martz2013-12-301-2/+15
|
* Undo an inadvertant revert from template changes so we still allow pythonic ↵Michael DeHaan2013-10-311-37/+31
| | | | imports in module land.
* Revert templating enhancements from 73dbab70 e6c28658 d409352c 9858b1f2 ↵James Tanner2013-10-301-30/+35
| | | | 4587528b 9b1fe455 214b0b05 8d3db803 7f9504d1 5031104c 35cb9dc2 2bd8cb57 1e85c754
* Enable imports to work on a snippet based system, allowing for instance a ↵Michael DeHaan2013-10-261-35/+30
| | | | | | | | library of common EC2 functions to be reused between modules. See library/system/service and library/system/ping for initial examples. Can work the old way to just import 'basic', or can import the new way to import multiple pieces of code from module_utils/.