@@ -2048,6 +2048,26 @@ def _pre_delete_port(self, context, port_id, port_check, port=None):
2048
2048
@utils .transaction_guard
2049
2049
@db_api .retry_if_session_inactive ()
2050
2050
def delete_port (self , context , id , l3_port_check = True ):
2051
+
2052
+ def handle_distributed_port_bindings (mech_contexts ):
2053
+ bindings = db .get_distributed_port_bindings (context , id )
2054
+ for bind in bindings :
2055
+ levels = db .get_binding_level_objs (context , id , bind .host )
2056
+ metadata ['bind' ] = bind
2057
+ metadata ['levels' ] = levels
2058
+ registry .publish (resources .PORT ,
2059
+ events .PRECOMMIT_DELETE ,
2060
+ self ,
2061
+ payload = events .DBEventPayload (
2062
+ context ,
2063
+ resource_id = id ,
2064
+ metadata = metadata ,
2065
+ states = (port ,)))
2066
+ mech_context = driver_context .PortContext (
2067
+ self , context , port , network , bind , levels )
2068
+ self .mechanism_manager .delete_port_precommit (mech_context )
2069
+ mech_contexts .append (mech_context )
2070
+
2051
2071
try :
2052
2072
port_db = self ._get_port (context , id )
2053
2073
port = self ._make_port_dict (port_db )
@@ -2062,48 +2082,38 @@ def delete_port(self, context, id, l3_port_check=True):
2062
2082
2063
2083
with db_api .CONTEXT_WRITER .using (context ):
2064
2084
binding = p_utils .get_port_binding_by_status_and_host (
2065
- port_db .port_bindings , const .ACTIVE ,
2066
- raise_if_not_found = True , port_id = id )
2085
+ port_db .port_bindings , const .ACTIVE , port_id = id )
2067
2086
2068
2087
network = self .get_network (context , port ['network_id' ])
2069
2088
bound_mech_contexts = []
2070
2089
device_owner = port ['device_owner' ]
2071
2090
metadata = {'network' : network ,
2072
2091
'port_db' : port_db ,
2073
2092
'bindings' : binding }
2074
- if device_owner == const .DEVICE_OWNER_DVR_INTERFACE :
2075
- bindings = db .get_distributed_port_bindings (context ,
2076
- id )
2077
- for bind in bindings :
2078
- levels = db .get_binding_level_objs (context , id , bind .host )
2079
- metadata ['bind' ] = bind
2093
+
2094
+ if not binding :
2095
+ LOG .warning ('The port %s has no binding information, the '
2096
+ '"ml2_port_bindings" register is not present' , id )
2097
+ if device_owner == const .DEVICE_OWNER_DVR_INTERFACE :
2098
+ handle_distributed_port_bindings (bound_mech_contexts )
2099
+ else :
2100
+ if device_owner == const .DEVICE_OWNER_DVR_INTERFACE :
2101
+ handle_distributed_port_bindings (bound_mech_contexts )
2102
+ else :
2103
+ levels = db .get_binding_level_objs (context , id ,
2104
+ binding .host )
2105
+ metadata ['bind' ] = None
2080
2106
metadata ['levels' ] = levels
2081
- registry .publish (resources .PORT ,
2082
- events .PRECOMMIT_DELETE ,
2083
- self ,
2084
- payload = events .DBEventPayload (
2107
+ registry .publish (resources .PORT , events .PRECOMMIT_DELETE ,
2108
+ self , payload = events .DBEventPayload (
2085
2109
context ,
2086
2110
resource_id = id ,
2087
2111
metadata = metadata ,
2088
2112
states = (port ,)))
2089
2113
mech_context = driver_context .PortContext (
2090
- self , context , port , network , bind , levels )
2114
+ self , context , port , network , binding , levels )
2091
2115
self .mechanism_manager .delete_port_precommit (mech_context )
2092
2116
bound_mech_contexts .append (mech_context )
2093
- else :
2094
- levels = db .get_binding_level_objs (context , id , binding .host )
2095
- metadata ['bind' ] = None
2096
- metadata ['levels' ] = levels
2097
- registry .publish (resources .PORT , events .PRECOMMIT_DELETE , self ,
2098
- payload = events .DBEventPayload (
2099
- context ,
2100
- resource_id = id ,
2101
- metadata = metadata ,
2102
- states = (port ,)))
2103
- mech_context = driver_context .PortContext (
2104
- self , context , port , network , binding , levels )
2105
- self .mechanism_manager .delete_port_precommit (mech_context )
2106
- bound_mech_contexts .append (mech_context )
2107
2117
if l3plugin :
2108
2118
router_ids = l3plugin .disassociate_floatingips (
2109
2119
context , id , do_notify = False )
0 commit comments