From e6b20e69232fadf36339f05471702e170fa7a677 Mon Sep 17 00:00:00 2001 From: amarsjac <131478790+amarsjac@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:31:01 -0500 Subject: [PATCH] chore: Update default endpoint URL to use AWS_ENDPOINT_URL_DEADLINE, (#30) Remove Endpoint URL from UI Signed-off-by: Marshall Jackson --- src/deadline/client/api/_session.py | 14 +- src/deadline/client/api/_telemetry.py | 4 +- .../client/cli/_groups/config_group.py | 3 - src/deadline/client/config/config_file.py | 13 +- .../ui/dialogs/deadline_config_dialog.py | 23 -- .../test_job_attachments.py | 6 +- .../deadline_client/api/test_api_session.py | 26 +- .../deadline_client/cli/test_cli_bundle.py | 1 + .../deadline_client/cli/test_cli_config.py | 4 +- .../unit/deadline_client/cli/test_cli_farm.py | 3 + .../deadline_client/cli/test_cli_fleet.py | 3 + .../cli/test_cli_handle_web_url.py | 184 ++++++------ test/unit/deadline_client/cli/test_cli_job.py | 281 +++++++++--------- .../config/test_config_file.py | 9 - 14 files changed, 284 insertions(+), 290 deletions(-) diff --git a/src/deadline/client/api/_session.py b/src/deadline/client/api/_session.py index 6bf2f0b7..cf962503 100644 --- a/src/deadline/client/api/_session.py +++ b/src/deadline/client/api/_session.py @@ -6,6 +6,7 @@ """ from __future__ import annotations import logging +import os from configparser import ConfigParser from contextlib import contextmanager from enum import Enum @@ -101,10 +102,19 @@ def invalidate_boto3_session_cache() -> None: __cached_queue_id_for_queue_session = None +def get_deadline_endpoint_url( + config: Optional[ConfigParser] = None, +) -> str: + url = os.getenv("AWS_ENDPOINT_URL_DEADLINE") + if not url: + url = f"https://deadline.{get_boto3_session(config=config).region_name}.amazonaws.com" + return url + + def get_boto3_client(service_name: str, config: Optional[ConfigParser] = None) -> BaseClient: """ Gets a client from the boto3 session returned by `get_boto3_session`. - If the client requested is `deadline`, it uses the configured + If the client requested is `deadline`, it uses the AWS_ENDPOINT_URL_DEADLINE deadline endpoint url. Args: @@ -114,7 +124,7 @@ def get_boto3_client(service_name: str, config: Optional[ConfigParser] = None) - session = get_boto3_session(config=config) if service_name == "deadline": - deadline_endpoint_url = get_setting("settings.deadline_endpoint_url", config=config) + deadline_endpoint_url = get_deadline_endpoint_url(config=config) client = session.client(service_name, endpoint_url=deadline_endpoint_url) return DeadlineClient(client) else: diff --git a/src/deadline/client/api/_telemetry.py b/src/deadline/client/api/_telemetry.py index 1e128fd9..4ec8ae16 100644 --- a/src/deadline/client/api/_telemetry.py +++ b/src/deadline/client/api/_telemetry.py @@ -18,7 +18,7 @@ from ...job_attachments.progress_tracker import SummaryStatistics -from ._session import get_studio_id, get_user_and_identity_store_id +from ._session import get_studio_id, get_user_and_identity_store_id, get_deadline_endpoint_url from ..config import config_file from .. import version @@ -76,7 +76,7 @@ def __init__( return self.package_name = package_name self.package_ver = ".".join(package_ver.split(".")[:3]) - self.endpoint: str = f"{config_file.get_setting('settings.deadline_endpoint_url', config=config)}/2023-10-12/telemetry" + self.endpoint: str = f"{get_deadline_endpoint_url(config=config)}/2023-10-12/telemetry" # IDs for this session self.session_id: str = str(uuid.uuid4()) diff --git a/src/deadline/client/cli/_groups/config_group.py b/src/deadline/client/cli/_groups/config_group.py index 4f986fe0..e58b5f90 100644 --- a/src/deadline/client/cli/_groups/config_group.py +++ b/src/deadline/client/cli/_groups/config_group.py @@ -36,9 +36,6 @@ def cli_config(): The directory in which to create new job bundles for submitting to Amazon Deadline Cloud, to produce a history of job submissions. - settings.deadline_endpoint_url: - The endpoint URL to access the Amazon Deadline Cloud service. - settings.auto_accept: Flag to automatically confirm any confirmation prompts diff --git a/src/deadline/client/config/config_file.py b/src/deadline/client/config/config_file.py index 3f104f5f..16dd6e82 100644 --- a/src/deadline/client/config/config_file.py +++ b/src/deadline/client/config/config_file.py @@ -9,7 +9,6 @@ "set_setting", "get_best_profile_for_farm", "str2bool", - "DEFAULT_DEADLINE_ENDPOINT_URL", ] import getpass @@ -32,8 +31,11 @@ # Environment variable that, if set, overrides the value of CONFIG_FILE_PATH CONFIG_FILE_PATH_ENV_VAR = "DEADLINE_CONFIG_FILE_PATH" # The default Amazon Deadline Cloud endpoint URL -# TODO: This is currently set to our closed-beta endpoint. We need to remove this for GA. -DEFAULT_DEADLINE_ENDPOINT_URL = "https://btpdb6qczg.execute-api.us-west-2.amazonaws.com" +# Environment variable that, if set, overrides the value of DEFAULT_DEADLINE_ENDPOINT_URL +DEFAULT_DEADLINE_ENDPOINT_URL = os.getenv( + "AWS_ENDPOINT_URL_DEADLINE", f"https://deadline.{boto3.Session().region_name}.amazonaws.com" +) + # The default directory within which to save the history of created jobs. DEFAULT_JOB_HISTORY_DIR = os.path.join("~", ".deadline", "job_history", "{aws_profile_name}") @@ -68,11 +70,6 @@ "depend": "defaults.aws_profile_name", "description": "The directory in which to place the job submission history for this AWS profile name.", }, - "settings.deadline_endpoint_url": { - "default": DEFAULT_DEADLINE_ENDPOINT_URL, - "depend": "defaults.aws_profile_name", - "description": "The endpoint URL for Amazon Deadline Cloud.", - }, "defaults.farm_id": { "default": "", "depend": "defaults.aws_profile_name", diff --git a/src/deadline/client/ui/dialogs/deadline_config_dialog.py b/src/deadline/client/ui/dialogs/deadline_config_dialog.py index c3db63cf..805e2918 100644 --- a/src/deadline/client/ui/dialogs/deadline_config_dialog.py +++ b/src/deadline/client/ui/dialogs/deadline_config_dialog.py @@ -29,7 +29,6 @@ QGroupBox, QHBoxLayout, QLabel, - QLineEdit, QMessageBox, QPushButton, QSizePolicy, @@ -239,13 +238,6 @@ def _build_profile_settings_ui(self, group, layout): self.default_farm_box.background_exception.connect(self.handle_background_exception) layout.addRow(default_farm_box_label, self.default_farm_box) - self.deadline_endpoint_url_edit = QLineEdit(parent=group) - deadline_endpoint_url_label = self.labels["settings.deadline_endpoint_url"] = QLabel( - "Amazon Deadline Cloud Endpoint URL" - ) - layout.addRow(deadline_endpoint_url_label, self.deadline_endpoint_url_edit) - self.deadline_endpoint_url_edit.editingFinished.connect(self.deadline_endpoint_url_edited) - def _build_farm_settings_ui(self, group, layout): self.default_queue_box = DeadlineQueueListComboBox(parent=group) default_queue_box_label = self.labels["defaults.queue_id"] = QLabel("Default Queue") @@ -449,12 +441,6 @@ def refresh(self): self.default_farm_box.refresh_selected_id() - with block_signals(self.deadline_endpoint_url_edit): - deadline_endpoint_url = config_file.get_setting( - "settings.deadline_endpoint_url", config=self.config - ) - self.deadline_endpoint_url_edit.setText(deadline_endpoint_url) - for refresh_callback in self._refresh_callbacks: refresh_callback() @@ -525,15 +511,6 @@ def default_farm_changed(self, index): self.default_queue_box.refresh_list() self.default_storage_profile_box.refresh_list() - def deadline_endpoint_url_edited(self): - deadline_endpoint_url = self.deadline_endpoint_url_edit.text() - # Only apply the change if the text was actually edited - if deadline_endpoint_url != config_file.get_setting( - "settings.deadline_endpoint_url", config=self.config - ): - self.changes["settings.deadline_endpoint_url"] = deadline_endpoint_url - self.refresh() - def default_queue_changed(self, index): self.changes["defaults.queue_id"] = self.default_queue_box.box.itemData(index) self.refresh() diff --git a/test/integ/deadline_job_attachments/test_job_attachments.py b/test/integ/deadline_job_attachments/test_job_attachments.py index 4e96d0a6..43b8cc96 100644 --- a/test/integ/deadline_job_attachments/test_job_attachments.py +++ b/test/integ/deadline_job_attachments/test_job_attachments.py @@ -79,9 +79,13 @@ def __init__( self.bucket = boto3.resource("s3").Bucket(self.job_attachment_resources.bucket_name) self.deadline_client = self.job_attachment_resources.deadline_client - self.deadline_endpoint = os.getenv("DEADLINE_ENDPOINT") + self.hash_cache_dir = tmp_path_factory.mktemp("hash_cache") self.session = boto3.Session() + self.deadline_endpoint = os.getenv( + "AWS_ENDPOINT_URL_DEADLINE", + f"https://deadline.{self.session.region_name}.amazonaws.com", + ) self.manifest_version = manifest_version diff --git a/test/unit/deadline_client/api/test_api_session.py b/test/unit/deadline_client/api/test_api_session.py index 639b94de..8804692d 100644 --- a/test/unit/deadline_client/api/test_api_session.py +++ b/test/unit/deadline_client/api/test_api_session.py @@ -184,25 +184,27 @@ def test_check_deadline_api_available_fails(fresh_deadline_config): def test_get_boto3_client_deadline(fresh_deadline_config): """Confirm that api.get_boto3_client uses the endpoint url for the deadline client""" config.set_setting("defaults.aws_profile_name", "SomeRandomProfileName") - config.set_setting("settings.deadline_endpoint_url", "some-endpoint-url") + with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint: + session_endpoint.return_value = "some-endpoint-url" + with patch.object(api._session, "get_boto3_session") as session_mock: + # Testing this function + api.get_boto3_client("deadline") - with patch.object(api._session, "get_boto3_session") as session_mock: - # Testing this function - api.get_boto3_client("deadline") - - session_mock().client.assert_called_once_with("deadline", endpoint_url="some-endpoint-url") + session_mock().client.assert_called_once_with( + "deadline", endpoint_url="some-endpoint-url" + ) def test_get_boto3_client_other(fresh_deadline_config): """Confirm that api.get_boto3_client doesn't use the endpoint url for other clients""" config.set_setting("defaults.aws_profile_name", "SomeRandomProfileName") - config.set_setting("settings.deadline_endpoint_url", "some-endpoint-url") - - with patch.object(api._session, "get_boto3_session") as session_mock: - # Testing this function - api.get_boto3_client("s3") + with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint: + session_endpoint.return_value = "some-endpoint-url" + with patch.object(api._session, "get_boto3_session") as session_mock: + # Testing this function + api.get_boto3_client("s3") - session_mock().client.assert_called_once_with("s3") + session_mock().client.assert_called_once_with("s3") class FakeClient: diff --git a/test/unit/deadline_client/cli/test_cli_bundle.py b/test/unit/deadline_client/cli/test_cli_bundle.py index d3a0de47..3c02a7b5 100644 --- a/test/unit/deadline_client/cli/test_cli_bundle.py +++ b/test/unit/deadline_client/cli/test_cli_bundle.py @@ -87,6 +87,7 @@ "template": MOCK_QUEUE_ENV_TEMPLATE_1, }, ] +os.environ["AWS_ENDPOINT_URL_DEADLINE"] = "https://fake-endpoint" def test_cli_bundle_submit(fresh_deadline_config, temp_job_bundle_dir): diff --git a/test/unit/deadline_client/cli/test_cli_config.py b/test/unit/deadline_client/cli/test_cli_config.py index 729e981e..2f3eb966 100644 --- a/test/unit/deadline_client/cli/test_cli_config.py +++ b/test/unit/deadline_client/cli/test_cli_config.py @@ -35,7 +35,7 @@ def test_cli_config_show_defaults(fresh_deadline_config): assert fresh_deadline_config in result.output # Assert the expected number of settings - assert len(settings.keys()) == 14 + assert len(settings.keys()) == 13 for setting_name in settings.keys(): assert setting_name in result.output @@ -92,7 +92,6 @@ def test_cli_config_show_modified_config(fresh_deadline_config): config.set_setting("deadline-cloud-monitor.path", "/User/auser/bin/DeadlineCloudMonitor") config.set_setting("defaults.aws_profile_name", "EnvVarOverrideProfile") config.set_setting("settings.job_history_dir", "~/alternate/job_history") - config.set_setting("settings.deadline_endpoint_url", "https://some-url-value") config.set_setting("defaults.farm_id", "farm-82934h23k4j23kjh") config.set_setting("settings.storage_profile_id", "sp-12345abcde12345") config.set_setting("defaults.queue_id", "queue-389348u234jhk34") @@ -116,7 +115,6 @@ def test_cli_config_show_modified_config(fresh_deadline_config): assert "~/alternate/job_history" in result.output assert result.output.count("False") == 1 assert result.output.count("True") == 1 - assert "https://some-url-value" in result.output assert "farm-82934h23k4j23kjh" in result.output assert "queue-389348u234jhk34" in result.output assert "job-239u40234jkl234nkl23" in result.output diff --git a/test/unit/deadline_client/cli/test_cli_farm.py b/test/unit/deadline_client/cli/test_cli_farm.py index 089d822a..c9315881 100644 --- a/test/unit/deadline_client/cli/test_cli_farm.py +++ b/test/unit/deadline_client/cli/test_cli_farm.py @@ -4,6 +4,7 @@ Tests for the CLI farm commands. """ from unittest.mock import patch +import os import boto3 # type: ignore[import] from botocore.exceptions import ClientError # type: ignore[import] @@ -25,6 +26,8 @@ }, ] +os.environ["AWS_ENDPOINT_URL_DEADLINE"] = "https://fake-endpoint" + def test_cli_farm_list(fresh_deadline_config): """ diff --git a/test/unit/deadline_client/cli/test_cli_fleet.py b/test/unit/deadline_client/cli/test_cli_fleet.py index b9fadece..7049e732 100644 --- a/test/unit/deadline_client/cli/test_cli_fleet.py +++ b/test/unit/deadline_client/cli/test_cli_fleet.py @@ -5,6 +5,7 @@ """ from unittest.mock import patch from copy import deepcopy +import os import boto3 # type: ignore[import] from botocore.exceptions import ClientError # type: ignore[import] @@ -44,6 +45,8 @@ }, ] +os.environ["AWS_ENDPOINT_URL_DEADLINE"] = "https://fake-endpoint" + def test_cli_fleet_list(fresh_deadline_config): """ diff --git a/test/unit/deadline_client/cli/test_cli_handle_web_url.py b/test/unit/deadline_client/cli/test_cli_handle_web_url.py index daf3f267..87ceb067 100644 --- a/test/unit/deadline_client/cli/test_cli_handle_web_url.py +++ b/test/unit/deadline_client/cli/test_cli_handle_web_url.py @@ -11,7 +11,7 @@ import pytest from click.testing import CliRunner -from deadline.client import api, config +from deadline.client import api from deadline.client.cli import main from deadline.client.cli._deadline_web_url import ( parse_query_string, @@ -242,49 +242,51 @@ def test_cli_handle_web_url_download_output_only_required_input(fresh_deadline_c Confirm that the CLI interface prints out the expected list of farms, given mock data. """ - config.set_setting("settings.deadline_endpoint_url", "fake-url-endpoint") - - with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object( - job_group, "OutputDownloader" - ) as MockOutputDownloader, 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 - 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] - - web_url = f"deadline://download-output?farm-id={MOCK_FARM_ID}&queue-id={MOCK_QUEUE_ID}&job-id={MOCK_JOB_ID}" - - runner = CliRunner() - result = runner.invoke(main, ["handle-web-url", web_url]) - - 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, - ) - mock_download.assert_called_once_with( - file_conflict_resolution=FileConflictResolution.CREATE_COPY, on_downloading_files=ANY - ) - assert result.exit_code == 0 + with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint: + session_endpoint.return_value = "fake-endpoint-url" + + with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object( + job_group, "OutputDownloader" + ) as MockOutputDownloader, 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 + 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] + + web_url = f"deadline://download-output?farm-id={MOCK_FARM_ID}&queue-id={MOCK_QUEUE_ID}&job-id={MOCK_JOB_ID}" + + runner = CliRunner() + result = runner.invoke(main, ["handle-web-url", web_url]) + + 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, + ) + mock_download.assert_called_once_with( + file_conflict_resolution=FileConflictResolution.CREATE_COPY, + on_downloading_files=ANY, + ) + assert result.exit_code == 0 def test_cli_handle_web_url_download_output_with_optional_input(fresh_deadline_config): @@ -292,52 +294,54 @@ def test_cli_handle_web_url_download_output_with_optional_input(fresh_deadline_c Confirm that the CLI interface prints out the expected list of farms, given mock data. """ - config.set_setting("settings.deadline_endpoint_url", "fake-url-endpoint") - - with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object( - job_group, "OutputDownloader" - ) as MockOutputDownloader, 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 - 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] - - web_url = ( - f"deadline://download-output?farm-id={MOCK_FARM_ID}&queue-id={MOCK_QUEUE_ID}&job-id={MOCK_JOB_ID}" - + f"&step-id={MOCK_STEP_ID}&task-id={MOCK_TASK_ID}&profile={MOCK_PROFILE_NAME}" - ) - - runner = CliRunner() - result = runner.invoke(main, ["handle-web-url", web_url]) - assert result.exit_code == 0, result.output - - 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=MOCK_STEP_ID, - task_id=MOCK_TASK_ID, - session=ANY, - ) - mock_download.assert_called_once_with( - file_conflict_resolution=FileConflictResolution.CREATE_COPY, on_downloading_files=ANY - ) + with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint: + session_endpoint.return_value = "fake-endpoint-url" + + with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object( + job_group, "OutputDownloader" + ) as MockOutputDownloader, 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 + 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] + + web_url = ( + f"deadline://download-output?farm-id={MOCK_FARM_ID}&queue-id={MOCK_QUEUE_ID}&job-id={MOCK_JOB_ID}" + + f"&step-id={MOCK_STEP_ID}&task-id={MOCK_TASK_ID}&profile={MOCK_PROFILE_NAME}" + ) + + runner = CliRunner() + result = runner.invoke(main, ["handle-web-url", web_url]) + assert result.exit_code == 0, result.output + + 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=MOCK_STEP_ID, + task_id=MOCK_TASK_ID, + session=ANY, + ) + mock_download.assert_called_once_with( + file_conflict_resolution=FileConflictResolution.CREATE_COPY, + on_downloading_files=ANY, + ) def test_cli_handle_web_url_unsupported_protocol_scheme(fresh_deadline_config): diff --git a/test/unit/deadline_client/cli/test_cli_job.py b/test/unit/deadline_client/cli/test_cli_job.py index 3452e55c..de5209f1 100644 --- a/test/unit/deadline_client/cli/test_cli_job.py +++ b/test/unit/deadline_client/cli/test_cli_job.py @@ -5,6 +5,7 @@ """ import datetime import json +import os from pathlib import Path import sys from unittest.mock import ANY, MagicMock, patch @@ -53,6 +54,8 @@ }, ] +os.environ["AWS_ENDPOINT_URL_DEADLINE"] = "https://fake-endpoint" + def test_cli_job_list(fresh_deadline_config): """ @@ -269,9 +272,10 @@ def test_cli_job_download_output_stdout_with_only_required_input( Tests whether the ouptut messages printed to stdout match expected messages when download-output command is executed. """ - config.set_setting("settings.deadline_endpoint_url", "fake-url-endpoint") - config.set_setting("defaults.farm_id", MOCK_FARM_ID) - config.set_setting("defaults.queue_id", MOCK_QUEUE_ID) + with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint: + session_endpoint.return_value = "some-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" @@ -360,86 +364,87 @@ def test_cli_job_dowuload_output_stdout_with_json_format( Tests whether the ouptut messages printed to stdout match expected messages when download-output command is executed with `--output json` option. """ - config.set_setting("settings.deadline_endpoint_url", "fake-url-endpoint") - 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, "round", return_value=0), patch.object( - job_group, "_get_conflicting_filenames", return_value=[] - ), patch.object( - job_group, "_assert_valid_path", return_value=None - ), patch.object( - api, "get_queue_user_boto3_session" - ): - mock_download = MagicMock() - MockOutputDownloader.return_value.download_job_output = mock_download - mock_root_path = "/root/path" if sys.platform != "win32" else "C:\\Users\\username" - mock_files_list = ["outputs/file1.txt", "outputs/file2.txt", "outputs/file3.txt"] - MockOutputDownloader.return_value.get_output_paths_by_root.side_effect = [ - { - f"{mock_root_path}": mock_files_list, - f"{mock_root_path}2": mock_files_list, - }, - { - f"{mock_root_path}": mock_files_list, - f"{mock_root_path}2": mock_files_list, - }, - { - f"{mock_root_path}": mock_files_list, - str(tmp_path): mock_files_list, - }, - ] - - 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", "json"], - input=json.dumps( + 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, "round", return_value=0), patch.object( + job_group, "_get_conflicting_filenames", return_value=[] + ), patch.object( + job_group, "_assert_valid_path", return_value=None + ), patch.object( + api, "get_queue_user_boto3_session" + ): + mock_download = MagicMock() + MockOutputDownloader.return_value.download_job_output = mock_download + mock_root_path = "/root/path" if sys.platform != "win32" else "C:\\Users\\username" + mock_files_list = ["outputs/file1.txt", "outputs/file2.txt", "outputs/file3.txt"] + MockOutputDownloader.return_value.get_output_paths_by_root.side_effect = [ + { + f"{mock_root_path}": mock_files_list, + f"{mock_root_path}2": mock_files_list, + }, + { + f"{mock_root_path}": mock_files_list, + f"{mock_root_path}2": mock_files_list, + }, + { + f"{mock_root_path}": mock_files_list, + str(tmp_path): mock_files_list, + }, + ] + + 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", "json"], + input=json.dumps( + {"messageType": "pathconfirm", "value": [mock_root_path, str(tmp_path)]} + ), + ) + + 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, + ) + + expected_json_title = json.dumps({"messageType": "title", "value": "Mock Job"}) + expected_json_path = json.dumps( + {"messageType": "path", "value": [mock_root_path, f"{mock_root_path}2"]} + ) + expected_json_pathconfirm = json.dumps( {"messageType": "pathconfirm", "value": [mock_root_path, str(tmp_path)]} - ), - ) - - 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, - ) - - expected_json_title = json.dumps({"messageType": "title", "value": "Mock Job"}) - expected_json_path = json.dumps( - {"messageType": "path", "value": [mock_root_path, f"{mock_root_path}2"]} - ) - expected_json_pathconfirm = json.dumps( - {"messageType": "pathconfirm", "value": [mock_root_path, str(tmp_path)]} - ) + ) - assert ( - f"{expected_json_title}\n{expected_json_path}\n {expected_json_pathconfirm}\n" - in result.output - ) - assert result.exit_code == 0 + assert ( + f"{expected_json_title}\n{expected_json_path}\n {expected_json_pathconfirm}\n" + in result.output + ) + assert result.exit_code == 0 def test_cli_job_download_output_handle_web_url_with_optional_input(fresh_deadline_config): @@ -447,60 +452,62 @@ def test_cli_job_download_output_handle_web_url_with_optional_input(fresh_deadli Confirm that the CLI interface prints out the expected list of farms, given mock data. """ - config.set_setting("settings.deadline_endpoint_url", "fake-url-endpoint") - - with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object( - job_group, "OutputDownloader" - ) as MockOutputDownloader, 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 - 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": ["."], - }, + with patch.object(api._session, "get_deadline_endpoint_url") as session_endpoint: + session_endpoint.return_value = "fake-endpoint-url" + + with patch.object(api, "get_boto3_client") as boto3_client_mock, patch.object( + job_group, "OutputDownloader" + ) as MockOutputDownloader, 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 + 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", + "--farm-id", + MOCK_FARM_ID, + "--queue-id", + MOCK_QUEUE_ID, + "--job-id", + MOCK_JOB_ID, + "--step-id", + "step-1", + "--task-id", + "task-2", ], - }, - } - boto3_client_mock().get_queue.side_effect = [MOCK_GET_QUEUE_RESPONSE] - - runner = CliRunner() - result = runner.invoke( - main, - [ - "job", - "download-output", - "--farm-id", - MOCK_FARM_ID, - "--queue-id", - MOCK_QUEUE_ID, - "--job-id", - MOCK_JOB_ID, - "--step-id", - "step-1", - "--task-id", - "task-2", - ], - ) - - 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="step-1", - task_id="task-2", - session=ANY, - ) - mock_download.assert_called_once_with( - file_conflict_resolution=FileConflictResolution.CREATE_COPY, on_downloading_files=ANY - ) - assert result.exit_code == 0 + ) + + 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="step-1", + task_id="task-2", + session=ANY, + ) + mock_download.assert_called_once_with( + file_conflict_resolution=FileConflictResolution.CREATE_COPY, + on_downloading_files=ANY, + ) + assert result.exit_code == 0 diff --git a/test/unit/deadline_client/config/test_config_file.py b/test/unit/deadline_client/config/test_config_file.py index 4e06b52b..20a64be2 100644 --- a/test/unit/deadline_client/config/test_config_file.py +++ b/test/unit/deadline_client/config/test_config_file.py @@ -15,7 +15,6 @@ from deadline.client import config from deadline.client.config import ( - DEFAULT_DEADLINE_ENDPOINT_URL, config_file, ) from deadline.client.exceptions import DeadlineOperationError @@ -23,11 +22,6 @@ # This is imported by `test_cli_config.py` for a matching CLI test CONFIG_SETTING_ROUND_TRIP = [ ("defaults.aws_profile_name", "(default)", "AnotherProfileName"), - ( - "settings.deadline_endpoint_url", - DEFAULT_DEADLINE_ENDPOINT_URL, - "https://some-other-url", - ), ("defaults.farm_id", "", "farm-82934h23k4j23kjh"), ("defaults.job_attachments_file_system", "COPIED", "VIRTUAL"), ] @@ -50,7 +44,6 @@ def test_config_settings_hierarchy(fresh_deadline_config): """ # First set some settings that apply to the defaults, changing the # hierarchy from queue inwards. - config.set_setting("settings.deadline_endpoint_url", "nondefault-endpoint-url") config.set_setting("settings.storage_profile_id", "storage-profile-for-farm-default") config.set_setting("defaults.queue_id", "queue-for-farm-default") config.set_setting("defaults.farm_id", "farm-for-profile-default") @@ -58,14 +51,12 @@ def test_config_settings_hierarchy(fresh_deadline_config): # Confirm that all child settings we changed are default, because they were # for a different profile. - assert config.get_setting("settings.deadline_endpoint_url") == DEFAULT_DEADLINE_ENDPOINT_URL assert config.get_setting("defaults.farm_id") == "" assert config.get_setting("defaults.queue_id") == "" assert config.get_setting("settings.storage_profile_id") == "" # Switch back to the default profile, and check the next layer of the onion config.set_setting("defaults.aws_profile_name", "(default)") - assert config.get_setting("settings.deadline_endpoint_url") == "nondefault-endpoint-url" assert config.get_setting("defaults.farm_id") == "farm-for-profile-default" # The queue id is still default assert config.get_setting("defaults.queue_id") == ""