Merge "NSX|P: Fix subnet gw validation" into stable/train

This commit is contained in:
Zuul 2021-03-03 13:28:03 +00:00 committed by Gerrit Code Review
commit 342b097ddb
1 changed files with 3 additions and 3 deletions

View File

@ -1386,17 +1386,16 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
def _validate_subnet_gw_ip(self, context, subnet, orig_subnet=None):
# Make sure the gw ip is legal and belongs to the subnet
raw_gw_ip = subnet.get('gateway_ip')
raw_gw_ip = subnet.get('gateway_ip', const.ATTR_NOT_SPECIFIED)
if orig_subnet and raw_gw_ip == const.ATTR_NOT_SPECIFIED:
# No change in GW ip
raw_gw_ip = orig_subnet.get('gateway_ip')
raw_cidr = subnet.get('cidr')
raw_cidr = subnet.get('cidr', const.ATTR_NOT_SPECIFIED)
if (orig_subnet and
(not raw_cidr or raw_cidr == const.ATTR_NOT_SPECIFIED)):
raw_cidr = orig_subnet.get('cidr')
if (not raw_gw_ip or raw_gw_ip == const.ATTR_NOT_SPECIFIED or
not raw_cidr or raw_cidr == const.ATTR_NOT_SPECIFIED):
if orig_subnet and raw_gw_ip is None:
# in update case, if the subnet is attached to a router the gw
# cannot be removes
@ -1408,6 +1407,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
if orig_subnet['id'] == interface_sub:
msg = _('Subnet for router interface must have a '
'gateway IP')
LOG.error(msg)
raise n_exc.BadRequest(resource='router', msg=msg)
# Nothing else to check here
return