Skip to content

Commit cf09634

Browse files
committed
Revert "[OVN][Trunk] Add port binding info on subport when parent is bound"
This reverts commit 955e621. Reason for revert: the port binding handling done in this patch is incorrect and leads to issues during the cold migration process with trunk ports in ML2/OVN. Change-Id: Ifc2d37e2042fad43dd838821953defd99a5f8665 Closes-Bug: #2033887 (cherry picked from commit 1b034f8)
1 parent a4efc2d commit cf09634

File tree

3 files changed

+17
-55
lines changed

3 files changed

+17
-55
lines changed

neutron/services/trunk/drivers/ovn/trunk_driver.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ def _set_sub_ports(self, parent_port, subports):
5151
context = n_context.get_admin_context()
5252
db_parent_port = port_obj.Port.get_object(context, id=parent_port)
5353
parent_port_status = db_parent_port.status
54-
parent_port_bindings = db_parent_port.bindings[0]
5554
for subport in subports:
5655
with db_api.CONTEXT_WRITER.using(context), (
5756
txn(check_error=True)) as ovn_txn:
5857
port = self._set_binding_profile(context, subport, parent_port,
59-
parent_port_status,
60-
parent_port_bindings, ovn_txn)
58+
parent_port_status, ovn_txn)
6159
db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS)
6260

6361
def _unset_sub_ports(self, subports):
@@ -71,8 +69,7 @@ def _unset_sub_ports(self, subports):
7169

