Skip to content

Commit d155a2b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "[OVN] Bump the port revision number in trunk driver" into stable/yoga
2 parents 9b1b61c + ff9d2fc commit d155a2b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from oslo_log import log
2323

2424
from neutron.common.ovn import constants as ovn_const
25+
from neutron.db import db_base_plugin_common
26+
from neutron.db import ovn_revision_numbers_db as db_rev
2527
from neutron.objects import ports as port_obj
2628
from neutron.services.trunk.drivers import base as trunk_base
2729

@@ -47,20 +49,23 @@ def _set_sub_ports(self, parent_port, subports):
4749
context = n_context.get_admin_context()
4850
db_parent_port = port_obj.Port.get_object(context, id=parent_port)
4951
parent_port_status = db_parent_port.status
50-
for port in subports:
52+
for subport in subports:
5153
with db_api.CONTEXT_WRITER.using(context), (
5254
txn(check_error=True)) as ovn_txn:
53-
self._set_binding_profile(context, port, parent_port,
54-
parent_port_status, ovn_txn)
55+
port = self._set_binding_profile(context, subport, parent_port,
56+
parent_port_status, ovn_txn)
57+
db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS)
5558

5659
def _unset_sub_ports(self, subports):
5760
txn = self.plugin_driver.nb_ovn.transaction
5861
context = n_context.get_admin_context()
59-
for port in subports:
62+
for subport in subports:
6063
with db_api.CONTEXT_WRITER.using(context), (
6164
txn(check_error=True)) as ovn_txn:
62-
self._unset_binding_profile(context, port, ovn_txn)
65+
port = self._unset_binding_profile(context, subport, ovn_txn)
66+
db_rev.bump_revision(context, port, ovn_const.TYPE_PORTS)
6367

68+
@db_base_plugin_common.convert_result_to_dict
6469
def _set_binding_profile(self, context, subport, parent_port,
6570
parent_port_status, ovn_txn):
6671
LOG.debug("Setting parent %s for subport %s",
@@ -71,6 +76,9 @@ def _set_binding_profile(self, context, subport, parent_port,
7176
"binding_profile: %s",
7277
subport.port_id)
7378
return
79+
check_rev_cmd = self.plugin_driver.nb_ovn.check_revision_number(
80+
db_port.id, db_port, ovn_const.TYPE_PORTS)
81+
ovn_txn.add(check_rev_cmd)
7482
try:
7583
# NOTE(flaviof): We expect binding's host to be set. Otherwise,
7684
# sub-port will not transition from DOWN to ACTIVE.
@@ -103,7 +111,9 @@ def _set_binding_profile(self, context, subport, parent_port,
103111
))
104112
LOG.debug("Done setting parent %s for subport %s",
105113
parent_port, subport.port_id)
114+
return db_port
106115

116+
@db_base_plugin_common.convert_result_to_dict
107117
def _unset_binding_profile(self, context, subport, ovn_txn):
108118
LOG.debug("Unsetting parent for subport %s", subport.port_id)
109119
db_port = port_obj.Port.get_object(context, id=subport.port_id)
@@ -112,6 +122,9 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
112122
"binding_profile: %s",
113123
subport.port_id)
114124
return
125+
check_rev_cmd = self.plugin_driver.nb_ovn.check_revision_number(
126+
db_port.id, db_port, ovn_const.TYPE_PORTS)
127+
ovn_txn.add(check_rev_cmd)
115128
try:
116129
db_port.device_owner = ''
117130
for binding in db_port.bindings:
@@ -140,6 +153,7 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
140153
external_ids_update=ext_ids,
141154
))
142155
LOG.debug("Done unsetting parent for subport %s", subport.port_id)
156+
return db_port
143157

144158
def trunk_created(self, trunk):
145159
# Check if parent port is handled by OVN.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ def _get_ovn_trunk_info(self):
6464
if row.parent_name and row.tag:
6565
device_owner = row.external_ids[
6666
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY]
67+
revision_number = row.external_ids[
68+
ovn_const.OVN_REV_NUM_EXT_ID_KEY]
6769
ovn_trunk_info.append({'port_id': row.name,
6870
'parent_port_id': row.parent_name,
6971
'tag': row.tag,
7072
'device_owner': device_owner,
73+
'revision_number': revision_number,
7174
})
7275
return ovn_trunk_info
7376

@@ -80,6 +83,7 @@ def _verify_trunk_info(self, trunk, has_items):
8083
'parent_port_id': [trunk['port_id']],
8184
'tag': [subport['segmentation_id']],
8285
'device_owner': trunk_consts.TRUNK_SUBPORT_OWNER,
86+
'revision_number': '2',
8387
})
8488
# Check that the subport has the binding is active.
8589
binding = obj_reg.load_class('PortBinding').get_object(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def setUp(self):
8787
"neutron.objects.ports.PortBinding.update_object").start()
8888
self.mock_clear_levels = mock.patch(
8989
"neutron.objects.ports.PortBindingLevel.delete_objects").start()
90+
self.mock_bump_revision = mock.patch(
91+
"neutron.db.ovn_revision_numbers_db.bump_revision").start()
9092

9193
def _get_fake_port_obj(self, port_id):
9294
with mock.patch('uuid.UUID') as mock_uuid:

0 commit comments

Comments
 (0)