Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ou_path_required config to saltworker #3124

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/watchmaker/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class InvalidProviderError(WatchmakerError):
"""Invalid Provider Error."""


class OuPathRequiredError(Exception):
"""Exception raised when the OU path is required but not provided."""


# Deprecated/renamed exceptions
WatchmakerException = WatchmakerError
InvalidValue = InvalidValueError
OuPathRequired = OuPathRequiredError
12 changes: 11 additions & 1 deletion src/watchmaker/workers/salt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

import watchmaker.utils
from watchmaker import static
from watchmaker.exceptions import InvalidValueError, WatchmakerError
from watchmaker.exceptions import (
InvalidValueError,
OuPathRequiredError,
WatchmakerError,
)
from watchmaker.managers.platform import (
LinuxPlatformManager,
PlatformManagerBase,
Expand Down Expand Up @@ -131,6 +135,7 @@ def __init__(self, *args, **kwargs):
self.salt_debug_log = kwargs.pop('salt_debug_log', None) or ''
self.salt_content = kwargs.pop('salt_content', None) or ''
self.salt_content_path = kwargs.pop('salt_content_path', None) or ''
self.ou_path_required = kwargs.pop('ou_path_required', None) or False
self.ou_path = kwargs.pop('ou_path', None) or ''
self.admin_groups = kwargs.pop('admin_groups', None) or ''
self.admin_users = kwargs.pop('admin_users', None) or ''
Expand Down Expand Up @@ -188,6 +193,11 @@ def before_install(self):
self.log.critical(msg)
raise InvalidValueError(msg)

if self.ou_path_required and not self.ou_path:
raise OuPathRequiredError(
"The 'ou_path' option is required, but not provided."
)

def install(self):
"""Install Salt."""
pass
Expand Down
17 changes: 16 additions & 1 deletion tests/test_saltworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest

from watchmaker.exceptions import InvalidValue
from watchmaker.exceptions import InvalidValue, OuPathRequired
from watchmaker.workers.salt import SaltBase, SaltLinux, SaltWindows

# Supports Python2 and Python3 test mocks
Expand Down Expand Up @@ -123,6 +123,21 @@ def test_bogus_environment(saltworker_client):
saltworker_client.before_install()


def test_ou_path_required(saltworker_client):
"""
Ensure that ou_path is required and raises OuPathRequiredError.

Args:
saltworker_client: (:obj:`src.workers.SaltBase`)

"""
saltworker_client.ou_path_required = True # Set ou_path_required to True
saltworker_client.ou_path = None # Don't provide ou_path

with pytest.raises(OuPathRequired):
saltworker_client.before_install()


def test_valid_environment(saltworker_client):
"""
Ensure that an environment within valid_environments works as expected.
Expand Down