Commit 523170de authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Michele Tartara
Browse files

Override get() method of ConfigParser



During backup import/export SafeConfigParser() is used to
save/restore instance's configuration. There is a possibility if an
export is done with a different Ganeti version, a specific value not
to be saved during export (e.g. the NIC/Disk name) but still
requested during import.

With this patch we override the get() method of SafeConfigParser()
and catch NoOptionError if raised and return None. Additionally we
translate "None" values read from .ini file into None.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarMichele Tartara <mtartara@google.com>
parent 95ee8abb
......@@ -2159,7 +2159,8 @@ class Network(TaggableObject):
return obj
class SerializableConfigParser(ConfigParser.SafeConfigParser):
# need to inherit object in order to use super()
class SerializableConfigParser(ConfigParser.SafeConfigParser, object):
"""Simple wrapper over ConfigParse that allows serialization.
This class is basically ConfigParser.SafeConfigParser with two
......@@ -2181,6 +2182,23 @@ class SerializableConfigParser(ConfigParser.SafeConfigParser):
cfp.readfp(buf)
return cfp
def get(self, section, option, **kwargs):
value = None
try:
value = super(SerializableConfigParser, self).get(section, option,
**kwargs)
if value.lower() == constants.VALUE_NONE:
value = None
except ConfigParser.NoOptionError:
r = re.compile(r"(disk|nic)\d+_name")
match = r.match(option)
if match:
pass
else:
raise
return value
class LvmPvInfo(ConfigObject):
"""Information about an LVM physical volume (PV).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment