From 83520770fc8b8eaebe2cfd3c921140d808827377 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Mon, 26 Jun 2017 18:23:50 +0300 Subject: [PATCH] NSX|V3: fix trunk issues The patch does a number of things: 1. Ensure that the parent VIF has the correct vif_type. This should be 'PARENT' 2. Ensures that correct constants should be used 3. Make sure that child port has the corrfect vif_type. This should be 'CHILD' 4. The logical ports for the 'children' will have a tag indicating the trunk id Depends-On: If7f1895db746d95d5f71360e0ca1e05feeda5db8 Change-Id: I80707a30d92249ed2706d599f749a216edb8f336 --- vmware_nsx/services/trunk/nsx_v3/driver.py | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/vmware_nsx/services/trunk/nsx_v3/driver.py b/vmware_nsx/services/trunk/nsx_v3/driver.py index 2250856b17..65f03e2fad 100644 --- a/vmware_nsx/services/trunk/nsx_v3/driver.py +++ b/vmware_nsx/services/trunk/nsx_v3/driver.py @@ -28,6 +28,7 @@ from vmware_nsx.common import nsx_constants as nsx_consts from vmware_nsx.common import utils as nsx_utils from vmware_nsx.db import db as nsx_db from vmware_nsxlib.v3 import exceptions as nsxlib_exc +from vmware_nsxlib.v3 import nsx_constants LOG = logging.getLogger(__name__) @@ -52,7 +53,7 @@ class NsxV3TrunkHandler(object): def _build_switching_profile_ids(self, profiles): switching_profile = self._nsxlib.switching_profile return switching_profile.build_switch_profile_ids( - switching_profile.client, profiles) + switching_profile.client, *profiles) def _update_port_at_backend(self, context, parent_port_id, subport): # Retrieve the child port details @@ -75,17 +76,22 @@ class NsxV3TrunkHandler(object): child_port) switching_profile_ids = self._build_switching_profile_ids( nsx_child_port.get('switching_profile_ids', [])) - attachment_type = None seg_id = None + tags_update = [] + attachment_type = nsx_constants.ATTACHMENT_VIF if parent_port_id: # Set properties for VLAN trunking if subport.segmentation_type == nsx_utils.NsxV3NetworkTypes.VLAN: - attachment_type = nsx_consts.ATTACHMENT_CIF seg_id = subport.segmentation_id + tags_update.append({'scope': 'os-neutron-trunk-id', + 'tag': subport.trunk_id}) + vif_type = nsx_constants.VIF_TYPE_CHILD else: # Unset the parent port properties from child port - attachment_type = nsx_consts.ATTACHMENT_VIF seg_id = None + vif_type = None + tags_update.append({'scope': 'os-neutron-trunk-id', + 'tag': None}) # Update logical port in the backend to set/unset parent port try: self._nsxlib.logical_port.update( @@ -97,7 +103,9 @@ class NsxV3TrunkHandler(object): switch_profile_ids=switching_profile_ids, attachment_type=attachment_type, parent_vif_id=parent_port_id, - traffic_tag=seg_id) + vif_type=vif_type, + traffic_tag=seg_id, + tags_update=tags_update) except nsxlib_exc.ManagerError as e: with excutils.save_and_reraise_exception(): LOG.error("Unable to update subport for attachment " @@ -116,6 +124,16 @@ class NsxV3TrunkHandler(object): context=context, parent_port_id=None, subport=subport) def trunk_created(self, context, trunk): + # Retrieve the logical port ID based on the parent port's neutron ID + nsx_parent_port_id = nsx_db.get_nsx_switch_and_port_id( + session=context.session, neutron_id=trunk.port_id)[1] + tags_update = [{'scope': 'os-neutron-trunk-id', + 'tag': trunk.id}] + self.plugin_driver.nsxlib.logical_port.update( + nsx_parent_port_id, + vif_uuid=trunk.port_id, + vif_type=nsx_constants.VIF_TYPE_PARENT, + tags_update=tags_update) try: if trunk.sub_ports: self._set_subports(context, trunk.port_id, trunk.sub_ports) @@ -124,6 +142,16 @@ class NsxV3TrunkHandler(object): trunk.update(status=trunk_consts.ERROR_STATUS) def trunk_deleted(self, context, trunk): + # Retrieve the logical port ID based on the parent port's neutron ID + nsx_parent_port_id = nsx_db.get_nsx_switch_and_port_id( + session=context.session, neutron_id=trunk.port_id)[1] + tags_update = [{'scope': 'os-neutron-trunk-id', + 'tag': None}] + self.plugin_driver.nsxlib.logical_port.update( + nsx_parent_port_id, + vif_uuid=trunk.port_id, + vif_type=None, + tags_update=tags_update) self._unset_subports(context, trunk.sub_ports) def subports_added(self, context, trunk, subports): @@ -169,7 +197,7 @@ class NsxV3TrunkDriver(base.DriverBase): cls.plugin_driver = plugin_driver return cls(nsx_consts.VMWARE_NSX_V3_PLUGIN_NAME, SUPPORTED_INTERFACES, SUPPORTED_SEGMENTATION_TYPES, - agent_type=None, can_trunk_bound_port=False) + agent_type=None, can_trunk_bound_port=True) @registry.receives(trunk_consts.TRUNK_PLUGIN, [events.AFTER_INIT]) def register(self, resource, event, trigger, **kwargs):