Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ galaxy_info:
license: MIT
min_ansible_version: "2.9"
platforms:
- name: Fedora
versions:
- all
- name: EL
versions:
- "7"
- "8"
- "9"
galaxy_tags:
- centos
- el7
- el8
- el9
- el10
- fedora
- lvm
- redhat
- rhel
Expand Down
5 changes: 0 additions & 5 deletions tasks/stat_device.yml

This file was deleted.

8 changes: 4 additions & 4 deletions tests/get_unused_disk.yml → tests/tasks/get_unused_disk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

- name: Find unused disks in the system
find_unused_disk:
min_size: "{{ min_size | d(omit) }}"
max_size: "{{ max_size | d(omit) }}"
max_return: "{{ max_return | d(omit) }}"
min_size: "{{ min_size | d(__storage_min_size | d(omit)) }}"
max_size: "{{ max_size | d(__storage_max_size | d(omit)) }}"
max_return: "{{ max_return | d(__storage_max_return | d(omit)) }}"
with_interface: "{{ storage_test_use_interface | d(omit) }}"
match_sector_size: "{{ match_sector_size | d(omit) }}"
match_sector_size: "{{ match_sector_size | d(__storage_match_sector_size | d(omit)) }}"
register: unused_disks_return

- name: Debug why there are no unused disks
Expand Down
83 changes: 83 additions & 0 deletions tests/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
# Single storage test setup entrypoint (typically the play's first task).
#
# Optional variables:
# __storage_include_prep — default true: run role with no storage_* config and set
# storage_skip_checks. Set false for a follow-up include that only needs
# package_facts / blivet facts (e.g. tests_resize.yml after initial setup).
# __storage_storage_skip_checks — if set, used as storage_skip_checks instead of
# the default [blivet_available, packages_installed conditional].
# __storage_get_package_facts — default false: ansible.builtin.package_facts, then
# blivet_pkg_version, and is_fedora / is_rhel* / is_rhel78.
# __storage_get_unused_disks — default true: whether to include get_unused_disk.yml.
# The playbook supplies this when needed; setup does not derive it.
# __storage_min_size, __storage_max_return, __storage_max_size,
# __storage_disks_needed, __storage_match_sector_size — passed to get_unused_disk.
#
- name: Run the role
when: __storage_include_prep | default(true)
block:
- name: Run the role
ansible.builtin.include_tasks: run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
ansible.builtin.set_fact:
storage_skip_checks: >-
{{
__storage_storage_skip_checks
if __storage_storage_skip_checks is defined
else (
['blivet_available',
(lookup('env', 'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false'])
| ternary('packages_installed', '')]
)
}}

- name: Gather package facts and set vars based on package facts
when: __storage_get_package_facts | default(false)
block:
- name: Gather package facts
ansible.builtin.package_facts:
no_log: "{{ ansible_verbosity < 3 }}"

- name: Set blivet package version
ansible.builtin.set_fact:
blivet_pkg_version: "{{
ansible_facts.packages[blivet_pkg_name[0]][0]['version'] +
'-' + ansible_facts.packages[blivet_pkg_name[0]][0]['release'] }}"
vars:
blivet_pkg_name: "{{ ansible_facts.packages |
select('search', 'blivet') | select('search', 'python') | list }}"

- name: Set distribution version flags
ansible.builtin.set_fact:
is_fedora: "{{ ansible_facts['distribution'] == 'Fedora' }}"
is_rhel7: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '7' }}"
is_rhel8: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '8' }}"
is_rhel9: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '9' }}"
is_rhel10: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '10' }}"
is_rhel78: "{{ ansible_facts['os_family'] == 'RedHat' and
ansible_facts['distribution_major_version'] in ['7', '8'] }}"

- name: Get unused disks for test
when: __storage_get_unused_disks | default(true)
ansible.builtin.include_tasks: get_unused_disk.yml

- name: Get info about storage devices
ansible.builtin.shell:
executable: /bin/bash
cmd: |
set -euxo pipefail
exec 1>&2
lsblk -p --pairs --bytes -o NAME,TYPE,SIZE,FSTYPE,LOG-SEC
if type -p mdadm >/dev/null; then
mdadm --misc --examine --scan
fi
if type -p dmsetup >/dev/null; then
dmsetup ls --tree --separator /
fi
if type -p lvm >/dev/null; then
lvm vgdisplay
fi
udevadm settle -t 0
changed_when: false
20 changes: 4 additions & 16 deletions tests/tests_change_disk_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,11 @@
if (ansible_facts['distribution'] == 'RedHat' and
ansible_facts['distribution_major_version'] == '6')
else 'ext4' }}"
__storage_min_size: "{{ volume_size }}"
__storage_max_return: 1
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
min_size: "{{ volume_size }}"
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: Create a disk device with the default file system type
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
20 changes: 4 additions & 16 deletions tests/tests_change_disk_mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
mount_location_before: '/opt/test1'
mount_location_after: '/opt/test2'
volume_size: '5g'
__storage_min_size: "{{ volume_size }}"
__storage_max_return: 1

