Fix iteration over remote_ip_prefixes field

The remote_ip_prefixes filed of a KuryrNetPolicy has the
format: {'remote_ip_prefixes': {'pod_ip': 'np-namespace'}}.
Right now, we're iterating over each remote_ip_prefixes
dicts and retrieving its keys and values without fetching the
dict items causing a ValueError. This commit fixes the
issue by iterating over the dict items.

Closes-bug: 1858301

Change-Id: Ic40878a830bcc32da06c0ab2763f593595e81bf2
This commit is contained in:
Maysa Macedo 2020-01-04 23:11:05 +00:00 committed by Luis Tomas Bolivar
parent 501bf41910
commit 674344b182
1 changed files with 3 additions and 3 deletions

View File

@ -380,12 +380,12 @@ def _parse_rules_on_delete_namespace(rule_list, direction, ns_name):
LOG.debug('Parsing %(dir)s Rule %(r)s', {'dir': direction, LOG.debug('Parsing %(dir)s Rule %(r)s', {'dir': direction,
'r': rule}) 'r': rule})
rule_namespace = rule.get('namespace', None) rule_namespace = rule.get('namespace', None)
remote_ip_prefixes = rule.get('remote_ip_prefixes', []) remote_ip_prefixes = rule.get('remote_ip_prefixes', {})
if rule_namespace and rule_namespace == ns_name: if rule_namespace and rule_namespace == ns_name:
matched = True matched = True
driver_utils.delete_security_group_rule( driver_utils.delete_security_group_rule(
rule['security_group_rule']['id']) rule['security_group_rule']['id'])
for remote_ip, namespace in remote_ip_prefixes: for remote_ip, namespace in list(remote_ip_prefixes.items()):
if namespace == ns_name: if namespace == ns_name:
matched = True matched = True
remote_ip_prefixes.pop(remote_ip) remote_ip_prefixes.pop(remote_ip)
@ -405,7 +405,7 @@ def _parse_rules_on_delete_pod(rule_list, direction, pod_ip):
'r': rule}) 'r': rule})
remote_ip_prefix = rule['security_group_rule'].get( remote_ip_prefix = rule['security_group_rule'].get(
'remote_ip_prefix') 'remote_ip_prefix')
remote_ip_prefixes = rule.get('remote_ip_prefixes', []) remote_ip_prefixes = rule.get('remote_ip_prefixes', {})
if remote_ip_prefix and remote_ip_prefix == pod_ip: if remote_ip_prefix and remote_ip_prefix == pod_ip:
matched = True matched = True
driver_utils.delete_security_group_rule( driver_utils.delete_security_group_rule(