From 50ef6a41bd382a7556744c1780b5bd3b52b9bb9b Mon Sep 17 00:00:00 2001
From: Bernardo Dal Seno <bdalseno@google.com>
Date: Wed, 16 Jan 2013 11:49:20 +0100
Subject: [PATCH] QA: Test for basic features of exclusive storage

Check that creation of instances doesn't trigger any error.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 qa/ganeti-qa.py   | 26 +++++++++++++++++++++++++-
 qa/qa-sample.json |  1 +
 qa/qa_cluster.py  | 19 +++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 26c2407ac..34a47efd5 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -1,7 +1,7 @@
 #!/usr/bin/python -u
 #
 
-# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -457,6 +457,28 @@ def RunHardwareFailureTests(instance, pnode, snode):
             pnode, snode)
 
 
+def RunExclusiveStorageTests():
+  """Test exclusive storage."""
+  if not qa_config.TestEnabled("cluster-exclusive-storage"):
+    return
+
+  node = qa_config.AcquireNode()
+  try:
+    old_es = qa_cluster.TestSetExclStorCluster(True)
+    if qa_config.TestEnabled("instance-add-plain-disk"):
+      # Make sure that the cluster doesn't have any pre-existing problem
+      qa_cluster.AssertClusterVerify()
+      instance1 = qa_instance.TestInstanceAddWithPlainDisk(node)
+      instance2 = qa_instance.TestInstanceAddWithPlainDisk(node)
+      # cluster-verify checks that disks are allocated correctly
+      qa_cluster.AssertClusterVerify()
+      qa_instance.TestInstanceRemove(instance1)
+      qa_instance.TestInstanceRemove(instance2)
+    qa_cluster.TestSetExclStorCluster(old_es)
+  finally:
+    qa_config.ReleaseNode(node)
+
+
 def RunQa():
   """Main QA body.
 
@@ -587,6 +609,8 @@ def RunQa():
   finally:
     qa_config.ReleaseNode(pnode)
 
+  RunExclusiveStorageTests()
+
   RunTestIf("create-cluster", qa_node.TestNodeRemoveAll)
 
   RunTestIf("cluster-destroy", qa_cluster.TestClusterDestroy)
diff --git a/qa/qa-sample.json b/qa/qa-sample.json
index 9b96484b6..4c47a62fc 100644
--- a/qa/qa-sample.json
+++ b/qa/qa-sample.json
@@ -111,6 +111,7 @@
     "cluster-epo": true,
     "cluster-redist-conf": true,
     "cluster-repair-disk-sizes": true,
+    "cluster-exclusive-storage": true,
 
     "haskell-confd": true,
     "htools": true,
diff --git a/qa/qa_cluster.py b/qa/qa_cluster.py
index 983993210..9fbcc3fa9 100644
--- a/qa/qa_cluster.py
+++ b/qa/qa_cluster.py
@@ -626,3 +626,22 @@ def TestClusterDestroy():
 def TestClusterRepairDiskSizes():
   """gnt-cluster repair-disk-sizes"""
   AssertCommand(["gnt-cluster", "repair-disk-sizes"])
+
+
+def TestSetExclStorCluster(newvalue):
+  """Set the exclusive_storage node parameter at the cluster level.
+
+  @type newvalue: bool
+  @param newvalue: New value of exclusive_storage
+  @rtype: bool
+  @return: The old value of exclusive_storage
+
+  """
+  oldvalue = _GetBoolClusterField("exclusive_storage")
+  AssertCommand(["gnt-cluster", "modify", "--node-parameters",
+                 "exclusive_storage=%s" % newvalue])
+  effvalue = _GetBoolClusterField("exclusive_storage")
+  if effvalue != newvalue:
+    raise qa_error.Error("exclusive_storage has the wrong value: %s instead"
+                         " of %s" % (effvalue, newvalue))
+  return oldvalue
-- 
GitLab