+ AssertCommand(["gnt-instance", "start", instance.name])
+
+
+def _AssertRecreateDisks(cmdargs, instance, fail=False, check=True,
+ destroy=True):
+ """Execute gnt-instance recreate-disks and check the result
+
+ @param cmdargs: Arguments (instance name excluded)
+ @param instance: Instance to operate on
+ @param fail: True if the command is expected to fail
+ @param check: If True and fail is False, check that the disks work
+ @prama destroy: If True, destroy the old disks first
+
+ """
+ if destroy:
+ _DestroyInstanceDisks(instance)
+ AssertCommand((["gnt-instance", "recreate-disks"] + cmdargs +
+ [instance.name]), fail)
+ if not fail and check:
+ # Quick check that the disks are there
+ AssertCommand(["gnt-instance", "activate-disks", instance.name])
+ AssertCommand(["gnt-instance", "activate-disks", "--wait-for-sync",
+ instance.name])
+ AssertCommand(["gnt-instance", "deactivate-disks", instance.name])
+
+
+def _BuildRecreateDisksOpts(en_disks, with_spindles, with_growth,
+ spindles_supported):
+ if with_spindles:
+ if spindles_supported:
+ if with_growth:
+ build_spindles_opt = (lambda disk:
+ ",spindles=%s" %
+ (disk["spindles"] + disk["spindles-growth"]))
+ else:
+ build_spindles_opt = (lambda disk:
+ ",spindles=%s" % disk["spindles"])
+ else:
+ build_spindles_opt = (lambda _: ",spindles=1")
+ else:
+ build_spindles_opt = (lambda _: "")
+ if with_growth:
+ build_size_opt = (lambda disk:
+ "size=%s" % (utils.ParseUnit(disk["size"]) +
+ utils.ParseUnit(disk["growth"])))
+ else:
+ build_size_opt = (lambda disk: "size=%s" % disk["size"])
+ build_disk_opt = (lambda (idx, disk):
+ "--disk=%s:%s%s" % (idx, build_size_opt(disk),
+ build_spindles_opt(disk)))
+ return map(build_disk_opt, en_disks)
+
+
+@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
+def TestRecreateDisks(instance, inodes, othernodes):
+ """gnt-instance recreate-disks
+
+ @param instance: Instance to work on
+ @param inodes: List of the current nodes of the instance
+ @param othernodes: list/tuple of nodes where to temporarily recreate disks
+
+ """
+ options = qa_config.get("options", {})
+ use_ialloc = options.get("use-iallocators", True)
+ other_seq = ":".join([n.primary for n in othernodes])
+ orig_seq = ":".join([n.primary for n in inodes])
+ # These fail because the instance is running
+ _AssertRecreateDisks(["-n", other_seq], instance, fail=True, destroy=False)
+ if use_ialloc:
+ _AssertRecreateDisks(["-I", "hail"], instance, fail=True, destroy=False)
+ else:
+ _AssertRecreateDisks(["-n", other_seq], instance, fail=True, destroy=False)
+ AssertCommand(["gnt-instance", "stop", instance.name])
+ # Disks exist: this should fail
+ _AssertRecreateDisks([], instance, fail=True, destroy=False)
+ # Unsupported spindles parameters: fail
+ if not qa_config.AreSpindlesSupported():
+ _AssertRecreateDisks(["--disk=0:spindles=2"], instance,
+ fail=True, destroy=False)
+ # Recreate disks in place
+ _AssertRecreateDisks([], instance)
+ # Move disks away
+ if use_ialloc:
+ _AssertRecreateDisks(["-I", "hail"], instance)
+ # Move disks somewhere else
+ _AssertRecreateDisks(["-I", constants.DEFAULT_IALLOCATOR_SHORTCUT],
+ instance)
+ else:
+ _AssertRecreateDisks(["-n", other_seq], instance)
+ # Move disks back
+ _AssertRecreateDisks(["-n", orig_seq], instance)
+ # Recreate resized disks
+ # One of the two commands fails because either spindles are given when they
+ # should not or vice versa
+ alldisks = qa_config.GetDiskOptions()
+ spindles_supported = qa_config.AreSpindlesSupported()
+ disk_opts = _BuildRecreateDisksOpts(enumerate(alldisks), True, True,
+ spindles_supported)
+ _AssertRecreateDisks(disk_opts, instance, destroy=True,
+ fail=not spindles_supported)
+ disk_opts = _BuildRecreateDisksOpts(enumerate(alldisks), False, True,
+ spindles_supported)
+ _AssertRecreateDisks(disk_opts, instance, destroy=False,
+ fail=spindles_supported)
+ # Recreate the disks one by one (with the original size)
+ for (idx, disk) in enumerate(alldisks):
+ # Only the first call should destroy all the disk
+ destroy = (idx == 0)
+ # Again, one of the two commands is expected to fail
+ disk_opts = _BuildRecreateDisksOpts([(idx, disk)], True, False,
+ spindles_supported)
+ _AssertRecreateDisks(disk_opts, instance, destroy=destroy, check=False,
+ fail=not spindles_supported)
+ disk_opts = _BuildRecreateDisksOpts([(idx, disk)], False, False,
+ spindles_supported)
+ _AssertRecreateDisks(disk_opts, instance, destroy=False, check=False,
+ fail=spindles_supported)
+ # This and InstanceCheck decoration check that the disks are working
+ AssertCommand(["gnt-instance", "reinstall", "-f", instance.name])
+ AssertCommand(["gnt-instance", "start", instance.name])