Salt Factories Manager

Salt Factories Manager

class saltfactories.manager.FactoriesManager(*, root_dir, log_server_port, log_server_level, log_server_host, code_dir=None, inject_coverage=False, inject_sitecustomize=False, cwd=None, environ=None, slow_stop=True, start_timeout=None, stats_processes=None, system_install=False, event_listener)[source]

Bases: object

The FactoriesManager is responsible for configuring and spawning Salt Daemons and making sure that any salt CLI tools are “targeted” to the right daemon.

It also keeps track of which daemons were started and adds their termination routines to PyTest’s request finalization routines.

If process statistics are enabled, it also adds the started daemons to those statistics.

Parameters
  • root_dir (pathlib.Path, str) –

  • log_server_port (int) – The port the log server should listen at

  • log_server_level (int) – The level of the log server

  • log_server_host (str) – The hostname/ip address of the host running the logs server. Defaults to “localhost”.

  • code_dir (str) – The path to the code root directory of the project being tested. This is important for proper code-coverage paths.

  • inject_coverage (bool) – Inject code-coverage related code in the generated CLI scripts

  • inject_sitecustomize (bool) – Inject code in the generated CLI scripts in order for our sitecustomise.py to be loaded by subprocesses.

  • cwd (str) – The path to the current working directory

  • environ (dict) – A dictionary of key, value pairs to add to the environment.

  • slow_stop (bool) – Whether to terminate the processes by sending a SIGTERM signal or by calling terminate() 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.

  • start_timeout (int) – The amount of time, in seconds, to wait, until a subprocess is considered as not started.

  • stats_processes (saltfactories.plugins.sysstats.StatsProcesses) – This will be an StatsProcesses class instantiated on the pytest_sessionstart() hook accessible as a session scoped stats_processes fixture.

  • system_install (bool) – If true, the daemons and CLI’s are run against a system installed salt setup, ie, the default salt system paths apply.

Return type

None

static get_salt_log_handlers_path()[source]

Returns the path to the Salt log handler this plugin provides

static get_salt_engines_path()[source]

Returns the path to the Salt engine this plugin provides

salt_master_daemon(master_id, order_masters=False, master_of_masters=None, defaults=None, overrides=None, max_start_attempts=3, start_timeout=None, factory_class=<class 'saltfactories.daemons.master.SaltMaster'>, **factory_class_kwargs)[source]

Configure a salt-master

Args:
master_id(str):

The master ID

order_masters(bool):

Boolean flag to set if this master is going to control other masters(ie, master of masters), like, for example, in a Syndic topology scenario

master_of_masters(saltfactories.daemons.master.SaltMaster):

A saltfactories.daemons.master.SaltMaster instance, like, for example, in a Syndic topology scenario

defaults(dict):

A dictionary of default configuration to use when configuring the master

overrides(dict):

A dictionary of configuration overrides to use when configuring the master

max_start_attempts(int):

How many attempts should be made to start the master in case of failure to validate that its running

factory_class_kwargs(dict):

Extra keyword arguments to pass to saltfactories.daemons.master.SaltMaster

Returns:
saltfactories.daemons.master.SaltMaster:

The master process class instance

salt_minion_daemon(minion_id, master=None, defaults=None, overrides=None, max_start_attempts=3, start_timeout=None, factory_class=<class 'saltfactories.daemons.minion.SaltMinion'>, **factory_class_kwargs)[source]

Spawn a salt-minion

Args:
minion_id(str):

The minion ID

master(saltfactories.daemons.master.SaltMaster):

An instance of saltfactories.daemons.master.SaltMaster that this minion will connect to.

defaults(dict):

A dictionary of default configuration to use when configuring the minion

overrides(dict):

A dictionary of configuration overrides to use when configuring the minion

max_start_attempts(int):

How many attempts should be made to start the minion in case of failure to validate that its running

factory_class_kwargs(dict):

Extra keyword arguments to pass to SaltMinion

Returns:
SaltMinion:

The minion process class instance

