Resolving issues in rule comparison algorithm

Port range min/max values are at times represented as string and
compared to int equivalents.  This fix explicitly ensures all
port range values are ints for proper comparisons.
This commit is contained in:
dagnello 2015-06-19 11:21:51 -07:00 committed by Matt Clay
parent e7dd93c5c1
commit 2c3fc61357

View file

@ -93,12 +93,11 @@ EXAMPLES = '''
def _find_matching_rule(module, secgroup): def _find_matching_rule(module, secgroup):
""" """
Find a rule in the group that matches the module parameters. Find a rule in the group that matches the module parameters.
:returns: The matching rule dict, or None if no matches. :returns: The matching rule dict, or None if no matches.
""" """
protocol = module.params['protocol'] protocol = module.params['protocol']
port_range_min = module.params['port_range_min'] port_range_min = int(module.params['port_range_min'])
port_range_max = module.params['port_range_max'] port_range_max = int(module.params['port_range_max'])
remote_ip_prefix = module.params['remote_ip_prefix'] remote_ip_prefix = module.params['remote_ip_prefix']
ethertype = module.params['ethertype'] ethertype = module.params['ethertype']
direction = module.params['direction'] direction = module.params['direction']
@ -106,14 +105,14 @@ def _find_matching_rule(module, secgroup):
for rule in secgroup['security_group_rules']: for rule in secgroup['security_group_rules']:
# No port, or -1, will be returned from shade as None # No port, or -1, will be returned from shade as None
if rule['port_range_min'] is None: if rule['port_range_min'] is None:
rule_port_range_min = "-1" rule_port_range_min = -1
else: else:
rule_port_range_min = str(rule['port_range_min']) rule_port_range_min = int(rule['port_range_min'])
if rule['port_range_max'] is None: if rule['port_range_max'] is None:
rule_port_range_max = "-1" rule_port_range_max = -1
else: else:
rule_port_range_max = str(rule['port_range_max']) rule_port_range_max = int(rule['port_range_max'])
if (protocol == rule['protocol'] if (protocol == rule['protocol']
@ -198,7 +197,7 @@ def main():
ethertype=module.params['ethertype'] ethertype=module.params['ethertype']
) )
changed = True changed = True
module.exit_json(changed=changed, rule=rule, id=rule.id) module.exit_json(changed=changed, rule=rule, id=rule['id'])
if state == 'absent' and secgroup: if state == 'absent' and secgroup:
rule = _find_matching_rule(module, secgroup) rule = _find_matching_rule(module, secgroup)
@ -215,4 +214,4 @@ def main():
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.openstack import * from ansible.module_utils.openstack import *
main() main()