Commit 58f0ce16 authored by Michael Hanselmann's avatar Michael Hanselmann

LUInstanceSetParams: Allow no-op change of instance offline status

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: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 3016bc1f
......@@ -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.
......
......@@ -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])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment