From 904910c4e4a3992fac3fd652cc2d4a6b52579dd9 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 14 Jun 2012 17:17:34 +0200
Subject: [PATCH] Upgrade wrong iv_names at cfgupgrade time

Since Ganeti 2.6 does warn about disks with wrong iv_names, it would
be better to fix them when upgrading to 2.6.

Not sure if this is too brittle and whether we want to add more
safeguards on the contents of the config/instance/disks before
touching them.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 tools/cfgupgrade | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tools/cfgupgrade b/tools/cfgupgrade
index 05022c906..81dce1dd2 100755
--- a/tools/cfgupgrade
+++ b/tools/cfgupgrade
@@ -188,6 +188,21 @@ def main():
     config_data["version"] = constants.BuildVersion(TARGET_MAJOR,
                                                     TARGET_MINOR, 0)
 
+    if "instances" not in config_data:
+      raise Error("Can't find the 'instances' key in the configuration!")
+    for instance, iobj in config_data["instances"].items():
+      if "disks" not in iobj:
+        raise Error("Instance '%s' doesn't have a disks entry?!" % instance)
+      disks = iobj["disks"]
+      for idx, dobj in enumerate(disks):
+        expected = "disk/%s" % idx
+        current = dobj.get("iv_name", "")
+        if current != expected:
+          logging.warning("Updating iv_name for instance %s/disk %s"
+                          " from '%s' to '%s'",
+                          instance, idx, current, expected)
+          dobj["iv_name"] = expected
+
   elif config_major == TARGET_MAJOR and config_minor == TARGET_MINOR:
     logging.info("No changes necessary")
 
-- 
GitLab