def _shutdown_instance(self, instance): ctx = context.ctx() if instance.node_group.floating_ip_pool: try: networks.delete_floating_ip(instance.instance_id) except nova_exceptions.NotFound: LOG.warn( "Attempted to delete non-existent floating IP in " "pool %s from instancie %s", instance.node_group.floating_ip_pool, instance.instance_id) try: volumes.detach_from_instance(instance) except Exception: LOG.warn("Detaching volumes from instance %s failed", instance.instance_id) try: nova.client().servers.delete(instance.instance_id) except nova_exceptions.NotFound: LOG.warn("Attempted to delete non-existent instance %s", instance.instance_id) conductor.instance_remove(ctx, instance)
def _shutdown_instance(self, instance): ctx = context.ctx() if instance.node_group.floating_ip_pool: try: networks.delete_floating_ip(instance.instance_id) except nova_exceptions.NotFound: LOG.warn("Attempted to delete non-existent floating IP in " "pool %s from instancie %s", instance.node_group.floating_ip_pool, instance.instance_id) try: volumes.detach_from_instance(instance) except Exception: LOG.warn("Detaching volumes from instance %s failed", instance.instance_id) try: nova.client().servers.delete(instance.instance_id) except nova_exceptions.NotFound: LOG.warn("Attempted to delete non-existent instance %s", instance.instance_id) conductor.instance_remove(ctx, instance)
def test_detach_volumes(self, p_get_volume, p_detach, p_delete, p_cond): class Instance: def __init__(self): self.instance_id = '123454321' self.volumes = [123] instance = Instance() p_get_volume.return_value = v.Volume(None, {'id': '123'}) p_detach.return_value = None p_delete.return_value = None self.assertIsNone(volumes.detach_from_instance(instance)) p_delete.side_effect = RuntimeError self.assertRaises(RuntimeError, volumes.detach_from_instance, instance)
def test_detach_volumes(self, p_get_volume, p_detach, p_delete, p_cond): class Instance: def __init__(self): self.instance_id = '123454321' self.volumes = [123] instance = Instance() p_get_volume.return_value = v.Volume(None, {'id': '123'}) p_detach.return_value = None p_delete.return_value = None self.assertIsNone( volumes.detach_from_instance(instance)) p_delete.side_effect = RuntimeError self.assertRaises(RuntimeError, volumes.detach_from_instance, instance)