From 4f9acdfb5eeeccdaf0206c1447da1e5bd420d908 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Tue, 3 Mar 2020 09:21:12 +0200 Subject: [PATCH] NSX|P: Do not use transactional apis if not supported Creating a segment port with transactional APIs resets the segment name if partial updates is not yet supported Change-Id: I3036227149c35c135d26469a90506f543d08dd2f --- vmware_nsx/plugins/nsx_p/plugin.py | 57 +++++++++++++++++++----------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index c1d655de50..f17c993230 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -1422,6 +1422,29 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): return tags + def _do_port_backend_calls(self, name, segment_id, + spoofguard_profile, seg_sec_profile, + mac_discovery_profile, qos_policy_id, **kwargs): + self.nsxpolicy.segment_port.create_or_overwrite( + name, segment_id, **kwargs) + + # add the security profiles to the port + self.nsxpolicy.segment_port_security_profiles.create_or_overwrite( + name, segment_id, port_id=kwargs['port_id'], + spoofguard_profile_id=spoofguard_profile, + segment_security_profile_id=seg_sec_profile) + + # add the mac discovery profile to the port + self.nsxpolicy.segment_port_discovery_profiles.create_or_overwrite( + name, segment_id, kwargs['port_id'], + mac_discovery_profile_id=mac_discovery_profile) + + # Add QoS segment profile (only if QoS is enabled) + if directory.get_plugin(plugin_const.QOS): + self.nsxpolicy.segment_port_qos_profiles.create_or_overwrite( + name, segment_id, kwargs['port_id'], + qos_profile_id=qos_policy_id) + def _create_or_update_port_on_backend(self, context, port_data, is_psec_on, qos_policy_id, original_port=None): is_create = original_port is None @@ -1495,27 +1518,19 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): 'admin_state_up' in port_data): kwargs['admin_state'] = port_data['admin_state_up'] - # Create/ update the backend port in a single transaction - with policy_trans.NsxPolicyTransaction(): - self.nsxpolicy.segment_port.create_or_overwrite( - name, segment_id, **kwargs) - - # add the security profiles to the port - self.nsxpolicy.segment_port_security_profiles.create_or_overwrite( - name, segment_id, port_data['id'], - spoofguard_profile_id=spoofguard_profile, - segment_security_profile_id=seg_sec_profile) - - # add the mac discovery profile to the port - self.nsxpolicy.segment_port_discovery_profiles.create_or_overwrite( - name, segment_id, port_data['id'], - mac_discovery_profile_id=mac_discovery_profile) - - # Add QoS segment profile (only if QoS is enabled) - if directory.get_plugin(plugin_const.QOS): - self.nsxpolicy.segment_port_qos_profiles.create_or_overwrite( - name, segment_id, port_data['id'], - qos_profile_id=qos_policy_id) + if not self.nsxpolicy.feature_supported( + nsxlib_consts.FEATURE_PARTIAL_UPDATES): + # If partial updates are not supported, using transactions will + # reset the backend segment name + self._do_port_backend_calls( + name, segment_id, spoofguard_profile, seg_sec_profile, + mac_discovery_profile, qos_policy_id, **kwargs) + else: + # Create/ update the backend port in a single transaction + with policy_trans.NsxPolicyTransaction(): + self._do_port_backend_calls( + name, segment_id, spoofguard_profile, seg_sec_profile, + mac_discovery_profile, qos_policy_id, **kwargs) # Update port admin status using passthrough api, only if it changed # or new port with disabled admin state