From ace16501e343c4636931300c4df08b3d4c80d118 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Mon, 6 Sep 2010 16:52:17 +0100
Subject: [PATCH] Check for duplicate nodegroup names

Since the nodegroups dict is indexed by uuid duplicate names might
happen as a result of bugs. Add a check to prevent them.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/config.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/config.py b/lib/config.py
index 5f13d7d8d..94dcf3c3c 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -462,11 +462,16 @@ class ConfigWriter:
                        node.offline))
 
     # nodegroups checks
+    nodegroups_names = set()
     for nodegroup_uuid in data.nodegroups:
       nodegroup = data.nodegroups[nodegroup_uuid]
       if nodegroup.uuid != nodegroup_uuid:
         result.append("nodegroup '%s' (uuid: '%s') indexed by wrong uuid '%s'"
                       % (nodegroup.name, nodegroup.uuid, nodegroup_uuid))
+      if nodegroup.name in nodegroups_names:
+        result.append("duplicate nodegroup name '%s'" % nodegroup.name)
+      else:
+        nodegroups_names.add(nodegroup.name)
 
     # drbd minors check
     _, duplicates = self._UnlockedComputeDRBDMap()
-- 
GitLab