load_yaml: if conversion fails, but string is empty, return default

the problem sovled here is that most callers of yaml_load do not pass
'None' as a allowed type.  I didn't want to change all the callers.

If the yaml.safe_load ended up being None we were raising a TypeError
and that was getting logged (meaning output to console).  Even though
the this was not really bad.

So, if the type is not in the list, *and* it is not empty, then log
exception.  If it in the list and empty, just debug.

empty input was occurring when cloud-config was empty (no user-data)
This commit is contained in:
Scott Moser 2012-07-12 15:43:35 -04:00
parent a857429d6a
commit fc3bafe528

View File

@ -609,6 +609,9 @@ def load_yaml(blob, default=None, allowed=(dict,)):
(allowed, obj_name(converted)))
loaded = converted
except (yaml.YAMLError, TypeError, ValueError):
if len(blob) == 0:
LOG.debug("load_yaml given empty string, returning default")
else:
logexc(LOG, "Failed loading yaml blob")
return loaded