diff options
Diffstat (limited to 'roles/lib_openshift')
-rw-r--r-- | roles/lib_openshift/library/oadm_manage_node.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_edit.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_env.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_label.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_obj.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_process.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_route.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_scale.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_secret.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_service.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_serviceaccount.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_serviceaccount_secret.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/library/oc_version.py | 20 | ||||
-rw-r--r-- | roles/lib_openshift/src/lib/base.py | 19 | ||||
-rw-r--r-- | roles/lib_openshift/src/lib/import.py | 1 |
15 files changed, 224 insertions, 56 deletions
diff --git a/roles/lib_openshift/library/oadm_manage_node.py b/roles/lib_openshift/library/oadm_manage_node.py index 0ac233c72..840882bbc 100644 --- a/roles/lib_openshift/library/oadm_manage_node.py +++ b/roles/lib_openshift/library/oadm_manage_node.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -963,10 +964,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -982,7 +991,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, diff --git a/roles/lib_openshift/library/oc_edit.py b/roles/lib_openshift/library/oc_edit.py index 1b1faf496..9d174ba31 100644 --- a/roles/lib_openshift/library/oc_edit.py +++ b/roles/lib_openshift/library/oc_edit.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -991,10 +992,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -1010,7 +1019,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, diff --git a/roles/lib_openshift/library/oc_env.py b/roles/lib_openshift/library/oc_env.py index 1426565b4..d32773c38 100644 --- a/roles/lib_openshift/library/oc_env.py +++ b/roles/lib_openshift/library/oc_env.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -958,10 +959,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -977,7 +986,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, diff --git a/roles/lib_openshift/library/oc_label.py b/roles/lib_openshift/library/oc_label.py index 0db8585a4..0f98728f8 100644 --- a/roles/lib_openshift/library/oc_label.py +++ b/roles/lib_openshift/library/oc_label.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -967,10 +968,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -986,7 +995,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, diff --git a/roles/lib_openshift/library/oc_obj.py b/roles/lib_openshift/library/oc_obj.py index 6d0b391b9..39da0ed5c 100644 --- a/roles/lib_openshift/library/oc_obj.py +++ b/roles/lib_openshift/library/oc_obj.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -970,10 +971,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -989,7 +998,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, diff --git a/roles/lib_openshift/library/oc_process.py b/roles/lib_openshift/library/oc_process.py index a1ee79f6e..d3b2de4dc 100644 --- a/roles/lib_openshift/library/oc_process.py +++ b/roles/lib_openshift/library/oc_process.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -959,10 +960,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -978,7 +987,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, diff --git a/roles/lib_openshift/library/oc_route.py b/roles/lib_openshift/library/oc_route.py index 4b5c4460c..d8d5e1891 100644 --- a/roles/lib_openshift/library/oc_route.py +++ b/roles/lib_openshift/library/oc_route.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -1001,10 +1002,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -1020,7 +1029,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, diff --git a/roles/lib_openshift/library/oc_scale.py b/roles/lib_openshift/library/oc_scale.py index c73e96e10..e2a004f54 100644 --- a/roles/lib_openshift/library/oc_scale.py +++ b/roles/lib_openshift/library/oc_scale.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -945,10 +946,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -964,7 +973,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, diff --git a/roles/lib_openshift/library/oc_secret.py b/roles/lib_openshift/library/oc_secret.py index 6ab5e81b2..23d61a4fb 100644 --- a/roles/lib_openshift/library/oc_secret.py +++ b/roles/lib_openshift/library/oc_secret.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -991,10 +992,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -1010,7 +1019,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, diff --git a/roles/lib_openshift/library/oc_service.py b/roles/lib_openshift/library/oc_service.py index 319ec4bd7..6e7b1b52e 100644 --- a/roles/lib_openshift/library/oc_service.py +++ b/roles/lib_openshift/library/oc_service.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -997,10 +998,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -1016,7 +1025,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, diff --git a/roles/lib_openshift/library/oc_serviceaccount.py b/roles/lib_openshift/library/oc_serviceaccount.py index 7104355f0..59dee8efb 100644 --- a/roles/lib_openshift/library/oc_serviceaccount.py +++ b/roles/lib_openshift/library/oc_serviceaccount.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -943,10 +944,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -962,7 +971,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, diff --git a/roles/lib_openshift/library/oc_serviceaccount_secret.py b/roles/lib_openshift/library/oc_serviceaccount_secret.py index 3a9380661..906134797 100644 --- a/roles/lib_openshift/library/oc_serviceaccount_secret.py +++ b/roles/lib_openshift/library/oc_serviceaccount_secret.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -943,10 +944,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -962,7 +971,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, diff --git a/roles/lib_openshift/library/oc_version.py b/roles/lib_openshift/library/oc_version.py index 9b660e1d3..eeb28e7fc 100644 --- a/roles/lib_openshift/library/oc_version.py +++ b/roles/lib_openshift/library/oc_version.py @@ -36,6 +36,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess @@ -915,10 +916,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -934,7 +943,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, diff --git a/roles/lib_openshift/src/lib/base.py b/roles/lib_openshift/src/lib/base.py index 9cad5e667..0018a6710 100644 --- a/roles/lib_openshift/src/lib/base.py +++ b/roles/lib_openshift/src/lib/base.py @@ -224,10 +224,18 @@ class OpenShiftCLI(object): def openshift_cmd(self, cmd, oadm=False, output=False, output_type='json', input_data=None): '''Base command for oc ''' cmds = [] - if oadm: - cmds = ['oadm'] + basecmd = 'oadm' if oadm else 'oc' + # 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 + if sys.version_info[0] == 3: + basepath = shutil.which(basecmd) # pylint: disable=no-member else: - cmds = ['oc'] + import distutils.spawn + basepath = distutils.spawn.find_executable(basecmd) # pylint: disable=no-name-in-module + if basepath is None and os.path.isfile('/usr/local/bin/' + basecmd): + basecmd = '/usr/local/bin/' + basecmd + cmds.append(basecmd) if self.all_namespaces: cmds.extend(['--all-namespaces']) @@ -243,7 +251,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, diff --git a/roles/lib_openshift/src/lib/import.py b/roles/lib_openshift/src/lib/import.py index a79297898..5b2479b87 100644 --- a/roles/lib_openshift/src/lib/import.py +++ b/roles/lib_openshift/src/lib/import.py @@ -10,6 +10,7 @@ import atexit import copy import json import os +import sys import re import shutil import subprocess |