From 9dbedb6d4c160d5c0c8122de1e372492756908c8 Mon Sep 17 00:00:00 2001 From: mandar Date: Tue, 13 Jul 2021 18:08:26 -0400 Subject: [PATCH] Adding tests, corrections --- .../220_synchronize_add_quiet_option.yml | 2 +- plugins/modules/synchronize.py | 4 +- .../targets/synchronize/tasks/main.yml | 56 ++++++++----------- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/changelogs/fragments/220_synchronize_add_quiet_option.yml b/changelogs/fragments/220_synchronize_add_quiet_option.yml index a9a7cb1..e64a50c 100644 --- a/changelogs/fragments/220_synchronize_add_quiet_option.yml +++ b/changelogs/fragments/220_synchronize_add_quiet_option.yml @@ -1,2 +1,2 @@ minor_changes: -- synchronize - add the ``quiet`` option to supress non-error messages (https://github.com/ansible-collections/ansible.posix/issues/171). +- synchronize - add the ``quiet`` option to suppress non-error messages (https://github.com/ansible-collections/ansible.posix/issues/171). diff --git a/plugins/modules/synchronize.py b/plugins/modules/synchronize.py index 2907fa2..b0fee74 100644 --- a/plugins/modules/synchronize.py +++ b/plugins/modules/synchronize.py @@ -431,7 +431,7 @@ def main(): delay_updates=dict(type='bool', default=True), mode=dict(type='str', default='push', choices=['pull', 'push']), link_dest=dict(type='list', elements='str'), - quiet=dict(type='bool',default=False) + quiet=dict(type='bool', default=False) ), supports_check_mode=True, ) @@ -604,7 +604,7 @@ def main(): cmd.append(shlex_quote(source)) cmd.append(shlex_quote(dest)) if quiet: - cmd.append('--quiet') + cmd.append('--quiet') cmdstr = ' '.join(cmd) diff --git a/tests/integration/targets/synchronize/tasks/main.yml b/tests/integration/targets/synchronize/tasks/main.yml index 125a406..0fe2a3b 100644 --- a/tests/integration/targets/synchronize/tasks/main.yml +++ b/tests/integration/targets/synchronize/tasks/main.yml @@ -265,46 +265,36 @@ - directory_a/foo.txt - directory_a - directory_b - -- name: setup - test for source with working dir with spaces in path - file: - state: directory - path: '{{output_dir}}/{{item}}' - delegate_to: '{{ inventory_hostname }}' - with_items: - - 'directory a' - - 'directory b' -- name: setup - create test new files - copy: - dest: '{{output_dir}}/directory a/{{item}}' - mode: '0644' - content: 'hello world' - with_items: - - foo.txt - delegate_to: '{{ inventory_hostname }}' -- name: copy source with spaces in dir path +- name: synchronize files with quiet option synchronize: - src: '{{output_dir}}/directory a/foo.txt' - dest: '{{output_dir}}/directory b/' - delegate_to: '{{ inventory_hostname }}' + src: '{{output_dir}}/foo.txt' + dest: '{{output_dir}}/foo.result' + quiet: true register: sync_result ignore_errors: true -- name: get stat information for directory_b - stat: - path: '{{ output_dir }}/directory b/foo.txt' - register: stat_result_b - assert: that: - - '''changed'' in sync_result' - - sync_result.changed == true - - stat_result_b.stat.exists == True - - stat_result_b.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' + - '''--quiet'' in sync_result.cmd' - name: Cleanup file: state: absent path: '{{output_dir}}/{{item}}' with_items: - - 'directory b/foo.txt' - - 'directory a/foo.txt' - - 'directory a' - - 'directory b' + - foo.result + - bar.result +- name: synchronize files without quiet option + synchronize: + src: '{{output_dir}}/foo.txt' + dest: '{{output_dir}}/foo.result' + register: sync_result + ignore_errors: true +- assert: + that: + - '''--quiet'' not in sync_result.cmd' +- name: Cleanup + file: + state: absent + path: '{{output_dir}}/{{item}}' + with_items: + - foo.result + - bar.result