Containers#

Container based factories.

exception saltfactories.daemons.container.PyWinTypesError[source]#

Bases: Exception

Define PyWinTypesError to avoid NameError.

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class saltfactories.daemons.container.Container(*, cwd=_Nothing.NOTHING, environ=_Nothing.NOTHING, image, name=_Nothing.NOTHING, display_name=None, check_ports=_Nothing.NOTHING, container_run_kwargs=_Nothing.NOTHING, start_timeout=30, max_start_attempts=3, pull_before_start=True, skip_on_pull_failure=False, skip_if_docker_client_not_connectable=False, docker_client=_Nothing.NOTHING, before_start_callbacks=_Nothing.NOTHING, before_terminate_callbacks=_Nothing.NOTHING, after_start_callbacks=_Nothing.NOTHING, after_terminate_callbacks=_Nothing.NOTHING, container_start_checks_callbacks=_Nothing.NOTHING)[source]#

Bases: BaseFactory

Docker containers daemon implementation.

Args:
param str image:

The container image to use, for example ‘centos:7’

param str name:

The name to give to the started container.

keyword dict check_ports:

This dictionary is a mapping where the keys are the container port bindings and the values are the host port bindings.

If this mapping is empty, the container class will inspect the container_run_kwargs for a ports key to build this mapping.

Take as an example the following container_run_kwargs:

container_run_kwargs = {
    "ports": {
        "5000/tcp": None,
        "12345/tcp": 54321,
    }
}

This would build the following check ports mapping:

{5000: None, 12345: 54321}

At runtime, the Container class would query docker for the host port binding to the container port binding of 5000.

keyword dict container_run_kwargs:

This mapping will be passed directly to the python docker library:

container = self.docker_client.containers.run(
    self.image,
    name=self.name,
    detach=True,
    stdin_open=True,
    command=list(command) or None,
    **self.container_run_kwargs,
)
keyword int start_timeout:

The maximum number of seconds we should wait until the container is running.

keyword int max_start_attempts:

The maximum number of attempts to try and start the container

keyword bool pull_before_start:

When True, the image is pulled before trying to start it

keyword bool skip_on_pull_failure:

When True, and there’s a failure when pulling the image, the test is skipped.

keyword bool skip_if_docker_client_not_connectable:

When True, it skips the test if there’s a failure when connecting to docker

keyword Docker docker_client:

An instance of the python docker client to use. When nothing is passed, a default docker client is instantiated.

Parameters:
before_start(callback, *args, **kwargs)[source]#

Register a function callback to run before the container 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 container 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 container 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 container 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

container_start_check(callback, *args, **kwargs)[source]#

Register a function to run after the container starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

For example:

def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
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_display_name()[source]#

Returns a human readable name for the factory.

start(*command, max_start_attempts=None, start_timeout=None)[source]#

Start the container.

started(*command, max_start_attempts=None, start_timeout=None)[source]#

Start the container and return it’s instance so it can be used as a context manager.

terminate()[source]#

Terminate the container.

get_check_ports()[source]#

Return a list of TCP ports to check against to ensure the daemon is running.

get_host_port_binding(port, protocol='tcp', ipv6=False)[source]#

Return the host binding for a port on the container.

Parameters:
  • port (int) – The port.

  • protocol (str) – The port protocol. Defaults to tcp.

  • ipv6 (bool) – If true, return the ipv6 port binding.

Returns:

int: The matched port binding on the host. None: When not port binding was matched.

get_container_start_check_callbacks()[source]#

Return a list of the start check callbacks.

is_running()[source]#

Returns true if the container is running.

run(*cmd, **kwargs)[source]#

Run a command inside the container.

static client_connectable(docker_client)[source]#

Check if the docker client can connect to the docker daemon.

run_container_start_checks(started_at, timeout_at)[source]#

Run startup checks.

