From 5346266575045e1a42914e10249dc6e9874da7ec Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 15 Jun 2016 12:07:05 -0300 Subject: More stable containerized version lookup. --- roles/openshift_facts/library/openshift_facts.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'roles') diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index 97cca2e5c..eb6369f50 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1133,7 +1133,10 @@ def get_openshift_version(facts): if os.path.isfile('/usr/bin/openshift'): _, output, _ = module.run_command(['/usr/bin/openshift', 'version']) version = parse_openshift_version(output) - elif 'node' in facts and 'common' in facts and 'is_containerized' in facts['common']: + # TODO: it probably makes more sense to read this from sysconfig service env files, + # these control the running versions when containerized, and would work even if the service + # is dead for some reason. + elif 'common' in facts and 'is_containerized' in facts['common']: version = get_containerized_node_openshift_version(facts) return version @@ -1148,6 +1151,23 @@ def get_containerized_node_openshift_version(facts): _, output, _ = module.run_command(['docker', 'exec', '-ti', node_svc, 'openshift', 'version']) return parse_openshift_version(output) + # If containerized, see if we can determine the installed version via the systemd environment files: + node_env = '/etc/sysconfig/%s-node' % facts['common']['service_type'] + if not os.path.exists(node_env): + return None + + with open(node_env) as f: + for line in f: + if line.startwith("IMAGE_VERSION="): + tag = line[len("IMAGE_VERSION="):] + # Remove leading "v" and any trailing release info, we just want + # a version number here: + version = tag[1:].split("-")[0] + return version + return None + + + def parse_openshift_version(output): """ Apply provider facts to supplied facts dict -- cgit v1.2.3