Skip to content

Commit 05e6abf

Browse files
committed
gen_hosts: use kdevops_workflow_name directly for template selection
The hosts.j2 template had become unwieldy with 40+ lines of conditional logic to select which workflow template to include. Since kdevops already defines KDEVOPS_WORKFLOW_NAME in Kconfig that's always set (either to the workflow name or "mix" for non-dedicated), we can eliminate ALL conditional logic. The entire hosts.j2 is now just: {% include 'workflows/' + kdevops_workflow_name + '.j2' %} This massive simplification: - Reduces hosts.j2 from 40+ lines to just 1 line of logic - Removes ALL conditional template selection from gen_hosts playbook - Eliminates ALL workflow-specific template overrides from Makefiles - Makes adding new workflows trivial - just define KDEVOPS_WORKFLOW_NAME Additional changes: - Split monolithic hosts.j2 into per-workflow templates under workflows/ - Rename default.j2 to mix.j2 to match non-dedicated workflow name - Add missing 'cxl' to KDEVOPS_WORKFLOW_NAME in main Kconfig - Add KDEVOPS_WORKFLOW_NAME to reboot-limit demo workflow Generated-by: Claude AI Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 453a5b2 commit 05e6abf

File tree

32 files changed

+841
-534
lines changed

32 files changed

+841
-534
lines changed

kconfigs/workflows/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ config KDEVOPS_WORKFLOW_NAME
228228
output yaml
229229
default "fstests" if KDEVOPS_WORKFLOW_DEDICATE_FSTESTS
230230
default "blktests" if KDEVOPS_WORKFLOW_DEDICATE_BLKTESTS
231+
default "cxl" if KDEVOPS_WORKFLOW_DEDICATE_CXL
231232
default "pynfs" if KDEVOPS_WORKFLOW_DEDICATE_PYNFS
232233
default "selftests" if KDEVOPS_WORKFLOW_DEDICATE_SELFTESTS
233234
default "gitr" if KDEVOPS_WORKFLOW_DEDICATE_GITR
@@ -514,4 +515,12 @@ endif # WORKFLOWS_LINUX_TESTS
514515

515516
endif # WORKFLOWS_TESTS
516517

518+
# For Linux custom workflow without tests, still need workflow name for templating
519+
if WORKFLOW_LINUX_CUSTOM && !WORKFLOWS_TESTS
520+
config KDEVOPS_WORKFLOW_NAME
521+
string
522+
output yaml
523+
default "linux"
524+
endif
525+
517526
endif # WORKFLOWS

playbooks/roles/gen_hosts/tasks/main.yml

Lines changed: 34 additions & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -56,180 +56,22 @@
5656
when:
5757
- is_fstests|bool
5858