salt_syndic_daemon(syndic_id, master_of_masters=None, defaults=None, overrides=None, max_start_attempts=3, start_timeout=None, factory_class=<class 'saltfactories.daemons.syndic.SaltSyndic'>, master_defaults=None, master_overrides=None, master_factory_class=<class 'saltfactories.daemons.master.SaltMaster'>, minion_defaults=None, minion_overrides=None, minion_factory_class=<class 'saltfactories.daemons.minion.SaltMinion'>, **factory_class_kwargs)[source]

Spawn a salt-syndic

Args:
syndic_id(str):

The Syndic ID. This ID will be shared by the salt-master, salt-minion and salt-syndic processes.

master_of_masters(saltfactories.daemons.master.SaltMaster):

An instance of saltfactories.daemons.master.SaltMaster that the master configured in this Syndic topology scenario shall connect to.

defaults(dict):

A dictionary of default configurations with three top level keys, master, minion and syndic, to use when configuring the salt-master, salt-minion and salt-syndic respectively.

overrides(dict):

A dictionary of configuration overrides with three top level keys, master, minion and syndic, to use when configuring the salt-master, salt-minion and salt-syndic respectively.

max_start_attempts(int):

How many attempts should be made to start the syndic in case of failure to validate that its running

factory_class_kwargs(dict):

Extra keyword arguments to pass to SaltSyndic

Returns:
SaltSyndic:

The syndic process class instance

salt_proxy_minion_daemon(proxy_minion_id, master=None, defaults=None, overrides=None, max_start_attempts=3, start_timeout=None, factory_class=<class 'saltfactories.daemons.proxy.SaltProxyMinion'>, **factory_class_kwargs)[source]

Spawn a salt-proxy

Args:
proxy_minion_id(str):

The proxy minion ID

master(saltfactories.daemons.master.SaltMaster):

An instance of saltfactories.daemons.master.SaltMaster that this minion will connect to.

defaults(dict):

A dictionary of default configuration to use when configuring the proxy minion

overrides(dict):

A dictionary of configuration overrides to use when configuring the proxy minion

max_start_attempts(int):

How many attempts should be made to start the proxy minion in case of failure to validate that its running

factory_class_kwargs(dict):

Extra keyword arguments to pass to SaltProxyMinion

Returns:
SaltProxyMinion:

The proxy minion process class instance

salt_api_daemon(master, max_start_attempts=3, start_timeout=None, factory_class=<class 'saltfactories.daemons.api.SaltApi'>, **factory_class_kwargs)[source]

Spawn a salt-api

Please see py:class:~saltfactories.manager.FactoriesManager.salt_master_daemon for argument documentation.

Returns:
SaltApi:

The salt-api process class instance

get_sshd_daemon(config_dir=None, listen_address=None, listen_port=None, sshd_config_dict=None, display_name=None, script_name='sshd', max_start_attempts=3, start_timeout=None, factory_class=<class 'saltfactories.daemons.sshd.Sshd'>, **factory_class_kwargs)[source]

Start an sshd daemon

Args:
max_start_attempts(int):

How many attempts should be made to start the proxy minion in case of failure to validate that its running

config_dir(pathlib.Path):

The path to the sshd config directory

listen_address(str):

The address where the sshd server will listen to connections. Defaults to 127.0.0.1

listen_port(int):

The port where the sshd server will listen to connections

sshd_config_dict(dict):

A dictionary of key-value pairs to construct the sshd config file

script_name(str):

The name or path to the binary to run. Defaults to sshd.

factory_class_kwargs(dict):

Extra keyword arguments to pass to Sshd

Returns:
Sshd:

The sshd process class instance

get_container(container_name, image_name, docker_client=None, display_name=None, factory_class=<class 'saltfactories.daemons.container.Container'>, max_start_attempts=3, start_timeout=None, **factory_class_kwargs)[source]

Start a docker container

Args:
container_name(str):

The name to give the container

image_name(str):

The image to use

docker_client:

An instance of the docker client to use

display_name(str):

Human readable name for the factory

factory_class:

A factory class. (Default Container)

max_start_attempts(int):

How many attempts should be made to start the container in case of failure to validate that its running.

start_timeout(int):

The amount of time, in seconds, to wait, until the container is considered as not started.

factory_class_kwargs(dict):

Extra keyword arguments to pass to Container

Returns:
Container:

The factory instance

get_salt_script_path(script_name)[source]

Return the path to the customized script path, generating one if needed.