Skip to content

Commit

Permalink
fix(firewalldfactsactor): handle parse errors
Browse files Browse the repository at this point in the history
Fixes: RHEL-40148
  • Loading branch information
erig0 committed Feb 7, 2025
1 parent c5accf4 commit 34e9d4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from xml.etree import ElementTree
from xml.etree.ElementTree import ParseError

from leapp.actors import Actor
from leapp.libraries.actor import firewalldfactsactor
Expand All @@ -26,14 +27,14 @@ def process(self):
tree = ElementTree.parse('/etc/firewalld/lockdown-whitelist.xml')
root = tree.getroot()
facts.firewall_config_command = firewalldfactsactor.getLockdownFirewallConfigCommand(root)
except IOError:
except (ParseError, IOError):
pass

try:
tree = ElementTree.parse('/etc/firewalld/direct.xml')
root = tree.getroot()
facts.ebtablesTablesInUse = firewalldfactsactor.getEbtablesTablesInUse(root)
except IOError:
except (ParseError, IOError):
pass

ipsetTypesInUse = set()
Expand All @@ -46,7 +47,7 @@ def process(self):
tree = ElementTree.parse(os.path.join(directory, filename))
root = tree.getroot()
ipsetTypesInUse |= set(firewalldfactsactor.getIpsetTypesInUse(root))
except IOError:
except (ParseError, IOError):
pass
facts.ipsetTypesInUse = list(ipsetTypesInUse)
except OSError:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import xml.etree.ElementTree as ElementTree
from xml.etree.ElementTree import ParseError

from leapp.models import FirewalldFacts
from leapp.libraries.actor import firewalldfactsactor


Expand Down Expand Up @@ -31,6 +33,13 @@ def test_firewalldfactsactor_direct():
)
assert set(firewalldfactsactor.getEbtablesTablesInUse(root)) == set(['broute', 'nat'])

# emulate a parse error
try:
facts = FirewalldFacts()
raise ParseError()
except ParseError:
assert not facts.ebtablesTablesInUse


def test_firewalldfactsactor_firewallConfigCommand():
root = ElementTree.fromstring(
Expand Down

0 comments on commit 34e9d4d

Please sign in to comment.