seport.py: fix the "change" indication

pull/18777/head
Dan Keder 10 years ago committed by Matt Clay
parent cda2aeb6c0
commit f7d1d35709

@ -134,10 +134,12 @@ def semanage_port_add(module, ports, proto, setype, do_reload, serange='s0', ses
try: try:
seport = seobject.portRecords(sestore) seport = seobject.portRecords(sestore)
seport.set_reload(do_reload) seport.set_reload(do_reload)
change = False
for port in ports: for port in ports:
change = not semanage_port_exists(seport, port, proto) exists = semanage_port_exists(seport, port, proto)
if change and not module.check_mode: if not exists and not module.check_mode:
seport.add(port, proto, serange, setype) seport.add(port, proto, serange, setype)
change = change or not exists
except ValueError as e: except ValueError as e:
module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e))) module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
@ -177,10 +179,12 @@ def semanage_port_del(module, ports, proto, do_reload, sestore=''):
try: try:
seport = seobject.portRecords(sestore) seport = seobject.portRecords(sestore)
seport.set_reload(do_reload) seport.set_reload(do_reload)
change = False
for port in ports: for port in ports:
change = not semanage_port_exists(seport, port, proto) exists = semanage_port_exists(seport, port, proto)
if change and not module.check_mode: if not exists and not module.check_mode:
seport.delete(port, proto) seport.delete(port, proto)
change = change or not exists
except ValueError as e: except ValueError as e:
module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e))) module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))

Loading…
Cancel
Save