class saltfactories.daemons.container.SaltDaemon(*, cwd=_Nothing.NOTHING, environ=_Nothing.NOTHING, image, name=_Nothing.NOTHING, display_name=None, check_ports=_Nothing.NOTHING, container_run_kwargs=_Nothing.NOTHING, start_timeout=30, max_start_attempts=3, pull_before_start=True, skip_on_pull_failure=False, skip_if_docker_client_not_connectable=False, docker_client=_Nothing.NOTHING, before_start_callbacks=_Nothing.NOTHING, before_terminate_callbacks=_Nothing.NOTHING, after_start_callbacks=_Nothing.NOTHING, after_terminate_callbacks=_Nothing.NOTHING, container_start_checks_callbacks=_Nothing.NOTHING, config, config_dir=_Nothing.NOTHING, python_executable=None, system_service=False, slow_stop=True, system_encoding=_Nothing.NOTHING, timeout=_Nothing.NOTHING, script_name, base_script_args=_Nothing.NOTHING, stats_processes=None, extra_cli_arguments_after_first_start_failure=_Nothing.NOTHING, start_checks_callbacks=_Nothing.NOTHING, event_listener=None, factories_manager=None, started_at=None)[source]#

Bases: Container, SaltDaemon

Salt Daemon inside a container implementation.

Parameters:
  • cwd (str | Path) –

  • environ (EnvironDict) –

  • slow_stop (bool) –

  • system_encoding (str) –

  • timeout (int | float) –

  • script_name (str) –

  • base_script_args (List[str]) –

  • stats_processes (StatsProcesses) –

  • extra_cli_arguments_after_first_start_failure (List[str]) –

  • start_checks_callbacks (List[Callback]) –

get_display_name()[source]#

Returns a human readable name for the factory.

run(*cmd, **kwargs)[source]#

Run a command inside the container.

cmdline(*args)[source]#

Construct a list of arguments to use when starting the container.

Parameters:

args (str) – Additional arguments to use when starting the container

start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)[source]#

Start the daemon.

terminate()[source]#

Terminate the container.

is_running()[source]#

Returns true if the container is running.

get_check_ports()[source]#

Return a list of ports to check against to ensure the daemon is running.

before_start(callback, *args, on_container=False, **kwargs)[source]#

Register a function callback to run before the daemon starts.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

after_start(callback, *args, on_container=False, **kwargs)[source]#

Register a function callback to run after the daemon starts.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

before_terminate(callback, *args, on_container=False, **kwargs)[source]#

Register a function callback to run before the daemon terminates.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

after_terminate(callback, *args, on_container=False, **kwargs)[source]#

Register a function callback to run after the daemon terminates.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • 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.

get_check_events()[source]#

Return salt events to check.

Return a list of tuples in the form of (master_id, event_tag) check against to ensure the daemon is running

static client_connectable(docker_client)#

Check if the docker client can connect to the docker daemon.

classmethod configure(factories_manager, daemon_id, root_dir=None, defaults=None, overrides=None, **configure_kwargs)[source]#

Configure the salt daemon.

container_start_check(callback, *args, **kwargs)#

Register a function to run after the container starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

For example:

def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
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.

Return type:

List[str]

get_container_start_check_callbacks()#

Return a list of the start check callbacks.

get_host_port_binding(port, protocol='tcp', ipv6=False)#

Return the host binding for a port on the container.

Parameters:
  • port (int) – The port.

  • protocol (str) – The port protocol. Defaults to tcp.

  • ipv6 (bool) – If true, return the ipv6 port binding.

Returns:

int: The matched port binding on the host. None: When not port binding was matched.

get_script_args()#

Returns any additional arguments to pass to the CLI script.

Return type:

List[str]

get_script_path()#

Returns the path to the script to run.

Return type:

str

get_start_check_callbacks()#

Return a list of the start check callbacks.

Return type:

List[Callback]

classmethod load_config(config_file, config)[source]#

Return the loaded configuration.

Should return the configuration as the daemon would have loaded after parsing the CLI

property pid: int | None#

The pid of the running process. None if not running.

process_output(stdout, stderr, cmdline=None)#

Process the output. When possible JSON is loaded from the output.

Returns:

Returns a tuple in the form of (stdout, stderr, loaded_json)

Parameters:
  • stdout (str) –

  • stderr (str) –

  • cmdline (List[str] | None) –

