From: Iustin Pop Date: Tue, 12 Apr 2011 14:04:43 +0000 (+0200) Subject: Prevent ssconf values from having non-string values X-Git-Tag: v2.5.0beta1~439 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/2afc923800504bbc7f55c76f73d7706dcda08bea Prevent ssconf values from having non-string values 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 Reviewed-by: Guido Trotter --- diff --git a/lib/config.py b/lib/config.py index 64ec123..23024d1 100644 --- a/lib/config.py +++ b/lib/config.py @@ -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):