oslo_concurrency.processutils

System-level utilities and helper functions.

exception oslo_concurrency.processutils.InvalidArgumentError(message=None)

Bases: exceptions.Exception

exception oslo_concurrency.processutils.NoRootWrapSpecified(message=None)

Bases: exceptions.Exception

exception oslo_concurrency.processutils.ProcessExecutionError(stdout=None, stderr=None, exit_code=None, cmd=None, description=None)

Bases: exceptions.Exception

exception oslo_concurrency.processutils.UnknownArgumentError(message=None)

Bases: exceptions.Exception

oslo_concurrency.processutils.execute(*cmd, **kwargs)

Helper method to shell out and execute a command through subprocess.

Allows optional retry.

Parameters:
  • cmd (string) – Passed to subprocess.Popen.
  • process_input (string) – Send to opened process.
  • env_variables (dict) – Environment variables and their values that will be set for the process.
  • check_exit_code (boolean, int, or [int]) – Single bool, int, or list of allowed exit codes. Defaults to [0]. Raise ProcessExecutionError unless program exits with one of these code.
  • delay_on_retry (boolean) – True | False. Defaults to True. If set to True, wait a short amount of time before retrying.
  • attempts (int) – How many times to retry cmd.
  • run_as_root (boolean) – True | False. Defaults to False. If set to True, the command is prefixed by the command specified in the root_helper kwarg.
  • root_helper (string) – command to prefix to commands called with run_as_root=True
  • shell (boolean) – whether or not there should be a shell used to execute this command. Defaults to false.
  • loglevel (int. (Should be logging.DEBUG or logging.INFO)) – log level for execute commands.
  • log_errors (integer.) – Should stdout and stderr be logged on error? Possible values are None=default, LOG_FINAL_ERROR, or LOG_ALL_ERRORS. None implies no logging on errors. The values LOG_FINAL_ERROR and LOG_ALL_ERRORS are relevant when multiple attempts of command execution are requested using the ‘attempts’ parameter. If LOG_FINAL_ERROR is specified then only log an error on the last attempt, and LOG_ALL_ERRORS requires logging on each occurence of an error.
Returns:

(stdout, stderr) from process execution

Raises:

UnknownArgumentError on receiving unknown arguments

Raises:

ProcessExecutionError

Raises:

OSError

oslo_concurrency.processutils.get_worker_count()

Utility to get the default worker count.

@return: The number of CPUs if that can be determined, else a default
worker count of 1 is returned.
oslo_concurrency.processutils.ssh_execute(ssh, cmd, process_input=None, addl_env=None, check_exit_code=True)
oslo_concurrency.processutils.trycmd(*args, **kwargs)

A wrapper around execute() to more easily handle warnings and errors.

Returns an (out, err) tuple of strings containing the output of the command’s stdout and stderr. If ‘err’ is not empty then the command can be considered to have failed.

:discard_warnings True | False. Defaults to False. If set to True,
then for succeeding commands, stderr is cleared

Previous topic

oslo_concurrency.opts

Next topic

oslo_concurrency.watchdog

This Page