From 090128b64cb16607a6d4c054b04fd6a3b310198c Mon Sep 17 00:00:00 2001 From: Christos Stavrakakis <cstavr@grnet.gr> Date: Thu, 4 Apr 2013 11:51:16 +0300 Subject: [PATCH] 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: Christos Stavrakakis <cstavr@grnet.gr> Reviewed-by: Helga Velroyen <helgav@google.com> --- qa/ganeti-qa.py | 2 + qa/qa-sample.json | 17 +++++- qa/qa_cluster.py | 5 +- qa/qa_config.py | 47 +++++++++++++-- qa/qa_instance.py | 60 +++++++++++++++++-- qa/qa_rapi.py | 5 +- .../data/qa-minimal-nodes-instances-only.json | 13 +++- test/py/qa.qa_config_unittest.py | 5 +- 8 files changed, 132 insertions(+), 22 deletions(-) diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py index d7b6a237d..7af9ff80c 100755 --- a/qa/ganeti-qa.py +++ b/qa/ganeti-qa.py @@ -267,6 +267,8 @@ def RunCommonInstanceTests(instance): 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", diff --git a/qa/qa-sample.json b/qa/qa-sample.json index 3899a47cc..851a3b123 100644 --- a/qa/qa-sample.json +++ b/qa/qa-sample.json @@ -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, diff --git a/qa/qa_cluster.py b/qa/qa_cluster.py index 210f8bf47..c4de57abd 100644 --- a/qa/qa_cluster.py +++ b/qa/qa_cluster.py @@ -800,13 +800,14 @@ def TestClusterBurnin(): 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") diff --git a/qa/qa_config.py b/qa/qa_config.py index 1c6a5430c..4e0d5f553 100644 --- a/qa/qa_config.py +++ b/qa/qa_config.py @@ -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") + 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: @@ -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. + + """ + 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. @@ -718,3 +746,10 @@ def NoVirtualCluster(): """ return not UseVirtualCluster() + + +def GetDiskOptions(): + """Wrapper for L{_QaConfig.GetDiskOptions}. + + """ + return GetConfig().GetDiskOptions() diff --git a/qa/qa_instance.py b/qa/qa_instance.py index 33376b46f..b348fc845 100644 --- a/qa/qa_instance.py +++ b/qa/qa_instance.py @@ -52,8 +52,10 @@ def _GetGenericAddParameters(inst, disk_template, force_mac=None): 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: @@ -780,8 +782,9 @@ def TestInstanceGrowDisk(instance): 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, @@ -801,6 +804,55 @@ def TestInstanceGrowDisk(instance): 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()) diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py index b2ff4f0b2..0ebe6356c 100644 --- a/qa/qa_rapi.py +++ b/qa/qa_rapi.py @@ -565,8 +565,9 @@ def TestRapiInstanceAdd(node, use_client): 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, diff --git a/test/data/qa-minimal-nodes-instances-only.json b/test/data/qa-minimal-nodes-instances-only.json index 6a5578ece..9a85241f2 100644 --- a/test/data/qa-minimal-nodes-instances-only.json +++ b/test/data/qa-minimal-nodes-instances-only.json @@ -1,8 +1,17 @@ { "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", diff --git a/test/py/qa.qa_config_unittest.py b/test/py/qa.qa_config_unittest.py index bb27dde30..4715153e3 100755 --- a/test/py/qa.qa_config_unittest.py +++ b/test/py/qa.qa_config_unittest.py @@ -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) -- GitLab