Skip to content

Commit 4e82886

Browse files
committed
[config_drive] Fix _net_data_change assertion for soft-clean scenario
Apply the same fix as _user_data_change: handle skipped tasks when cifmw_config_drive_networkconfig is undefined on subsequent runs. - Update assert to check: _userdata/_netdata is not none, since these are set in defaults/main.yml they will never be undefined. - Update assertion to check: _net_data_change is skipped or is not changed - Make network-config when condition consistent with user-data (add | length > 0) - Add soft-clean test coverage to default molecule scenario This prevents assertion failures when create-infra is run after a soft clean where the ISO already exists but network-config vars are undefined. Jira: OSPRH-22377 Assisted-By: Claude Code/claude-4.5-sonnet Signed-off-by: Harald Jensås <hjensas@redhat.com>
1 parent 06f336f commit 4e82886

File tree

2 files changed

+160
-5
lines changed

2 files changed

+160
-5
lines changed

roles/config_drive/molecule/default/converge.yml

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- name: Converge
1919
hosts: all
2020
tasks:
21-
- name: Include config_drive role
21+
- name: Include config_drive role with full configuration
2222
vars:
2323
cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850
2424
cifmw_config_drive_name: test01
@@ -54,3 +54,158 @@
5454
- 192.168.0.1
5555
ansible.builtin.include_role:
5656
name: config_drive
57+
58+
- name: Run config_drive role again without user-data or network-config (soft-clean scenario)
59+
vars:
60+
cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850
61+
cifmw_config_drive_name: test01
62+
cifmw_config_drive_hostname: test01.example.com
63+
# cifmw_config_drive_userdata is not defined (simulating soft clean)
64+
# cifmw_config_drive_networkconfig is not defined (simulating soft clean)
65+
ansible.builtin.include_role:
66+
name: config_drive
67+
68+
- name: Verify ISO still exists after soft-clean
69+
ansible.builtin.stat:
70+
path: "{{ cifmw_config_drive_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/artifacts/cifmw_config_drive/de2f369a-1886-4a90-8e50-e419289e6850.iso"
71+
register: _iso_check
72+
73+
- name: Assert ISO exists
74+
ansible.builtin.assert:
75+
that:
76+
- _iso_check.stat.exists
77+
fail_msg: "ISO file should exist after soft-clean scenario"
78+
success_msg: "Soft-clean scenario passed - ISO exists and role didn't fail on skipped tasks"
79+
80+
- name: Run config_drive role again with same configuration (should pass - no changes)
81+
vars:
82+
cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850
83+
cifmw_config_drive_name: test01
84+
cifmw_config_drive_hostname: test01.example.com
85+
cifmw_config_drive_userdata:
86+
ssh_authorized_keys:
87+
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCg1LHRahLiT1NFv4l/XH
88+
packages:
89+
- git
90+
- bind-utils
91+
write_files:
92+
- path: /root/test.file
93+
owner: root:root
94+
content: |-
95+
# Test file content
96+
runcmd:
97+
- ['sh', '-c', 'echo foo | tee -a /tmp/foo']
98+
cifmw_config_drive_networkconfig:
99+
network:
100+
version: 2
101+
ethernets:
102+
id0:
103+
match:
104+
macaddress: "aa:bb:cc:dd:ee:ff"
105+
addresses:
106+
- 192.168.0.101/24
107+
routes:
108+
- to: 0.0.0.0/0
109+
via: 192.168.0.1
110+
on-link: true
111+
nameservers:
112+
addresses:
113+
- 192.168.0.1
114+
ansible.builtin.include_role:
115+
name: config_drive
116+
117+
- name: Attempt to change user-data on existing ISO (should fail)
118+
block:
119+
- name: Include config_drive with modified user-data
120+
vars:
121+
cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850
122+
cifmw_config_drive_name: test01
123+
cifmw_config_drive_hostname: test01.example.com
124+
cifmw_config_drive_userdata:
125+
ssh_authorized_keys:
126+
- ssh-rsa DIFFERENT_KEY_HERE
127+
packages:
128+
- vim # Changed from git
129+
cifmw_config_drive_networkconfig:
130+
network:
131+
version: 2
132+
ethernets:
133+
id0:
134+
match:
135+
macaddress: "aa:bb:cc:dd:ee:ff"
136+
addresses:
137+
- 192.168.0.101/24
138+
routes:
139+
- to: 0.0.0.0/0
140+
via: 192.168.0.1
141+
on-link: true
142+
nameservers:
143+
addresses:
144+
- 192.168.0.1
145+
ansible.builtin.include_role:
146+
name: config_drive
147+
148+
- name: Fail if role didn't reject the change
149+
ansible.builtin.fail:
150+
msg: "Role should have failed when trying to change user-data on existing ISO"
151+
152+
rescue:
153+
- name: Verify the failure was due to ISO modification attempt
154+
ansible.builtin.assert:
155+
that:
156+
- ansible_failed_result.msg is defined
157+
- ansible_failed_result.msg is regex('trying to edit an existing ISO', ignorecase=True)
158+
fail_msg: "Role failed but not with expected error message. Got: {{ ansible_failed_result.msg | default('no message') }}"
159+
success_msg: "Role correctly rejected attempt to change user-data"
160+
161+
- name: Attempt to change network-config on existing ISO (should fail)
162+
block:
163+
- name: Include config_drive with modified network-config
164+
vars:
165+
cifmw_config_drive_uuid: de2f369a-1886-4a90-8e50-e419289e6850
166+
cifmw_config_drive_name: test01
167+
cifmw_config_drive_hostname: test01.example.com
168+
cifmw_config_drive_userdata:
169+
ssh_authorized_keys:
170+
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCg1LHRahLiT1NFv4l/XH
171+
packages:
172+
- git
173+
- bind-utils
174+
write_files:
175+
- path: /root/test.file
176+
owner: root:root
177+
content: |-
178+
# Test file content
179+
runcmd:
180+
- ['sh', '-c', 'echo foo | tee -a /tmp/foo']
181+
cifmw_config_drive_networkconfig:
182+
network:
183+
version: 2
184+
ethernets:
185+
id0:
186+
match:
187+
macaddress: "11:22:33:44:55:66" # Changed MAC address
188+
addresses:
189+
- 192.168.0.200/24 # Changed IP
190+
routes:
191+
- to: 0.0.0.0/0
192+
via: 192.168.0.1
193+
on-link: true
194+
nameservers:
195+
addresses:
196+
- 192.168.0.1
197+
ansible.builtin.include_role:
198+
name: config_drive
199+
200+
- name: Fail if role didn't reject the change
201+
ansible.builtin.fail:
202+
msg: "Role should have failed when trying to change network-config on existing ISO"
203+
204+
rescue:
205+
- name: Verify the failure was due to ISO modification attempt
206+
ansible.builtin.assert:
207+
that:
208+
- ansible_failed_result.msg is defined
209+
- ansible_failed_result.msg is regex('trying to edit an existing ISO', ignorecase=True)
210+
fail_msg: "Role failed but not with expected error message. Got: {{ ansible_failed_result.msg | default('no message') }}"
211+
success_msg: "Role correctly rejected attempt to change network-config"

roles/config_drive/tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
- name: Generate user-data
5252
register: _user_data_change
5353
when:
54-
- cifmw_config_drive_userdata is defined
54+
- cifmw_config_drive_userdata is not none
5555
- cifmw_config_drive_userdata | length > 0
5656
ansible.builtin.template:
5757
backup: true
@@ -62,8 +62,8 @@
6262
- name: Generate network-data
6363
register: _net_data_change
6464
when:
65-
- cifmw_config_drive_networkconfig is defined
66-
- cifmw_config_drive_networkconfig
65+
- cifmw_config_drive_networkconfig is not none
66+
- cifmw_config_drive_networkconfig | length > 0
6767
ansible.builtin.template:
6868
backup: true
6969
src: "network-config.j2"
@@ -85,7 +85,7 @@
8585
that:
8686
- _meta_data_change is not changed
8787
- _user_data_change is skipped or _user_data_change is not changed
88-
- _net_data_change is not changed
88+
- _net_data_change is skipped or _net_data_change is not changed
8989
msg: >-
9090
You're trying to edit an existing ISO. This isn't possible,
9191
since the ISO is usually attached to a virtual machine, and

0 commit comments

Comments
 (0)