Skip to content

Commit

Permalink
add support for mount_options (#270)
Browse files Browse the repository at this point in the history
* add support for mount_options

When support for argument validation was added, that support did not
include the `mount_options` parameter.  This fix adds back that
parameter.  In addition, the volume module arguments are refactored
so that the common volume parameters such as `mount_options` can be
specified in one place.

This adds a test for the `mount_options` parameter, and adds
verification for that parameter.

* only checkout mount_options if requested
  • Loading branch information
richm authored May 16, 2022
1 parent d891f26 commit ecf3d04
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
78 changes: 36 additions & 42 deletions library/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
elements: dict
'''

import copy
import logging
import os
import traceback
Expand Down Expand Up @@ -1500,6 +1501,39 @@ def activate_swaps(b, pools, volumes):

def run_module():
# available arguments/parameters that a user can pass
common_volume_opts = dict(encryption=dict(type='bool'),
encryption_cipher=dict(type='str'),
encryption_key=dict(type='str'),
encryption_key_size=dict(type='int'),
encryption_luks_version=dict(type='str'),
encryption_password=dict(type='str'),
fs_create_options=dict(type='str'),
fs_label=dict(type='str', default=''),
fs_type=dict(type='str'),
mount_options=dict(type='str'),
mount_point=dict(type='str'),
name=dict(type='str'),
raid_level=dict(type='str'),
size=dict(type='str'),
state=dict(type='str', default='present', choices=['present', 'absent']),
type=dict(type='str'))
volume_opts = copy.deepcopy(common_volume_opts)
volume_opts.update(
dict(disks=dict(type='list'),
raid_device_count=dict(type='int'),
raid_spare_count=dict(type='int'),
raid_metadata_version=dict(type='str')))
pool_volume_opts = copy.deepcopy(common_volume_opts)
pool_volume_opts.update(
dict(cached=dict(type='bool'),
cache_devices=dict(type='list', elements='str', default=list()),
cache_mode=dict(type='str'),
cache_size=dict(type='str'),
compression=dict(type='bool'),
deduplication=dict(type='bool'),
raid_disks=dict(type='list', elements='str', default=list()),
vdo_pool_size=dict(type='str')))

module_args = dict(
pools=dict(type='list', elements='dict',
options=dict(disks=dict(type='list', elements='str', default=list()),
Expand All @@ -1517,49 +1551,9 @@ def run_module():
state=dict(type='str', default='present', choices=['present', 'absent']),
type=dict(type='str'),
volumes=dict(type='list', elements='dict', default=list(),
options=dict(cached=dict(type='bool'),
cache_devices=dict(type='list', elements='str', default=list()),
cache_mode=dict(type='str'),
cache_size=dict(type='str'),
compression=dict(type='bool'),
deduplication=dict(type='bool'),
encryption=dict(type='bool'),
encryption_cipher=dict(type='str'),
encryption_key=dict(type='str'),
encryption_key_size=dict(type='int'),
encryption_luks_version=dict(type='str'),
encryption_password=dict(type='str'),
fs_create_options=dict(type='str'),
fs_label=dict(type='str', default=''),
fs_type=dict(type='str'),
mount_point=dict(type='str'),
name=dict(type='str'),
raid_disks=dict(type='list', elements='str', default=list()),
raid_level=dict(type='str'),
size=dict(type='str'),
state=dict(type='str', default='present', choices=['present', 'absent']),
type=dict(type='str'),
vdo_pool_size=dict(type='str'))))),
options=pool_volume_opts))),
volumes=dict(type='list', elements='dict',
options=dict(disks=dict(type='list'),
encryption=dict(type='bool'),
encryption_cipher=dict(type='str'),
encryption_key=dict(type='str'),
encryption_key_size=dict(type='int'),
encryption_luks_version=dict(type='str'),
encryption_password=dict(type='str'),
fs_create_options=dict(type='str'),
fs_label=dict(type='str', default=''),
fs_type=dict(type='str'),
mount_point=dict(type='str'),
name=dict(type='str'),
raid_level=dict(type='str'),
raid_device_count=dict(type='int'),
raid_spare_count=dict(type='int'),
raid_metadata_version=dict(type='str'),
size=dict(type='str'),
state=dict(type='str', default='present', choices=['present', 'absent']),
type=dict(type='str'))),
options=volume_opts),
packages_only=dict(type='bool', required=False, default=False),
disklabel_type=dict(type='str', required=False, default=None),
safe_mode=dict(type='bool', required=False, default=True),
Expand Down
22 changes: 21 additions & 1 deletion tests/test-verify-volume-fstab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
storage_test_fstab_expected_mount_point_matches: "{{ 1
if (_storage_test_volume_present and storage_test_volume.mount_point and storage_test_volume.mount_point.startswith('/'))
else 0 }}"
storage_test_fstab_mount_options_matches: "{{ storage_test_fstab.stdout_lines |
map('regex_search', ' ' + storage_test_volume.mount_point + ' .* ' + storage_test_volume.mount_options + ' +') |
select('string')|list if (
storage_test_volume.mount_options|d('none',true) != 'none'
and storage_test_volume.mount_point|d('none',true) != 'none'
) else [] }}"
storage_test_fstab_expected_mount_options_matches: "{{ 1
if (_storage_test_volume_present and storage_test_volume.mount_options)
else 0 }}"

# device id
- name: Verify that the device identifier appears in /etc/fstab
Expand All @@ -26,11 +35,22 @@
msg: "Expected number ({{ storage_test_fstab_expected_mount_point_matches }}) of
entries with volume '{{ storage_test_volume.name }}' mount point not found in /etc/fstab."

# todo: options
# mount options
- name: Verify mount_options
assert:
that: storage_test_fstab_mount_options_matches|length == storage_test_fstab_expected_mount_options_matches|int
msg: "Expected number ({{ storage_test_fstab_expected_mount_options_matches }}) of
entries with volume '{{ storage_test_volume.name }}' mount options not found in /etc/fstab."
when:
- __storage_verify_mount_options | d(false)
- "'mount_options' in storage_test_volume"
- "'mount_point' in storage_test_volume"

- name: Clean up variables
set_fact:
storage_test_fstab_id_matches: null
storage_test_fstab_mount_point_matches: null
storage_test_fstab_expected_id_matches: null
storage_test_fstab_expected_mount_point_matches: null
storage_test_fstab_mount_options_matches: null
storage_test_fstab_expected_mount_options_matches: null
3 changes: 3 additions & 0 deletions tests/tests_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@
fs_type: 'ext4'
fs_create_options: '-F'
mount_point: "{{ mount_location }}"
mount_options: rw,noatime,defaults

- include_tasks: verify-role-results.yml
vars:
__storage_verify_mount_options: true

- name: Remove the disk volume created above
include_role:
Expand Down

0 comments on commit ecf3d04

Please sign in to comment.