Skip to content

Commit

Permalink
feat: support --submitter-name option for bundle GUI submitter command
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crowe <[email protected]>
  • Loading branch information
crowecawcaw committed Jul 23, 2024
1 parent 0344537 commit 9bc3072
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/deadline/client/cli/_groups/bundle_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ def _decide_cancel_submission(upload_group: AssetUploadGroup) -> bool:
is_flag=True,
help="Installs GUI dependencies if they are not installed already",
)
@click.option(
"--submitter-name",
type=click.STRING,
help="Name of the application submitting the bundle. If a name is specified, the GUI will automatically close after submitting the job.",
)
@click.option(
"--output",
type=click.Choice(
Expand All @@ -269,7 +274,7 @@ def _decide_cancel_submission(upload_group: AssetUploadGroup) -> bool:
"parsed/consumed by custom scripts.",
)
@_handle_error
def bundle_gui_submit(job_bundle_dir, browse, output, install_gui, **args):
def bundle_gui_submit(job_bundle_dir, browse, output, install_gui, submitter_name, **args):
"""
Opens GUI to submit an Open Job Description job bundle to AWS Deadline Cloud.
"""
Expand All @@ -284,7 +289,9 @@ def bundle_gui_submit(job_bundle_dir, browse, output, install_gui, **args):
)
output = output.lower()

submitter = show_job_bundle_submitter(input_job_bundle_dir=job_bundle_dir, browse=browse)
submitter = show_job_bundle_submitter(
input_job_bundle_dir=job_bundle_dir, browse=browse, submitter_name=submitter_name
)

if not submitter:
return
Expand Down
19 changes: 11 additions & 8 deletions src/deadline/client/ui/dialogs/submit_job_to_deadline_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SubmitJobToDeadlineDialog(QDialog):
f: Qt Window Flags
show_host_requirements_tab: Display the host requirements tab in dialog if set to True. Default
to False.
submitter_name: Override the default submitter_name value
"""

def __init__(
Expand All @@ -85,13 +86,15 @@ def __init__(
parent=None,
f=Qt.WindowFlags(),
show_host_requirements_tab=False,
submitter_name: Optional[str] = None,
):
# The Qt.Tool flag makes sure our widget stays in front of the main application window
super().__init__(parent=parent, f=f)
self.setWindowTitle("Submit to AWS Deadline Cloud")
self.setMinimumSize(400, 400)

self.job_settings_type = type(initial_job_settings)
self.submitter_name = submitter_name or self.job_settings_type.submitter_name
self.on_create_job_bundle_callback = on_create_job_bundle_callback
self.create_job_response: Optional[Dict[str, Any]] = None
self.job_history_bundle_dir: Optional[str] = None
Expand Down Expand Up @@ -341,7 +344,7 @@ def on_export_bundle(self):
# Save the bundle
try:
self.job_history_bundle_dir = create_job_history_bundle_dir(
settings.submitter_name, settings.name
self.submitter_name, settings.name
)

if self.show_host_requirements_tab:
Expand Down Expand Up @@ -372,15 +375,15 @@ def on_export_bundle(self):
os.startfile(self.job_history_bundle_dir)
QMessageBox.information(
self,
f"{settings.submitter_name} job submission",
f"{self.submitter_name} job submission",
f"Saved the submission as a job bundle:\n{self.job_history_bundle_dir}",
)
# Close the submitter window to signal the submission is done
self.close()
except Exception as exc:
logger.exception("Error saving bundle")
message = str(exc)
QMessageBox.warning(self, f"{settings.submitter_name} job submission", message)
QMessageBox.warning(self, f"{self.submitter_name} job submission", message)

def on_submit(self):
"""
Expand All @@ -407,7 +410,7 @@ def on_submit(self):
deadline = api.get_boto3_client("deadline")

self.job_history_bundle_dir = create_job_history_bundle_dir(
settings.submitter_name, settings.name
self.submitter_name, settings.name
)

if self.show_host_requirements_tab:
Expand Down Expand Up @@ -465,7 +468,7 @@ def on_submit(self):
api.get_deadline_cloud_library_telemetry_client().record_event(
event_type="com.amazon.rum.deadline.submission",
event_details={
"submitter_name": settings.submitter_name,
"submitter_name": self.submitter_name,
},
from_gui=True,
)
Expand All @@ -483,7 +486,7 @@ def on_submit(self):
)
except UserInitiatedCancel as uic:
logger.info("Canceling submission.")
QMessageBox.information(self, f"{settings.submitter_name} job submission", str(uic))
QMessageBox.information(self, f"{self.submitter_name} job submission", str(uic))
job_progress_dialog.close()
except Exception as exc:
logger.exception("error submitting job")
Expand All @@ -492,11 +495,11 @@ def on_submit(self):
exception_type=str(type(exc)),
from_gui=True,
)
QMessageBox.warning(self, f"{settings.submitter_name} job submission", str(exc))
QMessageBox.warning(self, f"{self.submitter_name} job submission", str(exc))
job_progress_dialog.close()

if self.create_job_response:
# Close the submitter window to signal the submission is done but
# keep the standalone gui submitter open
if settings.submitter_name != "JobBundle":
if self.submitter_name != "JobBundle":
self.close()
8 changes: 7 additions & 1 deletion src/deadline/client/ui/job_bundle_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@


def show_job_bundle_submitter(
*, input_job_bundle_dir: str = "", browse: bool = False, parent=None, f=Qt.WindowFlags()
*,
input_job_bundle_dir: str = "",
browse: bool = False,
parent=None,
f=Qt.WindowFlags(),
submitter_name="JobBundle",
) -> Optional[SubmitJobToDeadlineDialog]:
"""
Opens an AWS Deadline Cloud job submission dialog for the provided job bundle.
Expand Down Expand Up @@ -177,6 +182,7 @@ def on_create_job_bundle_callback(
on_create_job_bundle_callback=on_create_job_bundle_callback,
parent=parent,
f=f,
submitter_name=submitter_name,
)
submitter_dialog.show()
return submitter_dialog
21 changes: 21 additions & 0 deletions test/unit/deadline_client/cli/test_cli_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Tests for the CLI job bundle commands.
"""
import os
import sys
import tempfile
import json
from unittest.mock import ANY, patch, Mock
Expand Down Expand Up @@ -750,3 +751,23 @@ def test_cli_bundle_reject_upload_confirmation(fresh_deadline_config, temp_job_b

upload_attachments_mock.assert_not_called()
assert result.exit_code == 0


@patch("deadline.client.ui.gui_context_for_cli")
def test_gui_submit_submitter_name(_mock_context):
"""
Verify that the --submitter-name arg gets passed through correctly
"""

# Unconventional mocking pattern because of how the function is imported in code
mock_job_bundle_submitter = Mock()
sys.modules["deadline.client.ui.job_bundle_submitter"] = mock_job_bundle_submitter
mock_job_bundle_submitter.show_job_bundle_submitter

runner = CliRunner()
runner.invoke(
main,
["bundle", "gui-submit", "--browse", "--submitter-name", "MyDCC"],
)
_args, kwargs = mock_job_bundle_submitter.show_job_bundle_submitter.call_args
assert kwargs["submitter_name"] == "MyDCC"

0 comments on commit 9bc3072

Please sign in to comment.