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(cli): add log message for no output in download-output command #99

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/deadline/client/cli/_groups/job_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ def _download_job_output(

output_paths_by_root = job_output_downloader.get_output_paths_by_root()

# If no output paths were found, log a message and exit.
if output_paths_by_root == {}:
click.echo(_get_no_output_message(is_json_format))
return

# Check if the asset roots came from different OS. If so, prompt users to
# select alternative root paths to download to, (regardless of the auto-accept.)
asset_roots = list(output_paths_by_root.keys())
Expand Down Expand Up @@ -456,6 +461,17 @@ def _get_start_message(
return f"Downloading output from Job {job_name!r} Step {step_name!r} Task {task_parameters_summary}"


def _get_no_output_message(is_json_format: bool) -> str:
msg = (
"There are no output files available for download at this moment. Please verify that"
" the Job/Step/Task you are trying to download output from has completed successfully."
)
if is_json_format:
return _get_json_line(JSON_MSG_TYPE_SUMMARY, msg)
else:
return msg


def _get_mismatch_os_root_warning(root: str, root_path_format: str, is_json_format: bool) -> str:
if is_json_format:
return _get_json_line(JSON_MSG_TYPE_PATH, [root])
Expand Down
2 changes: 1 addition & 1 deletion src/deadline/job_attachments/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def download_file(
if not s3_client:
s3_client = get_s3_client(session=session)

# The modified time in the manifest is in microseconds, but utime requires the time be expressed in seconds.
# The modified time in the manifest is in microseconds, but utime requires the time be expressed in seconds.
modified_time_override = file.mtime / 1000000 # type: ignore[attr-defined]

file_bytes = file.size
Expand Down
64 changes: 64 additions & 0 deletions test/unit/deadline_client/cli/test_cli_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,70 @@ def test_cli_job_download_output_handles_unc_path_on_windows(fresh_deadline_conf
assert result.exit_code == 0


def test_cli_job_download_no_output_stdout(fresh_deadline_config, tmp_path: Path):
"""
Tests whether the output messages printed to stdout match expected messages
when executing download-output command for a job that don't have any output yet.
"""
with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint:
session_endpoint.return_value = "fake-endpoint-url"
config.set_setting("defaults.farm_id", MOCK_FARM_ID)
config.set_setting("defaults.queue_id", MOCK_QUEUE_ID)

with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object(
job_group, "OutputDownloader"
) as MockOutputDownloader, patch.object(
job_group, "_get_conflicting_filenames", return_value=[]
), patch.object(
job_group, "round", return_value=0
), patch.object(
api, "get_queue_user_boto3_session"
):
mock_download = MagicMock()
MockOutputDownloader.return_value.download_job_output = mock_download
MockOutputDownloader.return_value.get_output_paths_by_root.return_value = {}

mock_host_path_format_name = PathFormat.get_host_path_format_string()
boto3_client_mock().get_job.return_value = {
"name": "Mock Job",
"attachments": {
"manifests": [
{
"rootPath": "/root/path",
"rootPathFormat": PathFormat(mock_host_path_format_name),
"outputRelativeDirectories": ["."],
}
],
},
}
boto3_client_mock().get_queue.side_effect = [MOCK_GET_QUEUE_RESPONSE]

runner = CliRunner()
result = runner.invoke(
main,
["job", "download-output", "--job-id", MOCK_JOB_ID, "--output", "verbose"],
input="",
)

MockOutputDownloader.assert_called_once_with(
s3_settings=JobAttachmentS3Settings(**MOCK_GET_QUEUE_RESPONSE["jobAttachmentSettings"]), # type: ignore
farm_id=MOCK_FARM_ID,
queue_id=MOCK_QUEUE_ID,
job_id=MOCK_JOB_ID,
step_id=None,
task_id=None,
session=ANY,
)

assert (
"""Downloading output from Job 'Mock Job'
There are no output files available for download at this moment. Please verify that the Job/Step/Task you are trying to download output from has completed successfully.
"""
in result.output
)
assert result.exit_code == 0


def test_cli_job_download_output_stdout_with_json_format(
fresh_deadline_config,
tmp_path: Path,
Expand Down