59-
- name: Generate the Ansible hosts file for a Linux kernel build
60-
tags: ["hosts"]
61-
ansible.builtin.template:
62-
src: "{{ kdevops_hosts_template }}"
63-
dest: "{{ ansible_cfg_inventory }}"
64-
force: true
65-
trim_blocks: true
66-
lstrip_blocks: true
67-
when:
68-
- bootlinux_builder
69-
- ansible_hosts_template.stat.exists
70-
71-
- name: Generate the Ansible inventory file
72-
tags: ["hosts"]
73-
ansible.builtin.template:
74-
src: "{{ kdevops_hosts_template }}"
75-
dest: "{{ ansible_cfg_inventory }}"
76-
force: true
77-
trim_blocks: true
78-
lstrip_blocks: true
79-
when:
80-
- not kdevops_workflows_dedicated_workflow
81-
- ansible_hosts_template.stat.exists
82-
- not kdevops_enable_nixos|default(false)|bool
83-
84-
- name: Generate the Ansible inventory file for NixOS
85-
tags: ['hosts']
86-
ansible.builtin.template:
87-
src: "{{ kdevops_hosts_template }}"
88-
dest: "{{ ansible_cfg_inventory }}"
89-
force: true
90-
trim_blocks: True
91-
lstrip_blocks: True
92-
when:
93-
- not kdevops_workflows_dedicated_workflow
94-
- ansible_hosts_template.stat.exists
95-
- kdevops_enable_nixos|default(false)|bool
96-
97-
- name: Update Ansible inventory access modification time so make sees it updated
98-
ansible.builtin.file:
99-
path: "{{ ansible_cfg_inventory }}"
100-
state: touch
101-
mode: "0755"
102-
103-
- name: Generate the Ansible inventory file for dedicated cxl work
104-
tags: ["hosts"]
105-
ansible.builtin.template:
106-
src: "{{ kdevops_hosts_template }}"
107-
dest: "{{ anisble_cfg_inventory }}"
108-
force: true
109-
trim_blocks: true
110-
lstrip_blocks: true
111-
when:
112-
- kdevops_workflows_dedicated_workflow
113-
- kdevops_workflow_enable_cxl
114-
- ansible_hosts_template.stat.exists
115-
116-
- name: Generate the Ansible inventory file for dedicated pynfs work
117-
tags: ["hosts"]
118-
ansible.builtin.template:
119-
src: "{{ kdevops_hosts_template }}"
120-
dest: "{{ ansible_cfg_inventory }}"
121-
force: true
122-
trim_blocks: true
123-
lstrip_blocks: true
124-
when:
125-
- kdevops_workflows_dedicated_workflow
126-
- kdevops_workflow_enable_pynfs
127-
- ansible_hosts_template.stat.exists
128-
129-
- name: Generate the Ansible inventory file for dedicated gitr workflow
130-
tags: ["hosts"]
131-
vars:
132-
gitr_enabled_hosts: "{{ gitr_enabled_test_groups | ansible.builtin.split }}"
133-
ansible.builtin.template:
134-
src: "{{ kdevops_hosts_template }}"
135-
dest: "{{ ansible_cfg_inventory }}"
136-
force: true
137-
trim_blocks: true
138-
lstrip_blocks: true
139-
when:
140-
- kdevops_workflows_dedicated_workflow
141-
- kdevops_workflow_enable_gitr
142-
- ansible_hosts_template.stat.exists
143-
144-
- name: Generate an Ansible inventory file for a dedicated ltp workflow
59+
- name: Infer enabled fstests test section types
14560
tags: ["hosts"]
146-
vars:
147-
ltp_enabled_hosts: "{{ ltp_enabled_test_groups | ansible.builtin.split }}"
148-
ansible.builtin.template:
149-
src: "{{ kdevops_hosts_template }}"
150-
dest: "{{ ansible_cfg_inventory }}"
151-
force: true
152-
trim_blocks: true
153-
lstrip_blocks: true
154-
when:
155-
- kdevops_workflows_dedicated_workflow
156-
- kdevops_workflow_enable_ltp
157-
- ansible_hosts_template.stat.exists
158-
159-
- name: Generate the Ansible inventory file for dedicated nfstest workflow
160-
tags: ["hosts"]
161-
vars:
162-
nfstest_enabled_hosts: "{{ nfstest_enabled_test_groups | ansible.builtin.split }}"
163-
ansible.builtin.template:
164-
src: "{{ kdevops_hosts_template }}"
165-
dest: "{{ ansible_cfg_inventory }}"
166-
force: true
167-
trim_blocks: true
168-
lstrip_blocks: true
169-
when:
170-
- kdevops_workflows_dedicated_workflow
171-
- kdevops_workflow_enable_nfstest
172-
- ansible_hosts_template.stat.exists
173-
174-
- name: Set empty enabled test types list for fstests
175-
tags: ["hosts"]
176-
ansible.builtin.set_fact:
177-
fstests_enabled_test_types: []
178-
when:
179-
- is_fstests
180-
- ansible_hosts_template.stat.exists
181-
182-
- name: Check which fstests test types are enabled
183-
register: fstests_enabled_test_types_reg
18461
vars:
18562
fs: "{{ fstests_fstyp | upper }}"
186-
config_val: "{{ 'CONFIG_FSTESTS_' + fs + '_SECTION_' }}"
187-
fs_config_data: "{{ lookup('file', fs_config_path) }}"
188-
sections_without_default: "{{ fs_config_data | regex_replace('\\[default\\]', multiline=True) }}"
189-
sections_without_default_and_nfsd: "{{ sections_without_default | regex_replace('\\[nfsd\\]', multiline=True) }}"
190-
sections_lines: "{{ sections_without_default_and_nfsd | regex_findall('^\\[(.*)', multiline=True) }}"
191-
clean_section_lines: "{{ sections_lines | regex_replace('\\[') | regex_replace('\\]') }}"
192-
clean_section_lines_without_fsname: "{{ clean_section_lines | regex_replace(fstests_fstyp + '_') }}"
193-
config_sections_targets: "{{ clean_section_lines_without_fsname | replace(\"'\", '') | split(', ') }}"
194-
ansible.builtin.lineinfile:
195-
path: "{{ topdir_path }}/.config"
196-
regexp: "^({{ config_val + item.upper() }})=y"
197-
line: ""
198-
check_mode: true
199-
with_items: "{{ config_sections_targets }}"
200-
loop_control:
201-
label: "Checking for {{ config_val + item.upper() }}"
202-
when:
203-
- is_fstests
204-
- ansible_hosts_template.stat.exists
205-
206-
- name: Now expand the list of enabled fstests for valid configuration sections
207-
tags: ["hosts"]
63+
config_prefix: "{{ 'CONFIG_FSTESTS_' + fs + '_SECTION_' }}"
20864
ansible.builtin.set_fact:
209-
fstests_enabled_test_types: "{{ fstests_enabled_test_types + [fstests_fstyp + '-' + item.item | regex_replace('_', '-')] }}"
210-
with_items: "{{ fstests_enabled_test_types_reg.results }}"
211-
loop_control:
212-
label: "Checking for {{ item.item }} "
213-
when:
214-
- is_fstests
215-
- ansible_hosts_template.stat.exists
216-
- item.changed
217-
218-
- name: Generate the Ansible inventory file for a dedicated fstests setup
219-
tags: ["hosts"]
220-
vars:
221-
fs_config_data: "{{ lookup('file', fs_config_path) }}"
222-
sections_without_default: "{{ fs_config_data | regex_replace('\\[default\\]', multiline=True) }}"
223-
sections_lines: "{{ sections_without_default | regex_findall('^\\[(.*)', multiline=True) }}"
224-
clean_section_lines: "{{ sections_lines | regex_replace('\\[') | regex_replace('\\]') }}"
225-
sections_replace_underscore: "{{ clean_section_lines | replace('_', '-') }}"
226-
sections: "{{ sections_replace_underscore | replace(\"'\", '') | split(', ') }}"
227-
ansible.builtin.template:
228-
src: "{{ kdevops_hosts_template }}"
229-
dest: "{{ ansible_cfg_inventory }}"
230-
force: true
231-
trim_blocks: true
232-
lstrip_blocks: true
65+
fstests_enabled_test_types: >-
66+
{{
67+
lookup('file', topdir_path + '/.config')
68+
| regex_findall('^' + config_prefix + '(.*)=y$', multiline=True)
69+
| reject('match', '.*_ENABLED$')
70+
| map('lower')
71+
| map('regex_replace', '_', '-')
72+
| map('regex_replace', '^', fstests_fstyp + '-')
73+
| list
74+
}}
23375
when:
23476
- is_fstests
23577
- ansible_hosts_template.stat.exists
@@ -257,19 +99,6 @@
25799
- kdevops_workflow_enable_blktests
258100
- ansible_hosts_template.stat.exists
259101

