From 6ea34c8d36c153444b103fd151ce745fc47d6e45 Mon Sep 17 00:00:00 2001 From: Charles Moore <122481442+moorec-aws@users.noreply.github.com> Date: Thu, 18 Jul 2024 11:55:47 -0500 Subject: [PATCH] test: update to support ec2_worker_type (#358) Signed-off-by: Charles Moore <122481442+moorec-aws@users.noreply.github.com> --- requirements-testing.txt | 2 +- .../sessions/actions/enter_env.py | 2 +- .../sessions/actions/exit_env.py | 2 +- .../sessions/actions/run_step_task.py | 2 +- .../actions/sync_input_job_attachments.py | 2 +- test/e2e/conftest.py | 22 ++++++++++++------- test/e2e/linux/test_credential_handling.py | 2 +- test/unit/scheduler/test_session_queue.py | 2 +- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/requirements-testing.txt b/requirements-testing.txt index b8760261..ebe05a5d 100644 --- a/requirements-testing.txt +++ b/requirements-testing.txt @@ -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.* diff --git a/src/deadline_worker_agent/sessions/actions/enter_env.py b/src/deadline_worker_agent/sessions/actions/enter_env.py index b0c55197..a2721baa 100644 --- a/src/deadline_worker_agent/sessions/actions/enter_env.py +++ b/src/deadline_worker_agent/sessions/actions/enter_env.py @@ -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 diff --git a/src/deadline_worker_agent/sessions/actions/exit_env.py b/src/deadline_worker_agent/sessions/actions/exit_env.py index 9c6ccb38..739bddd8 100644 --- a/src/deadline_worker_agent/sessions/actions/exit_env.py +++ b/src/deadline_worker_agent/sessions/actions/exit_env.py @@ -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 ) diff --git a/src/deadline_worker_agent/sessions/actions/run_step_task.py b/src/deadline_worker_agent/sessions/actions/run_step_task.py index 98ffb320..39484fc8 100644 --- a/src/deadline_worker_agent/sessions/actions/run_step_task.py +++ b/src/deadline_worker_agent/sessions/actions/run_step_task.py @@ -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 diff --git a/src/deadline_worker_agent/sessions/actions/sync_input_job_attachments.py b/src/deadline_worker_agent/sessions/actions/sync_input_job_attachments.py index 356f74f1..5dbd78c6 100644 --- a/src/deadline_worker_agent/sessions/actions/sync_input_job_attachments.py +++ b/src/deadline_worker_agent/sessions/actions/sync_input_job_attachments.py @@ -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 diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index eb429fc1..9014fe9e 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -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, @@ -182,8 +182,6 @@ 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], @@ -191,12 +189,15 @@ def worker_config( ), 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. @@ -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" @@ -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, @@ -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(): @@ -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", ) diff --git a/test/e2e/linux/test_credential_handling.py b/test/e2e/linux/test_credential_handling.py index 5fc663c3..be4d361a 100644 --- a/test/e2e/linux/test_credential_handling.py +++ b/test/e2e/linux/test_credential_handling.py @@ -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 diff --git a/test/unit/scheduler/test_session_queue.py b/test/unit/scheduler/test_session_queue.py index ae890b54..af536d27 100644 --- a/test/unit/scheduler/test_session_queue.py +++ b/test/unit/scheduler/test_session_queue.py @@ -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