From c45562e0e03e03c82bfcf60d4b3f8b7793133301 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 20 May 2016 15:14:28 -0300 Subject: Set openshift_version in config playbooks for first master. Starting to remove openshift.docker.openshift_version fact usage. openshift_version should no longer contain a leading 'v' for containerized installs, just a version number. --- roles/openshift_facts/library/openshift_facts.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 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 b13343776..6127948bf 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1133,15 +1133,9 @@ 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) - - # openshift_facts runs before openshift_docker_facts. However, it will be - # called again and set properly throughout the playbook run. This could be - # refactored to simply set the openshift.common.version in the - # openshift_docker_facts role but it would take reworking some assumptions - # on how get_openshift_version is called. - if 'is_containerized' in facts['common'] and safe_get_bool(facts['common']['is_containerized']): - if 'docker' in facts and 'openshift_version' in facts['docker']: - version = facts['docker']['openshift_version'] + elif os.path.isfile('/usr/local/bin/openshift'): + _, output, _ = module.run_command(['/usr/local/bin/openshift', 'version']) + version = parse_openshift_version(output) return version -- cgit v1.2.3 From 0c7433838c8c6409b8de907fcc946fc73fe90527 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Tue, 24 May 2016 09:46:33 -0300 Subject: Work towards determining openshift_version when unspecified. openshift_docker role was largely useless now, but also almost did what we needed. (deps ordering still needs to be changed) Remove defaulting of openshift_version. --- roles/openshift_facts/library/openshift_facts.py | 2 ++ 1 file changed, 2 insertions(+) (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 6127948bf..33596cd3e 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1134,6 +1134,8 @@ def get_openshift_version(facts): _, output, _ = module.run_command(['/usr/bin/openshift', 'version']) version = parse_openshift_version(output) elif os.path.isfile('/usr/local/bin/openshift'): + # TODO: this should probably make sure the actual image is already present, this can take awhile if it has to pull + # and is falsely acting like openshift is already installed _, output, _ = module.run_command(['/usr/local/bin/openshift', 'version']) version = parse_openshift_version(output) -- cgit v1.2.3 From 717012aa4d5df01e5859ce44705abfbf34be8047 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 25 May 2016 09:20:15 -0300 Subject: Hookup node configuration. --- roles/openshift_facts/library/openshift_facts.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 33596cd3e..eee4d2b8e 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -826,7 +826,7 @@ def set_version_facts_if_unset(facts): if 'common' in facts: deployment_type = facts['common']['deployment_type'] version = get_openshift_version(facts) - if version is not None: + if version: facts['common']['version'] = version if deployment_type == 'origin': version_gte_3_1_or_1_1 = LooseVersion(version) >= LooseVersion('1.1.0') @@ -1150,7 +1150,11 @@ def parse_openshift_version(output): string: the version number """ versions = dict(e.split(' v') for e in output.splitlines() if ' v' in e) - return versions.get('openshift', '') + ver = versions.get('openshift', '') + # Remove trailing build number and commit hash from older versions, we need to return a straight + # w.x.y.z version here for use as openshift_version throughout the playbooks/roles. (i.e. 3.1.1.6-64-g80b61da) + ver = ver.split('-')[0] + return ver def apply_provider_facts(facts, provider_facts): -- cgit v1.2.3 From bcf414e8b559d35909f26420d9e7dec3cd0a1897 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Thu, 9 Jun 2016 12:48:40 -0300 Subject: Fix missing openshift.common.version fact on containerized nodes. --- roles/openshift_facts/library/openshift_facts.py | 3 +++ 1 file changed, 3 insertions(+) (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 8824a663c..856dcbdb8 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1138,6 +1138,9 @@ def get_openshift_version(facts): # and is falsely acting like openshift is already installed _, output, _ = module.run_command(['/usr/local/bin/openshift', 'version']) version = parse_openshift_version(output) + elif 'node' in facts and 'common' in facts and 'is_containerized' in facts['common']: + _, output, _ = module.run_command(['docker', 'run', '--rm', facts['common']['cli_image'], 'version']) + version = parse_openshift_version(output) return version -- cgit v1.2.3 From 755a48c4ebf1061ce19892e5378fba769027bfc1 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 10 Jun 2016 10:21:19 -0300 Subject: Fix version unset bug, and set common ver fact on containerized nodes. --- roles/openshift_facts/library/openshift_facts.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 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 856dcbdb8..9d7705af7 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1139,11 +1139,21 @@ def get_openshift_version(facts): _, output, _ = module.run_command(['/usr/local/bin/openshift', 'version']) version = parse_openshift_version(output) elif 'node' in facts and 'common' in facts and 'is_containerized' in facts['common']: - _, output, _ = module.run_command(['docker', 'run', '--rm', facts['common']['cli_image'], 'version']) - version = parse_openshift_version(output) + version = get_containerized_node_openshift_version(facts) return version +def get_containerized_node_openshift_version(facts): + node_svc = "%s-node" % facts['common']['service_type'] + rc, _, _ = module.run_command(['systemctl', 'is-active', node_svc]) + if rc > 0: + # Node service not running or doesn't exist: + return None + # Node service running, exec in and get the version: + _, output, _ = module.run_command(['docker', 'exec', '-ti', node_svc, 'openshift', 'version']) + return parse_openshift_version(output) + + def parse_openshift_version(output): """ Apply provider facts to supplied facts dict -- cgit v1.2.3 From b26b6f8c5bd0767495ee3d256f0772e769029923 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 15 Jun 2016 10:24:00 -0300 Subject: Fix performance hit in openshift_facts. --- roles/openshift_facts/library/openshift_facts.py | 5 ----- 1 file changed, 5 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 9d7705af7..97cca2e5c 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1133,11 +1133,6 @@ 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 os.path.isfile('/usr/local/bin/openshift'): - # TODO: this should probably make sure the actual image is already present, this can take awhile if it has to pull - # and is falsely acting like openshift is already installed - _, output, _ = module.run_command(['/usr/local/bin/openshift', 'version']) - version = parse_openshift_version(output) elif 'node' in facts and 'common' in facts and 'is_containerized' in facts['common']: version = get_containerized_node_openshift_version(facts) -- cgit v1.2.3 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/openshift_facts/library') 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 From 78dd487871796a71c450a1a1daf78b079a3a1090 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Thu, 16 Jun 2016 14:27:20 -0300 Subject: Cleanup, fix 3.1 version bug in facts. --- roles/openshift_facts/library/openshift_facts.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 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 eb6369f50..a979639f8 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1113,7 +1113,9 @@ def get_docker_version_info(): return result def get_openshift_version(facts): - """ Get current version of openshift on the host + """ Get current version of openshift on the host. + + Checks a variety of ways ranging from fastest to slowest. Args: facts (dict): existing facts @@ -1139,18 +1141,17 @@ def get_openshift_version(facts): elif 'common' in facts and 'is_containerized' in facts['common']: version = get_containerized_node_openshift_version(facts) + # Handle containerized masters that have not yet been configured as a node. + # This can be very slow and may get re-run multiple times, so we only use this + # if other methods failed to find a version. + if not version and os.path.isfile('/usr/local/bin/openshift'): + _, output, _ = module.run_command(['/usr/local/bin/openshift', 'version']) + version = parse_openshift_version(output) + return version -def get_containerized_node_openshift_version(facts): - node_svc = "%s-node" % facts['common']['service_type'] - rc, _, _ = module.run_command(['systemctl', 'is-active', node_svc]) - if rc > 0: - # Node service not running or doesn't exist: - return None - # Node service running, exec in and get the version: - _, output, _ = module.run_command(['docker', 'exec', '-ti', node_svc, 'openshift', 'version']) - return parse_openshift_version(output) +def get_containerized_node_openshift_version(facts): # 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): @@ -1167,8 +1168,6 @@ def get_containerized_node_openshift_version(facts): return None - - def parse_openshift_version(output): """ Apply provider facts to supplied facts dict -- cgit v1.2.3 From f0f69623f6852badb7b912064de539371da6e2f1 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Thu, 16 Jun 2016 14:58:15 -0300 Subject: Fix typo in facts. --- roles/openshift_facts/library/openshift_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 a979639f8..6c31f0fa8 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1159,7 +1159,7 @@ def get_containerized_node_openshift_version(facts): with open(node_env) as f: for line in f: - if line.startwith("IMAGE_VERSION="): + if line.startswith("IMAGE_VERSION="): tag = line[len("IMAGE_VERSION="):] # Remove leading "v" and any trailing release info, we just want # a version number here: -- cgit v1.2.3 From 63ea5cce369710363dd09b2b64c40871c6ce55f9 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 17 Jun 2016 09:10:20 -0300 Subject: More stable lookup of running openshift version. --- roles/openshift_facts/library/openshift_facts.py | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 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 6c31f0fa8..62d478bfc 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1139,7 +1139,7 @@ def get_openshift_version(facts): # 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) + version = get_containerized_openshift_version(facts) # Handle containerized masters that have not yet been configured as a node. # This can be very slow and may get re-run multiple times, so we only use this @@ -1151,20 +1151,21 @@ def get_openshift_version(facts): return version -def get_containerized_node_openshift_version(facts): +def get_containerized_openshift_version(facts): # 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.startswith("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 + for filename in ['/etc/sysconfig/%s-master', '/etc/sysconfig/%s-node']: + env_file = filename % facts['common']['service_type'] + if not os.path.exists(env_file): + continue + + with open(env_file) as f: + for line in f: + if line.startswith("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 -- cgit v1.2.3 From 9ce7443cefb53a400f5b38ac004c41e1b443635c Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 17 Jun 2016 15:40:31 -0300 Subject: Fix version facts with trailing newline. --- roles/openshift_facts/library/openshift_facts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 62d478bfc..43cca90d6 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1161,7 +1161,7 @@ def get_containerized_openshift_version(facts): with open(env_file) as f: for line in f: if line.startswith("IMAGE_VERSION="): - tag = line[len("IMAGE_VERSION="):] + tag = line[len("IMAGE_VERSION="):].strip() # Remove leading "v" and any trailing release info, we just want # a version number here: version = tag[1:].split("-")[0] -- cgit v1.2.3 From 2a8b144073f474bf966c6ab92329442a1a526bde Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Fri, 8 Jul 2016 11:48:12 -0300 Subject: Remove/update TODOs. --- roles/openshift_facts/library/openshift_facts.py | 3 --- 1 file changed, 3 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 135224c16..fdd3e8708 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1142,9 +1142,6 @@ 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) - # 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_openshift_version(facts) -- cgit v1.2.3 From 2a4f65ad4b19fc594851195b3180d1fe81853909 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 13 Jul 2016 14:18:09 -0300 Subject: pylint fixes --- roles/openshift_facts/library/openshift_facts.py | 53 ++++++++++++------------ 1 file changed, 26 insertions(+), 27 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 fdd3e8708..3de8faace 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -7,16 +7,6 @@ """Ansible module for retrieving and setting openshift related facts""" -DOCUMENTATION = ''' ---- -module: openshift_facts -short_description: Cluster Facts -author: Jason DeTiberus -requirements: [ ] -''' -EXAMPLES = ''' -''' - import ConfigParser import copy import io @@ -30,6 +20,17 @@ from dbus import SystemBus, Interface from dbus.exceptions import DBusException +DOCUMENTATION = ''' +--- +module: openshift_facts +short_description: Cluster Facts +author: Jason DeTiberus +requirements: [ ] +''' +EXAMPLES = ''' +''' + + def migrate_docker_facts(facts): """ Apply migrations for docker facts """ params = { @@ -499,10 +500,8 @@ def set_dnsmasq_facts_if_unset(facts): """ if 'common' in facts: - if 'use_dnsmasq' not in facts['common'] and safe_get_bool(facts['common']['version_gte_3_2_or_1_2']): - facts['common']['use_dnsmasq'] = True - else: - facts['common']['use_dnsmasq'] = False + facts['common']['use_dnsmasq'] = bool('use_dnsmasq' not in facts['common'] and + safe_get_bool(facts['common']['version_gte_3_2_or_1_2'])) if 'master' in facts and 'dns_port' not in facts['master']: if safe_get_bool(facts['common']['use_dnsmasq']): facts['master']['dns_port'] = 8053 @@ -1143,7 +1142,7 @@ def get_openshift_version(facts): _, output, _ = module.run_command(['/usr/bin/openshift', 'version']) version = parse_openshift_version(output) elif 'common' in facts and 'is_containerized' in facts['common']: - version = get_containerized_openshift_version(facts) + version = get_container_openshift_version(facts) # Handle containerized masters that have not yet been configured as a node. # This can be very slow and may get re-run multiple times, so we only use this @@ -1155,15 +1154,18 @@ def get_openshift_version(facts): return version -def get_containerized_openshift_version(facts): - # If containerized, see if we can determine the installed version via the systemd environment files: +def get_container_openshift_version(facts): + """ + If containerized, see if we can determine the installed version via the + systemd environment files. + """ for filename in ['/etc/sysconfig/%s-master', '/etc/sysconfig/%s-node']: - env_file = filename % facts['common']['service_type'] - if not os.path.exists(env_file): + env_path = filename % facts['common']['service_type'] + if not os.path.exists(env_path): continue - with open(env_file) as f: - for line in f: + with open(env_path) as env_file: + for line in env_file: if line.startswith("IMAGE_VERSION="): tag = line[len("IMAGE_VERSION="):].strip() # Remove leading "v" and any trailing release info, we just want @@ -1218,7 +1220,7 @@ def apply_provider_facts(facts, provider_facts): # Disabling pylint too many branches. This function needs refactored # but is a very core part of openshift_facts. -# pylint: disable=too-many-branches +# pylint: disable=too-many-branches,too-many-nested-blocks def merge_facts(orig, new, additive_facts_to_overwrite, protected_facts_to_overwrite): """ Recursively merge facts dicts @@ -1766,10 +1768,7 @@ class OpenShiftFacts(object): if 'clock' in roles: exit_code, _, _ = module.run_command(['rpm', '-q', 'chrony']) - if exit_code == 0: - chrony_installed = True - else: - chrony_installed = False + chrony_installed = bool(exit_code == 0) defaults['clock'] = dict( enabled=True, chrony_installed=chrony_installed) @@ -2153,7 +2152,7 @@ def main(): ansible_facts=openshift_facts.facts) # ignore pylint errors related to the module_utils import -# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import +# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import, wrong-import-position # import module snippets from ansible.module_utils.basic import * from ansible.module_utils.facts import * -- cgit v1.2.3 From 6bfa3dee1efb32f20dcdcb4c7964ffd02969d1f1 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 13 Jul 2016 15:11:49 -0300 Subject: Remove too recent pylint option keys. --- roles/openshift_facts/library/openshift_facts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 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 3de8faace..226d707dc 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -1220,7 +1220,7 @@ def apply_provider_facts(facts, provider_facts): # Disabling pylint too many branches. This function needs refactored # but is a very core part of openshift_facts. -# pylint: disable=too-many-branches,too-many-nested-blocks +# pylint: disable=too-many-branches def merge_facts(orig, new, additive_facts_to_overwrite, protected_facts_to_overwrite): """ Recursively merge facts dicts @@ -2152,7 +2152,7 @@ def main(): ansible_facts=openshift_facts.facts) # ignore pylint errors related to the module_utils import -# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import, wrong-import-position +# pylint: disable=redefined-builtin, unused-wildcard-import, wildcard-import # import module snippets from ansible.module_utils.basic import * from ansible.module_utils.facts import * -- cgit v1.2.3