From 651a1cf7b8cdadac27b7a15c4f808925144f6199 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 28 Mar 2012 10:40:41 -0700 Subject: [PATCH] Allow our config parser to have case insensitive sections/keys --- devstack/cfg.py | 12 +++++++----- devstack/components/glance.py | 2 +- devstack/components/keystone.py | 2 +- devstack/components/melange.py | 17 ++++++++++------- devstack/components/quantum.py | 12 ++++++------ 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/devstack/cfg.py b/devstack/cfg.py index f7f4e1be..fa3331fa 100644 --- a/devstack/cfg.py +++ b/devstack/cfg.py @@ -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): diff --git a/devstack/components/glance.py b/devstack/components/glance.py index c9da3024..aaa31f33 100644 --- a/devstack/components/glance.py +++ b/devstack/components/glance.py @@ -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") diff --git a/devstack/components/keystone.py b/devstack/components/keystone.py index 48383db2..7313457b 100644 --- a/devstack/components/keystone.py +++ b/devstack/components/keystone.py @@ -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: diff --git a/devstack/components/melange.py b/devstack/components/melange.py index a11ba46f..181aab76 100644 --- a/devstack/components/melange.py +++ b/devstack/components/melange.py @@ -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() diff --git a/devstack/components/quantum.py b/devstack/components/quantum.py index 2efa3084..756fc3e0 100644 --- a/devstack/components/quantum.py +++ b/devstack/components/quantum.py @@ -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()