LUInstanceSetParams: Allow no-op change of instance offline status
authorMichael Hanselmann <hansmi@google.com>
Tue, 31 Jan 2012 06:39:02 +0000 (07:39 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 1 Feb 2012 06:19:15 +0000 (07:19 +0100)
With this patch marking an instance already marked offline (or online)
as offline/online again becomes a no-op. Also removed the unused
INSTANCE_UP variable.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/cmdlib.py
qa/qa_instance.py

index 7186ffa..ca77300 100644 (file)
@@ -68,12 +68,15 @@ import ganeti.masterd.instance # pylint: disable=W0611
 DRBD_META_SIZE = 128
 
 # States of instance
-INSTANCE_UP = [constants.ADMINST_UP]
-INSTANCE_DOWN = [constants.ADMINST_DOWN]
-INSTANCE_OFFLINE = [constants.ADMINST_OFFLINE]
 INSTANCE_ONLINE = [constants.ADMINST_DOWN, constants.ADMINST_UP]
 INSTANCE_NOT_RUNNING = [constants.ADMINST_DOWN, constants.ADMINST_OFFLINE]
 
+#: Instance status in which an instance can be marked as offline/online
+CAN_CHANGE_INSTANCE_OFFLINE = [
+  constants.ADMINST_DOWN,
+  constants.ADMINST_OFFLINE,
+  ]
+
 
 class ResultWithJobs:
   """Data container for LU results with jobs.
@@ -12326,17 +12329,12 @@ class LUInstanceSetParams(LogicalUnit):
                                      (disk_op, len(instance.disks)),
                                      errors.ECODE_INVAL)
 
-    if self.op.offline is None:
-      # Ignore
-      pass
-    elif self.op.offline:
-      # Mark instance as offline
-      _CheckInstanceState(self, instance, INSTANCE_DOWN,
-                          msg="cannot change instance state to offline")
-    else:
-      # Mark instance as online, but stopped
-      _CheckInstanceState(self, instance, INSTANCE_OFFLINE,
-                          msg="cannot make instance go online")
+    if self.op.offline is not None:
+      if self.op.offline:
+        msg = "can't change to offline"
+      else:
+        msg = "can't change to online"
+      _CheckInstanceState(self, instance, CAN_CHANGE_INSTANCE_OFFLINE, msg=msg)
 
   def _ConvertPlainToDrbd(self, feedback_fn):
     """Converts an instance from plain to drbd.
index 7b8523a..dce7936 100644 (file)
@@ -261,8 +261,8 @@ def TestInstanceStoppedModify(instance):
   """gnt-instance modify (stopped instance)"""
   name = instance["name"]
 
-  # Assume instance was not marked offline, so marking it online must fail
-  AssertCommand(["gnt-instance", "modify", "--online", name], fail=True)
+  # Instance was not marked offline; try marking it online once more
+  AssertCommand(["gnt-instance", "modify", "--online", name])
 
   # Mark instance as offline
   AssertCommand(["gnt-instance", "modify", "--offline", name])