+ set_online(snode)
+
+ # Clean up the disks on the offline node, if necessary
+ if instance.disk_template not in constants.DTS_EXT_MIRROR:
+ # FIXME: abstract the cleanup inside the disks
+ if info["storage-type"] == constants.ST_LVM_VG:
+ for minor in info["drbd-minors"][snode.primary]:
+ # DRBD 8.3 syntax comes first, then DRBD 8.4 syntax. The 8.4 syntax
+ # relies on the fact that we always create a resources for each minor,
+ # and that this resources is always named resource{minor}.
+ # As 'drbdsetup 0 down' does return success (even though that's invalid
+ # syntax), we always have to perform both commands and ignore the
+ # output.
+ drbd_shutdown_cmd = \
+ "(drbdsetup %d down >/dev/null 2>&1;" \
+ " drbdsetup down resource%d >/dev/null 2>&1) || /bin/true" % \
+ (minor, minor)
+ AssertCommand(drbd_shutdown_cmd, node=snode)
+ AssertCommand(["lvremove", "-f"] + info["volumes"], node=snode)
+ elif info["storage-type"] == constants.ST_FILE:
+ filestorage = qa_config.get("file-storage-dir",
+ pathutils.DEFAULT_FILE_STORAGE_DIR)
+ disk = os.path.join(filestorage, instance.name)
+ AssertCommand(["rm", "-rf", disk], node=snode)
+
+
+def TestInstanceCreationRestrictedByDiskTemplates():
+ """Test adding instances for disabled disk templates."""
+ if qa_config.TestEnabled("cluster-exclusive-storage"):
+ # These tests are valid only for non-exclusive storage
+ return
+
+ enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
+ nodes = qa_config.AcquireManyNodes(2)
+
+ # Setup the cluster with the enabled_disk_templates
+ AssertCommand(
+ ["gnt-cluster", "modify",
+ "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates),
+ "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates)],
+ fail=False)
+
+ # Test instance creation for enabled disk templates
+ for disk_template in enabled_disk_templates:
+ instance = CreateInstanceByDiskTemplate(nodes, disk_template, fail=False)
+ TestInstanceRemove(instance)
+ instance.Release()
+
+ # Test that instance creation fails for disabled disk templates
+ disabled_disk_templates = list(constants.DISK_TEMPLATES
+ - set(enabled_disk_templates))
+ for disk_template in disabled_disk_templates:
+ instance = CreateInstanceByDiskTemplate(nodes, disk_template, fail=True)
+
+ # Test instance creation for after disabling enabled disk templates
+ if (len(enabled_disk_templates) > 1):
+ # Partition the disk templates, enable them separately and check if the
+ # disabled ones cannot be used by instances.
+ middle = len(enabled_disk_templates) / 2
+ templates1 = enabled_disk_templates[:middle]
+ templates2 = enabled_disk_templates[middle:]
+
+ for (enabled, disabled) in [(templates1, templates2),
+ (templates2, templates1)]:
+ AssertCommand(["gnt-cluster", "modify",
+ "--enabled-disk-templates=%s" % ",".join(enabled),
+ "--ipolicy-disk-templates=%s" % ",".join(enabled)],
+ fail=False)
+ for disk_template in disabled:
+ CreateInstanceByDiskTemplate(nodes, disk_template, fail=True)
+ elif (len(enabled_disk_templates) == 1):
+ # If only one disk template is enabled in the QA config, we have to enable
+ # some other templates in order to test if the disabling the only enabled
+ # disk template prohibits creating instances of that template.
+ other_disk_templates = list(
+ set([constants.DT_DISKLESS, constants.DT_BLOCK]) -
+ set(enabled_disk_templates))
+ AssertCommand(["gnt-cluster", "modify",
+ "--enabled-disk-templates=%s" %
+ ",".join(other_disk_templates),
+ "--ipolicy-disk-templates=%s" %
+ ",".join(other_disk_templates)],
+ fail=False)
+ CreateInstanceByDiskTemplate(nodes, enabled_disk_templates[0], fail=True)