Skip to content

Commit 03e086a

Browse files
author
luk384090-cloud
committed
fix(deployments): exit with error on deployment status check failure
1 parent 9b2fb54 commit 03e086a

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎dashscope/cli/deployments.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ def _wait_for_deployment(
8585
except Exception as exc:
8686
logger.debug("wait_for_deployment error", exc_info=exc)
8787
err_console.print(
88+
f"[red]Error:[/red] Failed to check deployment status: {exc}. "
8889
f"You can get deployment status via: "
8990
f"[cyan]dashscope deployments get {deployed_model}[/cyan]",
9091
)
92+
raise typer.Exit(1)
9193

9294

9395
def _print_deployments(output):

‎dashscope/finetune/deployments.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def call( # pylint: disable=arguments-renamed # type: ignore[override]
4747
4848
Args:
4949
model (str): The model name.
50+
capacity (int): The model service capacity.
5051
version (str, optional): The model version, unnecessary
5152
for fine-tuned model. Defaults to None.
5253
suffix (str, optional): The name suffix of the model deployment,
5354
If specified, the final model name will be model_suffix.
5455
Defaults to None.
55-
capacity (int, optional): The model service capacity.
5656
plan (str, optional): The deployment plan required by the
5757
service: "ptu" (PTU reserved), "mu" (model unit) or
5858
"Lora" (LoRA deployment). Defaults to None.

‎tests/unit/test_cli_main.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,38 @@ def mock_call(**kwargs):
756756
assert "Create deployment failed: deployment failed" in result.output
757757
assert "Traceback" not in result.output
758758

759+
def test_deployments_create_exits_nonzero_when_status_poll_fails(
760+
self,
761+
monkeypatch,
762+
):
763+
def mock_call(**kwargs):
764+
return SimpleNamespace(
765+
status_code=200,
766+
output={"deployed_model": "deploy-1"},
767+
)
768+
769+
def mock_get(*_args, **_kwargs):
770+
raise RuntimeError("network down")
771+
772+
monkeypatch.setattr(
773+
"dashscope.cli.deployments.dashscope.Deployments.call",
774+
mock_call,
775+
)
776+
monkeypatch.setattr(
777+
"dashscope.cli.deployments.dashscope.Deployments.get",
778+
mock_get,
779+
)
780+
781+
result = CliRunner().invoke(
782+
cli_app,
783+
["deployments", "create", "--model", "qwen", "--plan", "ptu"],
784+
)
785+
786+
assert result.exit_code == 1
787+
assert "Failed to check deployment status" in result.output
788+
assert "deployments get deploy-1" in result.output
789+
assert "Traceback" not in result.output
790+
759791
def test_application_response_without_usage_is_supported(
760792
self,
761793
monkeypatch,

0 commit comments

Comments
 (0)