Skip to content

Commit

Permalink
Merge pull request #3124 from ihenyene/ou_path_required
Browse files Browse the repository at this point in the history
Adding ou_path_required config to saltworker
  • Loading branch information
ihenyene authored Aug 10, 2023
2 parents 6e45953 + ee6ffec commit a7db15c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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

0 comments on commit a7db15c

Please sign in to comment.