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

test: add worker log writing to local disk test #478

Merged
merged 3 commits into from
Nov 18, 2024
Merged
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
90 changes: 89 additions & 1 deletion test/e2e/test_job_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

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!


# Check that the session log file is not accessible by the job user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit of nits job user extra space!

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",
[
Expand Down