Return type:

Tuple[str, str, Dict[Any, Any] | None]

run_container_start_checks(started_at, timeout_at)#

Run startup checks.

run_start_checks(started_at, timeout_at)#

Run checks to confirm that the daemon has started.

Parameters:
Return type:

bool

start_check(callback, *args, **kwargs)#

Register a function to run after the daemon starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

Arguments:
callback:

The function to call back

Keyword Arguments:
args:

The arguments to pass to the callback

kwargs:

The keyword arguments to pass to the callback

Returns:

Nothing.

Example:
def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
Parameters:
Return type:

None

stopped(before_stop_callback=None, after_stop_callback=None, before_start_callback=None, after_start_callback=None)#

Stop the daemon and return it’s instance so it can be used as a context manager.

Keyword Arguments:
before_stop_callback:

A callable to run before stopping the daemon. The callback must accept one argument, the daemon instance.

after_stop_callback:

A callable to run after stopping the daemon. The callback must accept one argument, the daemon instance.

before_start_callback:

A callable to run before starting the daemon. The callback must accept one argument, the daemon instance.

after_start_callback:

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.

Example:
assert factory.is_running() is True

with factory.stopped():
    assert factory.is_running() is False

assert factory.is_running() is True
Parameters:
Return type:

Generator[Daemon, None, None]

classmethod verify_config(config)[source]#

Verify the configuration dictionary.

classmethod write_config(config)[source]#

Write the configuration to file.

class saltfactories.daemons.container.SaltMinion(*, cwd=_Nothing.NOTHING, environ=_Nothing.NOTHING, image, name=_Nothing.NOTHING, display_name=None, check_ports=_Nothing.NOTHING, container_run_kwargs=_Nothing.NOTHING, start_timeout=30, max_start_attempts=3, pull_before_start=True, skip_on_pull_failure=False, skip_if_docker_client_not_connectable=False, docker_client=_Nothing.NOTHING, before_start_callbacks=_Nothing.NOTHING, before_terminate_callbacks=_Nothing.NOTHING, after_start_callbacks=_Nothing.NOTHING, after_terminate_callbacks=_Nothing.NOTHING, container_start_checks_callbacks=_Nothing.NOTHING, config, config_dir=_Nothing.NOTHING, python_executable=None, system_service=False, slow_stop=True, system_encoding=_Nothing.NOTHING, timeout=_Nothing.NOTHING, script_name, base_script_args=_Nothing.NOTHING, stats_processes=None, extra_cli_arguments_after_first_start_failure=_Nothing.NOTHING, start_checks_callbacks=_Nothing.NOTHING, event_listener=None, factories_manager=None, started_at=None)[source]#

Bases: SaltDaemon, SaltMinion

Salt minion daemon implementation running in a docker container.

Parameters:
  • cwd (str | Path) –

  • environ (EnvironDict) –

  • slow_stop (bool) –

  • system_encoding (str) –

  • timeout (int | float) –

  • script_name (str) –

  • base_script_args (List[str]) –

  • stats_processes (StatsProcesses) –

  • extra_cli_arguments_after_first_start_failure (List[str]) –

  • start_checks_callbacks (List[Callback]) –

get_display_name()[source]#

Returns a human readable name for the factory.

get_check_events()[source]#

Return salt events to check.

Return a list of tuples in the form of (master_id, event_tag) check against to ensure the daemon is running

after_start(callback, *args, on_container=False, **kwargs)#

Register a function callback to run after the daemon starts.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

after_terminate(callback, *args, on_container=False, **kwargs)#

Register a function callback to run after the daemon terminates.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

before_start(callback, *args, on_container=False, **kwargs)#

Register a function callback to run before the daemon starts.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

before_terminate(callback, *args, on_container=False, **kwargs)#

Register a function callback to run before the daemon terminates.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

static client_connectable(docker_client)#

Check if the docker client can connect to the docker daemon.

cmdline(*args)#

Construct a list of arguments to use when starting the container.

Parameters:

args (str) – Additional arguments to use when starting the container

