Prevent ssconf values from having non-string values
authorIustin Pop <iustin@google.com>
Tue, 12 Apr 2011 14:04:43 +0000 (16:04 +0200)
committerIustin Pop <iustin@google.com>
Thu, 14 Apr 2011 08:36:57 +0000 (10:36 +0200)
For whatever reason, my test cluster managed to acquire
shared_file_storage_dir with a None value, instead of empty
string. This is not flagged in masterd itself, but the node daemon
will fail in writing the value to disk, as it calls len() on the
received value.

Since this is a bad case, we should detect it as soon as possible (we
basically shouldn't be able to set it), but in the meantime we at
least prevent ssconf writes with such values.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/config.py

index 64ec123..23024d1 100644 (file)
@@ -1744,7 +1744,7 @@ class ConfigWriter:
                   self._config_data.nodegroups.values()]
     nodegroups_data = fn(utils.NiceSort(nodegroups))
 
-    return {
+    ssconf_values = {
       constants.SS_CLUSTER_NAME: cluster.cluster_name,
       constants.SS_CLUSTER_TAGS: cluster_tags,
       constants.SS_FILE_STORAGE_DIR: cluster.file_storage_dir,
@@ -1767,6 +1767,13 @@ class ConfigWriter:
       constants.SS_UID_POOL: uid_pool,
       constants.SS_NODEGROUPS: nodegroups_data,
       }
+    bad_values = [(k, v) for k, v in ssconf_values.items()
+                  if not isinstance(v, (str, basestring))]
+    if bad_values:
+      err = utils.CommaJoin("%s=%s" % (k, v) for k, v in bad_values)
+      raise errors.ConfigurationError("Some ssconf key(s) have non-string"
+                                      " values: %s" % err)
+    return ssconf_values
 
   @locking.ssynchronized(_config_lock, shared=1)
   def GetSsconfValues(self):