Skip to content

Commit

Permalink
Merge branch 'mainline' into moorec/fix-integ-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jericht authored Jun 20, 2024
2 parents a7c9ade + 133b059 commit 94f2cb5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Code Quality

on:
pull_request:
branches: [ mainline, release ]
branches: [ mainline, release, feature_assets_cli ]
workflow_call:
inputs:
branch:
Expand Down
2 changes: 1 addition & 1 deletion requirements-integ-testing.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deadline-cloud-test-fixtures ~= 0.6.2
deadline-cloud-test-fixtures == 0.7.*
7 changes: 5 additions & 2 deletions src/deadline/client/config/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,11 @@ def _reset_directory_permissions_windows(directory: Path, username: str, permiss
*_get_grant_args(username, permissions),
# On Windows, both SYSTEM and the Administrators group normally
# have Full Access to files in the user's home directory.
*_get_grant_args("Administrators", permissions),
*_get_grant_args("SYSTEM", permissions),
# Use SIDs to represent the Administrators and SYSTEM to
# support multi-language operating systems
# Administrator(S-1-5-32-544), SYSTEM(S-1-5-18)
*_get_grant_args("*S-1-5-32-544", permissions),
*_get_grant_args("*S-1-5-18", permissions),
],
check=True,
capture_output=True,
Expand Down
27 changes: 27 additions & 0 deletions src/deadline/client/job_bundle/saver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import json
import os
from typing import Any
from ._yaml import deadline_yaml_dump


def save_yaml_or_json_to_file(
bundle_dir: str,
filename: str,
file_type: str,
data: Any,
) -> None:
"""
Saves data as either a JSON or YAML file depending on the file_type provided. Useful for saving
job bundle data files which can be in either format. file_type should be either "YAML" or "JSON".
"""
with open(
os.path.join(bundle_dir, f"{filename}.{file_type.lower()}"), "w", encoding="utf8"
) as f:
if file_type == "YAML":
deadline_yaml_dump(data, f)
elif file_type == "JSON":
json.dump(data, f, indent=2)
else:
raise RuntimeError(f"Unexpected file type '{file_type}' in job bundle:\n{bundle_dir}")
34 changes: 16 additions & 18 deletions src/deadline/client/ui/job_bundle_submitter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
from __future__ import annotations
import copy
import json
import os
from logging import getLogger
from typing import Any, Optional, Dict
Expand All @@ -14,13 +13,13 @@
)

from ..exceptions import DeadlineOperationError
from ..job_bundle import deadline_yaml_dump
from ..job_bundle.loader import (
parse_yaml_or_json_content,
read_yaml_or_json,
read_yaml_or_json_object,
validate_directory_symlink_containment,
)
from ..job_bundle.saver import save_yaml_or_json_to_file
from ..job_bundle.parameters import (
JobParameter,
apply_job_parameters,
Expand Down Expand Up @@ -99,20 +98,6 @@ def on_create_job_bundle_callback(
for step in template["steps"]:
step["hostRequirements"] = copy.deepcopy(host_requirements)

with open(
os.path.join(job_bundle_dir, f"template.{file_type.lower()}"), "w", encoding="utf8"
) as f:
if file_type == "YAML":
deadline_yaml_dump(template, f)
elif file_type == "JSON":
json.dump(template, f, indent=1)

if asset_references:
with open(
os.path.join(job_bundle_dir, "asset_references.yaml"), "w", encoding="utf8"
) as f:
deadline_yaml_dump(asset_references.to_dict(), f)

# First filter the queue parameters to exclude any from the job template,
# then extend it with the job template parameters.
job_parameter_names = {param["name"] for param in settings.parameters}
Expand All @@ -137,8 +122,21 @@ def on_create_job_bundle_callback(
AssetReferences(),
)

with open(os.path.join(job_bundle_dir, "parameter_values.yaml"), "w", encoding="utf8") as f:
deadline_yaml_dump({"parameterValues": parameters_values}, f)
save_yaml_or_json_to_file(
bundle_dir=job_bundle_dir, filename="template", file_type=file_type, data=template
)
save_yaml_or_json_to_file(
bundle_dir=job_bundle_dir,
filename="asset_references",
file_type=file_type,
data=asset_references.to_dict(),
)
save_yaml_or_json_to_file(
bundle_dir=job_bundle_dir,
filename="parameter_values",
file_type=file_type,
data={"parameterValues": parameters_values},
)

# Ensure the job bundle doesn't contain files that resolve outside of the bundle directory
validate_directory_symlink_containment(input_job_bundle_dir)
Expand Down
27 changes: 27 additions & 0 deletions test/unit/deadline_client/job_bundle/test_saver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import os
from pathlib import Path
import tempfile
import pytest
from deadline.client.job_bundle.saver import save_yaml_or_json_to_file


def test_save_yaml_or_json_to_file():
with tempfile.TemporaryDirectory() as temp_dir:
save_yaml_or_json_to_file(
bundle_dir=temp_dir, filename="test", data={"test": "test"}, file_type="YAML"
)
assert Path(os.path.join(temp_dir, "test.yaml")).read_text() == "test: test\n"

with tempfile.TemporaryDirectory() as temp_dir:
save_yaml_or_json_to_file(
bundle_dir=temp_dir, filename="test", data={"test": "test"}, file_type="JSON"
)
assert Path(os.path.join(temp_dir, "test.json")).read_text() == '{\n "test": "test"\n}'

with tempfile.TemporaryDirectory() as temp_dir:
with pytest.raises(RuntimeError):
save_yaml_or_json_to_file(
bundle_dir=temp_dir, filename="test", data={"test": "test"}, file_type="NOT_VALID"
)

0 comments on commit 94f2cb5

Please sign in to comment.