Commit 090128b6 authored by Christos Stavrakakis's avatar Christos Stavrakakis Committed by Helga Velroyen
Browse files

Update QA tests to check disk and NIC names

Modify existing tests to use the name option for instance disks. The
configuration options 'disk' and 'disk-growth' are merged into a single
'disks' option, which is a list of dictionaries with 'size', 'growth' and
'name' items.

Also, add 'instance-device-names' QA test, which tests addition, renaming
and removal of named devices.
Signed-off-by: default avatarChristos Stavrakakis <>
Reviewed-by: default avatarHelga Velroyen <>
parent 4e4433e8
......@@ -267,6 +267,8 @@ def RunCommonInstanceTests(instance):
RunTestIf(["instance-console", qa_rapi.Enabled],
qa_rapi.TestRapiInstanceConsole, instance)
RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
DOWN_TESTS = qa_config.Either([
......@@ -68,9 +68,19 @@
"#ispec_nic_count_min": null,
"#ispec_nic_count_std": null,
"# Lists of disk sizes": null,
"disk": ["1G", "512M"],
"disk-growth": ["2G", "768M"],
"# Lists of disks": null,
"disks": [
"size": "1G",
"name": "disk0",
"growth": "2G"
"size": "512M",
"name": "disk1",
"growth": "768M"
"# Script to check instance status": null,
"instance-check": null,
......@@ -197,6 +207,7 @@
"instance-reinstall": true,
"instance-rename": true,
"instance-shutdown": true,
"instance-device-names": true,
"job-list": true,
......@@ -800,13 +800,14 @@ def TestClusterBurnin():
script = qa_utils.UploadFile(master.primary, "../tools/burnin")
disks = qa_config.GetDiskOptions()
# Run burnin
cmd = [script,
"--os=%s" % qa_config.get("os"),
"--minmem-size=%s" % qa_config.get(constants.BE_MINMEM),
"--maxmem-size=%s" % qa_config.get(constants.BE_MAXMEM),
"--disk-size=%s" % ",".join(qa_config.get("disk")),
"--disk-growth=%s" % ",".join(qa_config.get("disk-growth")),
"--disk-size=%s" % ",".join([d.get("size") for d in disks]),
"--disk-growth=%s" % ",".join([d.get("growth") for d in disks]),
"--disk-template=%s" % disk_template]
if parallel:
......@@ -280,12 +280,14 @@ class _QaConfig(object):
if not self.get("instances"):
raise qa_error.Error("Need at least one instance")
if (self.get("disk") is None or
self.get("disk-growth") is None or
len(self.get("disk")) != len(self.get("disk-growth"))):
raise qa_error.Error("Config options 'disk' and 'disk-growth' must exist"
" and have the same number of items")
disks = self.GetDiskOptions()
if disks is None:
raise qa_error.Error("Config option 'disks' must exist")
for d in disks:
if d.get("size") is None or d.get("growth") is None:
raise qa_error.Error("Config options `size` and `growth` must exist"
" for all `disks` items")
check = self.GetInstanceCheckScript()
if check:
......@@ -425,6 +427,32 @@ class _QaConfig(object):
return (master, basedir)
def GetDiskOptions(self):
"""Return options for the disks of the instances.
Get 'disks' parameter from the configuration data. If 'disks' is missing,
try to create it from the legacy 'disk' and 'disk-growth' parameters.
return self._data["disks"]
except KeyError:
# Legacy interface
sizes = self._data.get("disk")
growths = self._data.get("disk-growth")
if sizes or growths:
if (sizes is None or growths is None or len(sizes) != len(growths)):
raise qa_error.Error("Config options 'disk' and 'disk-growth' must"
" exist and have the same number of items")
disks = []
for (size, growth) in zip(sizes, growths):
disks.append({"size": size, "growth": growth})
return disks
return None
def Load(path):
"""Loads the passed configuration file.
......@@ -718,3 +746,10 @@ def NoVirtualCluster():
return not UseVirtualCluster()
def GetDiskOptions():
"""Wrapper for L{_QaConfig.GetDiskOptions}.
return GetConfig().GetDiskOptions()
......@@ -52,8 +52,10 @@ def _GetGenericAddParameters(inst, disk_template, force_mac=None):
if disk_template != constants.DT_DISKLESS:
for idx, size in enumerate(qa_config.get("disk")):
params.extend(["--disk", "%s:size=%s" % (idx, size)])
for idx, disk in enumerate(qa_config.GetDiskOptions()):
size = disk.get("size")
name = disk.get("name")
params.extend(["--disk", "%s:size=%s,name=%s" % (idx, size, name)])
# Set static MAC address if configured
if force_mac:
......@@ -780,8 +782,9 @@ def TestInstanceGrowDisk(instance):
name =
all_size = qa_config.get("disk")
all_grow = qa_config.get("disk-growth")
disks = qa_config.GetDiskOptions()
all_size = [d.get("size") for d in disks]
all_grow = [d.get("growth") for d in disks]
if not all_grow:
# missing disk sizes but instance grow disk has been enabled,
......@@ -801,6 +804,55 @@ def TestInstanceGrowDisk(instance):
str(int_size + 2 * int_grow)])
def TestInstanceDeviceNames(instance):
if instance.disk_template == constants.DT_DISKLESS:
print qa_utils.FormatInfo("Test not supported for diskless instances")
name =
for dev_type in ["disk", "net"]:
if dev_type == "disk":
options = ",size=512M"
options = ""
# succeed in adding a device named 'test_device'
AssertCommand(["gnt-instance", "modify",
"--%s=-1:add,name=test_device%s" % (dev_type, options),
# succeed in removing the 'test_device'
AssertCommand(["gnt-instance", "modify",
"--%s=test_device:remove" % dev_type,
# fail to add two devices with the same name
AssertCommand(["gnt-instance", "modify",
"--%s=-1:add,name=test_device%s" % (dev_type, options),
"--%s=-1:add,name=test_device%s" % (dev_type, options),
name], fail=True)
# fail to add a device with invalid name
AssertCommand(["gnt-instance", "modify",
"--%s=-1:add,name=2%s" % (dev_type, options),
name], fail=True)
# Rename disks
disks = qa_config.GetDiskOptions()
disk_names = [d.get("name") for d in disks]
for idx, disk_name in enumerate(disk_names):
# Refer to disk by idx
AssertCommand(["gnt-instance", "modify",
"--disk=%s:modify,name=renamed" % idx,
# Refer to by name and rename to original name
AssertCommand(["gnt-instance", "modify",
"--disk=renamed:modify,name=%s" % disk_name,
if len(disks) >= 2:
# fail in renaming to disks to the same name
AssertCommand(["gnt-instance", "modify",
name], fail=True)
def TestInstanceList():
"""gnt-instance list"""
qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
......@@ -565,8 +565,9 @@ def TestRapiInstanceAdd(node, use_client):
instance = qa_config.AcquireInstance()
disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")]
disks = [{"size": size} for size in disk_sizes]
disks = [{"size": utils.ParseUnit(d.get("size")),
"name": str(d.get("name"))}
for d in qa_config.GetDiskOptions()]
nic0_mac = instance.GetNicMacAddr(0, constants.VALUE_GENERATE)
nics = [{
constants.INIC_MAC: nic0_mac,
"name": "xen-test-qa-minimal-nodes-instances-only",
"disk": ["1G", "512M"],
"disk-growth": ["2G", "768M"],
"# Lists of disks": null,
"disks": [
"size": "1G",
"growth": "2G"
"size": "512M",
"growth": "768M"
"enabled-disk-templates": [
......@@ -205,10 +205,9 @@ class TestQaConfigLoad(unittest.TestCase):
# Missing "disk" and "disk-growth"
check_fn("Config options 'disk' and 'disk-growth' ")
check_fn("Config option 'disks'")
testconfig["disk"] = []
testconfig["disk-growth"] = testconfig["disk"]
testconfig["disks"] = []
# Minimal accepted configuration
self._WriteConfig(filename, testconfig)
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