260-
- name: Generate the Ansible inventory file for a dedicated blktests setup
261-
tags: ["hosts"]
262-
ansible.builtin.template:
263-
src: "{{ kdevops_hosts_template }}"
264-
dest: "{{ ansible_cfg_inventory }}"
265-
force: true
266-
trim_blocks: true
267-
lstrip_blocks: true
268-
when:
269-
- kdevops_workflows_dedicated_workflow
270-
- kdevops_workflow_enable_blktests
271-
- ansible_hosts_template.stat.exists
272-
273102
- name: Infer enabled selftests test section types
274103
ansible.builtin.set_fact:
275104
selftests_enabled_test_types: >-
@@ -284,19 +113,6 @@
284113
- kdevops_workflow_enable_selftests
285114
- ansible_hosts_template.stat.exists
286115

287-
- name: Generate the Ansible inventory file for a dedicated selftests setup
288-
tags: ["hosts"]
289-
ansible.builtin.template:
290-
src: "{{ kdevops_hosts_template }}"
291-
dest: "{{ ansible_cfg_inventory }}"
292-
force: true
293-
trim_blocks: true
294-
lstrip_blocks: true
295-
when:
296-
- kdevops_workflows_dedicated_workflow
297-
- kdevops_workflow_enable_selftests
298-
- ansible_hosts_template.stat.exists
299-
300116
- name: Collect dynamically supported filesystems
301117
vars:
302118
supported_filesystems_variables: "{{ hostvars[inventory_hostname] | dict2items | selectattr('key', 'search', '^sysbench_supported_filesystem_') }}"
@@ -326,36 +142,6 @@
326142
- kdevops_workflows_dedicated_workflow
327143
- kdevops_workflow_enable_sysbench
328144

