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 "unformatted" value as a fs_type option.
In the same manner it also allows to remove an existing FS. To be able to do that the safe mode has to be off.
  • Loading branch information
japokorn committed Nov 1, 2023
1 parent 71b700b commit a919bd4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ variables:
This indicates the desired file system type to use, e.g.: "xfs", "ext4", "swap".
The default is determined according to the OS and release
(currently `xfs` for all the supported systems).
Use "unformatted" if you do not want file system to be present.

- `fs_label`

Expand Down
15 changes: 11 additions & 4 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 @@ -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() == 'unconfigured':

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)

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
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:
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 storage_test_volume.fs_type == "unconfigured")
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: unconfigured

- 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 a919bd4

Please sign in to comment.