From a70af8319cc7bef341e3f25b86a228e87d6d81aa Mon Sep 17 00:00:00 2001 From: Wen Zhi Yu Date: Tue, 19 Jan 2016 15:28:02 +0800 Subject: [PATCH] Add exception handling in _cleanup_allocated_network The _cleanup_allocated_network method used in nova.compute.manager.py has exception handling around deallocate_for_instance. That should be added in nova.condutor.manager as well. Without it we'll end up with the RPC layer complaining about unexpected exceptions. This commit add exception handling logic around deallocate_for_instance nova.conductor.manager._cleanup_allocated_network() method. Change-Id: Id536e2b4794d56a32af4d13577415e427e2eeb2d --- nova/conductor/manager.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py index b06dd3d3cdee..169e598c42ea 100644 --- a/nova/conductor/manager.py +++ b/nova/conductor/manager.py @@ -254,8 +254,22 @@ class ComputeTaskManager(base.Base): def _cleanup_allocated_networks( self, context, instance, requested_networks): - self.network_api.deallocate_for_instance( - context, instance, requested_networks=requested_networks) + try: + self.network_api.deallocate_for_instance( + context, instance, requested_networks=requested_networks) + except Exception: + msg = _LE('Failed to deallocate networks') + LOG.exception(msg, instance=instance) + return + + instance.system_metadata['network_allocated'] = 'False' + try: + instance.save() + except exception.InstanceNotFound: + # NOTE: It's possible that we're cleaning up the networks + # because the instance was deleted. If that's the case then this + # exception will be raised by instance.save() + pass def _live_migrate(self, context, instance, scheduler_hint, block_migration, disk_over_commit):