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 --- .../upgrades/v3_0_to_v3_1/upgrade.yml | 1 + playbooks/common/openshift-master/config.yml | 3 -- roles/openshift_facts/library/openshift_facts.py | 49 +++++++++++++--------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/playbooks/common/openshift-cluster/upgrades/v3_0_to_v3_1/upgrade.yml b/playbooks/common/openshift-cluster/upgrades/v3_0_to_v3_1/upgrade.yml index 78797f8b8..01415f3de 100644 --- a/playbooks/common/openshift-cluster/upgrades/v3_0_to_v3_1/upgrade.yml +++ b/playbooks/common/openshift-cluster/upgrades/v3_0_to_v3_1/upgrade.yml @@ -90,6 +90,7 @@ roles: - openshift_facts tasks: + # Ensure we persist the etcd role for this host in openshift_facts - openshift_facts: role: etcd local_facts: {} diff --git a/playbooks/common/openshift-master/config.yml b/playbooks/common/openshift-master/config.yml index 1b3fba3aa..b1da85d5d 100644 --- a/playbooks/common/openshift-master/config.yml +++ b/playbooks/common/openshift-master/config.yml @@ -51,9 +51,6 @@ console_url: "{{ openshift_master_console_url | default(None) }}" console_use_ssl: "{{ openshift_master_console_use_ssl | default(None) }}" public_console_url: "{{ openshift_master_public_console_url | default(None) }}" - - role: etcd - local_facts: {} - when: openshift.master.embedded_etcd | bool - name: Check status of external etcd certificatees stat: path: "{{ openshift.common.config_base }}/master/{{ item }}" 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 From 61adeef4c94eada5182539cf30c55c4b31534bf9 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Fri, 13 Nov 2015 15:09:15 -0500 Subject: pylint openshift_facts --- roles/openshift_facts/library/openshift_facts.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 192c3c4bc..091ba4e2b 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -35,10 +35,8 @@ def first_ip(network): Returns: str: first IPv4 address """ - def atoi(addr): - return struct.unpack("!I", socket.inet_aton(addr))[0] - def itoa(addr): - return socket.inet_ntoa(struct.pack("!I", addr)) + atoi = lambda addr: struct.unpack("!I", socket.inet_aton(addr))[0] + itoa = lambda addr: socket.inet_ntoa(struct.pack("!I", addr)) (address, netmask) = network.split('/') netmask_i = (0xffffffff << (32 - atoi(netmask))) & 0xffffffff -- cgit v1.2.3