Revision 090128b6

b/qa/ganeti-qa.py
267 267
  RunTestIf(["instance-console", qa_rapi.Enabled],
268 268
            qa_rapi.TestRapiInstanceConsole, instance)
269 269

  
270
  RunTestIf("instance-device-names", qa_instance.TestInstanceDeviceNames,
271
            instance)
270 272
  DOWN_TESTS = qa_config.Either([
271 273
    "instance-reinstall",
272 274
    "instance-rename",
b/qa/qa-sample.json
68 68
  "#ispec_nic_count_min": null,
69 69
  "#ispec_nic_count_std": null,
70 70

  
71
  "# Lists of disk sizes": null,
72
  "disk": ["1G", "512M"],
73
  "disk-growth": ["2G", "768M"],
71
  "# Lists of disks": null,
72
  "disks": [
73
    {
74
      "size": "1G",
75
      "name": "disk0",
76
      "growth": "2G"
77
    },
78
    {
79
      "size": "512M",
80
      "name": "disk1",
81
      "growth": "768M"
82
    }
83
  ],
74 84

  
75 85
  "# Script to check instance status": null,
76 86
  "instance-check": null,
......
197 207
    "instance-reinstall": true,
198 208
    "instance-rename": true,
199 209
    "instance-shutdown": true,
210
    "instance-device-names": true,
200 211

  
201 212
    "job-list": true,
202 213

  
b/qa/qa_cluster.py
800 800

  
801 801
    script = qa_utils.UploadFile(master.primary, "../tools/burnin")
802 802
    try:
803
      disks = qa_config.GetDiskOptions()
803 804
      # Run burnin
804 805
      cmd = [script,
805 806
             "--os=%s" % qa_config.get("os"),
806 807
             "--minmem-size=%s" % qa_config.get(constants.BE_MINMEM),
807 808
             "--maxmem-size=%s" % qa_config.get(constants.BE_MAXMEM),
808
             "--disk-size=%s" % ",".join(qa_config.get("disk")),
809
             "--disk-growth=%s" % ",".join(qa_config.get("disk-growth")),
809
             "--disk-size=%s" % ",".join([d.get("size") for d in disks]),
810
             "--disk-growth=%s" % ",".join([d.get("growth") for d in disks]),
810 811
             "--disk-template=%s" % disk_template]
811 812
      if parallel:
812 813
        cmd.append("--parallel")
b/qa/qa_config.py
280 280
    if not self.get("instances"):
281 281
      raise qa_error.Error("Need at least one instance")
282 282

  
283
    if (self.get("disk") is None or
284
        self.get("disk-growth") is None or
285
        len(self.get("disk")) != len(self.get("disk-growth"))):
286
      raise qa_error.Error("Config options 'disk' and 'disk-growth' must exist"
287
                           " and have the same number of items")
288

  
283
    disks = self.GetDiskOptions()
284
    if disks is None:
285
      raise qa_error.Error("Config option 'disks' must exist")
286
    else:
287
      for d in disks:
288
        if d.get("size") is None or d.get("growth") is None:
289
          raise qa_error.Error("Config options `size` and `growth` must exist"
290
                               " for all `disks` items")
289 291
    check = self.GetInstanceCheckScript()
290 292
    if check:
291 293
      try:
......
425 427

  
426 428
    return (master, basedir)
427 429

  
430
  def GetDiskOptions(self):
431
    """Return options for the disks of the instances.
432

  
433
    Get 'disks' parameter from the configuration data. If 'disks' is missing,
434
    try to create it from the legacy 'disk' and 'disk-growth' parameters.
435

  
436
    """
437
    try:
438
      return self._data["disks"]
439
    except KeyError:
440
      pass
441

  
442
    # Legacy interface
443
    sizes = self._data.get("disk")
444
    growths = self._data.get("disk-growth")
445
    if sizes or growths:
446
      if (sizes is None or growths is None or len(sizes) != len(growths)):
447
        raise qa_error.Error("Config options 'disk' and 'disk-growth' must"
448
                             " exist and have the same number of items")
449
      disks = []
450
      for (size, growth) in zip(sizes, growths):
451
        disks.append({"size": size, "growth": growth})
452
      return disks
453
    else:
454
      return None
455

  
428 456

  
429 457
def Load(path):
430 458
  """Loads the passed configuration file.
......
718 746

  
719 747
  """
720 748
  return not UseVirtualCluster()
749

  
750

  
751
def GetDiskOptions():
752
  """Wrapper for L{_QaConfig.GetDiskOptions}.
753

  
754
  """
755
  return GetConfig().GetDiskOptions()
b/qa/qa_instance.py
52 52
                                 qa_config.get(constants.BE_MAXMEM)))
53 53

  
54 54
  if disk_template != constants.DT_DISKLESS:
55
    for idx, size in enumerate(qa_config.get("disk")):
56
      params.extend(["--disk", "%s:size=%s" % (idx, size)])