329-
- name: Generate the Ansible inventory file for a dedicated sysbench setup
330-
tags: ["hosts"]
331-
ansible.builtin.template:
332-
src: "{{ kdevops_hosts_template }}"
333-
dest: "{{ ansible_cfg_inventory }}"
334-
force: true
335-
trim_blocks: true
336-
lstrip_blocks: true
337-
when:
338-
- kdevops_workflows_dedicated_workflow
339-
- kdevops_workflow_enable_sysbench
340-
- ansible_hosts_template.stat.exists
341-
342-
343-
- name: Generate the Ansible hosts file for a dedicated fio-tests setup
344-
tags: ["hosts"]
345-
ansible.builtin.template:
346-
src: "{{ kdevops_hosts_template }}"
347-
dest: "{{ ansible_cfg_inventory }}"
348-
force: true
349-
trim_blocks: true
350-
lstrip_blocks: true
351-
mode: "0644"
352-
when:
353-
- kdevops_workflows_dedicated_workflow
354-
- kdevops_workflow_enable_fio_tests
355-
- ansible_hosts_template.stat.exists
356-
- not kdevops_enable_nixos|default(false)|bool
357-
358-
359145
- name: Infer enabled mmtests test types
360146
ansible.builtin.set_fact:
361147
mmtests_enabled_test_types: >-
@@ -370,32 +156,6 @@
370156
- kdevops_workflow_enable_mmtests
371157
- ansible_hosts_template.stat.exists
372158

373-
- name: Generate the Ansible hosts file for a dedicated mmtests setup
374-
tags: ["hosts"]
375-
ansible.builtin.template:
376-
src: "{{ kdevops_hosts_template }}"
377-
dest: "{{ ansible_cfg_inventory }}"
378-
force: true
379-
trim_blocks: true
380-
lstrip_blocks: true
381-
when:
382-
- kdevops_workflows_dedicated_workflow
383-
- kdevops_workflow_enable_mmtests
384-
- ansible_hosts_template.stat.exists
385-
386-
- name: Generate the Ansible hosts file for a dedicated reboot-limit setup
387-
tags: ["hosts"]
388-
ansible.builtin.template:
389-
src: "{{ kdevops_hosts_template }}"
390-
dest: "{{ ansible_cfg_inventory }}"
391-
force: true
392-
trim_blocks: true
393-
lstrip_blocks: true
394-
when:
395-
- kdevops_workflows_dedicated_workflow
396-
- workflows_reboot_limit
397-
- ansible_hosts_template.stat.exists
398-
399159
- name: Load AI nodes configuration for multi-filesystem setup
400160
include_vars:
401161
file: "{{ topdir_path }}/{{ kdevops_nodes }}"
@@ -415,20 +175,35 @@
415175
- ai_enable_multifs_testing|default(false)|bool
416176
- guestfs_nodes is defined
417177

418-
- name: Generate the Ansible hosts file for a dedicated AI setup
419-
tags: ['hosts']
178+
- name: Generate the Ansible inventory file
179+
tags: ["hosts"]
180+
vars:
181+
# Variables for specific workflows
182+
gitr_enabled_hosts: "{{ gitr_enabled_test_groups | ansible.builtin.split if kdevops_workflow_enable_gitr else [] }}"
183+
ltp_enabled_hosts: "{{ ltp_enabled_test_groups | ansible.builtin.split if kdevops_workflow_enable_ltp else [] }}"
184+
nfstest_enabled_hosts: "{{ nfstest_enabled_test_groups | ansible.builtin.split if kdevops_workflow_enable_nfstest else [] }}"
185+
# Variables for fstests
186+
fs_config_data: "{{ lookup('file', fs_config_path) if is_fstests else '' }}"
187+
sections_without_default: "{{ fs_config_data | regex_replace('\\[default\\]', multiline=True) if is_fstests else '' }}"
188+
sections_lines: "{{ sections_without_default | regex_findall('^\\[(.*)', multiline=True) if is_fstests else [] }}"
189+
clean_section_lines: "{{ sections_lines | regex_replace('\\[') | regex_replace('\\]') if is_fstests else [] }}"
190+
sections_replace_underscore: "{{ clean_section_lines | replace('_', '-') if is_fstests else [] }}"
191+
sections: "{{ sections_replace_underscore | replace(\"'\", '') | split(', ') if is_fstests else [] }}"
420192
ansible.builtin.template:
421193
src: "{{ kdevops_hosts_template }}"
422194
dest: "{{ ansible_cfg_inventory }}"
423195
force: true
424-
trim_blocks: True
425-
lstrip_blocks: True
426-
mode: '0644'
196+
trim_blocks: true
197+
lstrip_blocks: true
427198
when:
428-
- kdevops_workflows_dedicated_workflow
429-
- kdevops_workflow_enable_ai
430199
- ansible_hosts_template.stat.exists
431200

201+
- name: Update Ansible inventory access modification time so make sees it updated
202+
ansible.builtin.file:
203+
path: "{{ ansible_cfg_inventory }}"
204+
state: touch
205+
mode: "0755"
206+
432207
- name: Verify if final host file exists
433208
ansible.builtin.stat:
434209
path: "{{ ansible_cfg_inventory }}"

0 commit comments

Comments
 (0)