TimeoutExpired,
UnauthorizedRegistryError,
)
+from cephadmlib.exe_utils import find_executable, find_program
FuncT = TypeVar('FuncT', bound=Callable)
os.chown(os.path.join(dirpath, filename), uid, gid)
-# copied from distutils
-def find_executable(executable: str, path: Optional[str] = None) -> Optional[str]:
- """Tries to find 'executable' in the directories listed in 'path'.
- A string listing directories separated by 'os.pathsep'; defaults to
- os.environ['PATH']. Returns the complete filename or None if not found.
- """
- _, ext = os.path.splitext(executable)
- if (sys.platform == 'win32') and (ext != '.exe'):
- executable = executable + '.exe' # pragma: no cover
-
- if os.path.isfile(executable):
- return executable
-
- if path is None:
- path = os.environ.get('PATH', None)
- if path is None:
- try:
- path = os.confstr('CS_PATH')
- except (AttributeError, ValueError):
- # os.confstr() or CS_PATH is not available
- path = os.defpath
- # bpo-35755: Don't use os.defpath if the PATH environment variable is
- # set to an empty string
-
- # PATH='' doesn't match, whereas PATH=':' looks in the current directory
- if not path:
- return None
-
- paths = path.split(os.pathsep)
- for p in paths:
- f = os.path.join(p, executable)
- if os.path.isfile(f):
- # the file exists, we have a shot at spawn working
- return f
- return None
-
-
-def find_program(filename):
- # type: (str) -> str
- name = find_executable(filename)
- if name is None:
- raise ValueError('%s not found' % filename)
- return name
-
-
def find_container_engine(ctx: CephadmContext) -> Optional[ContainerEngine]:
if ctx.docker:
return Docker()
--- /dev/null
+# exe_utils.py - functions used for finding external executables
+
+
+import os
+import sys
+
+from typing import Optional
+
+
+# copied from distutils
+def find_executable(executable: str, path: Optional[str] = None) -> Optional[str]:
+ """Tries to find 'executable' in the directories listed in 'path'.
+ A string listing directories separated by 'os.pathsep'; defaults to
+ os.environ['PATH']. Returns the complete filename or None if not found.
+ """
+ _, ext = os.path.splitext(executable)
+ if (sys.platform == 'win32') and (ext != '.exe'):
+ executable = executable + '.exe' # pragma: no cover
+
+ if os.path.isfile(executable):
+ return executable
+
+ if path is None:
+ path = os.environ.get('PATH', None)
+ if path is None:
+ try:
+ path = os.confstr('CS_PATH')
+ except (AttributeError, ValueError):
+ # os.confstr() or CS_PATH is not available
+ path = os.defpath
+ # bpo-35755: Don't use os.defpath if the PATH environment variable is
+ # set to an empty string
+
+ # PATH='' doesn't match, whereas PATH=':' looks in the current directory
+ if not path:
+ return None
+
+ paths = path.split(os.pathsep)
+ for p in paths:
+ f = os.path.join(p, executable)
+ if os.path.isfile(f):
+ # the file exists, we have a shot at spawn working
+ return f
+ return None
+
+
+def find_program(filename):
+ # type: (str) -> str
+ name = find_executable(filename)
+ if name is None:
+ raise ValueError('%s not found' % filename)
+ return name
with mock.patch('cephadm.attempt_bind'), \
mock.patch('cephadm.call', return_value=('', '', 0)), \
mock.patch('cephadm.call_timeout', return_value=0), \
- mock.patch('cephadm.find_executable', return_value='foo'), \
+ mock.patch('cephadmlib.exe_utils.find_executable', return_value='foo'), \
mock.patch('cephadm.get_container_info', return_value=None), \
mock.patch('cephadm.is_available', return_value=True), \
mock.patch('cephadm.json_loads_retry', return_value={'epoch' : 1}), \