Skip to content

Commit

Permalink
Read etcd data dir from appropriate config file.
Browse files Browse the repository at this point in the history
Rather than assuming the etcd data dir, we now read if from master-config.yaml
if using embedded etcd, otherwise from etcd.conf.

Doing so now required use of PyYAML to parse config file when gathering facts.

Fixed discrepancy with data_dir fact and openshift-enterprise deployment_type.
  • Loading branch information
dgoodwin committed Nov 9, 2015
1 parent 334c205 commit 30c3be6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion playbooks/adhoc/upgrades/upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@

- name: Ensure python-yaml present for config upgrade
yum:
pkg: python-yaml
pkg: PyYAML
state: installed

- name: Upgrade master configuration
Expand Down
53 changes: 44 additions & 9 deletions roles/openshift_facts/library/openshift_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import ConfigParser
import copy
import os
import StringIO
import yaml
from distutils.util import strtobool
from distutils.version import LooseVersion
from netaddr import IPNetwork
Expand Down Expand Up @@ -526,18 +528,51 @@ def set_aggregate_facts(facts):
first_svc_ip = str(IPNetwork(facts['master']['portal_net'])[1])
all_hostnames.add(first_svc_ip)
internal_hostnames.add(first_svc_ip)

if facts['master']['embedded_etcd']:
facts['master']['etcd_data_dir'] = os.path.join(
facts['common']['data_dir'], 'openshift.local.etcd')
else:
facts['master']['etcd_data_dir'] = '/var/lib/etcd'
_add_etcd_data_dir_fact(facts)

facts['common']['all_hostnames'] = list(all_hostnames)
facts['common']['internal_hostnames'] = list(internal_hostnames)

return facts


def _add_etcd_data_dir_fact(facts):
"""
If using embedded etcd, loads the data directory from master-config.yaml.
If using standalone etcd, loads ETCD_DATA_DIR from etcd.conf.
If anything goes wrong parsing these, the fact will not be set.
"""
if facts['master']['embedded_etcd']:
try:
# Parse master config to find actual etcd data dir:
master_cfg_path = os.path.join(facts['common']['config_base'],
'master/master-config.yaml')
master_cfg_f = open(master_cfg_path, 'r')
config = yaml.safe_load(master_cfg_f.read())
master_cfg_f.close()

facts['master']['etcd_data_dir'] = \
config['etcdConfig']['storageDirectory']
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['master']['etcd_data_dir'] = etcd_data_dir
except Exception:
pass


def set_deployment_facts_if_unset(facts):
""" Set Facts that vary based on deployment_type. This currently
includes common.service_type, common.config_base, master.registry_url,
Expand All @@ -558,17 +593,17 @@ def set_deployment_facts_if_unset(facts):
service_type = 'atomic-openshift'
if deployment_type == 'origin':
service_type = 'origin'
elif deployment_type in ['enterprise', 'online']:
elif deployment_type in ['openshift-enterprise', 'enterprise', 'online']:
service_type = 'openshift'
facts['common']['service_type'] = service_type
if 'config_base' not in facts['common']:
config_base = '/etc/origin'
if deployment_type in ['enterprise', 'online']:
if deployment_type in ['openshift-enterprise', 'enterprise', 'online']:
config_base = '/etc/openshift'
facts['common']['config_base'] = config_base
if 'data_dir' not in facts['common']:
data_dir = '/var/lib/origin'
if deployment_type in ['enterprise', 'online']:
if deployment_type in ['openshift-enterprise', 'enterprise', 'online']:
data_dir = '/var/lib/openshift'
facts['common']['data_dir'] = data_dir

Expand Down
7 changes: 5 additions & 2 deletions roles/openshift_facts/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
- ansible_version | version_compare('1.9.0', 'ne')
- ansible_version | version_compare('1.9.0.1', 'ne')

- name: Ensure python-netaddr is installed
yum: pkg=python-netaddr state=installed
- name: Ensure python-netaddr and PyYaml are installed
yum: pkg={{ item }} state=installed
with_items:
- python-netaddr
- PyYAML

- name: Gather Cluster facts
openshift_facts:

0 comments on commit 30c3be6

Please sign in to comment.