classmethod configure(factories_manager, daemon_id, root_dir=None, defaults=None, overrides=None, **configure_kwargs)#

Configure the salt daemon.

container_start_check(callback, *args, **kwargs)#

Register a function to run after the container starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

For example:

def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
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

classmethod default_config(root_dir, minion_id, defaults=None, overrides=None, master=None, system_service=False)[source]#

Return the default configuration.

get_base_script_args()#

Returns any additional arguments to pass to the CLI script.

Return type:

List[str]

get_check_ports()#

Return a list of ports to check against to ensure the daemon is running.

get_container_start_check_callbacks()#

Return a list of the start check callbacks.

get_host_port_binding(port, protocol='tcp', ipv6=False)#

Return the host binding for a port on the container.

Parameters:
  • port (int) – The port.

  • protocol (str) – The port protocol. Defaults to tcp.

  • ipv6 (bool) – If true, return the ipv6 port binding.

Returns:

int: The matched port binding on the host. None: When not port binding was matched.

get_script_args()[source]#

Return the script arguments.

get_script_path()#

Returns the path to the script to run.

Return type:

str

get_start_check_callbacks()#

Return a list of the start check callbacks.

Return type:

List[Callback]

is_running()#

Returns true if the container is running.

classmethod load_config(config_file, config)[source]#

Return the loaded configuration.

property pid: int | None#

The pid of the running process. None if not running.

process_output(stdout, stderr, cmdline=None)#

Process the output. When possible JSON is loaded from the output.

Returns:

Returns a tuple in the form of (stdout, stderr, loaded_json)

Parameters:
  • stdout (str) –

  • stderr (str) –

  • cmdline (List[str] | None) –

Return type:

Tuple[str, str, Dict[Any, Any] | None]

run(*cmd, **kwargs)#

Run a command inside the container.

run_container_start_checks(started_at, timeout_at)#

Run startup checks.

run_start_checks(started_at, timeout_at)#

Run checks to confirm that the daemon has started.

Parameters:
Return type:

bool

salt_call_cli(factory_class=<class 'saltfactories.cli.call.SaltCall'>, **factory_class_kwargs)[source]#

Return a salt-call CLI process for this minion instance.

start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)#

Start the daemon.

start_check(callback, *args, **kwargs)#

Register a function to run after the daemon starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

Arguments:
callback:

The function to call back

Keyword Arguments:
args:

The arguments to pass to the callback

kwargs:

The keyword arguments to pass to the callback

Returns:

Nothing.

Example:
def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
Parameters:
Return type:

None

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)#

Stop the daemon and return it’s instance so it can be used as a context manager.

Keyword Arguments:
before_stop_callback:

A callable to run before stopping the daemon. The callback must accept one argument, the daemon instance.

after_stop_callback:

A callable to run after stopping the daemon. The callback must accept one argument, the daemon instance.

before_start_callback:

A callable to run before starting the daemon. The callback must accept one argument, the daemon instance.

after_start_callback:

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.

Example:
assert factory.is_running() is True

with factory.stopped():
    assert factory.is_running() is False

assert factory.is_running() is True
Parameters:
Return type:

Generator[Daemon, None, None]

terminate()#

Terminate the container.

classmethod verify_config(config)#

Verify the configuration dictionary.

classmethod write_config(config)#

Write the configuration to file.

class saltfactories.daemons.container.SaltMaster(*, cwd=_Nothing.NOTHING, environ=_Nothing.NOTHING, image, name=_Nothing.NOTHING, display_name=None, check_ports=_Nothing.NOTHING, container_run_kwargs=_Nothing.NOTHING, start_timeout=30, max_start_attempts=3, pull_before_start=True, skip_on_pull_failure=False, skip_if_docker_client_not_connectable=False, docker_client=_Nothing.NOTHING, before_start_callbacks=_Nothing.NOTHING, before_terminate_callbacks=_Nothing.NOTHING, after_start_callbacks=_Nothing.NOTHING, after_terminate_callbacks=_Nothing.NOTHING, container_start_checks_callbacks=_Nothing.NOTHING, config, config_dir=_Nothing.NOTHING, python_executable=None, system_service=False, slow_stop=True, system_encoding=_Nothing.NOTHING, timeout=_Nothing.NOTHING, script_name, base_script_args=_Nothing.NOTHING, stats_processes=None, extra_cli_arguments_after_first_start_failure=_Nothing.NOTHING, start_checks_callbacks=_Nothing.NOTHING, event_listener=None, factories_manager=None, started_at=None, on_auth_event_callback=None)[source]#

