Merge pull request #145 from harlowja/master
Bunch of string updates and config parser case insensitivity...
This commit is contained in:
commit
071543eb97
@ -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,21 +82,21 @@ 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):
|
||||
if section == 'host' and option == 'ip':
|
||||
LOG.debug("Host ip from configuration/environment was empty, programatically attempting to determine it.")
|
||||
value_gotten = utils.get_host_ip()
|
||||
LOG.debug("Determined your host ip to be: [%s]" % (value_gotten))
|
||||
LOG.debug("Determined your host ip to be: %r" % (value_gotten))
|
||||
return value_gotten
|
||||
|
||||
def getdefaulted(self, section, option, default_val):
|
||||
val = self.get(section, option)
|
||||
if not val or not val.strip():
|
||||
LOG.debug("Value [%s] found was not good enough, returning provided default [%s]" % (val, default_val))
|
||||
LOG.debug("Value %r found was not good enough, returning provided default '%s'" % (val, default_val))
|
||||
return default_val
|
||||
return val
|
||||
|
||||
@ -102,23 +104,23 @@ class StackConfigParser(IgnoreMissingConfigParser):
|
||||
key = cfg_helpers.make_id(section, option)
|
||||
if key in self.configs_fetched:
|
||||
value = self.configs_fetched.get(key)
|
||||
LOG.debug("Fetched cached value [%s] for param [%s]" % (value, key))
|
||||
LOG.debug("Fetched cached value '%s' for param %r" % (value, key))
|
||||
else:
|
||||
LOG.debug("Fetching value for param [%s]" % (key))
|
||||
LOG.debug("Fetching value for param %r" % (key))
|
||||
gotten_value = self._get_bashed(section, option)
|
||||
value = self._resolve_value(section, option, gotten_value)
|
||||
LOG.debug("Fetched [%s] for [%s] %s" % (value, key, CACHE_MSG))
|
||||
LOG.debug("Fetched %r for %r %s" % (value, key, CACHE_MSG))
|
||||
self.configs_fetched[key] = value
|
||||
return value
|
||||
|
||||
def set(self, section, option, value):
|
||||
key = cfg_helpers.make_id(section, option)
|
||||
LOG.audit("Setting config value [%s] for param [%s]" % (value, key))
|
||||
LOG.audit("Setting config value '%s' for param %r" % (value, key))
|
||||
self.configs_fetched[key] = value
|
||||
IgnoreMissingConfigParser.set(self, section, option, value)
|
||||
|
||||
def _resolve_replacements(self, value):
|
||||
LOG.debug("Performing simple replacement on [%s]", value)
|
||||
LOG.debug("Performing simple replacement on %r", value)
|
||||
|
||||
#allow for our simple replacement to occur
|
||||
def replacer(match):
|
||||
@ -138,19 +140,19 @@ class StackConfigParser(IgnoreMissingConfigParser):
|
||||
env_key = mtch.group(1).strip()
|
||||
def_val = mtch.group(2).strip()
|
||||
if not def_val and not env_key:
|
||||
msg = "Invalid bash-like value [%s]" % (value)
|
||||
msg = "Invalid bash-like value %r" % (value)
|
||||
raise excp.BadParamException(msg)
|
||||
env_value = env.get_key(env_key)
|
||||
if env_value is None:
|
||||
LOG.debug("Extracting value from config provided default value [%s]" % (def_val))
|
||||
LOG.debug("Extracting value from config provided default value %r" % (def_val))
|
||||
extracted_val = self._resolve_replacements(def_val)
|
||||
LOG.debug("Using config provided default value [%s] (no environment key)" % (extracted_val))
|
||||
LOG.debug("Using config provided default value %r (no environment key)" % (extracted_val))
|
||||
else:
|
||||
extracted_val = env_value
|
||||
LOG.debug("Using enviroment provided value [%s]" % (extracted_val))
|
||||
LOG.debug("Using enviroment provided value %r" % (extracted_val))
|
||||
else:
|
||||
extracted_val = value
|
||||
LOG.debug("Using raw config provided value [%s]" % (extracted_val))
|
||||
LOG.debug("Using raw config provided value %r" % (extracted_val))
|
||||
return extracted_val
|
||||
|
||||
|
||||
|
@ -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")
|
||||
|
@ -112,7 +112,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
|
||||
return set(['swift', 'quantum'])
|
||||
|
||||
def _sync_db(self):
|
||||
LOG.info("Syncing keystone to database named %s.", DB_NAME)
|
||||
LOG.info("Syncing keystone to database named %r", DB_NAME)
|
||||
mp = self._get_param_map(None)
|
||||
cmds = [{'cmd': SYNC_DB_CMD}]
|
||||
utils.execute_template(*cmds, cwd=self.bin_dir, params=mp)
|
||||
@ -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()
|
||||
|
@ -288,7 +288,7 @@ class NovaInstaller(NovaMixin, comp.PythonInstallComponent):
|
||||
self.tracewriter.file_touched(tgt_fn)
|
||||
|
||||
def _sync_db(self):
|
||||
LOG.info("Syncing the database with nova.")
|
||||
LOG.info("Syncing nova to database named %r", DB_NAME)
|
||||
mp = self._get_param_map(None)
|
||||
utils.execute_template(*DB_SYNC_CMD, params=mp)
|
||||
|
||||
|
@ -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