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

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 <helgav@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 462f0faa
......@@ -577,16 +577,21 @@ def TestIPolicyPlainInstance():
def RunInstanceTests():
"""Create and exercise instances."""
instance_tests = [
("instance-add-plain-disk", constants.DT_PLAIN,
qa_instance.TestInstanceAddWithPlainDisk, 1),
("instance-add-drbd-disk", constants.DT_DRBD8,
qa_instance.TestInstanceAddWithDrbdDisk, 2),
("instance-add-diskless", constants.DT_DISKLESS,
qa_instance.TestInstanceAddDiskless, 1),
("instance-add-file", constants.DT_FILE,
qa_instance.TestInstanceAddFile, 1),
]
instance_tests = []
enabled_disk_templates = qa_config.GetEnabledDiskTemplates()
# FIXME: Refactor this to make the code more elegant wrt to disk templates.
if constants.DT_PLAIN in enabled_disk_templates:
instance_tests.append(("instance-add-plain-disk", constants.DT_PLAIN,
qa_instance.TestInstanceAddWithPlainDisk, 1))
if constants.DT_DRBD8 in enabled_disk_templates:
instance_tests.append(("instance-add-drbd-disk", constants.DT_DRBD8,
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:
if (qa_config.TestEnabled(test_name) and
......@@ -626,6 +631,10 @@ def RunInstanceTests():
qa_config.ReleaseManyNodes(inodes)
qa_cluster.AssertClusterVerify()
RunTestIf(
"instance-add-restricted-by-disktemplates",
qa_instance.TestInstanceCreationRestrictedByDiskTemplates)
def RunQa():
"""Main QA body.
......
......@@ -179,6 +179,7 @@
"instance-add-file": true,
"instance-add-drbd-disk": true,
"instance-add-diskless": true,
"instance-add-restricted-by-disktemplates": true,
"instance-convert-disk": true,
"instance-plain-rapi-common-tests": true,
"instance-remove-drbd-offline": true,
......
......@@ -160,12 +160,15 @@ def CreateInstanceByDiskTemplate(nodes, disk_template, fail=False):
"""
if disk_template == constants.DT_DRBD8:
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,
constants.DT_FILE]:
return _CreateInstanceByDiskTemplateOneNode(nodes, disk_template, fail=fail)
else:
#FIXME: Implement this for the remaining disk templates
qa_error.Error("Instance creation not implemented for disk type '%s'." %
disk_template)
# FIXME: This assumes that for all other disk templates, we only need one
# node and no disk template specific parameters. This else-branch is
# 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):
......@@ -1001,3 +1004,63 @@ def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online):
filestorage = pathutils.DEFAULT_FILE_STORAGE_DIR
disk = os.path.join(filestorage, instance.name)
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
AssertCommand(
["gnt-cluster", "modify",
"--enabled-disk-template=%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, False)
TestInstanceRemove(instance)
# 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" %
",".join(enabled)],
fail=False)
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" %
",".join(disabled_disk_templates)],
fail=False)
CreateInstanceByDiskTemplate(nodes, enabled_disk_templates[0], True)
else:
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" %
",".join(enabled_disk_templates)],
fail=False)
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