Skip to content

Commit

Permalink
feat: ability to supply openjd-sessions Python wheel (#165)
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Usiskin <56369778+jusiskin@users.noreply.github.com>
  • Loading branch information
jusiskin authored Nov 21, 2024
1 parent 5a6c0ee commit df45370
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/deadline_test_fixtures/example_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export AWS_DATA_PATH
# Default is to pip install the latest "deadline-cloud-worker-agent" package
export WORKER_AGENT_WHL_PATH

# Local path to the openjd-sessions .whl file to use for the tests
# Default is to pip install the latest openjd-sessions package
export OPENJD_SESSIONS_WHL_PATH

# DEPRECATED: Use REGION instead
# The AWS region to configure the worker for
# Falls back to AWS_DEFAULT_REGION, then defaults to us-west-2
Expand Down
48 changes: 41 additions & 7 deletions src/deadline_test_fixtures/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ def worker_config(
Builds the configuration for a DeadlineWorker.
Environment Variables:
OPENJD_SESSIONS_WHL_PATH: Path to the openjd-sessions wheel file to use.
WORKER_POSIX_USER: The POSIX user to configure the worker for
Defaults to "deadline-worker"
WORKER_POSIX_SHARED_GROUP: The shared POSIX group to configure the worker user and job user with
Expand All @@ -434,6 +435,8 @@ def worker_config(
"DEPRECATED: The environment variable WORKER_REGION is no longer supported. Please use REGION instead."
)

pip_install_requirement_specifiers: list[str] = []

# Prepare the Worker agent Python package
worker_agent_whl_path = os.getenv("WORKER_AGENT_WHL_PATH")
if worker_agent_whl_path:
Expand All @@ -444,23 +447,52 @@ def worker_config(
), f"Expected exactly one Worker agent whl path, but got {resolved_whl_paths} (from pattern {worker_agent_whl_path})"
resolved_whl_path = resolved_whl_paths[0]

if operating_system.name == "AL2023":
if operating_system.is_amazon_linux():
dest_path = posixpath.join("/tmp", os.path.basename(resolved_whl_path))
else:
elif operating_system.is_windows():
dest_path = posixpath.join(
"C:\\Windows\\System32\\Config\\systemprofile\\AppData\\Local\\Temp",
os.path.basename(resolved_whl_path),
)
else:
raise NotImplementedError(f"Unsupported operating system: {operating_system.name}")
file_mappings = [(resolved_whl_path, dest_path)]

LOG.info(f"The whl file will be copied to {dest_path} on the Worker environment")
worker_agent_requirement_specifier = dest_path
LOG.info(
f"The worker agent whl file will be copied to {dest_path} on the Worker environment"
)
pip_install_requirement_specifiers.append(dest_path)
else:
worker_agent_requirement_specifier = os.getenv(
"WORKER_AGENT_REQUIREMENT_SPECIFIER",
"deadline-cloud-worker-agent",
)
LOG.info(f"Using Worker agent package {worker_agent_requirement_specifier}")
pip_install_requirement_specifiers.append(worker_agent_requirement_specifier)

openjd_sessions_whl_path = os.getenv("OPENJD_SESSIONS_WHL_PATH")
if openjd_sessions_whl_path:
LOG.info(f"Using openjd-sessions agent whl file: {openjd_sessions_whl_path}")
resolved_whl_paths = glob.glob(openjd_sessions_whl_path)
assert (
len(resolved_whl_paths) == 1
), f"Expected exactly one openjd-sessions whl path, but got {resolved_whl_paths} (from pattern {openjd_sessions_whl_path})"
resolved_whl_path = resolved_whl_paths[0]

if operating_system.is_amazon_linux():
dest_path = posixpath.join("/tmp", os.path.basename(resolved_whl_path))
elif operating_system.is_windows():
dest_path = posixpath.join(
"C:\\Windows\\System32\\Config\\systemprofile\\AppData\\Local\\Temp",
os.path.basename(resolved_whl_path),
)
else:
raise NotImplementedError(f"Unsupported operating system: {operating_system.name}")
file_mappings.append((resolved_whl_path, dest_path))
LOG.info(
f"The openjd-sessions whl file will be copied to {dest_path} on the Worker environment"
)
pip_install_requirement_specifiers.append(dest_path)

# Path map the service model
with tempfile.TemporaryDirectory() as tmpdir:
Expand All @@ -470,12 +502,14 @@ def worker_config(
with src_path.open(mode="w") as f:
json.dump(service_model.model, f)

if operating_system.name == "AL2023":
if operating_system.is_amazon_linux():
dst_path = posixpath.join("/tmp", src_path.name)
else:
elif operating_system.is_windows():
dst_path = posixpath.join(
"C:\\Windows\\System32\\Config\\systemprofile\\AppData\\Local\\Temp", src_path.name
)
else:
raise NotImplementedError(f"Unsupported operating system: {operating_system.name}")
LOG.info(f"The service model will be copied to {dst_path} on the Worker environment")
file_mappings.append((str(src_path), dst_path))

Expand All @@ -485,7 +519,7 @@ def worker_config(
region=region,
allow_shutdown=True,
worker_agent_install=PipInstall(
requirement_specifiers=[worker_agent_requirement_specifier],
requirement_specifiers=pip_install_requirement_specifiers,
codeartifact=codeartifact,
),
service_model_path=dst_path,
Expand Down
6 changes: 6 additions & 0 deletions src/deadline_test_fixtures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class JobRunAsUser:
class OperatingSystem:
name: Literal["AL2023", "WIN2022"]

def is_amazon_linux(self) -> bool:
return self.name.startswith("AL")

def is_windows(self) -> bool:
return self.name.startswith("WIN")


@dataclass(frozen=True)
class CodeArtifactRepositoryInfo:
Expand Down

0 comments on commit df45370

Please sign in to comment.