NSX|P: Fix trunk driver detach calls
Use vif_id in case of compute ports to keep their VM link Depends-on: I7093fbf70a76a7560c9174b209259f167b21f74f Change-Id: I1150dc5336032c006e21ee91833f8949480abd4a
This commit is contained in:
parent
04db6e24d7
commit
e3706ed404
@ -22,6 +22,7 @@ from neutron_lib.api.definitions import portbindings
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.services.trunk import constants as trunk_consts
|
||||
|
||||
from vmware_nsx._i18n import _
|
||||
@ -50,13 +51,18 @@ class NsxpTrunkHandler(object):
|
||||
self.plugin_driver = plugin_driver
|
||||
|
||||
def _get_port_tags_and_network(self, context, port_id):
|
||||
_, tags, net = self._get_port_compute_tags_and_net(context, port_id)
|
||||
return tags, net
|
||||
|
||||
def _get_port_compute_tags_and_net(self, context, port_id):
|
||||
port = self.plugin_driver.get_port(context, port_id)
|
||||
segment_id = self.plugin_driver._get_network_nsx_segment_id(
|
||||
context, port['network_id'])
|
||||
lport = self.plugin_driver.nsxpolicy.segment_port.get(
|
||||
segment_id, port_id)
|
||||
|
||||
return segment_id, lport.get('tags', [])
|
||||
is_compute = port.get('device_owner', '').startswith(
|
||||
constants.DEVICE_OWNER_COMPUTE_PREFIX)
|
||||
return is_compute, segment_id, lport.get('tags', [])
|
||||
|
||||
def _update_tags(self, port_id, tags, tags_update, is_delete=False):
|
||||
if is_delete:
|
||||
@ -122,16 +128,19 @@ class NsxpTrunkHandler(object):
|
||||
tags_update = [{'scope': TRUNK_ID_TAG_NAME,
|
||||
'tag': subport.trunk_id}]
|
||||
|
||||
segment_id, tags = self._get_port_tags_and_network(
|
||||
is_compute, segment_id, tags = self._get_port_compute_tags_and_net(
|
||||
context, subport.port_id)
|
||||
|
||||
tags = self._update_tags(
|
||||
subport.port_id, tags, tags_update, is_delete=True)
|
||||
|
||||
# Update logical port in the backend to set/unset parent port
|
||||
vif_id = None
|
||||
if is_compute:
|
||||
vif_id = subport.port_id
|
||||
try:
|
||||
self.plugin_driver.nsxpolicy.segment_port.detach(
|
||||
segment_id, subport.port_id, tags=tags)
|
||||
segment_id, subport.port_id, vif_id=vif_id, tags=tags)
|
||||
|
||||
except nsxlib_exc.ManagerError as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
@ -164,15 +173,18 @@ class NsxpTrunkHandler(object):
|
||||
def trunk_deleted(self, context, trunk):
|
||||
tags_update = [{'scope': TRUNK_ID_TAG_NAME, 'tag': trunk.id}]
|
||||
|
||||
segment_id, tags = self._get_port_tags_and_network(
|
||||
is_compute, segment_id, tags = self._get_port_compute_tags_and_net(
|
||||
context, trunk.port_id)
|
||||
|
||||
tags = self._update_tags(
|
||||
trunk.port_id, tags, tags_update, is_delete=True)
|
||||
|
||||
try:
|
||||
vif_id = None
|
||||
if is_compute:
|
||||
vif_id = trunk.port_id
|
||||
self.plugin_driver.nsxpolicy.segment_port.detach(
|
||||
segment_id, trunk.port_id, tags=tags)
|
||||
segment_id, trunk.port_id, vif_id=vif_id, tags=tags)
|
||||
except Exception as e:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error("Parent port detachment for trunk %(trunk)s failed "
|
||||
|
@ -30,16 +30,16 @@ PLUGIN_NAME = 'vmware_nsx.plugins.nsx_p.plugin.NsxPolicyPlugin'
|
||||
class TestNsxpTrunkHandler(test_nsx_p_plugin.NsxPPluginTestCaseMixin,
|
||||
base.BaseTestCase):
|
||||
|
||||
def _get_port_tags_and_network(self, context, port_id):
|
||||
return 'net_' + port_id[-1:], []
|
||||
def _get_port_compute_tags_and_net(self, context, port_id):
|
||||
return True, 'net_' + port_id[-1:], []
|
||||
|
||||
def setUp(self):
|
||||
super(TestNsxpTrunkHandler, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
self.core_plugin = importutils.import_object(PLUGIN_NAME)
|
||||
self.handler = trunk_driver.NsxpTrunkHandler(self.core_plugin)
|
||||
self.handler._get_port_tags_and_network = mock.Mock(
|
||||
side_effect=self._get_port_tags_and_network)
|
||||
self.handler._get_port_compute_tags_and_net = mock.Mock(
|
||||
side_effect=self._get_port_compute_tags_and_net)
|
||||
self.trunk_1 = mock.Mock()
|
||||
self.trunk_1.port_id = "parent_port_1"
|
||||
self.trunk_1.id = "trunk_1_id"
|
||||
@ -135,7 +135,8 @@ class TestNsxpTrunkHandler(test_nsx_p_plugin.NsxPPluginTestCaseMixin,
|
||||
'detach') as m_detach:
|
||||
self.handler.trunk_deleted(self.context, self.trunk_1)
|
||||
m_detach.assert_called_with(
|
||||
'net_1', self.trunk_1.port_id, tags=mock.ANY)
|
||||
'net_1', self.trunk_1.port_id, vif_id=self.trunk_1.port_id,
|
||||
tags=mock.ANY)
|
||||
|
||||
# Delete trunk with 1 subport
|
||||
self.trunk_1.sub_ports = [self.sub_port_a]
|
||||
@ -145,9 +146,11 @@ class TestNsxpTrunkHandler(test_nsx_p_plugin.NsxPPluginTestCaseMixin,
|
||||
self.handler.trunk_deleted(self.context, self.trunk_1)
|
||||
calls = [
|
||||
mock.call.m_detach(
|
||||
'net_1', self.trunk_1.port_id, tags=mock.ANY),
|
||||
'net_1', self.trunk_1.port_id,
|
||||
vif_id=self.trunk_1.port_id, tags=mock.ANY),
|
||||
mock.call.m_detach(
|
||||
'net_a', self.sub_port_a.port_id, tags=mock.ANY)]
|
||||
'net_a', self.sub_port_a.port_id,
|
||||
vif_id=self.sub_port_a.port_id, tags=mock.ANY)]
|
||||
m_detach.assert_has_calls(calls, any_order=True)
|
||||
|
||||
# Delete trunk with multiple subports
|
||||
@ -158,11 +161,14 @@ class TestNsxpTrunkHandler(test_nsx_p_plugin.NsxPPluginTestCaseMixin,
|
||||
self.handler.trunk_deleted(self.context, self.trunk_2)
|
||||
calls = [
|
||||
mock.call.m_detach(
|
||||
'net_2', self.trunk_2.port_id, tags=mock.ANY),
|
||||
'net_2', self.trunk_2.port_id,
|
||||
vif_id=self.trunk_2.port_id, tags=mock.ANY),
|
||||
mock.call.m_detach(
|
||||
'net_b', self.sub_port_b.port_id, tags=mock.ANY),
|
||||
'net_b', self.sub_port_b.port_id,
|
||||
vif_id=self.sub_port_b.port_id, tags=mock.ANY),
|
||||
mock.call.m_detach(
|
||||
'net_c', self.sub_port_c.port_id, tags=mock.ANY)]
|
||||
'net_c', self.sub_port_c.port_id,
|
||||
vif_id=self.sub_port_c.port_id, tags=mock.ANY)]
|
||||
m_detach.assert_has_calls(calls, any_order=True)
|
||||
|
||||
def test_subports_added(self):
|
||||
@ -229,7 +235,8 @@ class TestNsxpTrunkHandler(test_nsx_p_plugin.NsxPPluginTestCaseMixin,
|
||||
self.handler.subports_deleted(
|
||||
self.context, self.trunk_1, sub_ports)
|
||||
m_detach.assert_called_with(
|
||||
'net_a', self.sub_port_a.port_id, tags=mock.ANY)
|
||||
'net_a', self.sub_port_a.port_id,
|
||||
vif_id=self.sub_port_a.port_id, tags=mock.ANY)
|
||||
|
||||
# Update trunk to remove multiple subports
|
||||
sub_ports = [self.sub_port_b, self.sub_port_c]
|
||||
@ -240,9 +247,11 @@ class TestNsxpTrunkHandler(test_nsx_p_plugin.NsxPPluginTestCaseMixin,
|
||||
self.context, self.trunk_2, sub_ports)
|
||||
calls = [
|
||||
mock.call.m_detach(
|
||||
'net_b', self.sub_port_b.port_id, tags=mock.ANY),
|
||||
'net_b', self.sub_port_b.port_id,
|
||||
vif_id=self.sub_port_b.port_id, tags=mock.ANY),
|
||||
mock.call.m_detach(
|
||||
'net_c', self.sub_port_c.port_id, tags=mock.ANY)]
|
||||
'net_c', self.sub_port_c.port_id,
|
||||
vif_id=self.sub_port_c.port_id, tags=mock.ANY)]
|
||||
m_detach.assert_has_calls(calls, any_order=True)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user