commit bab4f56a275e4d8347159b56831d61ac81bfdaec
Author: Helga Velroyen <helgav@google.com>
Date:   Wed Jul 24 16:53:20 2013 +0200

    QA: skip lvm-based tests if lvm disabled
    
    QA tests should make sure not to be run if the necessary
    environment for them is not present. This patch fixes that
    for a couple of tests that fail to check that before being
    executed.
    
    Signed-off-by: Helga Velroyen <helgav@google.com>
    Reviewed-by: Thomas Thrainer <thomasth@google.com>

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 9b4dc5e..4c8e90f 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -437,7 +437,8 @@ def RunExportImportTests(instance, inodes):
   # FIXME: inter-cluster-instance-move crashes on file based instances :/
   # See Issue 414.
   if (qa_config.TestEnabled([qa_rapi.Enabled, "inter-cluster-instance-move"])
-      and instance.disk_template != constants.DT_FILE):
+      and (instance.disk_template not in
+           [constants.DT_FILE, constants.DT_SHARED_FILE])):
     newinst = qa_config.AcquireInstance()
     try:
       tnode = qa_config.AcquireNode(exclude=inodes)
@@ -804,7 +805,8 @@ def RunQa():
     if qa_rapi.Enabled():
       RunTest(qa_rapi.TestNode, pnode)
 
-      if qa_config.TestEnabled("instance-add-plain-disk"):
+      if (qa_config.TestEnabled("instance-add-plain-disk")
+          and qa_config.IsTemplateSupported(constants.DT_PLAIN)):
         for use_client in [True, False]:
           rapi_instance = RunTest(qa_rapi.TestRapiInstanceAdd, pnode,
                                   use_client)
diff --git a/qa/qa_cluster.py b/qa/qa_cluster.py
index b1b0f55..c7e6058 100644
--- a/qa/qa_cluster.py
+++ b/qa/qa_cluster.py
@@ -407,6 +407,9 @@ def TestDelay(node):
 
 def TestClusterReservedLvs():
   """gnt-cluster reserved lvs"""
+  # if no lvm-based templates are supported, skip the test
+  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
+    return
   vgname = qa_config.get("vg-name", constants.DEFAULT_VG)
   lvname = _QA_LV_PREFIX + "test"
   lvfullname = "/".join([vgname, lvname])
diff --git a/qa/qa_config.py b/qa/qa_config.py
index 2bfa7a2..c590982 100644
--- a/qa/qa_config.py
+++ b/qa/qa_config.py
@@ -435,6 +435,20 @@ class _QaConfig(object):
     return enabled and (not self.GetExclusiveStorage() or
                         templ in constants.DTS_EXCL_STORAGE)
 
+  def IsStorageTypeSupported(self, storage_type):
+    """Is the given storage type supported by the current configuration?
+
+    This is determined by looking if at least one of the disk templates
+    which is associated with the storage type is enabled in the configuration.
+
+    """
+    enabled_disk_templates = self.GetEnabledDiskTemplates()
+    if storage_type == constants.ST_LVM_PV:
+      disk_templates = utils.GetDiskTemplatesOfStorageType(constants.ST_LVM_VG)
+    else:
+      disk_templates = utils.GetDiskTemplatesOfStorageType(storage_type)
+    return bool(set(enabled_disk_templates).intersection(set(disk_templates)))
+
   def AreSpindlesSupported(self):
     """Are spindles supported by the current configuration?
 
@@ -673,6 +687,13 @@ def IsTemplateSupported(templ):
   return GetConfig().IsTemplateSupported(templ)
 
 
+def IsStorageTypeSupported(storage_type):
+  """Wrapper for L{_QaConfig.IsTemplateSupported}.
+
+  """
+  return GetConfig().IsStorageTypeSupported(storage_type)
+
+
 def AreSpindlesSupported():
   """Wrapper for L{_QaConfig.AreSpindlesSupported}.
 
diff --git a/qa/qa_group.py b/qa/qa_group.py
index b8699e2..f11e512 100644
--- a/qa/qa_group.py
+++ b/qa/qa_group.py
@@ -225,6 +225,10 @@ def _TestGroupModifyIPolicy(groupname):
 
 def TestGroupModify():
   """gnt-group modify"""
+  # This tests assumes LVM to be enabled, thus it should skip if
+  # this is not the case
+  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
+    return
   (group1, ) = qa_utils.GetNonexistentGroups(1)
 
   AssertCommand(["gnt-group", "add", group1])
diff --git a/qa/qa_rapi.py b/qa/qa_rapi.py
index c794c75..a9e9bc0 100644
--- a/qa/qa_rapi.py
+++ b/qa/qa_rapi.py
@@ -246,6 +246,11 @@ def TestRapiQuery():
   """Testing resource queries via remote API.
 
   """
+  # FIXME: the tests are failing if no LVM is enabled, investigate
+  # if it is a bug in the QA or in the code
+  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
+    return
+
   master_name = qa_utils.ResolveNodeName(qa_config.GetMasterNode())
   rnd = random.Random(7818)
 
@@ -323,15 +328,17 @@ def TestRapiQuery():
       ("/2/query/%s?fields=%s" % (what, namefield),
        compat.partial(_Check, [namefield]), "PUT", {}),
 
-      # Fields in body
+      ("/2/query/%s" % what, compat.partial(_Check, [namefield] * 4), "PUT", {
+         "fields": [namefield] * 4,
+         }),
+
       ("/2/query/%s" % what, compat.partial(_Check, all_fields), "PUT", {
          "fields": all_fields,
          }),
 
       ("/2/query/%s" % what, compat.partial(_Check, [namefield] * 4), "PUT", {
-         "fields": [namefield] * 4,
-         }),
-      ])
+         "fields": [namefield] * 4
+         })])
 
     def _CheckFilter():
       _DoTests([
@@ -562,6 +569,8 @@ def TestRapiNodeGroups():
 
 def TestRapiInstanceAdd(node, use_client):
   """Test adding a new instance via RAPI"""
+  if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
+    return
   instance = qa_config.AcquireInstance()
   instance.SetDiskTemplate(constants.DT_PLAIN)
   try:
@@ -614,6 +623,11 @@ def TestRapiInstanceAdd(node, use_client):
 @InstanceCheck(None, INST_DOWN, FIRST_ARG)
 def TestRapiInstanceRemove(instance, use_client):
   """Test removing instance via RAPI"""
+  # FIXME: this does not work if LVM is not enabled. Find out if this is a bug
+  # in RAPI or in the test
+  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
+    return
+
   if use_client:
     job_id = _rapi_client.DeleteInstance(instance.name)
   else:
diff --git a/tools/move-instance b/tools/move-instance
index 3ea7e8a..b0b8a3e 100755
--- a/tools/move-instance
+++ b/tools/move-instance
@@ -569,7 +569,8 @@ class MoveSourceExecutor(object):
     logging.info("Retrieving instance information from source cluster")
     instinfo = self._GetInstanceInfo(src_client, mrt.PollJob,
                                      mrt.move.src_instance_name)
-    if instinfo["disk_template"] == constants.DT_FILE:
+    if (instinfo["disk_template"] in
+        [constants.DT_FILE, constants.DT_SHARED_FILE]):
       raise Error("Inter-cluster move of file-based instances is not"
                   " supported.")
 
