Skip to content

Commit b96f8ed

Browse files
fix: files: overwrite firewalld.conf on previous replaced (#176)
* fix: files: overwrite firewalld.conf on reset on previous replaced, revert firewalld.conf to fallback configuration instead of deletion Signed-off-by: Brennan Paciorek <bpaciore@redhat.com> * files: remove pipefail for rpm verify block * tests: purge_config: evaluate firewalld.conf checksums after purge --------- Signed-off-by: Brennan Paciorek <bpaciore@redhat.com>
1 parent e4042f1 commit b96f8ed

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

files/get_files_checksums.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ find "$firewall_conf_root" -name \*.xml | while read -r file; do
3030
fi
3131
done > "$listfile"
3232

33+
set +o pipefail
34+
3335
orig_conf="$firewall_conf_root/firewalld.conf"
3436
remove_firewall_conf=true
3537
if [ -f "$orig_conf" ]; then
@@ -48,10 +50,21 @@ fc.write()
4850
fi
4951
fi
5052

53+
set -o pipefail
54+
5155
if [ "${remove:-false}" = true ]; then
5256
find "$firewall_conf_root" -name \*.xml -exec rm -f {} \;
5357
if [ "$remove_firewall_conf" = true ]; then
54-
rm -f "$orig_conf"
58+
"$python_cmd" -c 'import sys
59+
from firewall.core.io.firewalld_conf import firewalld_conf
60+
fc = firewalld_conf(None) # open(None, "r") throws an Exception in fc.read()
61+
try:
62+
fc.read() # should populate fallback configuration
63+
except Exception:
64+
pass
65+
fc.filename=sys.argv[1] # Change target firewalld.conf write target
66+
fc.write() # update firewalld.conf
67+
' "$orig_conf" 2>/dev/null
5568
fi
5669
if [ -s "$listfile" ] ; then
5770
firewall-cmd --reload > /dev/null

tests/tests_purge_config.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,58 @@
143143
fail:
144144
msg: The role reported changes
145145
when: firewall_lib_result.changed # noqa no-handler
146+
147+
### Test firewalld.conf reset
148+
149+
- name: Change default zone (Change firewalld.conf)
150+
include_role:
151+
name: linux-system-roles.firewall
152+
vars:
153+
firewall:
154+
- set_default_zone: internal
155+
156+
- name: Get stats for firewalld.conf
157+
stat:
158+
path: /etc/firewalld/firewalld.conf
159+
register: __stat_before
160+
failed_when: not __stat_before.stat.exists
161+
162+
- name: Purge config
163+
include_role:
164+
name: linux-system-roles.firewall
165+
vars:
166+
firewall:
167+
- previous: replaced
168+
169+
- name: Fail if /etc/firewalld/firewalld.conf no longer exists
170+
stat:
171+
path: /etc/firewalld/firewalld.conf
172+
register: __stat_after_a
173+
failed_when: not __stat_after_a.stat.exists
174+
175+
- name: Assert that collected firewalld.conf checksums do not match
176+
fail:
177+
msg: firewalld.conf should have changed on reset
178+
when: __stat_before.stat.checksum == __stat_after_a.stat.checksum
179+
180+
- name: Purge config (no changes made since last purge)
181+
include_role:
182+
name: linux-system-roles.firewall
183+
vars:
184+
firewall:
185+
- previous: replaced
186+
187+
- name: Fail if /etc/firewalld/firewalld.conf no longer exists
188+
stat:
189+
path: /etc/firewalld/firewalld.conf
190+
register: __stat_after_b
191+
failed_when: not __stat_after_b.stat.exists
192+
193+
- name: Assert that collected firewalld.conf checksums match
194+
fail:
195+
msg: firewalld.conf should have changed on reset
196+
when: __stat_after_a.stat.checksum != __stat_after_b.stat.checksum
197+
146198
always:
147199
- name: Cleanup
148200
tags:

0 commit comments

Comments
 (0)