From 0a62f86ffae739c68f9aa16f1f89067547df5c00 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Thu, 9 Mar 2017 14:34:53 -0800 Subject: [PATCH] NSXv: Fix tempest test failures due to KeyError 'primaryAddress' Commit Ie29acfbe323b60205ade9d660f7497f5bf4a35ca may clean up the fixed_ips of ports earlier during delete_subnet. This patch skips those address groups without matching ip_addr when updating dhcp edge service. Change-Id: Idb64b5ed02e46718238821626fa09e8b30506934 --- vmware_nsx/plugins/nsx_v/plugin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index b07bf286c0..885c9bc10c 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -2689,8 +2689,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, address_groups = [] for subnet in subnets: address_group = {} - net = netaddr.IPNetwork(subnet['cidr']) - address_group['subnetPrefixLength'] = str(net.prefixlen) + ip_found = False for port in ports: fixed_ips = port['fixed_ips'] for fip in fixed_ips: @@ -2698,8 +2697,12 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, ip_addr = fip['ip_address'] if s_id == subnet['id'] and self._is_valid_ip(ip_addr): address_group['primaryAddress'] = ip_addr + ip_found = True break - address_groups.append(address_group) + if ip_found: + net = netaddr.IPNetwork(subnet['cidr']) + address_group['subnetPrefixLength'] = str(net.prefixlen) + address_groups.append(address_group) LOG.debug("Update the DHCP address group to %s", address_groups) return address_groups