Skip to content

Commit

Permalink
Merge branch 'mainline' into rmvh/add_callback_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
rmv authored Oct 26, 2023
2 parents f235b78 + a450090 commit 9b993a1
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 291 deletions.
14 changes: 12 additions & 2 deletions src/deadline/client/api/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from __future__ import annotations
import logging
import os
from configparser import ConfigParser
from contextlib import contextmanager
from enum import Enum
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/deadline/client/api/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
Expand Down
3 changes: 0 additions & 3 deletions src/deadline/client/cli/_groups/config_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions src/deadline/client/config/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"set_setting",
"get_best_profile_for_farm",
"str2bool",
"DEFAULT_DEADLINE_ENDPOINT_URL",
]

import getpass
Expand All @@ -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}")

Expand Down Expand Up @@ -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",
Expand Down
23 changes: 0 additions & 23 deletions src/deadline/client/ui/dialogs/deadline_config_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
QGroupBox,
QHBoxLayout,
QLabel,
QLineEdit,
QMessageBox,
QPushButton,
QSizePolicy,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/deadline/job_attachments/fus3.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def find_fus3(cls) -> Union[os.PathLike, str]:
environ_check = os.environ[FUS3_PATH_ENV_VAR] + f"/bin/{exe}"
else:
log.info(f"{FUS3_PATH_ENV_VAR} and {DEADLINE_VFS_ENV_VAR} env vars not set")
environ_check = ""
environ_check = EXE_TO_INSTALL_PATH[exe] + f"/bin/{exe}"
if os.path.exists(environ_check):
log.info(f"Environ check found {exe} at {environ_check}")
found_path = environ_check
Expand Down
6 changes: 5 additions & 1 deletion test/integ/deadline_job_attachments/test_job_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 14 additions & 12 deletions test/unit/deadline_client/api/test_api_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/unit/deadline_client/cli/test_cli_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions test/unit/deadline_client/cli/test_cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/unit/deadline_client/cli/test_cli_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -25,6 +26,8 @@
},
]

os.environ["AWS_ENDPOINT_URL_DEADLINE"] = "https://fake-endpoint"


def test_cli_farm_list(fresh_deadline_config):
"""
Expand Down
3 changes: 3 additions & 0 deletions test/unit/deadline_client/cli/test_cli_fleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -44,6 +45,8 @@
},
]

os.environ["AWS_ENDPOINT_URL_DEADLINE"] = "https://fake-endpoint"


def test_cli_fleet_list(fresh_deadline_config):
"""
Expand Down
Loading

0 comments on commit 9b993a1

Please sign in to comment.