mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Command module bug fix, tests and cleanup. (#30432)
* Add more command integration tests. * Remove unnecessary command test debug tasks. * Fix traceback in command module for empty args. * Remove unreachable code.
This commit is contained in:
parent
f128796782
commit
4ce13e983a
2 changed files with 64 additions and 10 deletions
|
@ -144,7 +144,7 @@ def main():
|
||||||
module.warn("As of Ansible 2.4, the parameter 'executable' is no longer supported with the 'command' module. Not using '%s'." % executable)
|
module.warn("As of Ansible 2.4, the parameter 'executable' is no longer supported with the 'command' module. Not using '%s'." % executable)
|
||||||
executable = None
|
executable = None
|
||||||
|
|
||||||
if args.strip() == '':
|
if not args or args.strip() == '':
|
||||||
module.fail_json(rc=256, msg="no command given")
|
module.fail_json(rc=256, msg="no command given")
|
||||||
|
|
||||||
if chdir:
|
if chdir:
|
||||||
|
@ -187,11 +187,6 @@ def main():
|
||||||
endd = datetime.datetime.now()
|
endd = datetime.datetime.now()
|
||||||
delta = endd - startd
|
delta = endd - startd
|
||||||
|
|
||||||
if out is None:
|
|
||||||
out = b''
|
|
||||||
if err is None:
|
|
||||||
err = b''
|
|
||||||
|
|
||||||
result = dict(
|
result = dict(
|
||||||
cmd=args,
|
cmd=args,
|
||||||
stdout=out.rstrip(b"\r\n"),
|
stdout=out.rstrip(b"\r\n"),
|
||||||
|
|
|
@ -16,6 +16,69 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
- name: use command to execute sudo
|
||||||
|
command: sudo -h
|
||||||
|
register: become
|
||||||
|
|
||||||
|
- name: assert become warning was reported
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "become.warnings | length() == 1"
|
||||||
|
- "'Consider using' in become.warnings[0]"
|
||||||
|
|
||||||
|
- name: use command to execute sudo without warnings
|
||||||
|
command: sudo -h warn=no
|
||||||
|
register: become
|
||||||
|
|
||||||
|
- name: assert become warning was not reported
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "'warnings' not in become"
|
||||||
|
|
||||||
|
- name: use command to execute tar
|
||||||
|
command: tar --help
|
||||||
|
register: tar
|
||||||
|
|
||||||
|
- name: assert tar warning was reported
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "tar.warnings | length() == 1"
|
||||||
|
- "'Consider using unarchive module rather than running tar' in tar.warnings[0]"
|
||||||
|
|
||||||
|
- name: use command to execute chown
|
||||||
|
command: chown -h
|
||||||
|
register: chown
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: assert chown warning was reported
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "chown.warnings | length() == 1"
|
||||||
|
- "'Consider using file module with owner rather than running chown' in chown.warnings[0]"
|
||||||
|
|
||||||
|
- name: use command with unsupported executable arg
|
||||||
|
command: ls /dev/null executable=/bogus
|
||||||
|
register: executable
|
||||||
|
|
||||||
|
- name: assert executable warning was reported
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "executable.stdout == '/dev/null'"
|
||||||
|
- "executable.warnings | length() == 1"
|
||||||
|
- "'no longer supported' in executable.warnings[0]"
|
||||||
|
|
||||||
|
- name: use command with no command
|
||||||
|
command: chdir=/
|
||||||
|
register: no_command
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: assert executable fails with no command
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "no_command.failed == true"
|
||||||
|
- "no_command.msg == 'no command given'"
|
||||||
|
- "no_command.rc == 256"
|
||||||
|
|
||||||
- set_fact: output_dir_test={{output_dir}}/test_command_shell
|
- set_fact: output_dir_test={{output_dir}}/test_command_shell
|
||||||
|
|
||||||
- name: make sure our testing sub-directory does not exist
|
- name: make sure our testing sub-directory does not exist
|
||||||
|
@ -143,8 +206,6 @@
|
||||||
this line is the last line
|
this line is the last line
|
||||||
register: command_result6
|
register: command_result6
|
||||||
|
|
||||||
- debug: var=command_result6
|
|
||||||
|
|
||||||
- name: assert the multiline input was passed correctly
|
- name: assert the multiline input was passed correctly
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -223,8 +284,6 @@
|
||||||
echo "this is a second line"
|
echo "this is a second line"
|
||||||
register: shell_result5
|
register: shell_result5
|
||||||
|
|
||||||
- debug: var=shell_result5
|
|
||||||
|
|
||||||
- name: assert the multiline shell command ran as expected
|
- name: assert the multiline shell command ran as expected
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
|
Loading…
Reference in a new issue