tasks:
- name: Create blockdev and loop mount
Expand All @@ -19,22 +21,8 @@
cat /proc/mounts | grep loop
changed_when: false

- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
min_size: "{{ volume_size }}"
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: Create a disk device mounted at "{{ mount_location_before }}"
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
20 changes: 4 additions & 16 deletions tests/tests_change_fs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,14 @@
fs_after: "{{ (ansible_facts['distribution'] == 'RedHat' and
ansible_facts['distribution_major_version'] == '6') |
ternary('ext4', 'xfs') }}"
__storage_min_size: "{{ volume_size }}"
__storage_max_return: 1
tags:
- tests::lvm

tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
min_size: "{{ volume_size }}"
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: Create a LVM logical volume with default fs_type
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
20 changes: 4 additions & 16 deletions tests/tests_change_fs_use_partitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@
if (ansible_facts['distribution'] == 'RedHat' and
ansible_facts['distribution_major_version'] == '6')
else 'ext4' }}"
__storage_min_size: "{{ volume_size }}"
__storage_max_return: 1
tags:
- tests::lvm
tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
min_size: "{{ volume_size }}"
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: Create an LVM partition with the default file system type
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
20 changes: 4 additions & 16 deletions tests/tests_change_mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@
mount_location_before: '/opt/test1'
mount_location_after: '/opt/test2'
volume_size: '3g'
__storage_min_size: "{{ volume_size }}"
__storage_max_return: 1
tags:
- tests::lvm

tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
min_size: "{{ volume_size }}"
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: Create a LVM logical volume mounted at {{ mount_location_before }}
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
18 changes: 3 additions & 15 deletions tests/tests_create_disk_then_remove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,11 @@
vars:
storage_safe_mode: false
mount_location: '/opt/test1'
__storage_max_return: 1

tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: >-
Create a disk device; specify disks as non-list mounted on
Expand Down
20 changes: 4 additions & 16 deletions tests/tests_create_lv_size_equal_to_vg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,14 @@
mount_location: '/opt/test1'
volume_group_size: '10g'
lv_size: '10g'
__storage_min_size: "{{ volume_group_size }}"
__storage_max_return: 1
tags:
- tests::lvm

tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
vars:
min_size: "{{ volume_group_size }}"
max_return: 1
- name: Prep storage role and discover unused disks
ansible.builtin.include_tasks: tasks/setup.yml

- name: Create one lv which size is equal to vg size
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
48 changes: 7 additions & 41 deletions tests/tests_create_lvm_cache_then_remove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,18 @@
volume_group_size: '10g'
volume_size: '5g'
cache_size: '4g'
__storage_min_size: "{{ volume_group_size }}"
__storage_max_return: 2
__storage_disks_needed: 2
__storage_match_sector_size: true
tags:
- tests::lvm

tasks:
- name: Run the role
include_tasks: tasks/run_role_with_clear_facts.yml

- name: Mark tasks to be skipped
set_fact:
storage_skip_checks:
- blivet_available
- "{{ (lookup('env',
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
ternary('packages_installed', '') }}"

- name: Gather package facts
package_facts:

- name: Set blivet package name
set_fact:
blivet_pkg_name: "{{ ansible_facts.packages |
select('search', 'blivet') | select('search', 'python') | list }}"

- name: Set blivet package version
set_fact:
blivet_pkg_version: "{{
ansible_facts.packages[blivet_pkg_name[0]][0]['version'] +
'-' + ansible_facts.packages[blivet_pkg_name[0]][0]['release'] }}"

- name: Set distribution version
set_fact:
is_rhel10: "{{ (ansible_facts['os_family'] == 'RedHat') and
ansible_facts.distribution_major_version == '10' }}"
is_rhel9: "{{ (ansible_facts['os_family'] == 'RedHat') and
ansible_facts.distribution_major_version == '9' }}"
is_rhel8: "{{ (ansible_facts['os_family'] == 'RedHat') and
ansible_facts.distribution_major_version == '8' }}"
is_fedora: "{{ ansible_facts.distribution == 'Fedora' }}"

- name: Get unused disks
include_tasks: get_unused_disk.yml
- name: Storage test setup
ansible.builtin.include_tasks: tasks/setup.yml
vars:
min_size: "{{ volume_group_size }}"
max_return: 2
disks_needed: 2
match_sector_size: true
__storage_get_package_facts: true

- name: Create a cached LVM logical volume under volume group 'foo'
include_tasks: tasks/run_role_with_clear_facts.yml
Expand Down
Loading
Loading