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

feat(asset-cli): asset snapshot subcommand to capture manifests #369

Merged
merged 12 commits into from
Jul 4, 2024

Conversation

stangch
Copy link

@stangch stangch commented Jun 24, 2024

What was the problem/requirement? (What/Why)

Allow users to call CLI command to capture directories of assets into manifests.

What was the solution? (How)

Added deadline asset snapshot subcommand to allow capture of manifests. Includes:

  • capturing manifest file into specified directory of assets
  • recursive capture of directories
  • can specify destination of where manifest can be created

What is the impact of this change?

Exposes functionality of creating manifests

How was this change tested?

  • Added unit tests mocking snapshot functionality at test/unit/deadline_client/cli/test_cli_asset.py, passing successfully
  • Added integ tests with temporary files in filesystem at test/integ/cli/test_cli_asset.py, passing successfully
  • Manual end to end tests with sample directories with assets:
deadline-cloud-stangch % hatch run deadline asset snapshot --root-dir /Users/stangch/Desktop/test_asset -r
Manifest creation path defaulted to /Users/stangch/Desktop/test_asset 

Hashing Attachments  [####################################]  100%
Hashing Summary:
    Processed 5 files totaling 7.5 KB.
    Skipped re-processing 1 files totaling 37.0 B.
    Total processing time of 0.00932 seconds at 804.07 KB/s.

Manifest created at /Users/stangch/Desktop/test_asset

Was this change documented?

N/A

Is this a breaking change?

N/A


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@stangch stangch requested a review from a team as a code owner June 24, 2024 23:40
@stangch stangch force-pushed the snapshot_prod branch 9 times, most recently from eb1ad9a to 3bf6fa6 Compare June 25, 2024 01:08
@jericht jericht self-requested a review June 25, 2024 01:22
@godobyte godobyte self-assigned this Jun 25, 2024
@stangch stangch changed the base branch from mainline to feature_assets_cli June 25, 2024 20:15
@stangch stangch force-pushed the snapshot_prod branch 3 times, most recently from f299b41 to e31c462 Compare June 25, 2024 21:44
src/deadline/client/api/_submit_job_bundle.py Show resolved Hide resolved
src/deadline/client/cli/_common.py Show resolved Hide resolved
src/deadline/client/cli/_groups/asset_group.py Outdated Show resolved Hide resolved
src/deadline/client/cli/_groups/asset_group.py Outdated Show resolved Hide resolved
src/deadline/client/cli/_groups/asset_group.py Outdated Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
@stangch stangch force-pushed the snapshot_prod branch 6 times, most recently from fbeb44e to 5daab26 Compare June 27, 2024 20:28
src/deadline/client/api/_submit_job_bundle.py Show resolved Hide resolved
hash_callback_manager = _ProgressBarCallbackManager(length=100, label="Hashing Attachments")

upload_group = asset_manager.prepare_paths_for_upload(
input_paths=inputs, output_paths=[root_dir], referenced_paths=[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious - what is this referenced_paths?

Copy link
Author

Choose a reason for hiding this comment

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

There's some comments on this page: https://github.com/ddneilson/deadline-cloud-samples/blob/the_job_bundle/job_bundles/README.md

tldr: it's neither input nor output, but in case job references the name of the folder; in the case of snapshot + upload, the main goal is to upload files we care about, so I don't think referenced_paths are relevant here.

@@ -182,7 +179,7 @@ def upload_assets(

if manifest_write_dir:
self._write_local_manifest(
manifest_write_dir, manifest_name, full_manifest_key, manifest
manifest_write_dir, manifest_name, full_manifest_key, manifest, None
Copy link
Contributor

Choose a reason for hiding this comment

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

What about adding default to the function parameter rather than passing None from the caller?

Comment on lines 20 to 21
with tempfile.TemporaryDirectory() as tmpdirname:
yield tmpdirname
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - the naming is a bit confusing, I assume it's tmpdir rather than name?

manifest_data = json.load(f)
assert manifest_data["paths"][0]["path"] == "file.txt"
assert (
manifest_data["paths"][0]["hash"] == "0741993e50c8bc250cefba3959c81eb8"
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you get this hash, could it be a call with the input? i.e. we don't need to update the hash if there is any change to the input.

manifest_data["paths"][0]["hash"] == "a5fc4a07191e2c90364319d2fd503cc1"
) # hashed with xxh128
assert manifest_data["paths"][1]["path"] == posixpath.join(
"subdir1", "subdir2", "subdir_file.txt"
Copy link
Contributor

Choose a reason for hiding this comment

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

In general for tests, the test input can be defined as a variable and pass to the call and assertion. Take a look at how it's done in other test cli implementation.

@@ -33,11 +42,61 @@ def cli_asset():
default=False,
)
@_handle_error
def asset_snapshot(**args):
def asset_snapshot(root_dir: str, manifest_out: str, recursive: bool, **args):
Copy link
Contributor

Choose a reason for hiding this comment

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

Question for the type annotation: Is manifest_out always a str? Is it a different type when the user does not provide --manifest-out?

Copy link
Author

Choose a reason for hiding this comment

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

I think the click library doesn't allow users to specify optional in the function params, rather in the above @click.options, so I added a default=None for --manifest-out

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, so the typing should say it can either be None or str right?

@godobyte
Copy link
Contributor

This CLI implementation seems to capture the basic functionality. Were you able to call it and verify? If so, could you add to testing evidence?

test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
test/integ/cli/test_cli_asset.py Show resolved Hide resolved
test/unit/deadline_client/cli/test_cli_asset.py Outdated Show resolved Hide resolved
@stangch stangch force-pushed the snapshot_prod branch 3 times, most recently from 40716c2 to eaebbe1 Compare July 2, 2024 22:40
Copy link
Contributor

@jericht jericht left a comment

Choose a reason for hiding this comment

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

There's still some comments I have on the tests that I think we should address, but we can do that in a future PR. Approved.

root_dir = str(tmp_path)

temp_file = tmp_path / "temp_file.txt"
temp_file.touch()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Ideally we shouldn't be creating files/dirs in our unit tests, but we can address this later.

Comment on lines +81 to +113
def test_valid_manifest_out(
self, tmp_path, mock_prepare_paths_for_upload, mock_hash_attachments, upload_group_mock
):
"""
Tests if CLI snapshot command correctly calls with --manifest-out arguement
"""
root_dir = str(tmp_path)
manifest_out_dir = tmp_path / "manifest_out"
manifest_out_dir.mkdir()

temp_file = tmp_path / "temp_file.txt"
temp_file.touch()

mock_prepare_paths_for_upload.return_value = upload_group_mock

runner = CliRunner()
result = runner.invoke(
main,
[
"asset",
"snapshot",
"--root-dir",
root_dir,
"--manifest-out",
str(manifest_out_dir),
],
)

assert result.exit_code == 0
mock_prepare_paths_for_upload.assert_called_once_with(
input_paths=[str(temp_file)], output_paths=[root_dir], referenced_paths=[]
)
mock_hash_attachments.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we're missing an assertion here to verify the command would have actually written the manifest file to manifest_out_dir

runner = CliRunner()
result = runner.invoke(main, ["asset", "snapshot", "--root-dir", invalid_root_dir])

assert result.exit_code != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: if we know what the expected exit code should be, we should assert equality on that expected value rather than checking for non-zero exit code.

test/integ/cli/test_cli_asset.py Outdated Show resolved Hide resolved
@jericht jericht requested review from godobyte and jericht July 3, 2024 23:11
@stangch stangch merged commit a954d40 into aws-deadline:feature_assets_cli Jul 4, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants