Skip to content

Commit c253135

Browse files
committed
test: add test for crashkernel, dracut settings
Add tests for crashkernel, dracut_args settings. Add Fedora as a platform that has support for crashkernel and dracut_args. Refactor the code somewhat.
1 parent d4ff228 commit c253135

File tree

3 files changed

+107
-31
lines changed

3 files changed

+107
-31
lines changed

tasks/main.yml

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,22 @@
3838
- name: Set the kdump_reboot_required fact
3939
set_fact:
4040
kdump_reboot_required: "{{
41-
kexec_crash_size.content | b64decode | int < 1
42-
}}"
41+
kexec_crash_size.content | b64decode | int < 1 }}"
4342

44-
- name: Use kdumpctl reset-crashkernel if needed
45-
command: kdumpctl reset-crashkernel --kernel=ALL
43+
- name: Update crashkernel setting if needed
4644
when:
4745
- kdump_reboot_required | bool
48-
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
49-
- ansible_facts['distribution_major_version'] | int >= 9
50-
changed_when:
51-
- kdump_reboot_required | bool
52-
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
53-
- ansible_facts['distribution_major_version'] | int >= 9
46+
- ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Fedora']
47+
block:
48+
- name: Use kdumpctl reset-crashkernel if needed
49+
command: kdumpctl reset-crashkernel --kernel=ALL
50+
when: ansible_facts['distribution_major_version'] | int >= 9
51+
changed_when: true
5452

55-
- name: Use grubby to update crashkernel=auto if needed
56-
command: grubby --args="crashkernel=auto" --update-kernel=ALL
57-
when:
58-
- kdump_reboot_required | bool
59-
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
60-
- ansible_facts['distribution_major_version'] | int <= 8
61-
changed_when:
62-
- kdump_reboot_required | bool
63-
- ansible_facts['distribution'] in ['RedHat', 'CentOS']
64-
- ansible_facts['distribution_major_version'] | int <= 8
53+
- name: Use grubby to update crashkernel=auto if needed
54+
command: grubby --args=crashkernel=auto --update-kernel=ALL
55+
when: ansible_facts['distribution_major_version'] | int <= 8
56+
changed_when: true
6557

6658
- name: Fail if reboot is required and kdump_reboot_ok is false
6759
fail:

templates/kdump.conf.j2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ core_collector {{ kdump_core_collector }}
2020
{% endif %}
2121
default {{ kdump_system_action }}
2222

23-
{% if ansible_facts['distribution'] in ['RedHat', 'CentOS'] %}
23+
{% if ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Fedora'] %}
2424
{% if ansible_facts['distribution_major_version'] | int >= 9 %}
25-
{% if kdump_auto_reset_crashkernel %}
26-
auto_reset_crashkernel yes
27-
{% else %}
28-
auto_reset_crashkernel no
29-
{% endif %}
25+
auto_reset_crashkernel {{ kdump_auto_reset_crashkernel | bool | ternary("yes", "no") }}
3026
{% endif %}
3127
{% if ansible_facts['distribution_major_version'] | int >= 7 %}
3228
{% if kdump_dracut_args %}

tests/tests_default_reboot.yml

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
hosts: all
44
vars:
55
kdump_reboot_ok: true
6+
kdump_dracut_args: --kernel-cmdline nopti
7+
kdump_auto_reset_crashkernel: true
68
tags:
79
- tests::reboot
810
tasks:
@@ -12,10 +14,96 @@
1214

1315
- name: Check generated files for ansible_managed, fingerprint
1416
include_tasks: tasks/check_header.yml
15-
loop:
16-
- /etc/kdump.conf
17-
- /etc/sysconfig/kdump
18-
loop_control:
19-
loop_var: __file
2017
vars:
2118
__fingerprint: "system_role:kdump"
19+
__file: /etc/kdump.conf
20+
21+
- name: See if el9 or later, or el7 or el8
22+
set_fact:
23+
is_el9: "{{
24+
ansible_facts['distribution'] in ['RedHat', 'CentOS', 'Fedora']
25+
and ansible_facts['distribution_major_version'] | int >= 9 }}"
26+
is_el7_or_el8: "{{
27+
ansible_facts['distribution'] in ['RedHat', 'CentOS']
28+
and ansible_facts['distribution_major_version'] | int in [7, 8] }}"
29+
30+
- name: Check for crashkernel, grubby settings
31+
when: is_el9 or is_el7_or_el8
32+
block:
33+
- name: Check parameters in conf file
34+
command: grep '^{{ item.param }} {{ item.value }}$' /etc/kdump.conf
35+
changed_when: false
36+
loop: "{{ params + (is_el9 | ternary(el9_params, [])) }}"
37+
vars:
38+
el9_params:
39+
- param: auto_reset_crashkernel
40+
value: "{{ kdump_auto_reset_crashkernel |
41+
ternary('yes', 'no') }}"
42+
params:
43+
- param: dracut_args
44+
value: "{{ kdump_dracut_args }}"
45+
46+
- name: Get crashkernel setting EL 9 and later
47+
command: kdumpctl get-default-crashkernel
48+
changed_when: false
49+
register: __crashkernel
50+
when: is_el9 | bool
51+
52+
- name: Get crashkernel setting EL 8 and earlier
53+
set_fact:
54+
__crashkernel:
55+
stdout: auto
56+
when: is_el7_or_el8 | bool
57+
58+
- name: Check for crashkernel setting
59+
shell: >
60+
set -euo pipefail;
61+
grubby --info=ALL | grep -E {{ pattern | quote }}
62+
changed_when: false
63+
vars:
64+
pattern: ^args=.* crashkernel={{ __crashkernel.stdout }}( |"|$)
65+
66+
- name: Change parameters and run the role again
67+
set_fact:
68+
kdump_auto_reset_crashkernel: false
69+
kdump_dracut_args: --print-cmdline
70+
71+
- name: Run the role again with new parameters
72+
include_role:
73+
name: linux-system-roles.kdump
74+
75+
- name: Check for crashkernel, grubby settings
76+
when: is_el9 or is_el7_or_el8
77+
block:
78+
- name: Check parameters in conf file
79+
command: grep '^{{ item.param }} {{ item.value }}$' /etc/kdump.conf
80+
changed_when: false
81+
loop: "{{ params + (is_el9 | ternary(el9_params, [])) }}"
82+
vars:
83+
el9_params:
84+
- param: auto_reset_crashkernel
85+
value: "{{ kdump_auto_reset_crashkernel |
86+
ternary('yes', 'no') }}"
87+
params:
88+
- param: dracut_args
89+
value: "{{ kdump_dracut_args }}"
90+
91+
- name: Get crashkernel setting EL 9 and later
92+
command: kdumpctl get-default-crashkernel
93+
changed_when: false
94+
register: __crashkernel
95+
when: is_el9 | bool
96+
97+
- name: Get crashkernel setting EL 8 and earlier
98+
set_fact:
99+
__crashkernel:
100+
stdout: auto
101+
when: is_el7_or_el8 | bool
102+
103+
- name: Check for crashkernel setting
104+
shell: >
105+
set -euo pipefail;
106+
grubby --info=ALL | grep -E {{ pattern | quote }}
107+
changed_when: false
108+
vars:
109+
pattern: ^args=.* crashkernel={{ __crashkernel.stdout }}( |"|$)

0 commit comments

Comments
 (0)