Hs2Py constants: add remaining '_autoconf.*' constants
[ganeti-local] / qa / qa_instance.py
index e1ede85..e7d8bb4 100644 (file)
@@ -48,7 +48,7 @@ def _GetDiskStatePath(disk):
   return "/sys/block/%s/device/state" % disk
 
 
-def _GetInstanceInfo(instance):
+def GetInstanceInfo(instance):
   """Return information about the actual state of an instance.
 
   @type instance: string
@@ -88,14 +88,14 @@ def _GetInstanceInfo(instance):
   disk_template = info["Disk template"]
   if not disk_template:
     raise qa_error.Error("Can't get instance disk template")
-  storage_type = constants.DISK_TEMPLATES_STORAGE_TYPE[disk_template]
+  storage_type = constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]
 
   re_drbdnode = re.compile(r"^([^\s,]+),\s+minor=([0-9]+)$")
   vols = []
   drbd_min = {}
   for (count, diskinfo) in enumerate(info["Disks"]):
     (dtype, _) = diskinfo["disk/%s" % count].split(",", 1)
-    if dtype == constants.LD_DRBD8:
+    if dtype == constants.DT_DRBD8:
       for child in diskinfo["child devices"]:
         vols.append(child["logical_id"])
       for key in ["nodeA", "nodeB"]:
@@ -106,7 +106,7 @@ def _GetInstanceInfo(instance):
         minor = int(m.group(2))
         minorlist = drbd_min.setdefault(node, [])
         minorlist.append(minor)
-    elif dtype == constants.LD_LV:
+    elif dtype == constants.DT_PLAIN:
       vols.append(diskinfo["logical_id"])
 
   assert nodes
@@ -129,17 +129,17 @@ def _DestroyInstanceDisks(instance):
   @param instance: the instance
 
   """
-  info = _GetInstanceInfo(instance.name)
+  info = GetInstanceInfo(instance.name)
   # FIXME: destruction/removal should be part of the disk class
   if info["storage-type"] == constants.ST_LVM_VG:
     vols = info["volumes"]
     for node in info["nodes"]:
       AssertCommand(["lvremove", "-f"] + vols, node=node)
   elif info["storage-type"] == constants.ST_FILE:
-    # FIXME: file storage dir not configurable in qa
     # Note that this works for both file and sharedfile, and this is intended.
-    filestorage = pathutils.DEFAULT_FILE_STORAGE_DIR
-    idir = os.path.join(filestorage, instance.name)
+    storage_dir = qa_config.get("file-storage-dir",
+                                pathutils.DEFAULT_FILE_STORAGE_DIR)
+    idir = os.path.join(storage_dir, instance.name)
     for node in info["nodes"]:
       AssertCommand(["rm", "-rf", idir], node=node)
   elif info["storage-type"] == constants.ST_DISKLESS:
@@ -277,6 +277,14 @@ def TestInstanceAddFile(nodes):
 
 
 @InstanceCheck(None, INST_UP, RETURN_VALUE)
+def TestInstanceAddSharedFile(nodes):
+  """gnt-instance add -t sharedfile"""
+  assert len(nodes) == 1
+  if constants.DT_SHARED_FILE in qa_config.GetEnabledDiskTemplates():
+    return CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_SHARED_FILE)
+
+
+@InstanceCheck(None, INST_UP, RETURN_VALUE)
 def TestInstanceAddDiskless(nodes):
   """gnt-instance add -t diskless"""
   assert len(nodes) == 1
@@ -357,7 +365,7 @@ def TestInstanceRenameAndBack(rename_source, rename_target):
   finally:
     qa_utils.RemoveFromEtcHosts(["meeeeh-not-exists", rename_target])
 
-  info = _GetInstanceInfo(rename_source)
+  info = GetInstanceInfo(rename_source)
 
   # Check instance volume tags correctly updated. Note that this check is lvm
   # specific, so we skip it for non-lvm-based instances.
@@ -558,9 +566,8 @@ def TestInstanceModifyPrimaryAndBack(instance, currentnode, othernode):
   current = currentnode.primary
   other = othernode.primary
 