7270
@db_base_plugin_common.convert_result_to_dict
7371
def _set_binding_profile(self, context, subport, parent_port,
74-
parent_port_status,
75-
parent_port_bindings, ovn_txn):
72+
parent_port_status, ovn_txn):
7673
LOG.debug("Setting parent %s for subport %s",
7774
parent_port, subport.port_id)
7875
db_port = port_obj.Port.get_object(context, id=subport.port_id)
@@ -84,9 +81,6 @@ def _set_binding_profile(self, context, subport, parent_port,
8481
check_rev_cmd = self.plugin_driver.nb_ovn.check_revision_number(
8582
db_port.id, db_port, ovn_const.TYPE_PORTS)
8683
ovn_txn.add(check_rev_cmd)
87-
parent_binding_host = ''
88-
if parent_port_bindings.host:
89-
parent_binding_host = parent_port_bindings.host
9084
try:
9185
# NOTE(flaviof): We expect binding's host to be set. Otherwise,
9286
# sub-port will not transition from DOWN to ACTIVE.
@@ -102,7 +96,6 @@ def _set_binding_profile(self, context, subport, parent_port,
10296
port_obj.PortBinding.update_object(
10397
context,
10498
{'profile': binding.profile,
105-
'host': parent_binding_host,
10699
'vif_type': portbindings.VIF_TYPE_OVS},
107100
port_id=subport.port_id,
108101
host=binding.host)
@@ -168,14 +161,6 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
168161
def _is_port_bound(port):
169162
return n_utils.is_port_bound(port, log_message=False)
170163

171-
def trunk_updated(self, trunk):
172-
# Check if parent port is handled by OVN.
173-
if not self.plugin_driver.nb_ovn.lookup('Logical_Switch_Port',
174-
trunk.port_id, default=None):
175-
return
176-
if trunk.sub_ports:
177-
self._set_sub_ports(trunk.port_id, trunk.sub_ports)
178-
179164
def trunk_created(self, trunk):
180165
# Check if parent port is handled by OVN.
181166
if not self.plugin_driver.nb_ovn.lookup('Logical_Switch_Port',
@@ -210,8 +195,6 @@ def subports_deleted(self, trunk, subports):
210195
def trunk_event(self, resource, event, trunk_plugin, payload):
211196
if event == events.AFTER_CREATE:
212197
self.trunk_created(payload.states[0])
213-
elif event == events.AFTER_UPDATE:
214-
self.trunk_updated(payload.states[0])
215198
elif event == events.AFTER_DELETE:
216199
self.trunk_deleted(payload.states[0])
217200
elif event == events.PRECOMMIT_CREATE:
@@ -248,9 +231,8 @@ def register(self, resource, event, trigger, payload=None):
248231
super(OVNTrunkDriver, self).register(
249232
resource, event, trigger, payload=payload)
250233
self._handler = OVNTrunkHandler(self.plugin_driver)
251-
for _event in (events.AFTER_CREATE, events.AFTER_UPDATE,
252-
events.AFTER_DELETE, events.PRECOMMIT_CREATE,
253-
events.PRECOMMIT_DELETE):
234+
for _event in (events.AFTER_CREATE, events.AFTER_DELETE,
235+
events.PRECOMMIT_CREATE, events.PRECOMMIT_DELETE):
254236
registry.subscribe(self._handler.trunk_event,
255237
resources.TRUNK,
256238
_event)

neutron/tests/functional/services/trunk/drivers/ovn/test_trunk_driver.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from neutron_lib.api.definitions import portbindings
1818
from neutron_lib.callbacks import exceptions as n_exc
1919
from neutron_lib import constants as n_consts
20-
from neutron_lib.db import api as db_api
20+
from neutron_lib.objects import registry as obj_reg
2121
from neutron_lib.plugins import utils
2222
from neutron_lib.services.trunk import constants as trunk_consts
2323
from oslo_utils import uuidutils
@@ -30,8 +30,8 @@
3030

3131
class TestOVNTrunkDriver(base.TestOVNFunctionalBase):
3232

33-
def setUp(self, **kwargs):
34-
super().setUp(**kwargs)
33+
def setUp(self):
34+
super(TestOVNTrunkDriver, self).setUp()
3535
self.trunk_plugin = trunk_plugin.TrunkPlugin()
3636
self.trunk_plugin.add_segmentation_type(
3737
trunk_consts.SEGMENTATION_TYPE_VLAN,
@@ -42,8 +42,7 @@ def trunk(self, sub_ports=None):
4242
sub_ports = sub_ports or []
4343
with self.network() as network:
4444
with self.subnet(network=network) as subnet:
45-
with self.port(subnet=subnet,
46-
device_owner='compute:nova') as parent_port:
45+
with self.port(subnet=subnet) as parent_port:
4746
tenant_id = uuidutils.generate_uuid()
4847
trunk = {'trunk': {
4948
'port_id': parent_port['port']['id'],
@@ -68,14 +67,17 @@ def _get_ovn_trunk_info(self):
6867
if row.parent_name and row.tag:
6968
device_owner = row.external_ids[
7069
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY]
70+
revision_number = row.external_ids[
71+
ovn_const.OVN_REV_NUM_EXT_ID_KEY]
7172
ovn_trunk_info.append({'port_id': row.name,
7273
'parent_port_id': row.parent_name,
7374
'tag': row.tag,
7475
'device_owner': device_owner,
76+
'revision_number': revision_number,
7577
})
7678
return ovn_trunk_info
7779

78-
def _verify_trunk_info(self, trunk, has_items, host=''):
80+
def _verify_trunk_info(self, trunk, has_items):
7981
ovn_subports_info = self._get_ovn_trunk_info()
8082
neutron_subports_info = []
8183
for subport in trunk.get('sub_ports', []):
@@ -84,27 +86,19 @@ def _verify_trunk_info(self, trunk, has_items, host=''):
8486
'parent_port_id': [trunk['port_id']],
8587
'tag': [subport['segmentation_id']],
8688
'device_owner': trunk_consts.TRUNK_SUBPORT_OWNER,
89+
'revision_number': '2',
8790
})
88-
# Check the subport binding.
89-
pb = port_obj.PortBinding.get_object(
90-
self.context, port_id=subport['port_id'], host=host)
91-
self.assertEqual(n_consts.PORT_STATUS_ACTIVE, pb.status)
92-
self.assertEqual(host, pb.host)
91+
# Check that the subport has the binding is active.
92+
binding = obj_reg.load_class('PortBinding').get_object(
93+
self.context, port_id=subport['port_id'], host='')
94+
self.assertEqual(n_consts.PORT_STATUS_ACTIVE, binding['status'])
9395

9496
self.assertCountEqual(ovn_subports_info, neutron_subports_info)
9597
self.assertEqual(has_items, len(neutron_subports_info) != 0)
9698

9799
if trunk.get('status'):
98100
self.assertEqual(trunk_consts.TRUNK_ACTIVE_STATUS, trunk['status'])
99101

100-
def _bind_port(self, port_id, host):
101-
with db_api.CONTEXT_WRITER.using(self.context):
102-
pb = port_obj.PortBinding.get_object(self.context,
103-
port_id=port_id, host='')
104-
pb.delete()
105-
port_obj.PortBinding(self.context, port_id=port_id, host=host,
106-
vif_type=portbindings.VIF_TYPE_OVS).create()
107-
108102
def test_trunk_create(self):
109103
with self.trunk() as trunk:
110104
self._verify_trunk_info(trunk, has_items=False)
@@ -141,22 +135,10 @@ def test_subport_add(self):
141135
new_trunk = self.trunk_plugin.get_trunk(self.context,
142136
trunk['id'])
143137
self._verify_trunk_info(new_trunk, has_items=True)
144-
# Bind parent port. That will trigger the binding of the
145-
# trunk subports too, using the same host ID.
146-
self._bind_port(trunk['port_id'], 'host1')
147-
self.mech_driver.set_port_status_up(trunk['port_id'])
148-
self._verify_trunk_info(new_trunk, has_items=True,
149-
host='host1')
150138

151139
def test_subport_delete(self):
152140
with self.subport() as subport:
153141
with self.trunk([subport]) as trunk:
154-
# Bind parent port.
155-
self._bind_port(trunk['port_id'], 'host1')
156-
self.mech_driver.set_port_status_up(trunk['port_id'])
157-
self._verify_trunk_info(trunk, has_items=True,
158-
host='host1')
159-
160142
self.trunk_plugin.remove_subports(self.context, trunk['id'],
161143
{'sub_ports': [subport]})
162144
new_trunk = self.trunk_plugin.get_trunk(self.context,

neutron/tests/unit/services/trunk/drivers/ovn/test_trunk_driver.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ def test_create_trunk(self):
122122
mock.call(mock.ANY,
123123
{'profile': {'parent_name': trunk.port_id,
124124
'tag': s_port.segmentation_id},
125-
'host': mock.ANY,
126125
'vif_type': portbindings.VIF_TYPE_OVS},
127126
host=mock.ANY,
128127
port_id=s_port.port_id)
@@ -153,7 +152,6 @@ def test_create_trunk_port_db_exception(self):
153152
self.mock_update_pb.assert_called_once_with(
154153
mock.ANY, {'profile': {'parent_name': self.sub_port_1.trunk_id,
155154
'tag': self.sub_port_1.segmentation_id},
156-
'host': 'foo.com',
157155
'vif_type': portbindings.VIF_TYPE_OVS},
158156
host='foo.com', port_id=self.sub_port_1.port_id)
159157
self.mock_port_update.assert_not_called()

0 commit comments

Comments
 (0)