From 602322b5cf72cf2456a29bfe4f9c92ee9f12bbae Mon Sep 17 00:00:00 2001 From: Mark Wiebe <399551+mwiebe@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:51:10 -0800 Subject: [PATCH] fix: Allow empty job parameters from the CLI Signed-off-by: Mark Wiebe <399551+mwiebe@users.noreply.github.com> --- .../client/cli/_groups/bundle_group.py | 2 +- .../deadline_client/cli/test_cli_bundle.py | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/deadline/client/cli/_groups/bundle_group.py b/src/deadline/client/cli/_groups/bundle_group.py index 4229e862..f3441aa9 100644 --- a/src/deadline/client/cli/_groups/bundle_group.py +++ b/src/deadline/client/cli/_groups/bundle_group.py @@ -45,7 +45,7 @@ def validate_parameters(ctx, param, value): """ parameters_split = [] for parameter in value: - regex_match = re.match("(.+)=(.+)", parameter) + regex_match = re.match("(.+)=(.*)", parameter) if not regex_match: raise click.BadParameter( f'Parameters must be provided in the format "Key=Value". Invalid Parameter: {parameter}' diff --git a/test/unit/deadline_client/cli/test_cli_bundle.py b/test/unit/deadline_client/cli/test_cli_bundle.py index 0189c4a1..73615dad 100644 --- a/test/unit/deadline_client/cli/test_cli_bundle.py +++ b/test/unit/deadline_client/cli/test_cli_bundle.py @@ -461,6 +461,56 @@ def test_cli_bundle_job_parameter_from_cli(fresh_deadline_config): assert result.exit_code == 0 +def test_cli_bundle_empty_job_parameter_from_cli(fresh_deadline_config): + """ + Verify that an empty job parameter specified at the CLI are passed to the CreateJob call + """ + # Use a temporary directory for the job bundle + with patch( + "deadline.client.api._session.DeadlineClient._get_deadline_api_input_shape" + ) as input_shape_mock: + input_shape_mock.return_value = {} + with tempfile.TemporaryDirectory() as tmpdir, patch.object( + boto3, "Session" + ) as session_mock: + session_mock().client("deadline").create_job.return_value = MOCK_CREATE_JOB_RESPONSE + session_mock().client("deadline").get_job.return_value = MOCK_GET_JOB_RESPONSE + session_mock.reset_mock() + + # Write a JSON template + with open(os.path.join(tmpdir, "template.json"), "w", encoding="utf8") as f: + f.write(MOCK_JOB_TEMPLATE_CASES["MINIMAL_JSON"][1]) + + runner = CliRunner() + result = runner.invoke( + main, + [ + "bundle", + "submit", + tmpdir, + "--farm-id", + MOCK_FARM_ID, + "--queue-id", + MOCK_QUEUE_ID, + "--parameter", + "sceneFile=", + ], + ) + + session_mock().client().create_job.assert_called_once_with( + farmId=MOCK_FARM_ID, + queueId=MOCK_QUEUE_ID, + template=ANY, + templateType="JSON", + parameters={ + "sceneFile": {"string": ""}, + }, + priority=50, + ) + + assert result.exit_code == 0 + + def test_cli_bundle_invalid_job_paramter(fresh_deadline_config): """ Verify that a badly formatted parameter value (without "Key=Value") throws an error