-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: Use the Python SDK in the CLI implementation (#365)
* migrate deploy cmd * change testing technique * migrate run * migrate status * removed unused module * make the test case more robust * simplify imports * restore code coverage
- Loading branch information
Showing
9 changed files
with
148 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import click | ||
|
||
|
||
from llama_deploy.cli.utils import request | ||
from llama_deploy import Client | ||
from llama_deploy.types.apiserver import StatusEnum | ||
|
||
|
||
@click.command() | ||
@click.pass_obj # global_config | ||
def status(global_config: tuple) -> None: | ||
server_url, disable_ssl, timeout = global_config | ||
status_url = f"{server_url}/status/" | ||
client = Client(api_server_url=server_url, disable_ssl=disable_ssl, timeout=timeout) | ||
|
||
r = request("GET", status_url, verify=not disable_ssl, timeout=timeout) | ||
if r.status_code >= 400: | ||
body = r.json() | ||
click.echo( | ||
f"Llama Deploy is unhealthy: [{r.status_code}] {r.json().get('detail')}" | ||
) | ||
return | ||
try: | ||
status = client.sync.apiserver.status() | ||
except Exception as e: | ||
raise click.ClickException(str(e)) | ||
|
||
click.echo("Llama Deploy is up and running.") | ||
body = r.json() | ||
if deployments := body.get("deployments"): | ||
click.echo("\nActive deployments:") | ||
for d in deployments: | ||
click.echo(f"- {d}") | ||
if status.status == StatusEnum.HEALTHY: | ||
click.echo("Llama Deploy is up and running.") | ||
if status.deployments: | ||
click.echo("\nActive deployments:") | ||
for d in status.deployments: | ||
click.echo(f"- {d}") | ||
else: | ||
click.echo("\nCurrently there are no active deployments") | ||
else: | ||
click.echo("\nCurrently there are no active deployments") | ||
click.echo(f"Llama Deploy is unhealthy: {status.status_message}") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,42 @@ | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import httpx | ||
from click.testing import CliRunner | ||
|
||
from llama_deploy.cli import llamactl | ||
|
||
|
||
def test_deploy(runner: CliRunner, data_path: Path) -> None: | ||
test_config_file = data_path / "deployment.yaml" | ||
mocked_response = mock.MagicMock(status_code=200, json=lambda: {}) | ||
with mock.patch("llama_deploy.cli.utils.httpx.request") as mocked_httpx: | ||
mocked_httpx.return_value = mocked_response | ||
mocked_result = mock.MagicMock(id="test_deployment") | ||
with mock.patch("llama_deploy.cli.deploy.Client") as mocked_client: | ||
mocked_client.return_value.sync.apiserver.deployments.create.return_value = ( | ||
mocked_result | ||
) | ||
|
||
result = runner.invoke(llamactl, ["-t", "5.0", "deploy", str(test_config_file)]) | ||
|
||
assert result.exit_code == 0 | ||
with open(test_config_file, "rb") as f: | ||
mocked_httpx.assert_called_with( | ||
"POST", | ||
"http://localhost:4501/deployments/create", | ||
files={"config_file": f.read()}, | ||
verify=True, | ||
timeout=5, | ||
) | ||
assert result.output == "Deployment successful: test_deployment\n" | ||
mocked_client.assert_called_with( | ||
api_server_url="http://localhost:4501", disable_ssl=False, timeout=5.0 | ||
) | ||
file_arg = ( | ||
mocked_client.return_value.sync.apiserver.deployments.create.call_args | ||
) | ||
assert str(test_config_file) == file_arg.args[0].name | ||
|
||
|
||
def test_deploy_failed(runner: CliRunner, data_path: Path) -> None: | ||
test_config_file = data_path / "deployment.yaml" | ||
mocked_response = mock.MagicMock( | ||
status_code=401, json=lambda: {"detail": "Unauthorized!"} | ||
) | ||
with mock.patch("llama_deploy.cli.utils.httpx.request") as mocked_httpx: | ||
mocked_httpx.return_value = mocked_response | ||
with mock.patch("llama_deploy.cli.deploy.Client") as mocked_client: | ||
mocked_client.return_value.sync.apiserver.deployments.create.side_effect = ( | ||
httpx.HTTPStatusError( | ||
"Unauthorized!", response=mock.MagicMock(), request=mock.MagicMock() | ||
) | ||
) | ||
|
||
result = runner.invoke(llamactl, ["deploy", str(test_config_file)]) | ||
assert result.exit_code == 1 | ||
assert result.output == "Error: Unauthorized!\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.