Bases: SaltDaemon, SaltMaster

Salt master daemon implementation running in a docker container.

Parameters:
  • cwd (str | Path) –

  • environ (EnvironDict) –

  • slow_stop (bool) –

  • system_encoding (str) –

  • timeout (int | float) –

  • script_name (str) –

  • base_script_args (List[str]) –

  • stats_processes (StatsProcesses) –

  • extra_cli_arguments_after_first_start_failure (List[str]) –

  • start_checks_callbacks (List[Callback]) –

get_display_name()[source]#

Returns a human readable name for the factory.

get_check_events()[source]#

Return salt events to check.

Return a list of tuples in the form of (master_id, event_tag) check against to ensure the daemon is running

after_start(callback, *args, on_container=False, **kwargs)#

Register a function callback to run after the daemon starts.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

after_terminate(callback, *args, on_container=False, **kwargs)#

Register a function callback to run after the daemon terminates.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

before_start(callback, *args, on_container=False, **kwargs)#

Register a function callback to run before the daemon starts.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

before_terminate(callback, *args, on_container=False, **kwargs)#

Register a function callback to run before the daemon terminates.

Parameters:
  • callback (Callable) – The function to call back

  • on_container (bool) – If true, the callback will be registered on the container and not the daemon.

  • args – The arguments to pass to the callback

  • kwargs – The keyword arguments to pass to the callback

static client_connectable(docker_client)#

Check if the docker client can connect to the docker daemon.

cmdline(*args)#

Construct a list of arguments to use when starting the container.

Parameters:

args (str) – Additional arguments to use when starting the container

classmethod configure(factories_manager, daemon_id, root_dir=None, defaults=None, overrides=None, **configure_kwargs)#

Configure the salt daemon.

container_start_check(callback, *args, **kwargs)#

Register a function to run after the container starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

For example:

def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
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

classmethod default_config(root_dir, master_id, defaults=None, overrides=None, order_masters=False, master_of_masters=None, system_service=False)[source]#

Return the default configuration.

get_base_script_args()#

Returns any additional arguments to pass to the CLI script.

Return type:

List[str]

get_check_ports()#

Return a list of ports to check against to ensure the daemon is running.

get_container_start_check_callbacks()#

Return a list of the start check callbacks.

get_host_port_binding(port, protocol='tcp', ipv6=False)#

Return the host binding for a port on the container.

Parameters:
  • port (int) – The port.

  • protocol (str) – The port protocol. Defaults to tcp.

  • ipv6 (bool) – If true, return the ipv6 port binding.

Returns:

int: The matched port binding on the host. None: When not port binding was matched.

get_script_args()#

Returns any additional arguments to pass to the CLI script.

Return type:

List[str]

get_script_path()#

Returns the path to the script to run.

Return type:

str

get_start_check_callbacks()#

Return a list of the start check callbacks.

Return type:

List[Callback]

is_running()#

Returns true if the container is running.

classmethod load_config(config_file, config)[source]#

Return the loaded configuration.

property pid: int | None#

The pid of the running process. None if not running.

process_output(stdout, stderr, cmdline=None)#

Process the output. When possible JSON is loaded from the output.

Returns:

Returns a tuple in the form of (stdout, stderr, loaded_json)

Parameters:
  • stdout (str) –

  • stderr (str) –

  • cmdline (List[str] | None) –

Return type:

Tuple[str, str, Dict[Any, Any] | None]

run(*cmd, **kwargs)#

Run a command inside the container.

run_container_start_checks(started_at, timeout_at)#

Run startup checks.

run_start_checks(started_at, timeout_at)#

