Dont raise exception if instance is not found
If the instance has been deleted before it could be created pylxd will raise an exception if the container or profile is not found. This is the correct thing to do in my opinon. However in nova when the exception is raised the instance will be put into an error state, since instance life cycle did not complete. This was discovered by tempest unit tests. Change-Id: Ia59cf13095dbbe933c5b96b4adb3f64a8dbe37ca Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
parent
8f7dca4e4b
commit
46c7357efa
|
@ -446,9 +446,9 @@ class LXDDriverTest(test.NoDBTestCase):
|
|||
lxd_driver.init_host(None)
|
||||
lxd_driver.cleanup = mock.Mock() # There is a separate cleanup test
|
||||
|
||||
self.assertRaises(
|
||||
lxdcore_exceptions.LXDAPIException,
|
||||
lxd_driver.destroy, ctx, instance, network_info)
|
||||
lxd_driver.destroy(ctx, instance, network_info)
|
||||
lxd_driver.cleanup.assert_called_once_with(
|
||||
ctx, instance, network_info, None)
|
||||
|
||||
@mock.patch('os.path.exists', mock.Mock(return_value=True))
|
||||
@mock.patch('pwd.getpwuid')
|
||||
|
|
|
@ -329,18 +329,17 @@ class LXDDriver(driver.ComputeDriver):
|
|||
container = self.client.containers.get(instance.name)
|
||||
if container.status != 'Stopped':
|
||||
container.stop(wait=True)
|
||||
container.delete(wait=True)
|
||||
except lxd_exceptions.LXDAPIException as e:
|
||||
if e.response.status_code != 200:
|
||||
raise
|
||||
elif e.response.status_code == 404:
|
||||
self.cleanup(
|
||||
context, instance, network_info, block_device_info)
|
||||
if e.response.status_code == 404:
|
||||
LOG.warning(_LW('Failed to delete instance. '
|
||||
'Container does not exist for %(instance)s.'),
|
||||
{'instance': instance.name})
|
||||
else:
|
||||
return
|
||||
|
||||
container.delete(wait=True)
|
||||
|
||||
self.cleanup(context, instance, network_info, block_device_info)
|
||||
raise
|
||||
finally:
|
||||
self.cleanup(
|
||||
context, instance, network_info, block_device_info)
|
||||
|
||||
def cleanup(self, context, instance, network_info, block_device_info=None,
|
||||
destroy_disks=True, migrate_data=None, destroy_vifs=True):
|
||||
|
@ -371,7 +370,15 @@ class LXDDriver(driver.ComputeDriver):
|
|||
container_dir, run_as_root=True)
|
||||
shutil.rmtree(container_dir)
|
||||
|
||||
self.client.profiles.get(instance.name).delete()
|
||||
try:
|
||||
self.client.profiles.get(instance.name).delete()
|
||||
except lxd_exceptions.LXDAPIException as e:
|
||||
if e.response.status_code == 404:
|
||||
LOG.warning(_LW('Failed to delete instance. '
|
||||
'Profile does not exist for %(instance)s.'),
|
||||
{'instance': instance.name})
|
||||
else:
|
||||
raise
|
||||
|
||||
def reboot(self, context, instance, network_info, reboot_type,
|
||||
block_device_info=None, bad_volumes_callback=None):
|
||||
|
|
Loading…
Reference in New Issue