summaryrefslogtreecommitdiffstats
path: root/roles/openshift_facts/library
diff options
context:
space:
mode:
authorSamuel Munilla <smunilla@redhat.com>2016-03-09 08:08:37 -0500
committerSamuel Munilla <smunilla@redhat.com>2016-03-10 11:27:42 -0500
commitfd182b10d30492cd9f29ea61f595b84af33a31c7 (patch)
treedb3f0e47730062e7372428dc398296194662f3c7 /roles/openshift_facts/library
parent29010917f5a988b9b621457fc43623e4f67715a2 (diff)
downloadopenshift-fd182b10d30492cd9f29ea61f595b84af33a31c7.tar.gz
openshift-fd182b10d30492cd9f29ea61f595b84af33a31c7.tar.bz2
openshift-fd182b10d30492cd9f29ea61f595b84af33a31c7.tar.xz
openshift-fd182b10d30492cd9f29ea61f595b84af33a31c7.zip
openshift-ansible: Wrap boolean facts
Centralize the very weird process for converting strings to booleans to help keep the code consistent.
Diffstat (limited to 'roles/openshift_facts/library')
-rwxr-xr-xroles/openshift_facts/library/openshift_facts.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
index 596e4f894..566a5ef8c 100755
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -775,7 +775,7 @@ def set_sdn_facts_if_unset(facts, system_facts):
if 'common' in facts:
use_sdn = facts['common']['use_openshift_sdn']
if not (use_sdn == '' or isinstance(use_sdn, bool)):
- use_sdn = bool(strtobool(str(use_sdn)))
+ use_sdn = safe_get_bool(use_sdn)
facts['common']['use_openshift_sdn'] = use_sdn
if 'sdn_network_plugin_name' not in facts['common']:
plugin = 'redhat/openshift-ovs-subnet' if use_sdn else ''
@@ -1097,6 +1097,15 @@ def get_local_facts_from_file(filename):
return local_facts
+def safe_get_bool(fact):
+ """ Get a boolean fact safely.
+
+ Args:
+ facts: fact to convert
+ Returns:
+ bool: given fact as a bool
+ """
+ return bool(strtobool(str(fact)))
def set_container_facts_if_unset(facts):
""" Set containerized facts.
@@ -1142,7 +1151,7 @@ def set_container_facts_if_unset(facts):
if 'ovs_image' not in facts['node']:
facts['node']['ovs_image'] = ovs_image
- if bool(strtobool(str(facts['common']['is_containerized']))):
+ if safe_get_bool(facts['common']['is_containerized']):
facts['common']['admin_binary'] = '/usr/local/bin/oadm'
facts['common']['client_binary'] = '/usr/local/bin/oc'
base_version = get_openshift_version(facts, cli_image).split('-')[0]