Skip to content

Commit

Permalink
test: update to support ec2_worker_type (#358)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles Moore <[email protected]>
  • Loading branch information
moorec-aws authored Jul 18, 2024
1 parent d4d98cb commit 6ea34c8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion requirements-testing.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage[toml] ~= 7.5
coverage-conditional-plugin == 0.9.*
deadline-cloud-test-fixtures == 0.10.*
deadline-cloud-test-fixtures == 0.12.*
pytest ~= 8.2
pytest-cov == 5.0.*
pytest-timeout == 2.3.*
Expand Down
2 changes: 1 addition & 1 deletion src/deadline_worker_agent/sessions/actions/enter_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(

def __eq__(self, other: Any) -> bool:
return (
type(self) == type(other)
type(self) is type(other)
and self._id == other._id
and self._job_env_id == other._job_env_id
and self._session_env_id == other._session_env_id
Expand Down
2 changes: 1 addition & 1 deletion src/deadline_worker_agent/sessions/actions/exit_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(

def __eq__(self, other: Any) -> bool:
return (
type(self) == type(other)
type(self) is type(other)
and self._id == other._id
and self._environment_id == other._environment_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(

def __eq__(self, other: Any) -> bool:
return (
type(self) == type(other)
type(self) is type(other)
and self._id == other._id
and self.step_id == other.step_id
and self.task_id == other.task_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(

def __eq__(self, other: Any) -> bool:
return (
type(self) == type(other)
type(self) is type(other)
and self._id == other._id
and self._job_attachment_details == other._job_attachment_details
and self._step_details == other._step_details
Expand Down
22 changes: 14 additions & 8 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest
import tempfile
from dataclasses import dataclass, field, InitVar
from typing import Generator
from typing import Generator, Type

from deadline_test_fixtures import (
DeadlineWorker,
Expand Down Expand Up @@ -182,21 +182,22 @@ def worker_config(
farm_id=deadline_resources.farm.id,
fleet=deadline_resources.fleet,
region=region,
user=os.getenv("WORKER_POSIX_USER", "deadline-worker"),
group=os.getenv("WORKER_POSIX_SHARED_GROUP", "shared-group"),
allow_shutdown=True,
worker_agent_install=PipInstall(
requirement_specifiers=[worker_agent_requirement_specifier],
codeartifact=codeartifact,
),
service_model_path=dst_path,
file_mappings=file_mappings or None,
operating_system=operating_system,
)


@pytest.fixture(scope="session")
def worker(request: pytest.FixtureRequest, worker_config) -> Generator[DeadlineWorker, None, None]:
def worker(
request: pytest.FixtureRequest,
worker_config: DeadlineWorkerConfiguration,
ec2_worker_type: Type[EC2InstanceWorker],
) -> Generator[DeadlineWorker, None, None]:
"""
Gets a DeadlineWorker for use in tests.
Expand Down Expand Up @@ -226,6 +227,9 @@ def worker(request: pytest.FixtureRequest, worker_config) -> Generator[DeadlineW
ami_id = os.getenv("AMI_ID")
subnet_id = os.getenv("SUBNET_ID")
security_group_id = os.getenv("SECURITY_GROUP_ID")
instance_type = os.getenv("WORKER_INSTANCE_TYPE", default="t3.micro")
instance_shutdown_behavior = os.getenv("WORKER_INSTANCE_SHUTDOWN_BEHAVIOR", default="stop")

assert subnet_id, "SUBNET_ID is required when deploying an EC2 worker"
assert security_group_id, "SECURITY_GROUP_ID is required when deploying an EC2 worker"

Expand All @@ -239,7 +243,7 @@ def worker(request: pytest.FixtureRequest, worker_config) -> Generator[DeadlineW
ssm_client = boto3.client("ssm")
deadline_client = boto3.client("deadline")

worker = EC2InstanceWorker(
worker = ec2_worker_type(
ec2_client=ec2_client,
s3_client=s3_client,
deadline_client=deadline_client,
Expand All @@ -250,6 +254,8 @@ def worker(request: pytest.FixtureRequest, worker_config) -> Generator[DeadlineW
security_group_id=security_group_id,
instance_profile_name=bootstrap_resources.worker_instance_profile_name,
configuration=worker_config,
instance_type=instance_type,
instance_shutdown_behavior=instance_shutdown_behavior,
)

def stop_worker():
Expand Down Expand Up @@ -288,8 +294,8 @@ def region() -> str:
@pytest.fixture(scope="session")
def job_run_as_user() -> PosixSessionUser:
return PosixSessionUser(
user="jobuser",
group="shared-group",
user="job-user",
group="job-user",
)


Expand Down
2 changes: 1 addition & 1 deletion test/e2e/linux/test_credential_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_access_worker_credential_file_from_job(
########################################################################################
# WHEN
result = worker.send_command(
f'sudo -u "{worker_config.user}" cat /var/lib/deadline/credentials/{worker.worker_id}.json > /dev/null'
f'sudo -u "{worker_config.agent_user}" cat /var/lib/deadline/credentials/{worker.worker_id}.json > /dev/null'
)

# THEN
Expand Down
2 changes: 1 addition & 1 deletion test/unit/scheduler/test_session_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test(
result = session_queue.dequeue()

# THEN
assert type(result) == type(expected)
assert type(result) is type(expected)
assert result.id == expected.id # type: ignore
assert len(session_queue._actions) == 0
assert len(session_queue._actions_by_id) == 0
Expand Down

0 comments on commit 6ea34c8

Please sign in to comment.