diff options
author | Scott Dodson <sdodson@redhat.com> | 2017-02-23 09:18:45 -0500 |
---|---|---|
committer | Scott Dodson <sdodson@redhat.com> | 2017-02-23 09:18:45 -0500 |
commit | b0d441f8f42872f53fc084fe6b91fcd16b5ad8fe (patch) | |
tree | c05a8bb0b5490b4972596ac91ac0e45c24aad760 /roles/lib_openshift/library | |
parent | c8e8a798a5c1695fd497833f4dcd263ff9414e87 (diff) | |
download | openshift-b0d441f8f42872f53fc084fe6b91fcd16b5ad8fe.tar.gz openshift-b0d441f8f42872f53fc084fe6b91fcd16b5ad8fe.tar.bz2 openshift-b0d441f8f42872f53fc084fe6b91fcd16b5ad8fe.tar.xz openshift-b0d441f8f42872f53fc084fe6b91fcd16b5ad8fe.zip |
Re-generate lib_openshift and lib_utils libraries
Diffstat (limited to 'roles/lib_openshift/library')
-rw-r--r-- | roles/lib_openshift/library/oc_adm_ca_server_cert.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/roles/lib_openshift/library/oc_adm_ca_server_cert.py b/roles/lib_openshift/library/oc_adm_ca_server_cert.py index 720a37aa0..2324bbc67 100644 --- a/roles/lib_openshift/library/oc_adm_ca_server_cert.py +++ b/roles/lib_openshift/library/oc_adm_ca_server_cert.py @@ -777,6 +777,32 @@ class OpenShiftCLIError(Exception): pass +ADDITIONAL_PATH_LOOKUPS = ['/usr/local/bin', os.path.expanduser('~/bin')] + + +def locate_oc_binary(): + ''' Find and return oc binary file ''' + # https://github.com/openshift/openshift-ansible/issues/3410 + # oc can be in /usr/local/bin in some cases, but that may not + # be in $PATH due to ansible/sudo + paths = os.environ.get("PATH", os.defpath).split(os.pathsep) + ADDITIONAL_PATH_LOOKUPS + + oc_binary = 'oc' + + # Use shutil.which if it is available, otherwise fallback to a naive path search + try: + which_result = shutil.which(oc_binary, path=os.pathsep.join(paths)) + if which_result is not None: + oc_binary = which_result + except AttributeError: + for path in paths: + if os.path.exists(os.path.join(path, oc_binary)): + oc_binary = os.path.join(path, oc_binary) + break + + return oc_binary + + # pylint: disable=too-few-public-methods class OpenShiftCLI(object): ''' Class to wrap the command line tools ''' @@ -790,6 +816,7 @@ class OpenShiftCLI(object): self.verbose = verbose self.kubeconfig = Utils.create_tmpfile_copy(kubeconfig) self.all_namespaces = all_namespaces + self.oc_binary = locate_oc_binary() # Pylint allows only 5 arguments to be passed. # pylint: disable=too-many-arguments @@ -991,11 +1018,10 @@ class OpenShiftCLI(object): # pylint: disable=too-many-arguments,too-many-branches def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' - cmds = [] + cmds = [self.oc_binary] + if oadm: - cmds = ['oadm'] - else: - cmds = ['oc'] + cmds.append('adm') if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -1011,7 +1037,10 @@ class OpenShiftCLI(object): if self.verbose: print(' '.join(cmds)) - returncode, stdout, stderr = self._run(cmds, input_data) + try: + returncode, stdout, stderr = self._run(cmds, input_data) + except OSError as ex: + returncode, stdout, stderr = 1, '', 'Failed to execute {}: {}'.format(subprocess.list2cmdline(cmds), ex) rval = {"returncode": returncode, "results": results, |