HooksMaster: Add more assertions for variable names
authorMichael Hanselmann <hansmi@google.com>
Wed, 16 Mar 2011 12:59:32 +0000 (13:59 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 16 Mar 2011 17:58:35 +0000 (18:58 +0100)
Also replace explicit loop with dict.update.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/mcpu.py

index 9db223e..7493f99 100644 (file)
@@ -39,6 +39,7 @@ from ganeti import rpc
 from ganeti import cmdlib
 from ganeti import locking
 from ganeti import utils
+from ganeti import compat
 
 
 _OP_PREFIX = "Op"
@@ -448,10 +449,11 @@ class HooksMaster(object):
       }
 
     if self.lu.HPATH is not None:
-      lu_env, lu_nodes_pre, lu_nodes_post = self.lu.BuildHooksEnv()
+      (lu_env, lu_nodes_pre, lu_nodes_post) = self.lu.BuildHooksEnv()
       if lu_env:
-        for key in lu_env:
-          env["GANETI_" + key] = lu_env[key]
+        assert not compat.any(key.upper().startswith("GANETI")
+                              for key in lu_env)
+        env.update(("GANETI_%s" % key, value) for (key, value) in lu_env)
     else:
       lu_nodes_pre = lu_nodes_post = []
 
@@ -472,6 +474,10 @@ class HooksMaster(object):
 
     env = dict([(str(key), str(val)) for key, val in env.iteritems()])
 
+    assert compat.all(key == key.upper() and
+                      (key == "PATH" or key.startswith("GANETI_"))
+                      for key in env)
+
     return self.callfn(node_list, hpath, phase, env)
 
   def RunPhase(self, phase, nodes=None):