NSX-mh: fix default l2 gw connections
This patch fixes connections to the default layer-2 gateway ensuring that: 1) no "None" value is sent for tags to nsxlib. In particular this patch ensures that the tenant_id is populated when the request is sent with admin credentials. 2) the segmentation_id attribute is converted to integer before validating whether it's a valid VLAN tag. Change-Id: I959edab036c32a3a2cfdbe4d7567daf29dc75797 Closes-Bug: #1462973 Closes-Bug: #1462974
This commit is contained in:
parent
9b46393903
commit
e3733b1b89
|
@ -64,7 +64,7 @@ def device_id_to_vm_id(device_id, obfuscate=False):
|
|||
if len(device_id) > MAX_DISPLAY_NAME_LEN or obfuscate:
|
||||
return hashlib.sha1(device_id).hexdigest()
|
||||
else:
|
||||
return device_id
|
||||
return device_id or "N/A"
|
||||
|
||||
|
||||
def check_and_truncate(display_name):
|
||||
|
|
|
@ -141,6 +141,14 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
|||
connection_attrs))
|
||||
seg_type = network_mapping_info.get(SEGMENTATION_TYPE)
|
||||
seg_id = network_mapping_info.get(SEGMENTATION_ID)
|
||||
# It is important to validate that the segmentation ID is actually an
|
||||
# integer value
|
||||
try:
|
||||
seg_id = int(seg_id)
|
||||
except ValueError:
|
||||
msg = _("An invalid segmentation ID was specified. The "
|
||||
"segmentation ID must be a positive integer number")
|
||||
raise exceptions.InvalidInput(error_message=msg)
|
||||
# The NSX plugin accepts 0 as a valid vlan tag
|
||||
seg_id_valid = seg_id == 0 or utils.is_valid_vlan_tag(seg_id)
|
||||
if seg_type.lower() == 'flat' and seg_id:
|
||||
|
@ -148,7 +156,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
|||
"the segmentation type is flat")
|
||||
raise exceptions.InvalidInput(error_message=msg)
|
||||
elif (seg_type.lower() == 'vlan' and not seg_id_valid):
|
||||
msg = _("Invalid segmentation id (%d) for "
|
||||
msg = _("Invalid segmentation id (%s) for "
|
||||
"vlan segmentation type") % seg_id
|
||||
raise exceptions.InvalidInput(error_message=msg)
|
||||
return network_id
|
||||
|
@ -269,6 +277,10 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
|||
with context.session.begin(subtransactions=True):
|
||||
gw_db = self._get_network_gateway(context, network_gateway_id)
|
||||
tenant_id = self._get_tenant_id_for_create(context, gw_db)
|
||||
# _get_tenant_id_for_create might return None in some cases.
|
||||
# This is not acceptable for the NSX plugin
|
||||
if context.is_admin and not tenant_id:
|
||||
tenant_id = context.tenant_id
|
||||
# TODO(salvatore-orlando): Leverage unique constraint instead
|
||||
# of performing another query!
|
||||
if self._retrieve_gateway_connections(context,
|
||||
|
|
Loading…
Reference in New Issue