mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-25 05:23:58 -07:00 
			
		
		
		
	add _load_params debug overrides for module args/file passed on cmdline
Updated python module wrapper explode method to drop 'args' file next to module. Both execute() and excommunicate() debug methods now pass the module args via file to enable debuggers that are picky about stdin. Updated unit tests to use a context manager for masking/restoring default streams and argv.
This commit is contained in:
		
					parent
					
						
							
								6322ed833e
							
						
					
				
			
			
				commit
				
					
						5b336832af
					
				
			
		
					 10 changed files with 358 additions and 448 deletions
				
			
		|  | @ -25,12 +25,11 @@ import sys | |||
| import time | ||||
| from io import BytesIO, StringIO | ||||
| 
 | ||||
| from ansible.compat.six import PY3 | ||||
| from ansible.utils.unicode import to_bytes | ||||
| 
 | ||||
| from ansible.compat.tests import unittest | ||||
| from ansible.compat.tests.mock import call, MagicMock, Mock, patch, sentinel | ||||
| 
 | ||||
| from units.mock.procenv import swap_stdin_and_argv | ||||
| 
 | ||||
| from ansible.module_utils import basic | ||||
| from ansible.module_utils.basic import AnsibleModule | ||||
| 
 | ||||
|  | @ -46,9 +45,7 @@ class OpenBytesIO(BytesIO): | |||
| 
 | ||||
| @unittest.skipIf(sys.version_info[0] >= 3, "Python 3 is not supported on targets (yet)") | ||||
| class TestAnsibleModuleRunCommand(unittest.TestCase): | ||||
| 
 | ||||
|     def setUp(self): | ||||
| 
 | ||||
|         self.cmd_out = { | ||||
|             # os.read() is returning 'bytes', not strings | ||||
|             sentinel.stdout: BytesIO(), | ||||
|  | @ -66,11 +63,10 @@ class TestAnsibleModuleRunCommand(unittest.TestCase): | |||
|                 raise OSError(errno.EPERM, "Permission denied: '/inaccessible'") | ||||
| 
 | ||||
|         args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={})) | ||||
|         if PY3: | ||||
|             sys.stdin = StringIO(args) | ||||
|             sys.stdin.buffer = BytesIO(to_bytes(args)) | ||||
|         else: | ||||
|             sys.stdin = BytesIO(to_bytes(args)) | ||||
|         # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually | ||||
|         self.stdin_swap = swap_stdin_and_argv(stdin_data=args) | ||||
|         self.stdin_swap.__enter__() | ||||
| 
 | ||||
|         self.module = AnsibleModule(argument_spec=dict()) | ||||
|         self.module.fail_json = MagicMock(side_effect=SystemExit) | ||||
| 
 | ||||
|  | @ -96,6 +92,11 @@ class TestAnsibleModuleRunCommand(unittest.TestCase): | |||
| 
 | ||||
|         self.addCleanup(patch.stopall) | ||||
| 
 | ||||
| 
 | ||||
|     def tearDown(self): | ||||
|         # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually | ||||
|         self.stdin_swap.__exit__(None, None, None) | ||||
| 
 | ||||
|     def test_list_as_args(self): | ||||
|         self.module.run_command(['/bin/ls', 'a', ' b', 'c ']) | ||||
|         self.assertTrue(self.subprocess.Popen.called) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue