From 4b8b172db2da14e7bf51a6ef54afac8cf97c8c05 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 24 Jan 2013 14:29:18 +0100
Subject: [PATCH] hv_xen: Remove config after shutdown was successful

If stopping an instance failed, the configuration would already be gone
and other operations depending on it (e.g. migration) would no longer
work. With this patch the configuration file is only removed once the
instance was succesfully stopped or destroyed.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>
---
 lib/hypervisor/hv_xen.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 623f1bd0c..626994f32 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -272,7 +272,7 @@ class XenHypervisor(hv_base.BaseHypervisor):
     """
     if name is None:
       name = instance.name
-    self._RemoveConfigFile(name)
+
     if force:
       command = [constants.XEN_CMD, "destroy", name]
     else:
@@ -283,6 +283,9 @@ class XenHypervisor(hv_base.BaseHypervisor):
       raise errors.HypervisorError("Failed to stop instance %s: %s, %s" %
                                    (name, result.fail_reason, result.output))
 
+    # Remove configuration file if stopping/starting instance was successful
+    self._RemoveConfigFile(name)
+
   def RebootInstance(self, instance):
     """Reboot an instance.
 
-- 
GitLab