From 89d6ac45161b1bfaca58f463abd05b6b7bee637f Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 7 Mar 2012 12:10:24 -0800 Subject: [PATCH] updated so empty keys are handled better in cfg/env --- devstack/cfg.py | 10 +++++----- devstack/env_rc.py | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/devstack/cfg.py b/devstack/cfg.py index 7c025f77..a3bc4472 100644 --- a/devstack/cfg.py +++ b/devstack/cfg.py @@ -30,6 +30,7 @@ PW_TMPL = "Enter a password for %s: " ENV_PAT = re.compile(r"^\s*\$\{([\w\d]+):\-(.*)\}\s*$") SUB_MATCH = re.compile(r"(?:\$\(([\w\d]+):([\w\d]+))\)") CACHE_MSG = "(value will now be internally cached)" +PW_SECTIONS = ['passwords'] DEF_PW_MSG = "[or press enter to get a generated one]" PW_PROMPTS = { 'horizon_keystone_admin': "Enter a password to use for horizon and keystone (20 chars or less) %s: " % (DEF_PW_MSG), @@ -95,14 +96,13 @@ class StackConfigParser(IgnoreMissingConfigParser): def _resolve_special(self, section, option, value_gotten, auto_pw): key = self._makekey(section, option) - if value_gotten and len(value_gotten): - if section == 'passwords': - self.pws[key] = value_gotten - elif section == 'host' and option == 'ip': + if section in PW_SECTIONS and key not in self.pws: + self.pws[key] = 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)) - elif section == 'passwords' and auto_pw: + elif section in PW_SECTIONS and auto_pw and len(value_gotten) == 0: LOG.debug("Being forced to ask for password for \"%s\" since the configuration value is empty.", key) prompt = PW_PROMPTS.get(option, PW_TMPL % (key)) value_gotten = sh.password(prompt) diff --git a/devstack/env_rc.py b/devstack/env_rc.py index 2469c33a..3fa6316b 100644 --- a/devstack/env_rc.py +++ b/devstack/env_rc.py @@ -65,7 +65,10 @@ class RcGenerator(object): def _make_export_cfg(self, export_name, cfg_section_key, default_val=''): (section, key) = cfg_section_key value = self.cfg.getdefaulted(section, key, default_val, auto_pw=False) - return self._make_export(export_name, value) + if len(value) != 0: + return self._make_export(export_name, value) + else: + return list() def _generate_ec2_env(self): lines = list()