Skip to content

Commit

Permalink
feat: Support for creating volumes without a FS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
japokorn committed Oct 27, 2023
1 parent 71b700b commit dac879a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
17 changes: 12 additions & 5 deletions library/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Check warning on line 151 in library/blivet.py

View check run for this annotation

Codecov / codecov/patch

library/blivet.py#L151

Added line #L151 was not covered by tests

if BLIVET_PACKAGE:
blivet_flags.debug = True
Expand Down Expand Up @@ -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']:

Check warning on line 439 in library/blivet.py

View check run for this annotation

Codecov / codecov/patch

library/blivet.py#L439

Added line #L439 was not covered by tests
# Do not create any fs when user explicitly said so
return None

Check warning on line 441 in library/blivet.py

View check run for this annotation

Codecov / codecov/patch

library/blivet.py#L441

Added line #L441 was not covered by tests

fmt = get_format(self._volume['fs_type'],
mountpoint=self._volume.get('mount_point'),
label=self._volume['fs_label'],
Expand Down Expand Up @@ -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

Check warning on line 568 in library/blivet.py

View check run for this annotation

Codecov / codecov/patch

library/blivet.py#L568

Added line #L568 was not covered by tests
(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:
Expand All @@ -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:

Check warning on line 583 in library/blivet.py

View check run for this annotation

Codecov / codecov/patch

library/blivet.py#L583

Added line #L583 was not covered by tests
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)

Check warning on line 586 in library/blivet.py

View check run for this annotation

Codecov / codecov/patch

library/blivet.py#L585-L586

Added lines #L585 - L586 were not covered by tests

def manage(self):
""" Schedule actions to configure this volume according to the yaml input. """
Expand Down
4 changes: 3 additions & 1 deletion tests/test-verify-volume-fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 7 in tests/test-verify-volume-fs.yml

View workflow job for this annotation

GitHub Actions / ansible_lint

yaml[line-length]

Line too long (86 > 80 characters)
storage_test_volume.fs_type == "None")
when: storage_test_volume.fs_type and _storage_test_volume_present

# label
Expand Down
16 changes: 16 additions & 0 deletions tests/tests_change_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dac879a

Please sign in to comment.