Commit 3016bc1f authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

OpInstanceSetParams: Merge {off,on}line_inst parameters

Instead of having two separate parameters, a single boolean parameter is
used. Unfortunately we need a third state to say “no change”, so the
value can be None, True or False (similar to other parameters). There
are no user interface changes.

New QA tests are added, too.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarGuido Trotter <>
parent 784b6603
......@@ -1327,6 +1327,13 @@ def SetInstanceParams(opts, args):
" specifying a secondary node")
return 1
if opts.offline_inst:
offline = True
elif opts.online_inst:
offline = False
offline = None
op = opcodes.OpInstanceSetParams(instance_name=args[0],
......@@ -1340,8 +1347,7 @@ def SetInstanceParams(opts, args):
# even if here we process the result, we allow submit only
......@@ -11806,8 +11806,7 @@ class LUInstanceSetParams(LogicalUnit):
def CheckArguments(self):
if not (self.op.nics or self.op.disks or self.op.disk_template or
self.op.hvparams or self.op.beparams or self.op.os_name or
self.op.online_inst or self.op.offline_inst or
self.op.offline is not None or self.op.runtime_mem):
raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
if self.op.hvparams:
......@@ -12327,13 +12326,15 @@ class LUInstanceSetParams(LogicalUnit):
(disk_op, len(instance.disks)),
# disabling the instance
if self.op.offline_inst:
if self.op.offline is None:
# Ignore
elif self.op.offline:
# Mark instance as offline
_CheckInstanceState(self, instance, INSTANCE_DOWN,
msg="cannot change instance state to offline")
# enabling the instance
if self.op.online_inst:
# Mark instance as online, but stopped
_CheckInstanceState(self, instance, INSTANCE_OFFLINE,
msg="cannot make instance go online")
......@@ -12619,13 +12620,17 @@ class LUInstanceSetParams(LogicalUnit):
for key, val in self.op.osparams.iteritems():
result.append(("os/%s" % key, val))
# online/offline instance
if self.op.online_inst:
result.append(("admin_state", constants.ADMINST_DOWN))
if self.op.offline_inst:
if self.op.offline is None:
# Ignore
elif self.op.offline:
# Mark instance as offline
result.append(("admin_state", constants.ADMINST_OFFLINE))
# Mark instance as online, but stopped
result.append(("admin_state", constants.ADMINST_DOWN))
self.cfg.Update(instance, feedback_fn)
......@@ -1401,10 +1401,7 @@ class OpInstanceSetParams(OpCode):
("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
("wait_for_sync", True, ht.TBool,
"Whether to wait for the disk to synchronize, when changing template"),
("offline_inst", False, ht.TBool,
"Whether to turn off the down instance completely"),
("online_inst", False, ht.TBool,
"Whether to enable the offline instance"),
("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
OP_RESULT = _TSetParamsResult
......@@ -226,6 +226,8 @@ def RunCommonInstanceTests(instance):
RunTestIf("instance-shutdown", qa_instance.TestInstanceShutdown, instance)
RunTestIf(["instance-shutdown", "instance-console", "rapi"],
qa_rapi.TestRapiStoppedInstanceConsole, instance)
RunTestIf(["instance-shutdown", "instance-modify"],
qa_instance.TestInstanceStoppedModify, instance)
RunTestIf("instance-shutdown", qa_instance.TestInstanceStartup, instance)
# Test shutdown/start via RAPI
......@@ -252,6 +252,24 @@ def TestInstanceModify(instance):
# check no-modify
AssertCommand(["gnt-instance", "modify", instance["name"]], fail=True)
# Marking offline/online while instance is running must fail
for arg in ["--online", "--offline"]:
AssertCommand(["gnt-instance", "modify", arg, instance["name"]], fail=True)
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)
# Mark instance as offline
AssertCommand(["gnt-instance", "modify", "--offline", name])
# And online again
AssertCommand(["gnt-instance", "modify", "--online", name])
def TestInstanceConvertDisk(instance, snode):
"""gnt-instance modify -t"""
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