Skip to content

Commit 388395f

Browse files
committed
test: refactor test setup to add device info
Refactor the tests so that we can have a common tests/tasks/setup.yml to handle common setup tasks as well as print some diagnostic information before each test run to see if we can solve some of these test flakes. Signed-off-by: Rich Megginson <[email protected]>
1 parent 780f241 commit 388395f

50 files changed

Lines changed: 321 additions & 881 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tasks/stat_device.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
- name: Find unused disks in the system
1717
find_unused_disk:
18-
min_size: "{{ min_size | d(omit) }}"
19-
max_size: "{{ max_size | d(omit) }}"
20-
max_return: "{{ max_return | d(omit) }}"
18+
min_size: "{{ min_size | d(__storage_min_size | d(omit)) }}"
19+
max_size: "{{ max_size | d(__storage_max_size | d(omit)) }}"
20+
max_return: "{{ max_return | d(__storage_max_return | d(omit)) }}"
2121
with_interface: "{{ storage_test_use_interface | d(omit) }}"
22-
match_sector_size: "{{ match_sector_size | d(omit) }}"
22+
match_sector_size: "{{ match_sector_size | d(__storage_match_sector_size | d(omit)) }}"
2323
register: unused_disks_return
2424

2525
- name: Debug why there are no unused disks

tests/tasks/setup.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
# Single storage test setup entrypoint (typically the play's first task).
3+
#
4+
# Optional variables:
5+
# __storage_include_prep — default true: run role with no storage_* config and set
6+
# storage_skip_checks. Set false for a follow-up include that only needs
7+
# package_facts / blivet facts (e.g. tests_resize.yml after initial setup).
8+
# __storage_storage_skip_checks — if set, used as storage_skip_checks instead of
9+
# the default [blivet_available, packages_installed conditional].
10+
# __storage_get_package_facts — default false: ansible.builtin.package_facts, then
11+
# blivet_pkg_version, and is_fedora / is_rhel* / is_rhel78.
12+
# __storage_get_unused_disks — default true: whether to include get_unused_disk.yml.
13+
# The playbook supplies this when needed; setup does not derive it.
14+
# __storage_min_size, __storage_max_return, __storage_max_size,
15+
# __storage_disks_needed, __storage_match_sector_size — passed to get_unused_disk.
16+
#
17+
- name: Run the role
18+
when: __storage_include_prep | default(true)
19+
block:
20+
- name: Run the role
21+
ansible.builtin.include_tasks: run_role_with_clear_facts.yml
22+
23+
- name: Mark tasks to be skipped
24+
ansible.builtin.set_fact:
25+
storage_skip_checks: >-
26+
{{
27+
__storage_storage_skip_checks
28+
if __storage_storage_skip_checks is defined
29+
else (
30+
['blivet_available',
31+
(lookup('env', 'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false'])
32+
| ternary('packages_installed', '')]
33+
)
34+
}}
35+
36+
- name: Gather package facts and set vars based on package facts
37+
when: __storage_get_package_facts | default(false)
38+
block:
39+
- name: Gather package facts
40+
ansible.builtin.package_facts:
41+
no_log: "{{ ansible_verbosity < 3 }}"
42+
43+
- name: Set blivet package version
44+
ansible.builtin.set_fact:
45+
blivet_pkg_version: "{{
46+
ansible_facts.packages[blivet_pkg_name[0]][0]['version'] +
47+
'-' + ansible_facts.packages[blivet_pkg_name[0]][0]['release'] }}"
48+
vars:
49+
blivet_pkg_name: "{{ ansible_facts.packages |
50+
select('search', 'blivet') | select('search', 'python') | list }}"
51+
52+
- name: Set distribution version flags
53+
ansible.builtin.set_fact:
54+
is_fedora: "{{ ansible_facts['distribution'] == 'Fedora' }}"
55+
is_rhel7: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '7' }}"
56+
is_rhel8: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '8' }}"
57+
is_rhel9: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '9' }}"
58+
is_rhel10: "{{ ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '10' }}"
59+
is_rhel78: "{{ ansible_facts['os_family'] == 'RedHat' and
60+
ansible_facts['distribution_major_version'] in ['7', '8'] }}"
61+
62+
- name: Get unused disks for test
63+
when: __storage_get_unused_disks | default(true)
64+
ansible.builtin.include_tasks: get_unused_disk.yml
65+
66+
- name: Get info about storage devices
67+
ansible.builtin.shell:
68+
executable: /bin/bash
69+
cmd: |
70+
set -euxo pipefail
71+
exec 1>&2
72+
lsblk -p --pairs --bytes -o NAME,TYPE,SIZE,FSTYPE,LOG-SEC,MOUNTPOINTS,PARTLABEL
73+
if type -p mdadm >/dev/null; then
74+
mdadm --misc --examine --scan
75+
fi
76+
if type -p dmsetup >/dev/null; then
77+
dmsetup ls --tree --separator /
78+
fi
79+
if type -p lvm >/dev/null; then
80+
lvm vgdisplay
81+
fi
82+
udevadm settle -t 0
83+
changed_when: false

tests/tests_change_disk_fs.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,11 @@
1010
if (ansible_facts['distribution'] == 'RedHat' and
1111
ansible_facts['distribution_major_version'] == '6')
1212
else 'ext4' }}"
13+
__storage_min_size: "{{ volume_size }}"
14+
__storage_max_return: 1
1315
tasks:
14-
- name: Run the role
15-
include_tasks: tasks/run_role_with_clear_facts.yml
16-
17-
- name: Mark tasks to be skipped
18-
set_fact:
19-
storage_skip_checks:
20-
- blivet_available
21-
- "{{ (lookup('env',
22-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
23-
ternary('packages_installed', '') }}"
24-
25-
- name: Get unused disks
26-
include_tasks: get_unused_disk.yml
27-
vars:
28-
min_size: "{{ volume_size }}"
29-
max_return: 1
16+
- name: Prep storage role and discover unused disks
17+
ansible.builtin.include_tasks: tasks/setup.yml
3018

3119
- name: Create a disk device with the default file system type
3220
include_tasks: tasks/run_role_with_clear_facts.yml

tests/tests_change_disk_mount.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
mount_location_before: '/opt/test1'
77
mount_location_after: '/opt/test2'
88
volume_size: '5g'
9+
__storage_min_size: "{{ volume_size }}"
10+
__storage_max_return: 1
911

1012
tasks:
1113
- name: Create blockdev and loop mount
@@ -19,22 +21,8 @@
1921
cat /proc/mounts | grep loop
2022
changed_when: false
2123

22-
- name: Run the role
23-
include_tasks: tasks/run_role_with_clear_facts.yml
24-
25-
- name: Mark tasks to be skipped
26-
set_fact:
27-
storage_skip_checks:
28-
- blivet_available
29-
- "{{ (lookup('env',
30-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
31-
ternary('packages_installed', '') }}"
32-
33-
- name: Get unused disks
34-
include_tasks: get_unused_disk.yml
35-
vars:
36-
min_size: "{{ volume_size }}"
37-
max_return: 1
24+
- name: Prep storage role and discover unused disks
25+
ansible.builtin.include_tasks: tasks/setup.yml
3826

3927
- name: Create a disk device mounted at "{{ mount_location_before }}"
4028
include_tasks: tasks/run_role_with_clear_facts.yml

tests/tests_change_fs.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,14 @@
99
fs_after: "{{ (ansible_facts['distribution'] == 'RedHat' and
1010
ansible_facts['distribution_major_version'] == '6') |
1111
ternary('ext4', 'xfs') }}"
12+
__storage_min_size: "{{ volume_size }}"
13+
__storage_max_return: 1
1214
tags:
1315
- tests::lvm
1416

1517
tasks:
16-
- name: Run the role
17-
include_tasks: tasks/run_role_with_clear_facts.yml
18-
19-
- name: Mark tasks to be skipped
20-
set_fact:
21-
storage_skip_checks:
22-
- blivet_available
23-
- "{{ (lookup('env',
24-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
25-
ternary('packages_installed', '') }}"
26-
27-
- name: Get unused disks
28-
include_tasks: get_unused_disk.yml
29-
vars:
30-
min_size: "{{ volume_size }}"
31-
max_return: 1
18+
- name: Prep storage role and discover unused disks
19+
ansible.builtin.include_tasks: tasks/setup.yml
3220

3321
- name: Create a LVM logical volume with default fs_type
3422
include_tasks: tasks/run_role_with_clear_facts.yml

tests/tests_change_fs_use_partitions.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,13 @@
1111
if (ansible_facts['distribution'] == 'RedHat' and
1212
ansible_facts['distribution_major_version'] == '6')
1313
else 'ext4' }}"
14+
__storage_min_size: "{{ volume_size }}"
15+
__storage_max_return: 1
1416
tags:
1517
- tests::lvm
1618
tasks:
17-
- name: Run the role
18-
include_tasks: tasks/run_role_with_clear_facts.yml
19-
20-
- name: Mark tasks to be skipped
21-
set_fact:
22-
storage_skip_checks:
23-
- blivet_available
24-
- "{{ (lookup('env',
25-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
26-
ternary('packages_installed', '') }}"
27-
28-
- name: Get unused disks
29-
include_tasks: get_unused_disk.yml
30-
vars:
31-
min_size: "{{ volume_size }}"
32-
max_return: 1
19+
- name: Prep storage role and discover unused disks
20+
ansible.builtin.include_tasks: tasks/setup.yml
3321

3422
- name: Create an LVM partition with the default file system type
3523
include_tasks: tasks/run_role_with_clear_facts.yml

tests/tests_change_mount.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,14 @@
66
mount_location_before: '/opt/test1'
77
mount_location_after: '/opt/test2'
88
volume_size: '3g'
9+
__storage_min_size: "{{ volume_size }}"
10+
__storage_max_return: 1
911
tags:
1012
- tests::lvm
1113

1214
tasks:
13-
- name: Run the role
14-
include_tasks: tasks/run_role_with_clear_facts.yml
15-
16-
- name: Mark tasks to be skipped
17-
set_fact:
18-
storage_skip_checks:
19-
- blivet_available
20-
- "{{ (lookup('env',
21-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
22-
ternary('packages_installed', '') }}"
23-
24-
- name: Get unused disks
25-
include_tasks: get_unused_disk.yml
26-
vars:
27-
min_size: "{{ volume_size }}"
28-
max_return: 1
15+
- name: Prep storage role and discover unused disks
16+
ansible.builtin.include_tasks: tasks/setup.yml
2917

3018
- name: Create a LVM logical volume mounted at {{ mount_location_before }}
3119
include_tasks: tasks/run_role_with_clear_facts.yml

tests/tests_create_disk_then_remove.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,11 @@
55
vars:
66
storage_safe_mode: false
77
mount_location: '/opt/test1'
8+
__storage_max_return: 1
89

910
tasks:
10-
- name: Run the role
11-
include_tasks: tasks/run_role_with_clear_facts.yml
12-
13-
- name: Mark tasks to be skipped
14-
set_fact:
15-
storage_skip_checks:
16-
- blivet_available
17-
- "{{ (lookup('env',
18-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
19-
ternary('packages_installed', '') }}"
20-
21-
- name: Get unused disks
22-
include_tasks: get_unused_disk.yml
23-
vars:
24-
max_return: 1
11+
- name: Prep storage role and discover unused disks
12+
ansible.builtin.include_tasks: tasks/setup.yml
2513

2614
- name: >-
2715
Create a disk device; specify disks as non-list mounted on

tests/tests_create_lv_size_equal_to_vg.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,14 @@
77
mount_location: '/opt/test1'
88
volume_group_size: '10g'
99
lv_size: '10g'
10+
__storage_min_size: "{{ volume_group_size }}"
11+
__storage_max_return: 1
1012
tags:
1113
- tests::lvm
1214

1315
tasks:
14-
- name: Run the role
15-
include_tasks: tasks/run_role_with_clear_facts.yml
16-
17-
- name: Mark tasks to be skipped
18-
set_fact:
19-
storage_skip_checks:
20-
- blivet_available
21-
- "{{ (lookup('env',
22-
'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
23-
ternary('packages_installed', '') }}"
24-
25-
- name: Get unused disks
26-
include_tasks: get_unused_disk.yml
27-
vars:
28-
min_size: "{{ volume_group_size }}"
29-
max_return: 1
16+
- name: Prep storage role and discover unused disks
17+
ansible.builtin.include_tasks: tasks/setup.yml
3018

3119
- name: Create one lv which size is equal to vg size
3220
include_tasks: tasks/run_role_with_clear_facts.yml

0 commit comments

Comments
 (0)