21
21
from oslo_config import cfg
22
22
from oslo_log import log
23
23
24
- from neutron .common .ovn .constants import OVN_ML2_MECH_DRIVER_NAME
24
+ 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
25
27
from neutron .objects import ports as port_obj
26
28
from neutron .services .trunk .drivers import base as trunk_base
27
29
@@ -47,20 +49,23 @@ def _set_sub_ports(self, parent_port, subports):
47
49
context = n_context .get_admin_context ()
48
50
db_parent_port = port_obj .Port .get_object (context , id = parent_port )
49
51
parent_port_status = db_parent_port .status
50
- for port in subports :
52
+ for subport in subports :
51
53
with db_api .CONTEXT_WRITER .using (context ), (
52
54
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 )
55
58
56
59
def _unset_sub_ports (self , subports ):
57
60
txn = self .plugin_driver .nb_ovn .transaction
58
61
context = n_context .get_admin_context ()
59
- for port in subports :
62
+ for subport in subports :
60
63
with db_api .CONTEXT_WRITER .using (context ), (
61
64
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 )
63
67
68
+ @db_base_plugin_common .convert_result_to_dict
64
69
def _set_binding_profile (self , context , subport , parent_port ,
65
70
parent_port_status , ovn_txn ):
66
71
LOG .debug ("Setting parent %s for subport %s" ,
@@ -71,6 +76,9 @@ def _set_binding_profile(self, context, subport, parent_port,
71
76
"binding_profile: %s" ,
72
77
subport .port_id )
73
78
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 )
74
82
try :
75
83
# NOTE(flaviof): We expect binding's host to be set. Otherwise,
76
84
# sub-port will not transition from DOWN to ACTIVE.
@@ -94,13 +102,18 @@ def _set_binding_profile(self, context, subport, parent_port,
94
102
LOG .debug ("Port not found while trying to set "
95
103
"binding_profile: %s" , subport .port_id )
96
104
return
105
+ ext_ids = {ovn_const .OVN_DEVICE_OWNER_EXT_ID_KEY : db_port .device_owner }
97
106
ovn_txn .add (self .plugin_driver .nb_ovn .set_lswitch_port (
98
107
lport_name = subport .port_id ,
99
108
parent_name = parent_port ,
100
- tag = subport .segmentation_id ))
109
+ tag = subport .segmentation_id ,
110
+ external_ids_update = ext_ids ,
111
+ ))
101
112
LOG .debug ("Done setting parent %s for subport %s" ,
102
113
parent_port , subport .port_id )
114
+ return db_port
103
115
116
+ @db_base_plugin_common .convert_result_to_dict
104
117
def _unset_binding_profile (self , context , subport , ovn_txn ):
105
118
LOG .debug ("Unsetting parent for subport %s" , subport .port_id )
106
119
db_port = port_obj .Port .get_object (context , id = subport .port_id )
@@ -109,6 +122,9 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
109
122
"binding_profile: %s" ,
110
123
subport .port_id )
111
124
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 )
112
128
try :
113
129
db_port .device_owner = ''
114
130
for binding in db_port .bindings :
@@ -128,12 +144,16 @@ def _unset_binding_profile(self, context, subport, ovn_txn):
128
144
LOG .debug ("Port not found while trying to unset "
129
145
"binding_profile: %s" , subport .port_id )
130
146
return
147
+ ext_ids = {ovn_const .OVN_DEVICE_OWNER_EXT_ID_KEY : db_port .device_owner }
131
148
ovn_txn .add (self .plugin_driver .nb_ovn .set_lswitch_port (
132
149
lport_name = subport .port_id ,
133
150
parent_name = [],
134
151
up = False ,
135
- tag = []))
152
+ tag = [],
153
+ external_ids_update = ext_ids ,
154
+ ))
136
155
LOG .debug ("Done unsetting parent for subport %s" , subport .port_id )
156
+ return db_port
137
157
138
158
def trunk_created (self , trunk ):
139
159
# Check if parent port is handled by OVN.
@@ -185,7 +205,8 @@ class OVNTrunkDriver(trunk_base.DriverBase):
185
205
@property
186
206
def is_loaded (self ):
187
207
try :
188
- return OVN_ML2_MECH_DRIVER_NAME in cfg .CONF .ml2 .mechanism_drivers
208
+ return (ovn_const .OVN_ML2_MECH_DRIVER_NAME in
209
+ cfg .CONF .ml2 .mechanism_drivers )
189
210
except cfg .NoSuchOptError :
190
211
return False
191
212
@@ -205,7 +226,7 @@ def register(self, resource, event, trigger, payload=None):
205
226
@classmethod
206
227
def create (cls , plugin_driver ):
207
228
cls .plugin_driver = plugin_driver
208
- return cls (OVN_ML2_MECH_DRIVER_NAME ,
229
+ return cls (ovn_const . OVN_ML2_MECH_DRIVER_NAME ,
209
230
SUPPORTED_INTERFACES ,
210
231
SUPPORTED_SEGMENTATION_TYPES ,
211
232
None ,
0 commit comments