Skip to content

Commit

Permalink
fix: install-deadline-worker doesn't create queues persistence dir on…
Browse files Browse the repository at this point in the history
… Windows (#377)

Signed-off-by: Josh Usiskin <56369778+jusiskin@users.noreply.github.com>
  • Loading branch information
jusiskin committed Aug 9, 2024
1 parent 17435b1 commit bd40074
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/deadline_worker_agent/installer/win_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def provision_directories(agent_username: str) -> WorkerAgentDirectories:
- %PROGRAMDATA%/Amazon/Deadline
- %PROGRAMDATA%/Amazon/Deadline/Logs
- %PROGRAMDATA%/Amazon/Deadline/Cache
- %PROGRAMDATA%/Amazon/Deadline/Cache/queues
- %PROGRAMDATA%/Amazon/Deadline/Config
Parameters
Expand Down Expand Up @@ -462,6 +463,11 @@ def provision_directories(agent_username: str) -> WorkerAgentDirectories:
os.makedirs(deadline_persistence_subdir, exist_ok=True)
logging.info(f"Done provisioning persistence directory ({deadline_persistence_subdir})")

deadline_persistence_queues_subdir = os.path.join(deadline_persistence_subdir, "queues")
logging.info(f"Provisioning persistence directory ({deadline_persistence_queues_subdir})")
os.makedirs(deadline_persistence_queues_subdir, exist_ok=True)
logging.info(f"Done provisioning persistence directory ({deadline_persistence_queues_subdir})")

deadline_config_subdir = os.path.join(deadline_dir, "Config")
logging.info(f"Provisioning config directory ({deadline_config_subdir})")
os.makedirs(deadline_config_subdir, exist_ok=True)
Expand Down
54 changes: 45 additions & 9 deletions test/unit/install/test_windows_installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import os
import sys
import typing
from typing import Generator
Expand Down Expand Up @@ -96,17 +97,16 @@ def test_start_windows_installer_fails_when_windows_job_user_not_exists(
)


@patch("deadline_worker_agent.installer.win_installer.users_equal", return_value=True)
@patch("deadline_worker_agent.installer.win_installer.check_account_existence", return_value=True)
@patch.object(shell, "IsUserAnAdmin", return_value=True)
def test_start_windows_installer_fails_when_windows_job_user_is_agent_user(
users_equal: MagicMock,
is_user_and_admin: MagicMock,
check_account_existence: MagicMock,
parsed_kwargs: dict,
) -> None:
# GIVEN
with pytest.raises(win_installer.InstallerFailedException) as exc_info:
with (
patch.object(win_installer, "users_equal", return_value=True) as mock_users_equal,
patch.object(win_installer, "check_account_existence", return_value=True),
patch.object(shell, "IsUserAnAdmin", return_value=True),
pytest.raises(win_installer.InstallerFailedException) as exc_info,
):
# WHEN
win_installer.start_windows_installer(**parsed_kwargs)

Expand All @@ -116,8 +116,8 @@ def test_start_windows_installer_fails_when_windows_job_user_is_agent_user(
== f"Argument for windows-job-user cannot be the same as the worker agent user: {parsed_kwargs['user_name']}. "
"If you wish to run jobs as the agent user, set run_jobs_as_agent_user = true in the agent configuration file."
)
assert users_equal.called_once_with(
parsed_kwargs["user_name"], parsed_kwargs["windows_job_user"]
mock_users_equal.assert_called_once_with(
parsed_kwargs["windows_job_user"], parsed_kwargs["user_name"]
)


Expand Down Expand Up @@ -889,3 +889,39 @@ def closes_handle_if_set_value_errors(
# THEN
assert raised_exc.value is mock_RegSetValueEx.side_effect
mock_CloseHandle.assert_called_once_with(mock_RegOpenKeyEx.return_value)


class TestProvisionDirectories:
"""Tests for the provision_directories function"""

@pytest.fixture(autouse=True)
def mock_os_makedirs(self) -> Generator[MagicMock, None, None]:
with patch.object(win_installer.os, "makedirs") as mock_os_makedirs:
yield mock_os_makedirs

@pytest.fixture(autouse=True)
def mock_set_windows_permissions(self) -> Generator[MagicMock, None, None]:
with patch.object(
win_installer, "_set_windows_permissions"
) as mock_set_windows_permissions:
yield mock_set_windows_permissions

@pytest.fixture
def agent_username(self) -> str:
return "deadline-worker"

def test_creates_queue_persistence_dir(
self,
mock_os_makedirs: MagicMock,
agent_username: str,
) -> None:
"""Tests that provision_directories creates the queue persistence directory"""

# WHEN
win_installer.provision_directories(agent_username)

# THEN
mock_os_makedirs.assert_any_call(
os.path.join(os.environ["PROGRAMDATA"], "Amazon", "Deadline", "Cache", "queues"),
exist_ok=True,
)
2 changes: 1 addition & 1 deletion test/unit/windows/test_win_logon.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_password_uses_secrets(self, secrets_choice: MagicMock, alphabet: str):

# THEN
assert secrets_choice.call_count >= 256
assert secrets_choice.has_calls(
secrets_choice.assert_has_calls(
[call(alphabet) for _ in range(secrets_choice.call_count)]
)

Expand Down

0 comments on commit bd40074

Please sign in to comment.