Commit 6f665bf7 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

QA: creating instances of dis/enabled disk templates

This patch makes sure that instance creation is only possible
for instances that use enabled disk templates.
Signed-off-by: default avatarHelga Velroyen <>
Reviewed-by: default avatarGuido Trotter <>
parent 462f0faa
...@@ -577,16 +577,21 @@ def TestIPolicyPlainInstance(): ...@@ -577,16 +577,21 @@ def TestIPolicyPlainInstance():
def RunInstanceTests(): def RunInstanceTests():
"""Create and exercise instances.""" """Create and exercise instances."""
instance_tests = [ instance_tests = []
("instance-add-plain-disk", constants.DT_PLAIN, enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
qa_instance.TestInstanceAddWithPlainDisk, 1), # FIXME: Refactor this to make the code more elegant wrt to disk templates.
("instance-add-drbd-disk", constants.DT_DRBD8, if constants.DT_PLAIN in enabled_disk_templates:
qa_instance.TestInstanceAddWithDrbdDisk, 2), instance_tests.append(("instance-add-plain-disk", constants.DT_PLAIN,
("instance-add-diskless", constants.DT_DISKLESS, qa_instance.TestInstanceAddWithPlainDisk, 1))
qa_instance.TestInstanceAddDiskless, 1), if constants.DT_DRBD8 in enabled_disk_templates:
("instance-add-file", constants.DT_FILE, instance_tests.append(("instance-add-drbd-disk", constants.DT_DRBD8,
qa_instance.TestInstanceAddFile, 1), qa_instance.TestInstanceAddWithDrbdDisk, 2))
] if constants.DT_DISKLESS in enabled_disk_templates:
instance_tests.append(("instance-add-diskless", constants.DT_DISKLESS,
qa_instance.TestInstanceAddDiskless, 1))
if constants.DT_FILE in enabled_disk_templates:
instance_tests.append(("instance-add-file", constants.DT_FILE,
qa_instance.TestInstanceAddFile, 1))
for (test_name, templ, create_fun, num_nodes) in instance_tests: for (test_name, templ, create_fun, num_nodes) in instance_tests:
if (qa_config.TestEnabled(test_name) and if (qa_config.TestEnabled(test_name) and
...@@ -626,6 +631,10 @@ def RunInstanceTests(): ...@@ -626,6 +631,10 @@ def RunInstanceTests():
qa_config.ReleaseManyNodes(inodes) qa_config.ReleaseManyNodes(inodes)
qa_cluster.AssertClusterVerify() qa_cluster.AssertClusterVerify()
def RunQa(): def RunQa():
"""Main QA body. """Main QA body.
...@@ -179,6 +179,7 @@ ...@@ -179,6 +179,7 @@
"instance-add-file": true, "instance-add-file": true,
"instance-add-drbd-disk": true, "instance-add-drbd-disk": true,
"instance-add-diskless": true, "instance-add-diskless": true,
"instance-add-restricted-by-disktemplates": true,
"instance-convert-disk": true, "instance-convert-disk": true,
"instance-plain-rapi-common-tests": true, "instance-plain-rapi-common-tests": true,
"instance-remove-drbd-offline": true, "instance-remove-drbd-offline": true,
...@@ -160,12 +160,15 @@ def CreateInstanceByDiskTemplate(nodes, disk_template, fail=False): ...@@ -160,12 +160,15 @@ def CreateInstanceByDiskTemplate(nodes, disk_template, fail=False):
""" """
if disk_template == constants.DT_DRBD8: if disk_template == constants.DT_DRBD8:
return _CreateInstanceDrbd8(nodes, fail=fail) return _CreateInstanceDrbd8(nodes, fail=fail)
elif disk_template in [constants.DT_DISKLESS, constants.DT_PLAIN]: elif disk_template in [constants.DT_DISKLESS, constants.DT_PLAIN,
return _CreateInstanceByDiskTemplateOneNode(nodes, disk_template, fail=fail) return _CreateInstanceByDiskTemplateOneNode(nodes, disk_template, fail=fail)
else: else:
#FIXME: Implement this for the remaining disk templates # FIXME: This assumes that for all other disk templates, we only need one
qa_error.Error("Instance creation not implemented for disk type '%s'." % # node and no disk template specific parameters. This else-branch is
disk_template) # currently only used in cases where we expect failure. Extend it when
# QA needs for these templates change.
return _CreateInstanceByDiskTemplateOneNode(nodes, disk_template, fail=fail)
def _GetInstanceInfo(instance): def _GetInstanceInfo(instance):
...@@ -1001,3 +1004,63 @@ def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online): ...@@ -1001,3 +1004,63 @@ def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online):
filestorage = pathutils.DEFAULT_FILE_STORAGE_DIR filestorage = pathutils.DEFAULT_FILE_STORAGE_DIR
disk = os.path.join(filestorage, disk = os.path.join(filestorage,
AssertCommand(["rm", "-rf", disk], node=snode) AssertCommand(["rm", "-rf", disk], node=snode)
def TestInstanceCreationRestrictedByDiskTemplates():
"""Test if adding instances is only possible if they use an enabled
disk template."""
enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
nodes = qa_config.AcquireManyNodes(2)
# Setup the cluster with the enabled_disk_templates
["gnt-cluster", "modify",
"--enabled-disk-template=%s" %
# Test instance creation for enabled disk templates
for disk_template in enabled_disk_templates:
instance = CreateInstanceByDiskTemplate(nodes, disk_template, False)
# 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, 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-template=%s" %
for disk_template in disabled:
CreateInstanceByDiskTemplate(nodes, disk_template, True)
elif (len(enabled_disk_templates) == 1):
# If only one disk template is enabled in the QA config, we have to enable
# some of the disabled disk templates in order to test if the disabling the
# only enabled disk template prohibits creating instances of that template.
AssertCommand(["gnt-cluster", "modify",
"--enabled-disk-template=%s" %
CreateInstanceByDiskTemplate(nodes, enabled_disk_templates[0], True)
raise qa_error.Error("Please enable at least one disk template"
" in your QA setup.")
# Restore initially enabled disk templates
AssertCommand(["gnt-cluster", "modify",
"--enabled-disk-template=%s" %
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