RunTestIf(["instance-console", qa_rapi.Enabled],
qa_rapi.TestRapiInstanceConsole, instance)
+ RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
+ instance)
DOWN_TESTS = qa_config.Either([
"instance-reinstall",
"instance-rename",
"#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,
"instance-reinstall": true,
"instance-rename": true,
"instance-shutdown": true,
+ "instance-device-names": true,
"job-list": true,
script = qa_utils.UploadFile(master.primary, "../tools/burnin")
try:
+ 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:
cmd.append("--parallel")
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")
+ else:
+ 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:
try:
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.
+
+ """
+ try:
+ return self._data["disks"]
+ except KeyError:
+ pass
+
+ # 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
+ else:
+ return None
+
def Load(path):
"""Loads the passed configuration file.
"""
return not UseVirtualCluster()
+
+
+def GetDiskOptions():
+ """Wrapper for L{_QaConfig.GetDiskOptions}.
+
+ """
+ return GetConfig().GetDiskOptions()
qa_config.get(constants.BE_MAXMEM)))
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:
return
name = 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,
str(int_size + 2 * int_grow)])
+@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
+def TestInstanceDeviceNames(instance):
+ if instance.disk_template == constants.DT_DISKLESS:
+ print qa_utils.FormatInfo("Test not supported for diskless instances")
+ return
+
+ name = instance.name
+ for dev_type in ["disk", "net"]:
+ if dev_type == "disk":
+ options = ",size=512M"
+ else:
+ options = ""
+ # succeed in adding a device named 'test_device'
+ AssertCommand(["gnt-instance", "modify",
+ "--%s=-1:add,name=test_device%s" % (dev_type, options),
+ name])
+ # succeed in removing the 'test_device'
+ AssertCommand(["gnt-instance", "modify",
+ "--%s=test_device:remove" % dev_type,
+ name])
+ # 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,
+ name])
+ # Refer to by name and rename to original name
+ AssertCommand(["gnt-instance", "modify",
+ "--disk=renamed:modify,name=%s" % disk_name,
+ name])
+ if len(disks) >= 2:
+ # fail in renaming to disks to the same name
+ AssertCommand(["gnt-instance", "modify",
+ "--disk=0:modify,name=same_name",
+ "--disk=1:modify,name=same_name",
+ name], fail=True)
+
+
def TestInstanceList():
"""gnt-instance list"""
qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
instance = qa_config.AcquireInstance()
instance.SetDiskTemplate(constants.DT_PLAIN)
try:
- 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": [
"plain",
]
# 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)