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