MCPcopy
hub / github.com/saltstack/salt / run_script

Method run_script

tests/support/case.py:339–553  ·  view source on GitHub ↗

Execute a script with the given argument string The ``log_output`` argument is ternary, it can be True, False, or None. If the value is boolean, then it forces the results to either be logged or not logged. If it is None, then the return code of the subprocess

(
        self,
        script,
        arg_str,
        catch_stderr=False,
        with_retcode=False,
        catch_timeout=False,
        # FIXME A timeout of zero or disabling timeouts may not return results!
        timeout=15,
        raw=False,
        popen_kwargs=None,
        log_output=None,
        config_dir=None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

337 return ret
338
339 def run_script(
340 self,
341 script,
342 arg_str,
343 catch_stderr=False,
344 with_retcode=False,
345 catch_timeout=False,
346 # FIXME A timeout of zero or disabling timeouts may not return results!
347 timeout=15,
348 raw=False,
349 popen_kwargs=None,
350 log_output=None,
351 config_dir=None,
352 **kwargs,
353 ):
354 """
355 Execute a script with the given argument string
356
357 The ``log_output`` argument is ternary, it can be True, False, or None.
358 If the value is boolean, then it forces the results to either be logged
359 or not logged. If it is None, then the return code of the subprocess
360 determines whether or not to log results.
361 """
362
363 import salt.utils.platform
364
365 script_path = self.get_script_path(script)
366 if not os.path.isfile(script_path):
367 return False
368 popen_kwargs = popen_kwargs or {}
369
370 python_path_env_var = os.environ.get("PYTHONPATH") or None
371 if python_path_env_var is None:
372 python_path_entries = [RUNTIME_VARS.CODE_DIR]
373 else:
374 python_path_entries = python_path_env_var.split(os.pathsep)
375 if RUNTIME_VARS.CODE_DIR in python_path_entries:
376 python_path_entries.remove(RUNTIME_VARS.CODE_DIR)
377 python_path_entries.insert(0, RUNTIME_VARS.CODE_DIR)
378 python_path_entries.extend(sys.path[0:])
379
380 if "env" not in popen_kwargs:
381 popen_kwargs["env"] = os.environ.copy()
382
383 popen_kwargs["env"]["PYTHONPATH"] = os.pathsep.join(python_path_entries)
384
385 if "cwd" not in popen_kwargs:
386 popen_kwargs["cwd"] = RUNTIME_VARS.TMP
387
388 # Always invoke the same interpreter that's running the tests. Falling
389 # back to bare ``python`` on PATH can pick up a different Python build
390 # (e.g. system Python 3.13) than the one pytest was launched with,
391 # which produces ``_sre.MAGIC`` mismatches when importing the stdlib.
392 cmd = f'"{sys.executable}" '
393
394 cmd += "{} --config-dir={} {} ".format(
395 script_path, config_dir or RUNTIME_VARS.TMP_CONF_DIR, arg_str
396 )

Callers 12

run_saltMethod · 0.95
run_sshMethod · 0.95
run_runMethod · 0.95
run_keyMethod · 0.95
run_cpMethod · 0.95
run_callMethod · 0.95
run_cloudMethod · 0.95
run_spmMethod · 0.95
run_cloudMethod · 0.80

Calls 15

formatMethod · 0.80
debugMethod · 0.80
nowMethod · 0.80
pollMethod · 0.80
get_script_pathMethod · 0.45
getMethod · 0.45
removeMethod · 0.45
insertMethod · 0.45
extendMethod · 0.45
copyMethod · 0.45
itemsMethod · 0.45
dumpsMethod · 0.45