diff --git a/networking_ccloud/ml2/mech_driver.py b/networking_ccloud/ml2/mech_driver.py index 33c0dfaf..1559b80f 100644 --- a/networking_ccloud/ml2/mech_driver.py +++ b/networking_ccloud/ml2/mech_driver.py @@ -543,10 +543,20 @@ def update_port_postcommit(self, context): LOG.debug("Port %s does not have two binding levels, no update will be sent. Old host %s, levels %s", context.current['id'], old_host, context.original_binding_levels) return + orig_network_id = None + if context.network.original is not None: + orig_network_id = context.network.original['id'] + elif 'network_id' in context.original_binding_levels[1][ml2_api.BOUND_SEGMENT]: + orig_network_id = context.original_binding_levels[1][ml2_api.BOUND_SEGMENT]['network_id'] + else: + LOG.warning("Port %s transitioning from %s to %s does not have an original network attached to it, " + "old host will not be cleaned up", + context.current['id'], old_host, new_host) + return self.driver_handle_binding_host_removed(context._plugin_context, context, context.original, context.original_binding_levels[0][ml2_api.BOUND_SEGMENT], context.original_binding_levels[1][ml2_api.BOUND_SEGMENT], - context.network.original['id']) + orig_network_id) def delete_port_postcommit(self, context): """Delete a port.