From 31443e57b1d40310e269d7385755666971ea9ba5 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Tue, 24 Nov 2020 10:41:36 +0330 Subject: [PATCH] archive: Fix paramater types (#1039) * archive: Fix ignored sanity test parameter-list-no-elements * Fix wrong argument type * Add changelog * Add integration test for a list of files --- .../1039-archive-fix-paramater-types.yaml | 3 +++ plugins/modules/files/archive.py | 18 +++++---------- .../targets/archive/tasks/main.yml | 23 +++++++++++++++++++ tests/sanity/ignore-2.10.txt | 2 -- tests/sanity/ignore-2.11.txt | 2 -- tests/sanity/ignore-2.9.txt | 1 - 6 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 changelogs/fragments/1039-archive-fix-paramater-types.yaml diff --git a/changelogs/fragments/1039-archive-fix-paramater-types.yaml b/changelogs/fragments/1039-archive-fix-paramater-types.yaml new file mode 100644 index 0000000000..b02315c98f --- /dev/null +++ b/changelogs/fragments/1039-archive-fix-paramater-types.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - archive - fix paramater types (https://github.com/ansible-collections/community.general/pull/1039). diff --git a/plugins/modules/files/archive.py b/plugins/modules/files/archive.py index a7775dda95..e63aa8cef9 100644 --- a/plugins/modules/files/archive.py +++ b/plugins/modules/files/archive.py @@ -23,6 +23,7 @@ options: description: - Remote absolute path, glob, or list of paths or globs for the file or files to compress or archive. type: list + elements: path required: true format: description: @@ -40,6 +41,7 @@ options: description: - Remote absolute path, glob, or list of paths or globs for the file or files to exclude from I(path) list and glob expansion. type: list + elements: path force_archive: description: - Allow you to force the module to treat this as an archive even if only a single file is specified. @@ -187,10 +189,10 @@ else: def main(): module = AnsibleModule( argument_spec=dict( - path=dict(type='list', required=True), + path=dict(type='list', elements='path', required=True), format=dict(type='str', default='gz', choices=['bz2', 'gz', 'tar', 'xz', 'zip']), dest=dict(type='path'), - exclude_path=dict(type='list'), + exclude_path=dict(type='list', elements='path'), force_archive=dict(type='bool', default=False), remove=dict(type='bool', default=False), ), @@ -226,11 +228,7 @@ def main(): module.fail_json(msg="lzma or backports.lzma is required when using xz format.") for path in paths: - b_path = os.path.expanduser( - os.path.expandvars( - to_bytes(path, errors='surrogate_or_strict') - ) - ) + b_path = to_bytes(path, errors='surrogate_or_strict') # Expand any glob characters. If found, add the expanded glob to the # list of expanded_paths, which might be empty. @@ -246,11 +244,7 @@ def main(): # Only attempt to expand the exclude paths if it exists if exclude_paths: for exclude_path in exclude_paths: - b_exclude_path = os.path.expanduser( - os.path.expandvars( - to_bytes(exclude_path, errors='surrogate_or_strict') - ) - ) + b_exclude_path = to_bytes(exclude_path, errors='surrogate_or_strict') # Expand any glob characters. If found, add the expanded glob to the # list of expanded_paths, which might be empty. diff --git a/tests/integration/targets/archive/tasks/main.yml b/tests/integration/targets/archive/tasks/main.yml index 7e9f198bf6..51504e6bf8 100644 --- a/tests/integration/targets/archive/tasks/main.yml +++ b/tests/integration/targets/archive/tasks/main.yml @@ -256,6 +256,29 @@ - name: remove our xz file: path="{{ output_dir }}/archive_02.xz" state=absent +- name: archive multiple files as list + archive: + path: + - "{{ output_dir }}/empty.txt" + - "{{ output_dir }}/foo.txt" + - "{{ output_dir }}/bar.txt" + dest: "{{ output_dir }}/archive_list.gz" + format: gz + register: archive_gz_list_result + +- name: verify that the files archived + file: path={{output_dir}}/archive_list.gz state=file + +- name: check if gz file exists and includes all text files + assert: + that: + - "{{ archive_gz_list_result.changed }}" + - "{{ 'archived' in archive_gz_list_result }}" + - "{{ archive_gz_list_result['archived'] | length }} == 3" + +- name: remove our gz + file: path="{{ output_dir }}/archive_list.gz" state=absent + - name: test that gz archive that contains non-ascii filenames archive: path: "{{ output_dir }}/*.txt" diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 7f5ee77015..614f9f4842 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -312,8 +312,6 @@ plugins/modules/database/vertica/vertica_schema.py validate-modules:doc-missing- plugins/modules/database/vertica/vertica_schema.py validate-modules:undocumented-parameter plugins/modules/database/vertica/vertica_user.py validate-modules:doc-missing-type plugins/modules/database/vertica/vertica_user.py validate-modules:undocumented-parameter -plugins/modules/files/archive.py use-argspec-type-path # fix needed -plugins/modules/files/archive.py validate-modules:parameter-list-no-elements plugins/modules/files/iso_extract.py validate-modules:doc-default-does-not-match-spec plugins/modules/files/xml.py validate-modules:doc-required-mismatch plugins/modules/files/xml.py validate-modules:parameter-list-no-elements diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 7f5ee77015..614f9f4842 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -312,8 +312,6 @@ plugins/modules/database/vertica/vertica_schema.py validate-modules:doc-missing- plugins/modules/database/vertica/vertica_schema.py validate-modules:undocumented-parameter plugins/modules/database/vertica/vertica_user.py validate-modules:doc-missing-type plugins/modules/database/vertica/vertica_user.py validate-modules:undocumented-parameter -plugins/modules/files/archive.py use-argspec-type-path # fix needed -plugins/modules/files/archive.py validate-modules:parameter-list-no-elements plugins/modules/files/iso_extract.py validate-modules:doc-default-does-not-match-spec plugins/modules/files/xml.py validate-modules:doc-required-mismatch plugins/modules/files/xml.py validate-modules:parameter-list-no-elements diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index b91d2e4fce..98780f87eb 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -261,7 +261,6 @@ plugins/modules/database/vertica/vertica_schema.py validate-modules:doc-missing- plugins/modules/database/vertica/vertica_schema.py validate-modules:undocumented-parameter plugins/modules/database/vertica/vertica_user.py validate-modules:doc-missing-type plugins/modules/database/vertica/vertica_user.py validate-modules:undocumented-parameter -plugins/modules/files/archive.py use-argspec-type-path # fix needed plugins/modules/files/iso_extract.py validate-modules:doc-default-does-not-match-spec plugins/modules/identity/keycloak/keycloak_client.py validate-modules:doc-default-does-not-match-spec plugins/modules/identity/keycloak/keycloak_client.py validate-modules:doc-missing-type