Base Classes¶
Factories base classes
- class saltfactories.bases.Factory(*, display_name=None, cwd=None, environ=None)[source]¶
Bases:
object
Base factory class
- Parameters
- Return type
None
- class saltfactories.bases.SubprocessImpl(*, factory)[source]¶
Bases:
object
Subprocess interaction implementation
- Parameters
factory (Factory) – The factory instance, either
Factory
or a sub-class of it.- Return type
None
- cmdline(*args)[source]¶
Construct a list of arguments to use when starting the subprocess
- Parameters
args (str) – Additional arguments to use when starting the subprocess
By default, this method will just call it’s factory’s
cmdline()
method, but can be overridden, as is the case ofsaltfactories.base.SystemdSaltDaemonImpl
.
- init_terminal(cmdline, env=None)[source]¶
Instantiate a terminal with the passed command line(
cmdline
) and return it.Additionally, it sets a reference to it in
self._terminal
and also collects an initial listing of child processes which will be used when terminating the terminal
- property pid¶
The pid of the running process. None if not running.
- class saltfactories.bases.Subprocess(*, display_name=None, cwd=None, environ=None, script_name, base_script_args=NOTHING, slow_stop=True)[source]¶
Bases:
saltfactories.bases.Factory
Base CLI script/binary class
- Parameters
script_name (str) – This is the string containing the name of the binary to call on the subprocess, either the full path to it, or the basename. In case of the basename, the directory containing the basename must be in your
$PATH
variable.base_script_args (list,tuple) – An list or tuple iterable of the base arguments to use when building the command line to launch the process
slow_stop (bool) – Whether to terminate the processes by sending a
SIGTERM
signal or by callingterminate()
on the sub-process. When code coverage is enabled, one will want slow_stop set to True so that coverage data can be written down to disk.
- Return type
None
Please look at
Factory
for the additional supported keyword arguments documentation.- property pid¶
The pid of the running process. None if not running.
- class saltfactories.bases.Process(*, display_name=None, cwd=None, environ=None, script_name, base_script_args=NOTHING, slow_stop=True, timeout=NOTHING)[source]¶
Bases:
saltfactories.bases.Subprocess
Base process factory
- Parameters
timeout (int) – The default maximum amount of seconds that a script should run. This value can be overridden when calling
run()
through the_timeout
keyword argument, and, in that case, the timeout value applied would be that of_timeout
instead ofself.timeout
.- Return type
None
Please look at
Subprocess
for the additional supported keyword arguments documentation.- process_output(stdout, stderr, cmdline=None)[source]¶
Process the output. When possible JSON is loaded from the output.
- Returns
Returns a tuple in the form of
(stdout, stderr, loaded_json)
- Return type
- cmdline(*args)¶
Construct a list of arguments to use when starting the subprocess
- get_base_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_display_name()¶
Returns a human readable name for the factory
- get_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_script_path()¶
Returns the path to the script to run
- is_running()¶
Returns true if the sub-process is alive
- property pid¶
The pid of the running process. None if not running.
- terminate()¶
Terminate the started daemon
- class saltfactories.bases.StartDaemonCallArguments(*, args, kwargs)[source]¶
Bases:
object
This class holds the arguments and keyword arguments used to start a daemon.
It’s used when restarting the daemon so that the same call is used.
- class saltfactories.bases.DaemonImpl(*, factory, before_start_callbacks=NOTHING, after_start_callbacks=NOTHING, before_terminate_callbacks=NOTHING, after_terminate_callbacks=NOTHING)[source]¶
Bases:
saltfactories.bases.SubprocessImpl
Daemon subprocess interaction implementation
Please look at
SubprocessImpl
for the additional supported keyword arguments documentation.- Return type
None
- before_start(callback, *args, **kwargs)[source]¶
Register a function callback to run before the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- after_start(callback, *args, **kwargs)[source]¶
Register a function callback to run after the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- before_terminate(callback, *args, **kwargs)[source]¶
Register a function callback to run before the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- after_terminate(callback, *args, **kwargs)[source]¶
Register a function callback to run after the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)[source]¶
Start the daemon
- Parameters
- get_start_arguments()[source]¶
Return the arguments and keyword arguments used when starting the daemon:
- Return type
- cmdline(*args)¶
Construct a list of arguments to use when starting the subprocess
- Parameters
args (str) – Additional arguments to use when starting the subprocess
By default, this method will just call it’s factory’s
cmdline()
method, but can be overridden, as is the case ofsaltfactories.base.SystemdSaltDaemonImpl
.
- init_terminal(cmdline, env=None)¶
Instantiate a terminal with the passed command line(
cmdline
) and return it.Additionally, it sets a reference to it in
self._terminal
and also collects an initial listing of child processes which will be used when terminating the terminal
- property pid¶
The pid of the running process. None if not running.
- run(*args, **kwargs)¶
Run the given command synchronously
- class saltfactories.bases.Daemon(*, display_name=None, cwd=None, environ=None, script_name, base_script_args=NOTHING, slow_stop=True, check_ports=None, factories_manager=None, start_timeout, max_start_attempts=3, extra_cli_arguments_after_first_start_failure=NOTHING)[source]¶
Bases:
saltfactories.bases.Subprocess
Base daemon factory
- Parameters
check_ports (list) – List of ports to try and connect to while confirming that the daemon is up and running
extra_cli_arguments_after_first_start_failure (tuple,) – Extra arguments to pass to the CLI that starts the daemon after the first failure
max_start_attempts (int) – Maximum number of attempts to try and start the daemon in case of failures
start_timeout (int) – The maximum number of seconds to wait before considering that the daemon did not start
- Return type
None
Please look at
Subprocess
for the additional supported keyword arguments documentation.- before_start(callback, *args, **kwargs)[source]¶
Register a function callback to run before the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- after_start(callback, *args, **kwargs)[source]¶
Register a function callback to run after the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- before_terminate(callback, *args, **kwargs)[source]¶
Register a function callback to run before the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- after_terminate(callback, *args, **kwargs)[source]¶
Register a function callback to run after the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- started(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)[source]¶
Start the daemon and return it’s instance so it can be used as a context manager
- stopped(before_stop_callback=None, after_stop_callback=None, before_start_callback=None, after_start_callback=None)[source]¶
- Parameters
before_stop_callback (Callable) – A callable to run before stopping the daemon. The callback must accept one argument, the daemon instance.
after_stop_callback (Callable) – A callable to run after stopping the daemon. The callback must accept one argument, the daemon instance.
before_start_callback (Callable) – A callable to run before starting the daemon. The callback must accept one argument, the daemon instance.
after_start_callback (Callable) – A callable to run after starting the daemon. The callback must accept one argument, the daemon instance.
This context manager will stop the factory while the context is in place, it re-starts it once out of context.
For example:
assert factory.is_running() is True with factory.stopped(): assert factory.is_running() is False assert factory.is_running() is True
- cmdline(*args)¶
Construct a list of arguments to use when starting the subprocess
- get_base_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_display_name()¶
Returns a human readable name for the factory
- get_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_script_path()¶
Returns the path to the script to run
- is_running()¶
Returns true if the sub-process is alive
- property pid¶
The pid of the running process. None if not running.
- terminate()¶
Terminate the started daemon
- class saltfactories.bases.Salt(*, config, python_executable=None, system_install=False)[source]¶
Bases:
object
Base factory for salt cli’s and daemon’s
- Parameters
- Return type
None
- class saltfactories.bases.SaltCliImpl(*, factory)[source]¶
Bases:
saltfactories.bases.SubprocessImpl
Salt CLI’s subprocess interaction implementation
Please look at
SubprocessImpl
for the additional supported keyword arguments documentation.- Return type
None
- cmdline(*args, minion_tgt=None, **kwargs)[source]¶
Construct a list of arguments to use when starting the subprocess
- init_terminal(cmdline, env=None)¶
Instantiate a terminal with the passed command line(
cmdline
) and return it.Additionally, it sets a reference to it in
self._terminal
and also collects an initial listing of child processes which will be used when terminating the terminal
- property pid¶
The pid of the running process. None if not running.
- run(*args, **kwargs)¶
Run the given command synchronously
- terminate()¶
Terminate the started daemon
- Return type
- class saltfactories.bases.SaltCli(*, config, python_executable=None, system_install=False, cwd=None, environ=None, script_name, base_script_args=NOTHING, slow_stop=True, timeout=NOTHING, hard_crash=False, merge_json_output=True)[source]¶
Bases:
saltfactories.bases.Salt
,saltfactories.bases.Process
Base factory for salt cli’s
- Parameters
hard_crash (bool) – Pass
--hard-crash
to Salt’s CLI’s- Return type
None
Please look at
Salt
andProcess
for the additional supported keyword arguments documentation.- cmdline(*args, minion_tgt=None, merge_json_output=None, **kwargs)[source]¶
Construct a list of arguments to use when starting the subprocess
- Parameters
args (str) – Additional arguments to use when starting the subprocess
minion_tgt (str) – The minion ID to target
merge_json_output (bool) – The default behavior of salt outputters is to print one line per minion return, which makes parsing the whole output as JSON impossible when targeting multiple minions. If this value is
True
, an attempt is made to merge each JSON line into a single dictionary.kwargs – Additional keyword arguments will be converted into
key=value
pairs to be consumed by the salt CLI’s
- process_output(stdout, stderr, cmdline=None)[source]¶
Process the output. When possible JSON is loaded from the output.
- Returns
Returns a tuple in the form of
(stdout, stderr, loaded_json)
- Return type
- get_base_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_display_name()¶
Returns a human readable name for the factory
- get_script_path()¶
Returns the path to the script to run
- is_running()¶
Returns true if the sub-process is alive
- property pid¶
The pid of the running process. None if not running.
- run(*args, _timeout=None, **kwargs)¶
Run the given command synchronously
- terminate()¶
Terminate the started daemon
- class saltfactories.bases.SystemdSaltDaemonImpl(*, factory, before_start_callbacks=NOTHING, after_start_callbacks=NOTHING, before_terminate_callbacks=NOTHING, after_terminate_callbacks=NOTHING)[source]¶
Bases:
saltfactories.bases.DaemonImpl
Daemon systemd interaction implementation
Please look at
DaemonImpl
for the additional supported keyword arguments documentation.- Return type
None
- cmdline(*args)[source]¶
Construct a list of arguments to use when starting the subprocess
- Parameters
args (str) – Additional arguments to use when starting the subprocess
- start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)[source]¶
Start the daemon
- Parameters
- property pid¶
The pid of the running process. None if not running.
- after_start(callback, *args, **kwargs)¶
Register a function callback to run after the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- after_terminate(callback, *args, **kwargs)¶
Register a function callback to run after the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- before_start(callback, *args, **kwargs)¶
Register a function callback to run before the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- before_terminate(callback, *args, **kwargs)¶
Register a function callback to run before the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- get_start_arguments()¶
Return the arguments and keyword arguments used when starting the daemon:
- Return type
- init_terminal(cmdline, env=None)¶
Instantiate a terminal with the passed command line(
cmdline
) and return it.Additionally, it sets a reference to it in
self._terminal
and also collects an initial listing of child processes which will be used when terminating the terminal
- run(*args, **kwargs)¶
Run the given command synchronously
- terminate()¶
Terminate the daemon
- class saltfactories.bases.SaltDaemon(*, config, python_executable=None, system_install=False, cwd=None, environ=None, script_name, base_script_args=NOTHING, slow_stop=True, check_ports=None, factories_manager=None, start_timeout, max_start_attempts=3, extra_cli_arguments_after_first_start_failure=NOTHING, event_listener=None, started_at=None)[source]¶
Bases:
saltfactories.bases.Salt
,saltfactories.bases.Daemon
Base factory for salt daemon’s
Please look at
Salt
andDaemon
for the additional supported keyword arguments documentation.- Return type
None
- classmethod configure(factories_manager, daemon_id, root_dir=None, defaults=None, overrides=None, **configure_kwargs)[source]¶
Configure the salt daemon
- classmethod load_config(config_file, config)[source]¶
Should return the configuration as the daemon would have loaded after parsing the CLI
- get_check_events()[source]¶
Return a list of tuples in the form of (master_id, event_tag) check against to ensure the daemon is running
- cmdline(*args)[source]¶
Construct a list of arguments to use when starting the subprocess
- Parameters
args (str) – Additional arguments to use when starting the subprocess
- after_start(callback, *args, **kwargs)¶
Register a function callback to run after the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- after_terminate(callback, *args, **kwargs)¶
Register a function callback to run after the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- before_start(callback, *args, **kwargs)¶
Register a function callback to run before the daemon starts
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- before_terminate(callback, *args, **kwargs)¶
Register a function callback to run before the daemon terminates
- Parameters
callback (Callable) – The function to call back
args – The arguments to pass to the callback
kwargs – The keyword arguments to pass to the callback
- get_base_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_check_ports()¶
Return a list of ports to check against to ensure the daemon is running
- get_display_name()¶
Returns a human readable name for the factory
- get_script_args()¶
Returns any additional arguments to pass to the CLI script
- get_script_path()¶
Returns the path to the script to run
- is_running()¶
Returns true if the sub-process is alive
- property pid¶
The pid of the running process. None if not running.
- start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)¶
Start the daemon
- started(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)¶
Start the daemon and return it’s instance so it can be used as a context manager
- stopped(before_stop_callback=None, after_stop_callback=None, before_start_callback=None, after_start_callback=None)¶
- Parameters
before_stop_callback (Callable) – A callable to run before stopping the daemon. The callback must accept one argument, the daemon instance.
after_stop_callback (Callable) – A callable to run after stopping the daemon. The callback must accept one argument, the daemon instance.
before_start_callback (Callable) – A callable to run before starting the daemon. The callback must accept one argument, the daemon instance.
after_start_callback (Callable) – A callable to run after starting the daemon. The callback must accept one argument, the daemon instance.
This context manager will stop the factory while the context is in place, it re-starts it once out of context.
For example:
assert factory.is_running() is True with factory.stopped(): assert factory.is_running() is False assert factory.is_running() is True
- terminate()¶
Terminate the started daemon