mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-30 08:31:28 -07:00
filesystem: revamp module (#2472)
* revamp filesystem module to prepare next steps * pass all commands to module.run_command() as lists * refactor grow() and grow_cmd() to not need to override them so much * refactor all existing get_fs_size() overrides to raise a ValueError if not able to parse command output and return an integer. * override MKFS_FORCE_FLAGS the same way for all fstypes that require it * improve documentation of limitations of the module regarding FreeBSD * fix indentation in DOCUMENTATION * add/update function/method docstrings * fix pylint hints filesystem: refactor integration tests * Include *reiserfs* and *swap* in tests. * Fix reiserfs related code and tests accordingly. * Replace "other fs" (unhandled by this module), from *swap* to *minix* (both mkswap and mkfs.minix being provided by util-linux). * Replace *dd* commands by *filesize* dedicated module. * Use FQCNs and name the tasks. * Update main tests conditionals. * add a changelog fragment * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * declare variables as lists when lists are needed * fix construction without useless conversion Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
d24fc92466
commit
f6db0745fc
9 changed files with 434 additions and 288 deletions
|
@ -1,98 +1,98 @@
|
|||
---
|
||||
# We assume 'create_fs' tests have passed.
|
||||
|
||||
- name: filesystem creation
|
||||
filesystem:
|
||||
- name: "Create filesystem"
|
||||
community.general.filesystem:
|
||||
dev: '{{ dev }}'
|
||||
fstype: '{{ fstype }}'
|
||||
|
||||
- name: get filesystem UUID with 'blkid'
|
||||
command:
|
||||
- name: "Get filesystem UUID with 'blkid'"
|
||||
ansible.builtin.command:
|
||||
cmd: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||
changed_when: false
|
||||
register: blkid_ref
|
||||
|
||||
- name: Assert that a filesystem exists on top of the device
|
||||
assert:
|
||||
- name: "Assert that a filesystem exists on top of the device"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- blkid_ref.stdout | length > 0
|
||||
|
||||
|
||||
# Test check_mode first
|
||||
- name: filesystem removal (check mode)
|
||||
filesystem:
|
||||
- name: "Remove filesystem (check mode)"
|
||||
community.general.filesystem:
|
||||
dev: '{{ dev }}'
|
||||
state: absent
|
||||
register: wipefs
|
||||
check_mode: yes
|
||||
|
||||
- name: get filesystem UUID with 'blkid' (should remain the same)
|
||||
command:
|
||||
- name: "Get filesystem UUID with 'blkid' (should remain the same)"
|
||||
ansible.builtin.command:
|
||||
cmd: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||
changed_when: false
|
||||
register: blkid
|
||||
|
||||
- name: Assert that the state changed but the filesystem still exists
|
||||
assert:
|
||||
- name: "Assert that the state changed but the filesystem still exists"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wipefs is changed
|
||||
- blkid.stdout == blkid_ref.stdout
|
||||
|
||||
# Do it
|
||||
- name: filesystem removal
|
||||
filesystem:
|
||||
- name: "Remove filesystem"
|
||||
community.general.filesystem:
|
||||
dev: '{{ dev }}'
|
||||
state: absent
|
||||
register: wipefs
|
||||
|
||||
- name: get filesystem UUID with 'blkid' (should be empty)
|
||||
command:
|
||||
- name: "Get filesystem UUID with 'blkid' (should be empty)"
|
||||
ansible.builtin.command:
|
||||
cmd: 'blkid -c /dev/null -o value -s UUID {{ dev }}'
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
register: blkid
|
||||
|
||||
- name: Assert that the state changed and the device has no filesystem
|
||||
assert:
|
||||
- name: "Assert that the state changed and the device has no filesystem"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wipefs is changed
|
||||
- blkid.stdout | length == 0
|
||||
- blkid.rc == 2
|
||||
|
||||
# Do it again
|
||||
- name: filesystem removal (idempotency)
|
||||
filesystem:
|
||||
- name: "Remove filesystem (idempotency)"
|
||||
community.general.filesystem:
|
||||
dev: '{{ dev }}'
|
||||
state: absent
|
||||
register: wipefs
|
||||
|
||||
- name: Assert that the state did not change
|
||||
assert:
|
||||
- name: "Assert that the state did not change"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wipefs is not changed
|
||||
|
||||
# and again
|
||||
- name: filesystem removal (idempotency, check mode)
|
||||
filesystem:
|
||||
- name: "Remove filesystem (idempotency, check mode)"
|
||||
community.general.filesystem:
|
||||
dev: '{{ dev }}'
|
||||
state: absent
|
||||
register: wipefs
|
||||
check_mode: yes
|
||||
|
||||
- name: Assert that the state did not change
|
||||
assert:
|
||||
- name: "Assert that the state did not change"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wipefs is not changed
|
||||
|
||||
|
||||
# By the way, test removal of a filesystem on unexistent device
|
||||
- name: filesystem removal (unexistent device)
|
||||
filesystem:
|
||||
- name: "Remove filesystem (unexistent device)"
|
||||
community.general.filesystem:
|
||||
dev: '/dev/unexistent_device'
|
||||
state: absent
|
||||
register: wipefs
|
||||
|
||||
- name: Assert that the state did not change
|
||||
assert:
|
||||
- name: "Assert that the state did not change"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wipefs is not changed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue