From dac879aebb9abfb62e9a49c0c6590c09f06e25f1 Mon Sep 17 00:00:00 2001 From: Jan Pokorny Date: Fri, 27 Oct 2023 14:17:38 +0200 Subject: [PATCH] feat: Support for creating volumes without a FS Currently whenever volume is created without fs_type specification, a filesystem of default type (i.e. xfs) is automatically put on it. This change allows user to prevent FS creation by explicitly using None value as a fs_type option. In the same manner it also allows to remove an existing FS. --- library/blivet.py | 17 ++++++++++++----- tests/test-verify-volume-fs.yml | 4 +++- tests/tests_change_fs.yml | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/library/blivet.py b/library/blivet.py index 6b2b8673..aaa9e8a1 100644 --- a/library/blivet.py +++ b/library/blivet.py @@ -20,7 +20,7 @@ description: - "WARNING: Do not use this module directly! It is only for role internal use." - "Module configures storage pools and volumes to match the state specified - in input parameters. It does not do any management of /etc/fstab entries." + in input parameters." options: pools: @@ -148,7 +148,7 @@ LIB_IMP_ERR = traceback.format_exc() from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.storage_lsr.argument_validator import validate_parameters +from ansible.module_utils.storage_lsr.argument_validator import validate_parameters, BOOLEANS_FALSE if BLIVET_PACKAGE: blivet_flags.debug = True @@ -435,6 +435,11 @@ def _apply_defaults(self): def _get_format(self): """ Return a blivet.formats.DeviceFormat instance for this volume. """ + + if self._volume['fs_type'].lower() in BOOLEANS_FALSE + ['none']: + # Do not create any fs when user explicitly said so + return None + fmt = get_format(self._volume['fs_type'], mountpoint=self._volume.get('mount_point'), label=self._volume['fs_label'], @@ -560,7 +565,8 @@ def _reformat(self): """ Schedule actions as needed to ensure the volume is formatted as specified. """ fmt = self._get_format() - if self._device.format.type == fmt.type: + if ((fmt is None and self._device.format.type is None) or + (fmt is not None and self._device.format.type == fmt.type)): # format is the same, no need to run reformatting dev_label = '' if self._device.format.label is None else self._device.format.label if dev_label != fmt.label: @@ -574,9 +580,10 @@ def _reformat(self): if self._device.format.status and (self._device.format.mountable or self._device.format.type == "swap"): self._device.format.teardown() - if not self._device.isleaf: + if not self._device.isleaf or fmt is None: self._blivet.devicetree.recursive_remove(self._device, remove_device=False) - self._blivet.format_device(self._device, fmt) + if fmt is not None: + self._blivet.format_device(self._device, fmt) def manage(self): """ Schedule actions to configure this volume according to the yaml input. """ diff --git a/tests/test-verify-volume-fs.yml b/tests/test-verify-volume-fs.yml index 5ec6bf9d..3687165c 100644 --- a/tests/test-verify-volume-fs.yml +++ b/tests/test-verify-volume-fs.yml @@ -3,7 +3,9 @@ - name: Verify fs type assert: that: storage_test_blkinfo.info[storage_test_volume._device].fstype == - storage_test_volume.fs_type + storage_test_volume.fs_type or + (storage_test_blkinfo.info[storage_test_volume._device].fstype | length == 0 and + storage_test_volume.fs_type == "None") when: storage_test_volume.fs_type and _storage_test_volume_present # label diff --git a/tests/tests_change_fs.yml b/tests/tests_change_fs.yml index b2aae78f..d22f5338 100644 --- a/tests/tests_change_fs.yml +++ b/tests/tests_change_fs.yml @@ -101,6 +101,22 @@ - name: Verify role results include_tasks: verify-role-results.yml + - name: Remove the FS + include_role: + name: linux-system-roles.storage + vars: + storage_pools: + - name: foo + disks: "{{ unused_disks }}" + volumes: + - name: test1 + size: "{{ volume_size }}" + fs_type: None + + - name: Verify role results + include_tasks: verify-role-results.yml + + - name: Clean up include_role: name: linux-system-roles.storage