From ec596c24f343013471313ebb05c17581b2f1d970 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 7 Jan 2009 17:01:46 +0000
Subject: [PATCH] Catch BlockDeviceError when starting instance

This is a forward-port of commit 1149 on the 1.2 branch:
  _GatherAndLinkBlockDevs used to raise the errors.BlockDeviceError
  exception when it failed to create a block device, and with this patch
  set it does so also when it fails to create a symlink to it.

  With this patch we move the call to this function into a pre-existing
  try-except block in the code, and catch the BlockDeviceError exception,
  logging a message and returning a failure state if it happens.

  Reviewed-by: iustinp

The changes are related to the new hypervisor and logging syntax.

Original-Author: ultrotter
---
 lib/backend.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 2a483dbbb..4839c6162 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -809,11 +809,13 @@ def StartInstance(instance, extra_args):
   if instance.name in running_instances:
     return True
 
-  block_devices = _GatherAndLinkBlockDevs(instance)
-  hyper = hypervisor.GetHypervisor(instance.hypervisor)
-
   try:
+    block_devices = _GatherAndLinkBlockDevs(instance)
+    hyper = hypervisor.GetHypervisor(instance.hypervisor)
     hyper.StartInstance(instance, block_devices, extra_args)
+  except errors.BlockDeviceError, err:
+    logging.exception("Failed to start instance")
+    return False
   except errors.HypervisorError, err:
     logging.exception("Failed to start instance")
     return False
-- 
GitLab