Skip to content

Commit

Permalink
Fix firewall cleanup in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolenz committed Sep 20, 2022
1 parent 471ed5d commit a39f69a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions plugins/modules/vmware_host_firewall_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ def check_params(self):
try:
is_ipaddress(ip_address)
except ValueError:
self.module.fail_json(msg="%s is not a valid IP." % ip_address)
self.module.fail_json(msg="The provided IP address %s is not a valid IP"
" for the rule %s" % (ip_address, rule_name))

for ip_network in allowed_hosts.get('ip_network'):
try:
is_ipaddress(ip_network)
except ValueError:
self.module.fail_json(msg="%s is not a valid network" % ip_network)
self.module.fail_json(msg="The provided IP network %s is not a valid network"
" for the rule %s" % (ip_network, rule_name))

def ensure(self):
"""
Expand Down Expand Up @@ -324,10 +326,10 @@ def ensure(self):
rule_allowed_ips = set(permitted_networking['allowed_hosts']['ip_address'])
rule_allowed_networks = set(permitted_networking['allowed_hosts']['ip_network'])

allowed_hosts = rule_option.get('allowed_hosts', {})
playbook_allows_all = allowed_hosts.get('all_ip', False)
playbook_allowed_ips = set(allowed_hosts.get('ip_address', []))
playbook_allowed_networks = set(allowed_hosts.get('ip_network', []))
allowed_hosts = rule_option.get('allowed_hosts')
playbook_allows_all = False if allowed_hosts is None else allowed_hosts.get('all_ip')
playbook_allowed_ips = set([]) if allowed_hosts is None else set(allowed_hosts.get('ip_address'))
playbook_allowed_networks = set([]) if allowed_hosts is None else set(allowed_hosts.get('ip_network'))

# compare what is configured on the firewall rule with what the playbook provides
allowed_all_ips_different = bool(rule_allows_all != playbook_allows_all)
Expand Down

0 comments on commit a39f69a

Please sign in to comment.