55
    for idx, disk in enumerate(qa_config.GetDiskOptions()):
56
      size = disk.get("size")
57
      name = disk.get("name")
58
      params.extend(["--disk", "%s:size=%s,name=%s" % (idx, size, name)])
57 59

  
58 60
  # Set static MAC address if configured
59 61
  if force_mac:
......
780 782
    return
781 783

  
782 784
  name = instance.name
783
  all_size = qa_config.get("disk")
784
  all_grow = qa_config.get("disk-growth")
785
  disks = qa_config.GetDiskOptions()
786
  all_size = [d.get("size") for d in disks]
787
  all_grow = [d.get("growth") for d in disks]
785 788

  
786 789
  if not all_grow:
787 790
    # missing disk sizes but instance grow disk has been enabled,
......
801 804
                   str(int_size + 2 * int_grow)])
802 805

  
803 806

  
807
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG)
808
def TestInstanceDeviceNames(instance):
809
  if instance.disk_template == constants.DT_DISKLESS:
810
    print qa_utils.FormatInfo("Test not supported for diskless instances")
811
    return
812

  
813
  name = instance.name
814
  for dev_type in ["disk", "net"]:
815
    if dev_type == "disk":
816
      options = ",size=512M"
817
    else:
818
      options = ""
819
    # succeed in adding a device named 'test_device'
820
    AssertCommand(["gnt-instance", "modify",
821
                   "--%s=-1:add,name=test_device%s" % (dev_type, options),
822
                   name])
823
    # succeed in removing the 'test_device'
824
    AssertCommand(["gnt-instance", "modify",
825
                   "--%s=test_device:remove" % dev_type,
826
                   name])
827
    # fail to add two devices with the same name
828
    AssertCommand(["gnt-instance", "modify",
829
                   "--%s=-1:add,name=test_device%s" % (dev_type, options),
830
                   "--%s=-1:add,name=test_device%s" % (dev_type, options),
831
                   name], fail=True)
832
    # fail to add a device with invalid name
833
    AssertCommand(["gnt-instance", "modify",
834
                   "--%s=-1:add,name=2%s" % (dev_type, options),
835
                   name], fail=True)
836
  # Rename disks
837
  disks = qa_config.GetDiskOptions()
838
  disk_names = [d.get("name") for d in disks]
839
  for idx, disk_name in enumerate(disk_names):
840
    # Refer to disk by idx
841
    AssertCommand(["gnt-instance", "modify",
842
                   "--disk=%s:modify,name=renamed" % idx,
843
                   name])
844
    # Refer to by name and rename to original name
845
    AssertCommand(["gnt-instance", "modify",
846
                   "--disk=renamed:modify,name=%s" % disk_name,
847
                   name])
848
  if len(disks) >= 2:
849
    # fail in renaming to disks to the same name
850
    AssertCommand(["gnt-instance", "modify",
851
                   "--disk=0:modify,name=same_name",
852
                   "--disk=1:modify,name=same_name",
853
                   name], fail=True)
854

  
855

  
804 856
def TestInstanceList():
805 857
  """gnt-instance list"""
806 858
  qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
b/qa/qa_rapi.py
565 565
  instance = qa_config.AcquireInstance()
566 566
  instance.SetDiskTemplate(constants.DT_PLAIN)
567 567
  try:
568
    disk_sizes = [utils.ParseUnit(size) for size in qa_config.get("disk")]
569
    disks = [{"size": size} for size in disk_sizes]
568
    disks = [{"size": utils.ParseUnit(d.get("size")),
569
              "name": str(d.get("name"))}
570
             for d in qa_config.GetDiskOptions()]
570 571
    nic0_mac = instance.GetNicMacAddr(0, constants.VALUE_GENERATE)
571 572
    nics = [{
572 573
      constants.INIC_MAC: nic0_mac,
b/test/data/qa-minimal-nodes-instances-only.json
1 1
{
2 2
  "name": "xen-test-qa-minimal-nodes-instances-only",
3 3

  
4
  "disk": ["1G", "512M"],
5
  "disk-growth": ["2G", "768M"],
4
  "# Lists of disks": null,
5
  "disks": [
6
    {
7
      "size": "1G",
8
      "growth": "2G"
9
    },
10
    {
11
      "size": "512M",
12
      "growth": "768M"
13
    }
14
  ],
6 15

  
7 16
  "enabled-disk-templates": [
8 17
    "plain",
b/test/py/qa.qa_config_unittest.py
205 205
      ]
206 206

  
207 207
    # Missing "disk" and "disk-growth"
208
    check_fn("Config options 'disk' and 'disk-growth' ")
208
    check_fn("Config option 'disks'")
209 209

  
210
    testconfig["disk"] = []
211
    testconfig["disk-growth"] = testconfig["disk"]
210
    testconfig["disks"] = []
212 211

  
213 212
    # Minimal accepted configuration
214 213
    self._WriteConfig(filename, testconfig)

Also available in: Unified diff