Run checks to confirm that the daemon has started.

Parameters:
Return type:

bool

salt_api_daemon(**kwargs)[source]#

Please see the documentation in salt_api_daemon.

salt_cli(factory_class=<class 'saltfactories.cli.salt.Salt'>, **factory_class_kwargs)[source]#

Return a salt CLI process for this master instance.

salt_client(functions_known_to_return_none=None, factory_class=<class 'saltfactories.client.LocalClient'>)[source]#

Return a local salt client object.

salt_cloud_cli(defaults=None, overrides=None, factory_class=<class 'saltfactories.cli.cloud.SaltCloud'>, **factory_class_kwargs)[source]#

Return a salt-cloud CLI instance.

Args:
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

Returns:
SaltCloud:

The salt-cloud CLI script process class instance

salt_cp_cli(factory_class=<class 'saltfactories.cli.cp.SaltCp'>, **factory_class_kwargs)[source]#

Return a salt-cp CLI process for this master instance.

salt_key_cli(factory_class=<class 'saltfactories.cli.key.SaltKey'>, **factory_class_kwargs)[source]#

Return a salt-key CLI process for this master instance.

salt_master_daemon(master_id, **kwargs)[source]#

This method will configure a master under a master-of-masters.

Please see the documentation in salt_master_daemon

salt_minion_daemon(minion_id, **kwargs)[source]#

Please see the documentation in configure_salt_minion.

salt_proxy_minion_daemon(minion_id, **kwargs)[source]#

Please see the documentation in salt_proxy_minion_daemon.

salt_run_cli(factory_class=<class 'saltfactories.cli.run.SaltRun'>, **factory_class_kwargs)[source]#

Return a salt-run CLI process for this master instance.

salt_spm_cli(defaults=None, overrides=None, factory_class=<class 'saltfactories.cli.spm.Spm'>, **factory_class_kwargs)[source]#

Return a spm CLI process for this master instance.

salt_ssh_cli(factory_class=<class 'saltfactories.cli.ssh.SaltSsh'>, roster_file=None, target_host=None, client_key=None, ssh_user=None, **factory_class_kwargs)[source]#

Return a salt-ssh CLI process for this master instance.

Args:
roster_file(str):

The roster file to use

target_host(str):

The target host address to connect to

client_key(str):

The path to the private ssh key to use to connect

ssh_user(str):

The remote username to connect as

salt_syndic_daemon(syndic_id, **kwargs)[source]#

Please see the documentation in salt_syndic_daemon.

start(*extra_cli_arguments, max_start_attempts=None, start_timeout=None)#

Start the daemon.

start_check(callback, *args, **kwargs)#

Register a function to run after the daemon starts to confirm readiness for work.

The callback must accept as the first argument timeout_at which is a float. The callback must stop trying to confirm running behavior once time.time() > timeout_at. The callback should return True to confirm that the daemon is ready for work.

Arguments:
callback:

The function to call back

Keyword Arguments:
args:

The arguments to pass to the callback

kwargs:

The keyword arguments to pass to the callback

Returns:

Nothing.

Example:
def check_running_state(timeout_at: float) -> bool:
    while time.time() <= timeout_at:
        # run some checks
        ...
        # if all is good
        break
    else:
        return False
    return True
Parameters:
Return type:

None

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)#

Stop the daemon and return it’s instance so it can be used as a context manager.

Keyword Arguments:
before_stop_callback:

A callable to run before stopping the daemon. The callback must accept one argument, the daemon instance.

after_stop_callback:

A callable to run after stopping the daemon. The callback must accept one argument, the daemon instance.

before_start_callback:

A callable to run before starting the daemon. The callback must accept one argument, the daemon instance.

after_start_callback:

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.

Example:
assert factory.is_running() is True

with factory.stopped():
    assert factory.is_running() is False

assert factory.is_running() is True
Parameters:
Return type:

Generator[Daemon, None, None]

terminate()#

Terminate the container.

classmethod verify_config(config)#

Verify the configuration dictionary.

classmethod write_config(config)#

Write the configuration to file.