-  # FIXME: the qa doesn't have a customizable file storage dir parameter. As
-  # such for now we use the default.
-  filestorage = pathutils.DEFAULT_FILE_STORAGE_DIR
+  filestorage = qa_config.get("file-storage-dir",
+                              pathutils.DEFAULT_FILE_STORAGE_DIR)
   disk = os.path.join(filestorage, name)
 
   AssertCommand(["gnt-instance", "modify", "--new-primary=%s" % other, name],
@@ -916,6 +923,9 @@ def TestRecreateDisks(instance, inodes, othernodes):
 def TestInstanceExport(instance, node):
   """gnt-backup export -n ..."""
   name = instance.name
+  # Export does not work for file-based templates, thus we skip the test
+  if instance.disk_template in [constants.DT_FILE, constants.DT_SHARED_FILE]:
+    return
   AssertCommand(["gnt-backup", "export", "-n", node.primary, name])
   return qa_utils.ResolveInstanceName(name)
 
@@ -937,6 +947,8 @@ def TestInstanceExportNoTarget(instance):
 def TestInstanceImport(newinst, node, expnode, name):
   """gnt-backup import"""
   templ = constants.DT_PLAIN
+  if not qa_config.IsTemplateSupported(templ):
+    return
   cmd = (["gnt-backup", "import",
           "--disk-template=%s" % templ,
           "--no-ip-check",
@@ -972,7 +984,7 @@ def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online):
   @param set_online: function to call to set the node on-line
 
   """
-  info = _GetInstanceInfo(instance.name)
+  info = GetInstanceInfo(instance.name)
   set_offline(snode)
   try:
     TestInstanceRemove(instance)
@@ -991,26 +1003,32 @@ def TestRemoveInstanceOfflineNode(instance, snode, set_offline, set_online):
         # syntax), we always have to perform both commands and ignore the
         # output.
         drbd_shutdown_cmd = \
-          "(drbdsetup %d down && drbdsetup down resource%d) || /bin/true" % \
+          "(drbdsetup %d down >/dev/null 2>&1;" \
+          " drbdsetup down resource%d >/dev/null 2>&1) || /bin/true" % \
             (minor, minor)
         AssertCommand(drbd_shutdown_cmd, node=snode)
       AssertCommand(["lvremove", "-f"] + info["volumes"], node=snode)
     elif info["storage-type"] == constants.ST_FILE:
-      filestorage = pathutils.DEFAULT_FILE_STORAGE_DIR
+      filestorage = qa_config.get("file-storage-dir",
+                                  pathutils.DEFAULT_FILE_STORAGE_DIR)
       disk = os.path.join(filestorage, instance.name)
       AssertCommand(["rm", "-rf", disk], node=snode)
 
 
 def TestInstanceCreationRestrictedByDiskTemplates():
   """Test adding instances for disabled disk templates."""
+  if qa_config.TestEnabled("cluster-exclusive-storage"):
+    # These tests are valid only for non-exclusive storage
+    return
+
   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)],
+     "--enabled-disk-templates=%s" % ",".join(enabled_disk_templates),
+     "--ipolicy-disk-templates=%s" % ",".join(enabled_disk_templates)],
     fail=False)
 
   # Test instance creation for enabled disk templates
@@ -1036,8 +1054,8 @@ def TestInstanceCreationRestrictedByDiskTemplates():
     for (enabled, disabled) in [(templates1, templates2),
                                 (templates2, templates1)]:
       AssertCommand(["gnt-cluster", "modify",
-                     "--enabled-disk-template=%s" %
-                       ",".join(enabled)],
+                     "--enabled-disk-templates=%s" % ",".join(enabled),
+                     "--ipolicy-disk-templates=%s" % ",".join(enabled)],
                     fail=False)
       for disk_template in disabled:
         CreateInstanceByDiskTemplate(nodes, disk_template, fail=True)
@@ -1049,7 +1067,9 @@ def TestInstanceCreationRestrictedByDiskTemplates():
                              set([constants.DT_DISKLESS, constants.DT_BLOCK]) -
                              set(enabled_disk_templates))
     AssertCommand(["gnt-cluster", "modify",
-                   "--enabled-disk-template=%s" %
+                   "--enabled-disk-templates=%s" %
+                     ",".join(other_disk_templates),
+                   "--ipolicy-disk-templates=%s" %
                      ",".join(other_disk_templates)],
                   fail=False)
     CreateInstanceByDiskTemplate(nodes, enabled_disk_templates[0], fail=True)
@@ -1059,6 +1079,8 @@ def TestInstanceCreationRestrictedByDiskTemplates():
 
   # Restore initially enabled disk templates
   AssertCommand(["gnt-cluster", "modify",
-                 "--enabled-disk-template=%s" %
+                 "--enabled-disk-templates=%s" %
+                   ",".join(enabled_disk_templates),
+                 "--ipolicy-disk-templates=%s" %
                    ",".join(enabled_disk_templates)],
                  fail=False)