diff options
author | dagnello <dagnello@hp.com> | 2015-06-19 11:21:51 -0700 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-07-06 18:50:03 -0400 |
commit | 2e8daa23309ada2bfba8415ea6ec5d764b565f05 (patch) | |
tree | 91fc917ac55d458adc12cfc9992f2812f7175cf5 | |
parent | f027e759765e9dd7717b54c308ad1d46410c2cff (diff) | |
download | ansible-modules-core-2e8daa23309ada2bfba8415ea6ec5d764b565f05.tar.gz |
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.
-rw-r--r-- | cloud/openstack/os_security_group_rule.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/cloud/openstack/os_security_group_rule.py b/cloud/openstack/os_security_group_rule.py index eea47c0c..fc928394 100644 --- a/cloud/openstack/os_security_group_rule.py +++ b/cloud/openstack/os_security_group_rule.py @@ -91,12 +91,11 @@ EXAMPLES = ''' def _find_matching_rule(module, secgroup): """ Find a rule in the group that matches the module parameters. - :returns: The matching rule dict, or None if no matches. """ protocol = module.params['protocol'] - port_range_min = module.params['port_range_min'] - port_range_max = module.params['port_range_max'] + port_range_min = int(module.params['port_range_min']) + port_range_max = int(module.params['port_range_max']) remote_ip_prefix = module.params['remote_ip_prefix'] ethertype = module.params['ethertype'] direction = module.params['direction'] @@ -104,14 +103,14 @@ def _find_matching_rule(module, secgroup): for rule in secgroup['security_group_rules']: # No port, or -1, will be returned from shade as None if rule['port_range_min'] is None: - rule_port_range_min = "-1" + rule_port_range_min = -1 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: - rule_port_range_max = "-1" + rule_port_range_max = -1 else: - rule_port_range_max = str(rule['port_range_max']) + rule_port_range_max = int(rule['port_range_max']) if (protocol == rule['protocol'] @@ -195,7 +194,7 @@ def main(): ethertype=module.params['ethertype'] ) 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: rule = _find_matching_rule(module, secgroup) @@ -212,4 +211,4 @@ def main(): from ansible.module_utils.basic import * from ansible.module_utils.openstack import * -main() +main()
\ No newline at end of file |