From 8f13c402f24914694ff5c567740c1e88254e7cb9 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Thu, 14 Dec 2023 17:21:54 -0700 Subject: [PATCH] ci: Use supported ansible-lint action; run ansible-lint against the collection The old ansible-community ansible-lint is deprecated. There is a new ansible-lint github action. The new ansible-lint has several checks related to ansible-test and the ignore files. Many of our ignore settings are not allowed any more and are required to be fixed or addressed in the Ansible preferred way. The python imports have to be wrapped in a try/except ImportError, and where possible, an error must be returned from the module explaining what was not able to be imported. The module documentation must comply with the Ansible standards. One aspect of this is the `version_added` must be a valid ansible-core version in X.Y.Z format. Note that this version isn't really used anywhere, so it doesn't matter for users of the role, it is purely an `ansible-test` and import gating issue. I created a function `generate_module_doc` which will generate the DOCUMENTATION options section from the Ansible module_args, if necessary. Hopefully it won't be necessary going forward. I fought a losing battle with flake8, pep8, etc. in ansible-test to try to preserve the formatting in size.py - future developers are welcome to try. The result of this is that the .sanity files can be reduced to the bare minimum which will greatly reduce the maintenance burden of those files, make it easier to support newer versions of Ansible, and make it easier to import the system roles collection into Galaxy and Automation Hub. The latest Ansible repo gating tests run ansible-lint against the collection format instead of against individual roles. We have to convert the role to collection format before running ansible-test. Role developers can run this locally using `tox -e collection,ansible-lint-collection` See https://github.com/linux-system-roles/tox-lsr/pull/125 Add `---` doc start to .markdownlint.yaml Fixed some other linter errors in some tests files. Signed-off-by: Rich Megginson --- .markdownlint.yaml | 1 + .sanity-ansible-ignore-2.10.txt | 20 -- .sanity-ansible-ignore-2.11.txt | 21 -- .sanity-ansible-ignore-2.12.txt | 36 --- .sanity-ansible-ignore-2.13.txt | 36 --- .sanity-ansible-ignore-2.14.txt | 33 --- .sanity-ansible-ignore-2.15.txt | 33 --- .sanity-ansible-ignore-2.16.txt | 7 + .sanity-ansible-ignore-2.9.txt | 13 -- library/blivet.py | 366 +++++++++++++++++++++++++++--- library/blockdev_info.py | 3 +- library/bsize.py | 2 +- library/find_unused_disk.py | 12 +- library/lvm_gensym.py | 2 +- library/resolve_blockdev.py | 2 +- module_utils/storage_lsr/size.py | 84 +++---- tasks/main-blivet.yml | 4 + tests/roles/caller/tasks/main.yml | 6 +- tests/scripts/generate_tests.py | 6 +- tests/scripts/post-commit | 2 +- tests/scripts/pre-commit | 2 +- 21 files changed, 413 insertions(+), 278 deletions(-) create mode 100644 .sanity-ansible-ignore-2.16.txt diff --git a/.markdownlint.yaml b/.markdownlint.yaml index 4f8a9799..6bf4ccd9 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -1,3 +1,4 @@ +--- # Default state for all rules default: true diff --git a/.sanity-ansible-ignore-2.10.txt b/.sanity-ansible-ignore-2.10.txt index b791db6d..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.10.txt +++ b/.sanity-ansible-ignore-2.10.txt @@ -1,27 +1,7 @@ -plugins/modules/blivet.py import-2.6!skip -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py import-3.9!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license -plugins/modules/blivet.py validate-modules:module-invalid-version-added plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license -plugins/modules/blockdev_info.py validate-modules:module-invalid-version-added plugins/modules/bsize.py validate-modules:missing-gplv3-license -plugins/modules/bsize.py validate-modules:module-invalid-version-added plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license -plugins/modules/find_unused_disk.py validate-modules:return-syntax-error plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license -plugins/modules/lvm_gensym.py validate-modules:module-invalid-version-added plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/modules/resolve_blockdev.py validate-modules:module-invalid-version-added -plugins/module_utils/storage_lsr/argument_validator.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -tests/storage/scripts/generate_tests.py metaclass-boilerplate!skip -tests/storage/scripts/generate_tests.py future-import-boilerplate!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/.sanity-ansible-ignore-2.11.txt b/.sanity-ansible-ignore-2.11.txt index 0ea9c17d..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.11.txt +++ b/.sanity-ansible-ignore-2.11.txt @@ -1,28 +1,7 @@ -plugins/modules/blivet.py import-2.6!skip -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py import-3.9!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license -plugins/modules/blivet.py validate-modules:module-invalid-version-added plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license -plugins/modules/blockdev_info.py validate-modules:module-invalid-version-added plugins/modules/bsize.py validate-modules:missing-gplv3-license -plugins/modules/bsize.py validate-modules:module-invalid-version-added plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license -plugins/modules/find_unused_disk.py validate-modules:return-syntax-error plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license -plugins/modules/lvm_gensym.py validate-modules:module-invalid-version-added plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/modules/resolve_blockdev.py validate-modules:module-invalid-version-added -plugins/module_utils/storage_lsr/argument_validator.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -plugins/module_utils/storage_lsr/size.py pylint!skip -tests/storage/scripts/generate_tests.py metaclass-boilerplate!skip -tests/storage/scripts/generate_tests.py future-import-boilerplate!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/.sanity-ansible-ignore-2.12.txt b/.sanity-ansible-ignore-2.12.txt index 2bbb920f..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.12.txt +++ b/.sanity-ansible-ignore-2.12.txt @@ -1,43 +1,7 @@ -plugins/modules/blivet.py import-2.6!skip -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py import-3.9!skip -plugins/modules/blivet.py import-3.10!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license -plugins/modules/blivet.py validate-modules:module-invalid-version-added -plugins/modules/blockdev_info.py import-2.7!skip -plugins/modules/blockdev_info.py import-3.5!skip plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license -plugins/modules/blockdev_info.py validate-modules:module-invalid-version-added -plugins/modules/bsize.py import-2.7!skip -plugins/modules/bsize.py import-3.5!skip plugins/modules/bsize.py validate-modules:missing-gplv3-license -plugins/modules/bsize.py validate-modules:module-invalid-version-added -plugins/modules/find_unused_disk.py import-2.7!skip -plugins/modules/find_unused_disk.py import-3.5!skip plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license -plugins/modules/find_unused_disk.py validate-modules:return-syntax-error -plugins/modules/lvm_gensym.py import-2.7!skip -plugins/modules/lvm_gensym.py import-3.5!skip plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license -plugins/modules/lvm_gensym.py validate-modules:module-invalid-version-added -plugins/modules/resolve_blockdev.py import-2.7!skip -plugins/modules/resolve_blockdev.py import-3.5!skip plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/modules/resolve_blockdev.py validate-modules:module-invalid-version-added -plugins/module_utils/storage_lsr/__init__.py import-2.6!skip -plugins/module_utils/storage_lsr/__init__.py import-2.7!skip -plugins/module_utils/storage_lsr/__init__.py import-3.5!skip -plugins/module_utils/storage_lsr/argument_validator.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py import-2.7!skip -plugins/module_utils/storage_lsr/size.py import-3.5!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -plugins/module_utils/storage_lsr/size.py pylint!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/.sanity-ansible-ignore-2.13.txt b/.sanity-ansible-ignore-2.13.txt index 2bbb920f..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.13.txt +++ b/.sanity-ansible-ignore-2.13.txt @@ -1,43 +1,7 @@ -plugins/modules/blivet.py import-2.6!skip -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py import-3.9!skip -plugins/modules/blivet.py import-3.10!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license -plugins/modules/blivet.py validate-modules:module-invalid-version-added -plugins/modules/blockdev_info.py import-2.7!skip -plugins/modules/blockdev_info.py import-3.5!skip plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license -plugins/modules/blockdev_info.py validate-modules:module-invalid-version-added -plugins/modules/bsize.py import-2.7!skip -plugins/modules/bsize.py import-3.5!skip plugins/modules/bsize.py validate-modules:missing-gplv3-license -plugins/modules/bsize.py validate-modules:module-invalid-version-added -plugins/modules/find_unused_disk.py import-2.7!skip -plugins/modules/find_unused_disk.py import-3.5!skip plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license -plugins/modules/find_unused_disk.py validate-modules:return-syntax-error -plugins/modules/lvm_gensym.py import-2.7!skip -plugins/modules/lvm_gensym.py import-3.5!skip plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license -plugins/modules/lvm_gensym.py validate-modules:module-invalid-version-added -plugins/modules/resolve_blockdev.py import-2.7!skip -plugins/modules/resolve_blockdev.py import-3.5!skip plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/modules/resolve_blockdev.py validate-modules:module-invalid-version-added -plugins/module_utils/storage_lsr/__init__.py import-2.6!skip -plugins/module_utils/storage_lsr/__init__.py import-2.7!skip -plugins/module_utils/storage_lsr/__init__.py import-3.5!skip -plugins/module_utils/storage_lsr/argument_validator.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py import-2.7!skip -plugins/module_utils/storage_lsr/size.py import-3.5!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -plugins/module_utils/storage_lsr/size.py pylint!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/.sanity-ansible-ignore-2.14.txt b/.sanity-ansible-ignore-2.14.txt index 0e98e9af..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.14.txt +++ b/.sanity-ansible-ignore-2.14.txt @@ -1,40 +1,7 @@ -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py import-3.9!skip -plugins/modules/blivet.py import-3.10!skip -plugins/modules/blivet.py import-3.11!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license -plugins/modules/blivet.py validate-modules:module-invalid-version-added -plugins/modules/blockdev_info.py import-2.7!skip -plugins/modules/blockdev_info.py import-3.5!skip plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license -plugins/modules/blockdev_info.py validate-modules:module-invalid-version-added -plugins/modules/bsize.py import-2.7!skip -plugins/modules/bsize.py import-3.5!skip plugins/modules/bsize.py validate-modules:missing-gplv3-license -plugins/modules/bsize.py validate-modules:module-invalid-version-added -plugins/modules/find_unused_disk.py import-2.7!skip -plugins/modules/find_unused_disk.py import-3.5!skip plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license -plugins/modules/find_unused_disk.py validate-modules:return-syntax-error -plugins/modules/lvm_gensym.py import-2.7!skip -plugins/modules/lvm_gensym.py import-3.5!skip plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license -plugins/modules/lvm_gensym.py validate-modules:module-invalid-version-added -plugins/modules/resolve_blockdev.py import-2.7!skip -plugins/modules/resolve_blockdev.py import-3.5!skip plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/modules/resolve_blockdev.py validate-modules:module-invalid-version-added -plugins/module_utils/storage_lsr/__init__.py import-2.7!skip -plugins/module_utils/storage_lsr/__init__.py import-3.5!skip -plugins/module_utils/storage_lsr/size.py import-2.7!skip -plugins/module_utils/storage_lsr/size.py import-3.5!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -plugins/module_utils/storage_lsr/size.py pylint!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/.sanity-ansible-ignore-2.15.txt b/.sanity-ansible-ignore-2.15.txt index 0e98e9af..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.15.txt +++ b/.sanity-ansible-ignore-2.15.txt @@ -1,40 +1,7 @@ -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py import-3.9!skip -plugins/modules/blivet.py import-3.10!skip -plugins/modules/blivet.py import-3.11!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license -plugins/modules/blivet.py validate-modules:module-invalid-version-added -plugins/modules/blockdev_info.py import-2.7!skip -plugins/modules/blockdev_info.py import-3.5!skip plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license -plugins/modules/blockdev_info.py validate-modules:module-invalid-version-added -plugins/modules/bsize.py import-2.7!skip -plugins/modules/bsize.py import-3.5!skip plugins/modules/bsize.py validate-modules:missing-gplv3-license -plugins/modules/bsize.py validate-modules:module-invalid-version-added -plugins/modules/find_unused_disk.py import-2.7!skip -plugins/modules/find_unused_disk.py import-3.5!skip plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license -plugins/modules/find_unused_disk.py validate-modules:return-syntax-error -plugins/modules/lvm_gensym.py import-2.7!skip -plugins/modules/lvm_gensym.py import-3.5!skip plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license -plugins/modules/lvm_gensym.py validate-modules:module-invalid-version-added -plugins/modules/resolve_blockdev.py import-2.7!skip -plugins/modules/resolve_blockdev.py import-3.5!skip plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/modules/resolve_blockdev.py validate-modules:module-invalid-version-added -plugins/module_utils/storage_lsr/__init__.py import-2.7!skip -plugins/module_utils/storage_lsr/__init__.py import-3.5!skip -plugins/module_utils/storage_lsr/size.py import-2.7!skip -plugins/module_utils/storage_lsr/size.py import-3.5!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -plugins/module_utils/storage_lsr/size.py pylint!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/.sanity-ansible-ignore-2.16.txt b/.sanity-ansible-ignore-2.16.txt new file mode 100644 index 00000000..79bb2a01 --- /dev/null +++ b/.sanity-ansible-ignore-2.16.txt @@ -0,0 +1,7 @@ +plugins/modules/blivet.py validate-modules:missing-gplv3-license +plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license +plugins/modules/bsize.py validate-modules:missing-gplv3-license +plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license +plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license +plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license +tests/storage/scripts/generate_tests.py shebang!skip diff --git a/.sanity-ansible-ignore-2.9.txt b/.sanity-ansible-ignore-2.9.txt index bc53b484..79bb2a01 100644 --- a/.sanity-ansible-ignore-2.9.txt +++ b/.sanity-ansible-ignore-2.9.txt @@ -1,20 +1,7 @@ -plugins/modules/blivet.py import-2.6!skip -plugins/modules/blivet.py import-2.7!skip -plugins/modules/blivet.py import-3.5!skip -plugins/modules/blivet.py import-3.6!skip -plugins/modules/blivet.py import-3.7!skip -plugins/modules/blivet.py import-3.8!skip -plugins/modules/blivet.py validate-modules:import-error plugins/modules/blivet.py validate-modules:missing-gplv3-license plugins/modules/blockdev_info.py validate-modules:missing-gplv3-license plugins/modules/bsize.py validate-modules:missing-gplv3-license plugins/modules/find_unused_disk.py validate-modules:missing-gplv3-license plugins/modules/lvm_gensym.py validate-modules:missing-gplv3-license plugins/modules/resolve_blockdev.py validate-modules:missing-gplv3-license -plugins/module_utils/storage_lsr/argument_validator.py import-2.6!skip -plugins/module_utils/storage_lsr/size.py pep8!skip -tests/storage/scripts/generate_tests.py metaclass-boilerplate!skip -tests/storage/scripts/generate_tests.py future-import-boilerplate!skip tests/storage/scripts/generate_tests.py shebang!skip -tests/storage/scripts/post-commit shebang!skip -tests/storage/scripts/pre-commit shebang!skip diff --git a/library/blivet.py b/library/blivet.py index 53cb0b4a..9d600215 100644 --- a/library/blivet.py +++ b/library/blivet.py @@ -15,7 +15,7 @@ short_description: Module for management of linux block device stacks -version_added: "2.5" +version_added: "2.13.0" description: - "WARNING: Do not use this module directly! It is only for role internal use." @@ -24,51 +24,304 @@ options: pools: - description: - - list of dicts describing pools + description: pools + type: list + elements: dict + suboptions: + disks: + description: disks + type: list + default: [] + elements: str + encryption: + description: encryption + type: bool + encryption_cipher: + description: encryption_cipher + type: str + encryption_key: + description: encryption_key + type: str + encryption_key_size: + description: encryption_key_size + type: int + encryption_luks_version: + description: encryption_luks_version + type: str + encryption_password: + description: encryption_password + type: str + name: + description: name + type: str + raid_level: + description: raid_level + type: str + raid_device_count: + description: raid_device_count + type: int + raid_spare_count: + description: raid_spare_count + type: int + raid_metadata_version: + description: raid_metadata_version + type: str + raid_chunk_size: + description: raid_chunk_size + type: str + shared: + description: shared + type: bool + state: + description: state + type: str + default: present + choices: ['present', 'absent'] + type: + description: type + type: str + volumes: + description: volumes + type: list + default: [] + elements: dict + suboptions: + encryption: + description: encryption + type: bool + encryption_cipher: + description: encryption_cipher + type: str + encryption_key: + description: encryption_key + type: str + encryption_key_size: + description: encryption_key_size + type: int + encryption_luks_version: + description: encryption_luks_version + type: str + encryption_password: + description: encryption_password + type: str + fs_create_options: + description: fs_create_options + type: str + fs_label: + description: fs_label + type: str + default: '' + fs_type: + description: fs_type + type: str + mount_options: + description: mount_options + type: str + mount_point: + description: mount_point + type: str + mount_user: + description: mount_user + type: str + mount_group: + description: mount_group + type: str + mount_mode: + description: mount_mode + type: str + name: + description: name + type: str + raid_level: + description: raid_level + type: str + size: + description: size + type: str + state: + description: state + type: str + default: present + choices: ['present', 'absent'] + type: + description: type + type: str + cached: + description: cached + type: bool + cache_devices: + description: cache_devices + type: list + default: [] + elements: str + cache_mode: + description: cache_mode + type: str + cache_size: + description: cache_size + type: str + compression: + description: compression + type: bool + deduplication: + description: deduplication + type: bool + raid_disks: + description: raid_disks + type: list + default: [] + elements: str + raid_stripe_size: + description: raid_stripe_size + type: str + thin_pool_name: + description: thin_pool_name + type: str + thin_pool_size: + description: thin_pool_size + type: str + thin: + description: thin + type: bool + default: false + vdo_pool_size: + description: vdo_pool_size + type: str volumes: - description: - - list of dicts describing volumes - use_partitions: - description: - - boolean indicating whether to create partitions on disks for pool backing devices + description: volumes + type: list + elements: dict + suboptions: + encryption: + description: encryption + type: bool + encryption_cipher: + description: encryption_cipher + type: str + encryption_key: + description: encryption_key + type: str + encryption_key_size: + description: encryption_key_size + type: int + encryption_luks_version: + description: encryption_luks_version + type: str + encryption_password: + description: encryption_password + type: str + fs_create_options: + description: fs_create_options + type: str + fs_label: + description: fs_label + type: str + default: '' + fs_type: + description: fs_type + type: str + mount_options: + description: mount_options + type: str + mount_point: + description: mount_point + type: str + mount_user: + description: mount_user + type: str + mount_group: + description: mount_group + type: str + mount_mode: + description: mount_mode + type: str + name: + description: name + type: str + raid_level: + description: raid_level + type: str + size: + description: size + type: str + state: + description: state + type: str + default: present + choices: ['present', 'absent'] + type: + description: type + type: str + disks: + description: disks + type: list + default: [] + elements: str + raid_device_count: + description: raid_device_count + type: int + raid_spare_count: + description: raid_spare_count + type: int + raid_metadata_version: + description: raid_metadata_version + type: str + raid_chunk_size: + description: raid_chunk_size + type: str + packages_only: + description: packages_only + type: bool + default: false disklabel_type: description: - | disklabel type string (eg: 'gpt') to use, overriding the built-in logic in blivet + type: str safe_mode: description: - boolean indicating that we should fail rather than implicitly/automatically removing devices or formatting + type: bool + default: true + pool_defaults: + description: pool_defaults + type: dict + volume_defaults: + description: volume_defaults + type: dict + use_partitions: + description: boolean indicating whether to create partitions on disks for pool backing devices + type: bool diskvolume_mkfs_option_map: description: - dict which maps filesystem names to additional mkfs options that should be used when creating a disk volume (that is, a whole disk filesystem) - + type: dict + default: {} author: - David Lehman (@dwlehman) ''' EXAMPLES = ''' - - name: Manage devices blivet: pools: - - name: "{{ app_pool }}" - disks: ["sdd", "sde"] - volumes: - - name: shared - size: "10 GiB" - mount_point: /opt/{{ app_pool }}/shared - - name: web - size: 8g - mount_point: /opt/{{ app_pool }}/web + - name: "{{ app_pool }}" + disks: ["sdd", "sde"] + volumes: + - name: shared + size: "10 GiB" + mount_point: /opt/{{ app_pool }}/shared + - name: web + size: 8g + mount_point: /opt/{{ app_pool }}/web volumes: - - name: whole_disk1 - disks: ['sdc'] - mount_point: /whole_disk1 - fs_type: ext4 - mount_options: journal_checksum,async,noexec + - name: whole_disk1 + disks: ['sdc'] + mount_point: /whole_disk1 + fs_type: ext4 + mount_options: journal_checksum,async,noexec ''' RETURN = ''' @@ -146,6 +399,12 @@ BLIVET_PACKAGE = 'blivet' except ImportError: LIB_IMP_ERR = traceback.format_exc() + # make ansible-test import and compile tests happy + + class FakeDevices(object): + def __getattr__(self, val): + return val + devices = FakeDevices() from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.storage_lsr.argument_validator import validate_parameters @@ -1777,14 +2036,59 @@ def activate_swaps(b, pools, volumes): device.format.setup() +def format_option(name, option, input, indent): + output = input + space = " " * indent + output = output + space + name + ":\n" + space = space + (" " * 4) + opt_type = option.get("type") + opt_description = option.get("description", name) + output = output + space + "description: " + opt_description + "\n" + output = output + space + "type: " + opt_type + "\n" + opt_default = option.get("default") + if opt_default is not None: + if opt_type == "list" and not opt_default: + opt_default = "[]" + elif opt_type == "dict" and not opt_default: + opt_default = "{}" + elif opt_type == "bool": + if opt_default is True or opt_default is False: + opt_default = str(opt_default).lower() + elif opt_type == "str" and opt_default == "": + opt_default = "''" + output = output + space + "default: " + opt_default + "\n" + if option.get("required"): + output = output + space + "required: true\n" + if "choices" in option: + output = output + space + "choices: " + str(option["choices"]) + "\n" + if "elements" in option: + output = output + space + "elements: " + str(option["elements"]) + "\n" + if "aliases" in option: + output = output + space + "aliases: " + str(option["aliases"]) + "\n" + return output + + +def generate_module_doc(module_args, input="", indent=4): + init_space = " " * indent + opt_space = init_space + (" " * 4) + output = input + for key, value in module_args.items(): + output = format_option(key, value, output, indent) + suboptions = value.get("options") + if suboptions: + output = output + opt_space + "suboptions:\n" + output = generate_module_doc(suboptions, output, indent + 8) + return output + + 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=dict(type='str', no_log=True), encryption_key_size=dict(type='int'), encryption_luks_version=dict(type='str'), - encryption_password=dict(type='str'), + encryption_password=dict(type='str', no_log=True), fs_create_options=dict(type='str'), fs_label=dict(type='str', default=''), fs_type=dict(type='str'), @@ -1800,7 +2104,7 @@ def run_module(): type=dict(type='str')) volume_opts = copy.deepcopy(common_volume_opts) volume_opts.update( - dict(disks=dict(type='list'), + dict(disks=dict(type='list', elements='str', default=list()), raid_device_count=dict(type='int'), raid_spare_count=dict(type='int'), raid_metadata_version=dict(type='str'), @@ -1825,10 +2129,10 @@ def run_module(): options=dict(disks=dict(type='list', elements='str', default=list()), encryption=dict(type='bool'), encryption_cipher=dict(type='str'), - encryption_key=dict(type='str'), + encryption_key=dict(type='str', no_log=True), encryption_key_size=dict(type='int'), encryption_luks_version=dict(type='str'), - encryption_password=dict(type='str'), + encryption_password=dict(type='str', no_log=True), name=dict(type='str'), raid_level=dict(type='str'), raid_device_count=dict(type='int'), @@ -1850,6 +2154,9 @@ def run_module(): use_partitions=dict(type='bool', required=False), diskvolume_mkfs_option_map=dict(type='dict', required=False, default={})) + # comment this out if not generating module docs + # mod_arg_str = generate_module_doc(module_args) + # seed the result dict in the object result = dict( changed=False, @@ -1860,6 +2167,7 @@ def run_module(): pools=list(), volumes=list(), packages=list(), + # mod_arg_str=mod_arg_str, ) module = AnsibleModule(argument_spec=module_args, diff --git a/library/blockdev_info.py b/library/blockdev_info.py index cb5b59c5..13858fb0 100644 --- a/library/blockdev_info.py +++ b/library/blockdev_info.py @@ -14,7 +14,7 @@ --- module: blockdev_info short_description: Collect info about block devices in the system. -version_added: "2.5" +version_added: "2.13.0" description: - "WARNING: Do not use this module directly! It is only for role internal use." - "This module collects information about block devices" @@ -27,7 +27,6 @@ - name: Get info about block devices blockdev_info: register: blk_info - ''' RETURN = ''' diff --git a/library/bsize.py b/library/bsize.py index 147dd239..f4a3bfb1 100644 --- a/library/bsize.py +++ b/library/bsize.py @@ -16,7 +16,7 @@ short_description: Module for basic manipulation with byte sizes -version_added: "2.5" +version_added: "2.13.0" description: - "WARNING: Do not use this module directly! It is only for role internal use." diff --git a/library/find_unused_disk.py b/library/find_unused_disk.py index 15bbc70c..09b8ad53 100644 --- a/library/find_unused_disk.py +++ b/library/find_unused_disk.py @@ -42,15 +42,15 @@ ''' EXAMPLES = ''' -- name: test finding first unused device module +- name: Test finding first unused device module hosts: localhost tasks: - - name: run module + - name: Run module find_unused_disk: min_size: '10g' register: testout - - name: dump test output + - name: Dump test output debug: msg: '{{ testout }}' ''' @@ -65,12 +65,12 @@ description: Unused disk(s) that have been found returned: On success type: list - samples: | + sample: | ["sda1", "dm-0", "dm-3"] - none: + empty: description: No unused disks were found returned: On success - type: string + type: str sample: "Unable to find unused disk" ''' diff --git a/library/lvm_gensym.py b/library/lvm_gensym.py index edddb50f..f9265b27 100644 --- a/library/lvm_gensym.py +++ b/library/lvm_gensym.py @@ -15,7 +15,7 @@ --- module: lvm_gensym short_description: Generate default names for lvm variables -version_added: "2.4" +version_added: "2.13.0" description: - "WARNING: Do not use this module directly! It is only for role internal use." - "Module accepts two input strings consisting of a file system type and diff --git a/library/resolve_blockdev.py b/library/resolve_blockdev.py index c29a8450..e9627945 100644 --- a/library/resolve_blockdev.py +++ b/library/resolve_blockdev.py @@ -14,7 +14,7 @@ --- module: resolve_blockdev short_description: Resolve block device specification to device node path. -version_added: "2.5" +version_added: "2.13.0" description: - "WARNING: Do not use this module directly! It is only for role internal use." - "This module accepts various forms of block device identifiers and diff --git a/module_utils/storage_lsr/size.py b/module_utils/storage_lsr/size.py index dbf9955b..5523e14f 100644 --- a/module_utils/storage_lsr/size.py +++ b/module_utils/storage_lsr/size.py @@ -4,22 +4,24 @@ import re -DECIMAL_FACTOR = 10 ** 3 -BINARY_FACTOR = 2 ** 10 +DECIMAL_FACTOR = 10**3 +BINARY_FACTOR = 2**10 # index of the item in the list determines the exponent for size computation # e.g. size_in_bytes = value * (DECIMAL_FACTOR ** (index(mega)+1)) = value * (1000 ** (1+1)) -# pylint: disable=bad-whitespace -PREFIXES_DECIMAL = [["k", "M", "G", "T", "P", "E", "Z", "Y"], # noqa: E241 - ["kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"]] # noqa: E241 -PREFIXES_BINARY = [["Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"], # noqa: E221,E241 - ["kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"]] # noqa: E241 +PREFIXES_DECIMAL = [ + ["k", "M", "G", "T", "P", "E", "Z", "Y"], + ["kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta"], +] +PREFIXES_BINARY = [ + ["Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"], + ["kibi", "mebi", "gibi", "tebi", "pebi", "exbi", "zebi", "yobi"], +] SUFFIXES = ["bytes", "byte", "B"] class Size(object): - ''' Class for basic manipulation of the sizes in *bytes - ''' + """Class for basic manipulation of the sizes in *bytes""" def __init__(self, value): raw_number, raw_units = self._parse_input(str(value)) @@ -29,9 +31,9 @@ def __init__(self, value): self.units = raw_units def _parse_input(self, value): - ''' splits input string into number and unit parts - returns number part, unit part - ''' + """splits input string into number and unit parts + returns number part, unit part + """ m = re.search("^(.*?)([^0-9]*)$", value) raw_number = m.group(1).strip() @@ -43,12 +45,12 @@ def _parse_input(self, value): return raw_number, raw_units def _parse_units(self, raw_units): - ''' - gets string containing size units and - returns *_FACTOR (BINARY or DECIMAL) and the prefix position (not index!) - in the PREFIXES_* list - If no unit is specified defaults to BINARY and Bytes - ''' + """ + gets string containing size units and + returns *_FACTOR (BINARY or DECIMAL) and the prefix position (not index!) + in the PREFIXES_* list + If no unit is specified defaults to BINARY and Bytes + """ prefix = raw_units no_suffix_flag = True @@ -59,7 +61,7 @@ def _parse_units(self, raw_units): for suffix in SUFFIXES: if raw_units.lower().endswith(suffix.lower()): no_suffix_flag = False - prefix = raw_units[:-len(suffix)] + prefix = raw_units[: -len(suffix)] break if prefix == "": @@ -95,15 +97,15 @@ def _parse_units(self, raw_units): return used_factor, idx + 1 def _parse_number(self, raw_number): - ''' parse input string containing number - return float - ''' + """parse input string containing number + return float + """ return float(raw_number) def _get_unit(self, factor, exponent, unit_type=0): - ''' based on decimal or binary factor and exponent - obtain and return correct unit - ''' + """based on decimal or binary factor and exponent + obtain and return correct unit + """ if unit_type == 0: suffix = "B" @@ -121,12 +123,10 @@ def _get_unit(self, factor, exponent, unit_type=0): @property def bytes(self): - ''' returns size value in bytes as int - ''' - return int((self.factor ** self.exponent) * self.number) + """returns size value in bytes as int""" + return int((self.factor**self.exponent) * self.number) def _format(self, format_str, factor, exponent): - result = format_str result = result.replace(r"%sb", self._get_unit(factor, exponent, 0)) result = result.replace(r"%lb", self._get_unit(factor, exponent, 1)) @@ -134,20 +134,20 @@ def _format(self, format_str, factor, exponent): return result def get(self, units="autobin", fmt="%0.1f %sb"): - ''' returns size value as a string with given units and format + """returns size value as a string with given units and format - "units" parameter allows to select preferred unit: - for example "KiB" or "megabytes" - accepted values are also: - "autobin" (default) - uses the highest human readable unit (binary) - "autodec" - uses the highest human readable unit (decimal) + "units" parameter allows to select preferred unit: + for example "KiB" or "megabytes" + accepted values are also: + "autobin" (default) - uses the highest human readable unit (binary) + "autodec" - uses the highest human readable unit (decimal) - "fmt" parameter allows to specify the output format: - %sb - will be replaced with the short byte size unit (e.g. MiB) - %lb - will be replaced with the long byte size unit (e.g. kilobytes) - value can be formatted using standard string replacements (e.g. %d, %f) + "fmt" parameter allows to specify the output format: + %sb - will be replaced with the short byte size unit (e.g. MiB) + %lb - will be replaced with the long byte size unit (e.g. kilobytes) + value can be formatted using standard string replacements (e.g. %d, %f) - ''' + """ ftr = BINARY_FACTOR if units == "autodec": @@ -160,6 +160,8 @@ def get(self, units="autobin", fmt="%0.1f %sb"): exp += 1 else: ftr, exp = self._parse_units(units.strip()) - value = (float(self.factor ** self.exponent) / float(ftr ** exp)) * self.number + value = ( + float(self.factor**self.exponent) / float(ftr**exp) + ) * self.number return self._format(fmt, ftr, exp) % value diff --git a/tasks/main-blivet.yml b/tasks/main-blivet.yml index b773e889..f73be000 100644 --- a/tasks/main-blivet.yml +++ b/tasks/main-blivet.yml @@ -118,6 +118,10 @@ var: blivet_output verbosity: 1 +# - name: Print mod args +# debug: +# msg: mod_args {{ blivet_output.mod_arg_str }} + - name: Set the list of pools for test verification set_fact: _storage_pools_list: "{{ blivet_output.pools }}" diff --git a/tests/roles/caller/tasks/main.yml b/tests/roles/caller/tasks/main.yml index ae5e81d8..4fb1f9f9 100644 --- a/tests/roles/caller/tasks/main.yml +++ b/tests/roles/caller/tasks/main.yml @@ -1,8 +1,10 @@ --- # tasks file for caller -- include_role: +- name: Include the role + include_role: name: "{{ roletoinclude }}" -- assert: +- name: Check variable override + assert: that: not __caller_override diff --git a/tests/scripts/generate_tests.py b/tests/scripts/generate_tests.py index 842717bb..6a875765 100755 --- a/tests/scripts/generate_tests.py +++ b/tests/scripts/generate_tests.py @@ -56,9 +56,13 @@ def generate_file(org_filename, iface): f.write(TEST_FILE_CONTENTS % (org_filename, iface, iface, iface, org_filename, iface)) +# These are files for which we do not need scsi and nvme testing +SKIP_FILES = set(("tests_lvm_pool_shared.yml",)) + + # will new test be generated based on this item? def is_test_file(filename): - return regex.match(filename) is not None + return filename not in SKIP_FILES and regex.match(filename) is not None if __name__ == "__main__": diff --git a/tests/scripts/post-commit b/tests/scripts/post-commit index 097f469e..7389f8c9 100755 --- a/tests/scripts/post-commit +++ b/tests/scripts/post-commit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Run script generate_tests.py and append test files generated by it to the commit. diff --git a/tests/scripts/pre-commit b/tests/scripts/pre-commit index 52ba58d9..3bd4abe6 100755 --- a/tests/scripts/pre-commit +++ b/tests/scripts/pre-commit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This script is intended to be used as git pre-commit hook. # Make sure file is executable and copy it into /.git/hooks/