Allow our config parser to have case insensitive sections/keys
This commit is contained in:
parent
6b231348d6
commit
651a1cf7b8
@ -48,10 +48,12 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
||||
DEF_BOOLEAN = False
|
||||
DEF_BASE = None
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, cs=True):
|
||||
ConfigParser.RawConfigParser.__init__(self)
|
||||
#make option names case sensitive
|
||||
self.optionxform = str
|
||||
if cs:
|
||||
# Make option names case sensitive
|
||||
# See: http://docs.python.org/library/configparser.html#ConfigParser.RawConfigParser.optionxform
|
||||
self.optionxform = str
|
||||
|
||||
def get(self, section, option):
|
||||
value = IgnoreMissingConfigParser.DEF_BASE
|
||||
@ -80,8 +82,8 @@ class IgnoreMissingConfigParser(ConfigParser.RawConfigParser):
|
||||
|
||||
|
||||
class StackConfigParser(IgnoreMissingConfigParser):
|
||||
def __init__(self):
|
||||
IgnoreMissingConfigParser.__init__(self)
|
||||
def __init__(self, cs=True):
|
||||
IgnoreMissingConfigParser.__init__(self, cs)
|
||||
self.configs_fetched = dict()
|
||||
|
||||
def _resolve_value(self, section, option, value_gotten):
|
||||
|
@ -129,7 +129,7 @@ class GlanceInstaller(GlanceMixin, comp.PythonInstallComponent):
|
||||
# then extract known configs that
|
||||
# will need locations/directories/files made (or touched)...
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||
config.readfp(stream)
|
||||
if config.getboolean('default', 'image_cache_enabled'):
|
||||
cache_dir = config.get('default', "image_cache_datadir")
|
||||
|
@ -142,7 +142,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
|
||||
# then extract known configs that
|
||||
# ill need locations/directories/files made (or touched)...
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||
config.readfp(stream)
|
||||
log_filename = config.get('default', 'log_file')
|
||||
if log_filename:
|
||||
|
@ -85,11 +85,14 @@ class MelangeInstaller(comp.PythonInstallComponent):
|
||||
self._sync_db()
|
||||
|
||||
def _sync_db(self):
|
||||
LOG.info("Syncing the database with melange.")
|
||||
mp = dict()
|
||||
mp['BIN_DIR'] = self.bin_dir
|
||||
LOG.info("Syncing melange to database named %r", DB_NAME)
|
||||
utils.execute_template(*DB_SYNC_CMD, params=self._get_param_map(None))
|
||||
|
||||
def _get_param_map(self, config_fn):
|
||||
mp = comp.PythonInstallComponent._get_param_map(self, config_fn)
|
||||
mp['CFG_FILE'] = sh.joinpths(self.cfg_dir, ROOT_CONF_REAL_NAME)
|
||||
utils.execute_template(*DB_SYNC_CMD, params=mp)
|
||||
mp['BIN_DIR'] = self.bin_dir
|
||||
return mp
|
||||
|
||||
def _get_config_files(self):
|
||||
return list(CONFIGS)
|
||||
@ -98,12 +101,12 @@ class MelangeInstaller(comp.PythonInstallComponent):
|
||||
if config_fn == ROOT_CONF:
|
||||
newcontents = contents
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||
config.readfp(stream)
|
||||
db_dsn = db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME)
|
||||
old_dbsn = config.get('DEFAULT', 'sql_connection')
|
||||
old_dbsn = config.get('default', 'sql_connection')
|
||||
if db_dsn != old_dbsn:
|
||||
config.set('DEFAULT', 'sql_connection', db_dsn)
|
||||
config.set('default', 'sql_connection', db_dsn)
|
||||
with io.BytesIO() as outputstream:
|
||||
config.write(outputstream)
|
||||
outputstream.flush()
|
||||
|
@ -97,11 +97,11 @@ class QuantumInstaller(QuantumMixin, comp.PkgInstallComponent):
|
||||
# Need to fix the "Quantum plugin provider module"
|
||||
newcontents = contents
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||
config.readfp(stream)
|
||||
provider = config.get("PLUGIN", "provider")
|
||||
provider = config.get("plugin", "provider")
|
||||
if provider != V_PROVIDER:
|
||||
config.set("PLUGIN", "provider", V_PROVIDER)
|
||||
config.set("plugin", "provider", V_PROVIDER)
|
||||
with io.BytesIO() as outputstream:
|
||||
config.write(outputstream)
|
||||
outputstream.flush()
|
||||
@ -111,13 +111,13 @@ class QuantumInstaller(QuantumMixin, comp.PkgInstallComponent):
|
||||
# Need to adjust the sql connection
|
||||
newcontents = contents
|
||||
with io.BytesIO(contents) as stream:
|
||||
config = cfg.IgnoreMissingConfigParser()
|
||||
config = cfg.IgnoreMissingConfigParser(cs=False)
|
||||
config.readfp(stream)
|
||||
db_dsn = config.get("DATABASE", "sql_connection")
|
||||
db_dsn = config.get("database", "sql_connection")
|
||||
if db_dsn:
|
||||
generated_dsn = db.fetch_dbdsn(self.cfg, self.pw_gen, DB_NAME)
|
||||
if generated_dsn != db_dsn:
|
||||
config.set("DATABASE", "sql_connection", generated_dsn)
|
||||
config.set("database", "sql_connection", generated_dsn)
|
||||
with io.BytesIO() as outputstream:
|
||||
config.write(outputstream)
|
||||
outputstream.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user