The only problem was that at the end of the operation, the check for
deactivating the disks was too strict, requiring that the instance is
DOWN. This relaxes the check to allow OFFLINE as well.

Signed-off-by: Petr Pudlak <[email protected]>
---
 lib/cmdlib/instance_storage.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/cmdlib/instance_storage.py b/lib/cmdlib/instance_storage.py
index f28e76a..ab89075 100644
--- a/lib/cmdlib/instance_storage.py
+++ b/lib/cmdlib/instance_storage.py
@@ -1335,14 +1335,16 @@ def ShutdownInstanceDisks(lu, instance, disks=None, 
ignore_primary=False):
   return all_result
 
 
-def _SafeShutdownInstanceDisks(lu, instance, disks=None):
+def _SafeShutdownInstanceDisks(lu, instance, disks=None, req_states=None):
   """Shutdown block devices of an instance.
 
   This function checks if an instance is running, before calling
   _ShutdownInstanceDisks.
 
   """
-  CheckInstanceState(lu, instance, INSTANCE_DOWN, msg="cannot shutdown disks")
+  if req_states is None:
+    req_states = INSTANCE_DOWN
+  CheckInstanceState(lu, instance, req_states, msg="cannot shutdown disks")
   ShutdownInstanceDisks(lu, instance, disks=disks)
 
 
@@ -2250,7 +2252,8 @@ class TLReplaceDisks(Tasklet):
       # Deactivate the instance disks if we're replacing them on a
       # down instance
       if activate_disks:
-        _SafeShutdownInstanceDisks(self.lu, self.instance)
+        _SafeShutdownInstanceDisks(self.lu, self.instance,
+                                   req_states=INSTANCE_NOT_RUNNING)
 
     assert not self.lu.owned_locks(locking.LEVEL_NODE)
 
-- 
2.1.0.rc2.206.gedb03e5

Reply via email to