1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/btrfs_subvolume/tasks/test_filesystem_matching.yml
Gregory Furlong ae5090d90e
New modules btrfs_subvolume / btrfs_info (#5832)
* Initial implementation for new modules btrfs_subvolume and btrfs_info

* Improve/flesh out documentation. Add ability to target filesystem by uuid, label or device. Update tests to test targeting filesystem by each supported parameter and when only mountpoint.

* Updates for btrfs modules. Add missing copyright notices. Switch options to contains in return documentation. Update btrfs_subvolume to always use closest parent mount.

* Add maintainers for btrfs module(s) and remove unused class member cause lint failure.

* Add changelog fragment. Attempt to only run against the VMs as part of CI.

* Updates per code review. Remove changelog fragment. Switch use of map to list comprehension. Add trailing comma to last item in multi-line dicts. Clean up documentation with complete senstences for descriptions and correct/consistent use of macros.

* Improved error handling in btrfs_subvolume module: add custom exception type, favor exceptions over immediate call to fail_json and add single top level return for failure scenarios. Normalize name and snapshot_source parameters early in module execution and remove unecessary duplicate normalization throughout processing.

* Add azp/posix/3 to aliases per feedback

* Clean up automatic mounting. Prevent automount when check_mode=True. Immediately fail if a mount is identified as required and automount=True. Identify the minimal subset of subvolumes that need to be mounted instead of just finding a single common root.

* Skip btrfs_subvolume integration tests if btrfs-progs isn't successfully installed.

* Bump version_added for btrfs modules to 6.6.0. Ensure consistent trailing punctuation for module descriptions and document check_mode behavior as attribute description rather than a module level note.

* Remove unused imports from btrfs_subvolume module.

* Fix import.

* Docs improvements.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
2023-04-20 06:35:29 +02:00

80 lines
2.6 KiB
YAML

---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Match targeted filesystem by label"
block:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem by label
community.general.btrfs_subvolume:
automount: Yes
name: "/match_label"
filesystem_label: "{{ btrfs_subvolume_target_label }}"
state: "present"
register: result
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
- name: "Match targeted filesystem by uuid"
block:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem by uuid
community.general.btrfs_subvolume:
automount: Yes
name: "/match_uuid"
filesystem_uuid: "{{ result.filesystem.uuid }}"
state: "present"
register: result
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
- name: "Match targeted filesystem by devices"
block:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem by device
community.general.btrfs_subvolume:
automount: Yes
name: "/match_device"
filesystem_device: "{{ result.filesystem.devices | first }}"
state: "present"
register: result
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
- name: "Match only mounted filesystem"
block:
- name: "Mount filesystem '{{ btrfs_subvolume_target_label }}'"
ansible.posix.mount:
src: "{{ result.filesystem.devices | first }}"
path: /mnt
opts: "subvolid={{ 5 }}"
fstype: btrfs
state: mounted
- name: Print current status
community.general.btrfs_info:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem when only mount
community.general.btrfs_subvolume:
automount: Yes
name: "/match_only_mounted"
state: "present"
register: result
- name: "Unmount filesystem '{{ btrfs_subvolume_target_label }}'"
ansible.posix.mount:
path: /mnt
state: absent
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
when: False # TODO don't attempt this if the host already has a pre-existing btrfs filesystem