-
Notifications
You must be signed in to change notification settings - Fork 21
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
test: add worker log writing to local disk test #478
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,13 @@ | |
from typing import Any, Dict, List, Optional | ||
import pytest | ||
import logging | ||
from deadline_test_fixtures import Job, DeadlineClient, TaskStatus, EC2InstanceWorker | ||
from deadline_test_fixtures import ( | ||
Job, | ||
DeadlineClient, | ||
PosixSessionUser, | ||
TaskStatus, | ||
EC2InstanceWorker, | ||
) | ||
from e2e.conftest import DeadlineResources | ||
import backoff | ||
import boto3 | ||
|
@@ -55,6 +61,88 @@ def test_success( | |
|
||
assert job.task_run_status == TaskStatus.SUCCEEDED | ||
|
||
@pytest.mark.skipif( | ||
os.environ["OPERATING_SYSTEM"] == "windows", | ||
reason="Linux specific worker log test", | ||
) | ||
def test_worker_writes_logs_to_disk_securely( | ||
self, | ||
deadline_resources, | ||
session_worker: EC2InstanceWorker, | ||
posix_job_user: PosixSessionUser, | ||
deadline_client: DeadlineClient, | ||
) -> None: | ||
# WHEN | ||
|
||
job = submit_sleep_job( | ||
"Test Success Sleep Job", | ||
deadline_client, | ||
deadline_resources.farm, | ||
deadline_resources.queue_a, | ||
) | ||
|
||
# THEN | ||
LOG.info(f"Waiting for job {job.id} to complete") | ||
job.wait_until_complete(client=deadline_client) | ||
LOG.info(f"Job result: {job}") | ||
|
||
assert job.task_run_status == TaskStatus.SUCCEEDED | ||
|
||
sessions: list[dict[str, Any]] = deadline_client.list_sessions( | ||
farmId=job.farm.id, | ||
queueId=job.queue.id, | ||
jobId=job.id, | ||
).get("sessions") | ||
assert sessions | ||
|
||
worker_logs_directory: str = "/var/log/amazon/deadline" | ||
# Check that the session log file is accessible by the worker agent user only | ||
for session in sessions: | ||
session_id: str = session["sessionId"] | ||
session_logs_file_path: str = os.path.join( | ||
worker_logs_directory, job.queue.id, f"{session_id}.log" | ||
) | ||
|
||
check_session_log_exists_result = session_worker.send_command( | ||
command=f"sudo -u deadline-worker [ -e '{session_logs_file_path}' ]" | ||
) | ||
assert ( | ||
check_session_log_exists_result.exit_code == 0 | ||
) # The -e command returns 0 on linux if the file does exist | ||
|
||
# Check that the session log file is not accessible by the job user | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super nit of nits |
||
check_session_log_exists_result = session_worker.send_command( | ||
command=f"sudo -u {posix_job_user.user} [ -e '{session_logs_file_path}' ]" | ||
) | ||
assert ( | ||
check_session_log_exists_result.exit_code == 1 | ||
) # The job user should not have access to the file | ||
|
||
# Check that the worker agent log file is accessible by the worker user only | ||
|
||
check_worker_log_exists_result = session_worker.send_command( | ||
command=f"sudo -u deadline-worker [ -e '{worker_logs_directory}/worker-agent.log' ]" | ||
) | ||
assert check_worker_log_exists_result.exit_code == 0 | ||
|
||
# Check that the worker agent log file is not accessible by the job user | ||
check_worker_log_accessible_by_job_user_result = session_worker.send_command( | ||
command=f"sudo -u {posix_job_user.user} [ -e '{worker_logs_directory}/worker-agent.log' ]" | ||
) | ||
assert check_worker_log_accessible_by_job_user_result.exit_code == 1 | ||
|
||
# Check that the worker agent bootstrap log file is accessible by the worker user only | ||
check_worker_bootstrap_log_exists_result = session_worker.send_command( | ||
command=f"sudo -u deadline-worker [ -e '{worker_logs_directory}/worker-agent-bootstrap.log' ]" | ||
) | ||
assert check_worker_bootstrap_log_exists_result.exit_code == 0 | ||
|
||
# Check that the worker agent bootstrap log file is not accessible by the job user | ||
check_worker_bootstrap_log_accessible_by_job_user_result = session_worker.send_command( | ||
command=f"sudo -u {posix_job_user.user} [ -e '{worker_logs_directory}/worker-agent-bootstrap.log' ]" | ||
) | ||
assert check_worker_bootstrap_log_accessible_by_job_user_result.exit_code == 1 | ||
|
||
@pytest.mark.parametrize( | ||
"run_actions,environment_actions, expected_failed_action", | ||
[ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nit of nits
does exist
extra space!