def process(self): for facts in self.consume(FirewalldFacts): if facts.firewall_config_command: tree = ElementTree.parse('/etc/firewalld/lockdown-whitelist.xml') root = tree.getroot() need_write = private.updateFirewallConfigCommand(root, facts.firewall_config_command) if need_write: tree.write('/etc/firewalld/lockdown-whitelist.xml') self.log.info('Updated lockdown whitelist')
def test_firewalldupdatelockdownwhitelist_library(): root = ElementTree.fromstring( '''<?xml version="1.0" encoding="utf-8"?> <whitelist> <command name="/usr/bin/python -Es /usr/bin/firewall-config"/> <command name="/usr/bin/foobar"/> <selinux context="system_u:system_r:NetworkManager_t:s0"/> <selinux context="system_u:system_r:virtd_t:s0-s0:c0.c1023"/> <user id="0"/> </whitelist> ''') assert private.updateFirewallConfigCommand(root, '/usr/bin/python -Es /usr/bin/firewall-config')