From 133bea98b62718fbc23d3c1f74e22665b5293603 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Fri, 13 Nov 2015 14:55:01 -0500 Subject: Update etcd default facts setting --- roles/openshift_facts/library/openshift_facts.py | 49 +++++++++++++++--------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'roles/openshift_facts/library') diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index ae530eadd..192c3c4bc 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -560,8 +560,10 @@ def set_etcd_facts_if_unset(facts): If anything goes wrong parsing these, the fact will not be set. """ - if 'etcd' in facts: - if 'master' in facts and facts['master']['embedded_etcd']: + if 'master' in facts and facts['master']['embedded_etcd']: + etcd_facts = facts['etcd'] if 'etcd' in facts else dict() + + if 'etcd_data_dir' not in etcd_facts: try: # Parse master config to find actual etcd data dir: master_cfg_path = os.path.join(facts['common']['config_base'], @@ -570,28 +572,37 @@ def set_etcd_facts_if_unset(facts): config = yaml.safe_load(master_cfg_f.read()) master_cfg_f.close() - facts['etcd']['etcd_data_dir'] = \ + etcd_facts['etcd_data_dir'] = \ config['etcdConfig']['storageDirectory'] + + facts['etcd'] = etcd_facts + # We don't want exceptions bubbling up here: # pylint: disable=broad-except except Exception: pass - else: - # Read ETCD_DATA_DIR from /etc/etcd/etcd.conf: - try: - # Add a fake section for parsing: - ini_str = '[root]\n' + open('/etc/etcd/etcd.conf', 'r').read() - ini_fp = StringIO.StringIO(ini_str) - config = ConfigParser.RawConfigParser() - config.readfp(ini_fp) - etcd_data_dir = config.get('root', 'ETCD_DATA_DIR') - if etcd_data_dir.startswith('"') and etcd_data_dir.endswith('"'): - etcd_data_dir = etcd_data_dir[1:-1] - facts['etcd']['etcd_data_dir'] = etcd_data_dir - # We don't want exceptions bubbling up here: - # pylint: disable=broad-except - except Exception: - pass + else: + etcd_facts = facts['etcd'] if 'etcd' in facts else dict() + + # Read ETCD_DATA_DIR from /etc/etcd/etcd.conf: + try: + # Add a fake section for parsing: + ini_str = '[root]\n' + open('/etc/etcd/etcd.conf', 'r').read() + ini_fp = StringIO.StringIO(ini_str) + config = ConfigParser.RawConfigParser() + config.readfp(ini_fp) + etcd_data_dir = config.get('root', 'ETCD_DATA_DIR') + if etcd_data_dir.startswith('"') and etcd_data_dir.endswith('"'): + etcd_data_dir = etcd_data_dir[1:-1] + + etcd_facts['etcd_data_dir'] = etcd_data_dir + facts['etcd'] = etcd_facts + + # We don't want exceptions bubbling up here: + # pylint: disable=broad-except + except Exception: + pass + return facts def set_deployment_facts_if_unset(facts): -- cgit v1.2.3