From e32e1fb962dac25aa039bc305dc6e4fd8cee9615 Mon Sep 17 00:00:00 2001
From: Bernardo Dal Seno <bdalseno@google.com>
Date: Sun, 13 Jan 2013 18:47:27 +0100
Subject: [PATCH] Verify that templates are compatible with exclusive storage

cluster-verify reports instances with disk templates not compatible with
exclusive storage but that are running on nodes with the exclusive storage
flag set.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/cmdlib.py    | 12 ++++++++++++
 lib/constants.py |  3 +++
 2 files changed, 15 insertions(+)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 77226800d..d97795ccf 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -2688,6 +2688,18 @@ class LUClusterVerifyGroup(LogicalUnit, _VerifyErrors):
              utils.CommaJoin(inst_config.secondary_nodes),
              code=self.ETYPE_WARNING)
 
+    if inst_config.disk_template not in constants.DTS_EXCL_STORAGE:
+      # Disk template not compatible with exclusive_storage: no instance
+      # node should have the flag set
+      es_flags = rpc.GetExclusiveStorageForNodeNames(self.cfg,
+                                                     inst_config.all_nodes)
+      es_nodes = [n for (n, es) in es_flags.items()
+                  if es]
+      _ErrorIf(es_nodes, constants.CV_EINSTANCEUNSUITABLENODE, instance,
+               "instance has template %s, which is not supported on nodes"
+               " that have exclusive storage set: %s",
+               inst_config.disk_template, utils.CommaJoin(es_nodes))
+
     if inst_config.disk_template in constants.DTS_INT_MIRROR:
       instance_nodes = utils.NiceSort(inst_config.all_nodes)
       instance_groups = {}
diff --git a/lib/constants.py b/lib/constants.py
index 2fc7ce9af..fff1a662e 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -1476,6 +1476,9 @@ CV_EINSTANCESPLITGROUPS = \
 CV_EINSTANCEPOLICY = \
   (CV_TINSTANCE, "EINSTANCEPOLICY",
    "Instance does not meet policy")
+CV_EINSTANCEUNSUITABLENODE = \
+  (CV_TINSTANCE, "EINSTANCEUNSUITABLENODE",
+   "Instance running on nodes that are not suitable for it")
 CV_ENODEDRBD = \
   (CV_TNODE, "ENODEDRBD", "Error parsing the DRBD status file")
 CV_ENODEDRBDHELPER = \
-- 
GitLab