1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Amin Vakil 2020-11-24 10:41:36 +03:30 committed by GitHub
parent 28ac4b79e2
commit 31443e57b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 17 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- archive - fix paramater types (https://github.com/ansible-collections/community.general/pull/1039).

View file

@ -23,6 +23,7 @@ options:
description: description:
- Remote absolute path, glob, or list of paths or globs for the file or files to compress or archive. - Remote absolute path, glob, or list of paths or globs for the file or files to compress or archive.
type: list type: list
elements: path
required: true required: true
format: format:
description: description:
@ -40,6 +41,7 @@ options:
description: 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. - 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 type: list
elements: path
force_archive: force_archive:
description: description:
- Allow you to force the module to treat this as an archive even if only a single file is specified. - 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(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( 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']), format=dict(type='str', default='gz', choices=['bz2', 'gz', 'tar', 'xz', 'zip']),
dest=dict(type='path'), dest=dict(type='path'),
exclude_path=dict(type='list'), exclude_path=dict(type='list', elements='path'),
force_archive=dict(type='bool', default=False), force_archive=dict(type='bool', default=False),
remove=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.") module.fail_json(msg="lzma or backports.lzma is required when using xz format.")
for path in paths: for path in paths:
b_path = os.path.expanduser( b_path = to_bytes(path, errors='surrogate_or_strict')
os.path.expandvars(
to_bytes(path, errors='surrogate_or_strict')
)
)
# Expand any glob characters. If found, add the expanded glob to the # Expand any glob characters. If found, add the expanded glob to the
# list of expanded_paths, which might be empty. # list of expanded_paths, which might be empty.
@ -246,11 +244,7 @@ def main():
# Only attempt to expand the exclude paths if it exists # Only attempt to expand the exclude paths if it exists
if exclude_paths: if exclude_paths:
for exclude_path in exclude_paths: for exclude_path in exclude_paths:
b_exclude_path = os.path.expanduser( b_exclude_path = to_bytes(exclude_path, errors='surrogate_or_strict')
os.path.expandvars(
to_bytes(exclude_path, errors='surrogate_or_strict')
)
)
# Expand any glob characters. If found, add the expanded glob to the # Expand any glob characters. If found, add the expanded glob to the
# list of expanded_paths, which might be empty. # list of expanded_paths, which might be empty.

View file

@ -256,6 +256,29 @@
- name: remove our xz - name: remove our xz
file: path="{{ output_dir }}/archive_02.xz" state=absent 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 - name: test that gz archive that contains non-ascii filenames
archive: archive:
path: "{{ output_dir }}/*.txt" path: "{{ output_dir }}/*.txt"

View file

@ -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_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:doc-missing-type
plugins/modules/database/vertica/vertica_user.py validate-modules:undocumented-parameter 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/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:doc-required-mismatch
plugins/modules/files/xml.py validate-modules:parameter-list-no-elements plugins/modules/files/xml.py validate-modules:parameter-list-no-elements

View file

@ -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_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:doc-missing-type
plugins/modules/database/vertica/vertica_user.py validate-modules:undocumented-parameter 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/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:doc-required-mismatch
plugins/modules/files/xml.py validate-modules:parameter-list-no-elements plugins/modules/files/xml.py validate-modules:parameter-list-no-elements

View file

@ -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_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:doc-missing-type
plugins/modules/database/vertica/vertica_user.py validate-modules:undocumented-parameter 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/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-default-does-not-match-spec
plugins/modules/identity/keycloak/keycloak_client.py validate-modules:doc-missing-type plugins/modules/identity/keycloak/keycloak_client.py validate-modules:doc-missing-type