community.general/tests/integration/targets/decompress/tasks/misc.yml

75 lines
2.0 KiB
YAML
Raw Normal View History

Add decompress module (#9175) * adds simple implementation of `decompress` module * adds simple test, fixes src and dest arg types * minor refactoring * adds support for common file operations adds integration test for gz decompressing * makes tests parametrized to test all supported compression formats * checks that target file exists * writes to decompressed file now uses atomic_move * adds idempotency for decompression * refactoring, removed classes * adds support for check mode * adds check for destination file. If it exists and it is a directory, the module returns error * refactoring, moves code to a class. Also, simplifies tests (now only tests related to the module core functionality run as parametrized, tests for idempotency and check mode run only for one format) * adds 'remove' parameter that deletes original compressed file after decompression * adds documentation * fixes bug with 'remove' parameter in check mode * makes dest argument not required. Dest filename now can be produced from the src filename * adds dest to output * updates the documentation, adds "RETURN" block * fixes test * adds support for python2 * removes some of the test files that can be generated during testing. Adds copyright header to test files * adds maintainer * apply minor suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * fixes code review comments (idempotency issue with non existing src, existing dest and remove=true; fixes the issue and adds test) * refactors the module to use ModuleHelper * refactors lzma dependency manual check to use 'deps.validate' * minor fix * removes registered handlers check * minor refactoring * adds aliases * changes setup for tests * tests: ignores macos and fixes tests for FreeBSD * tests: reverts ignore for macos and fixes issue with centos7 * tests: adds liblzma dependency for python2 * tests: adds backports.lzma * fixes bz2 decompression for python2 * tests: install xz for osx * tests: install xz for osx (2) * fixes code review comments --------- Co-authored-by: Felix Fontein <felix@fontein.de>
2024-12-02 19:16:00 +00:00
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Decompress with check mode enabled
decompress:
src: "{{ remote_tmp_dir }}/file.txt.gz"
dest: "{{ remote_tmp_dir }}/file_from_gz.txt"
format: gz
check_mode: true
register: decompressed_check_mode
- name: Decompress second time with check mode enabled
decompress:
src: "{{ remote_tmp_dir }}/file.txt.gz"
dest: "{{ remote_tmp_dir }}/file_from_gz.txt"
format: gz
remove: true
check_mode: true
register: decompressed_check_mode_2
- name: Stat original compressed file
stat:
path: "{{ remote_tmp_dir }}/file.txt.gz"
register: original_file
- name: Stat non-existing file
stat:
path: "{{ remote_tmp_dir }}/file_from_gz.txt"
register: nonexisting_stat
- name: Check mode test
assert:
that:
- decompressed_check_mode.changed
- decompressed_check_mode_2.changed
- original_file.stat.exists
- not nonexisting_stat.stat.exists
- name: Copy compressed file
copy:
src: "{{ remote_tmp_dir }}/file.txt.gz"
dest: "{{ remote_tmp_dir }}/file_copied.txt.gz"
remote_src: true
- name: Decompress, deleting original file
decompress:
src: "{{ remote_tmp_dir }}/file_copied.txt.gz"
dest: "{{ remote_tmp_dir }}/file_copied.txt"
remove: true
- name: Decompress non existing src
decompress:
src: "{{ remote_tmp_dir }}/file_copied.txt.gz"
dest: "{{ remote_tmp_dir }}/file_copied.txt"
remove: true
register: decompress_non_existing_src
- name: Stat compressed file
stat:
path: "{{ remote_tmp_dir }}/file_copied.txt.gz"
register: compressed_stat
- name: Run tests
assert:
that:
- not compressed_stat.stat.exists
- not decompress_non_existing_src.changed
- name: Delete decompressed file
file:
path: "{{ remote_tmp_dir }}/file_copied.txt"
state: absent