Skip to content

Commit

Permalink
Enable cli test (#529)
Browse files Browse the repository at this point in the history
1. Update serve down to support input target model name
2. Update and enable cli test.

<!-- Thank you for your contribution! Please review
https://github.com/autonomi-ai/nos/blob/main/docs/CONTRIBUTING.md before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Summary

<!-- Please give a short summary of the change and the problem this
solves. -->

## Related issues

<!-- For example: "Closes #1234" -->

## Checks

- [ ] `make lint`: I've run `make lint` to lint the changes in this PR.
- [ ] `make test`: I've made sure the tests (`make test-cpu` or `make
test`) are passing.
- Additional tests:
   - [ ] Benchmark tests (when contributing new models)
   - [ ] GPU/HW tests
  • Loading branch information
Jiexiong Tang authored Jan 30, 2024
1 parent 8153126 commit 87e21a4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
18 changes: 13 additions & 5 deletions nos/cli/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,28 @@ def _serve(

@serve_cli.command("down", help="Tear down the NOS server.")
def _serve_down(
target: str = typer.Option(None, "--target", help="Tear down a specific target.", show_default=True),
verbose: bool = typer.Option(False, "-v", "--verbose", help="Verbose output.", show_default=False),
) -> None:
"""Main entrypoint for teardown ."""
from nos.common.system import docker_compose_command
from nos.logging import logger

sandbox_name: str = Path.cwd().name
compose_path = Path.cwd() / f"docker-compose.{sandbox_name}.yml"
if not compose_path.exists():
raise FileNotFoundError(f"File {compose_path} not found, cannot tear down.")
if target is not None:
from nos.constants import NOS_HOME

compose_path = NOS_HOME / f"tmp/serve/docker-compose.{target}.yml"
if not compose_path.exists():
raise FileNotFoundError(f"Target {target} compose file not found, cannot tear down.")
else:
sandbox_name: str = Path.cwd().name
compose_path = Path.cwd() / f"docker-compose.{sandbox_name}.yml"
if not compose_path.exists():
raise FileNotFoundError(f"File {compose_path} not found, cannot tear down.")

# Spin down the docker compose
print(f"[green]✓[/green] Tearing down docker compose with command: [bold white]{compose_path.name} down")
cmd = f"{docker_compose_command} -f {compose_path.name} down"
cmd = f"{docker_compose_command()} -f {compose_path} down"
proc = subprocess.run(cmd, shell=True)
if proc.returncode != 0:
logger.error(f"Failed to tear down, e={proc.stderr}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exclude = [


[tool.setuptools.package-data]
"*" = ["*.json", "*.proto", "*.j2", "test_data/*.*"]
"*" = ["*.json", "*.proto", "*.j2", "test_data/**/*.*"]

[tool.black]
line-length = 119
Expand Down
25 changes: 18 additions & 7 deletions tests/cli/test_cli_serve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import os
from pathlib import Path
from typing import Union
Expand All @@ -10,6 +11,7 @@
runner = CliRunner()


@contextlib.contextmanager
def path_ctx(path: Union[Path, str]):
prev_cwd = Path.cwd()
os.chdir(str(path))
Expand All @@ -24,15 +26,24 @@ def test_cli_serve_help():
assert result.exit_code == 0


@pytest.mark.skip
def test_cli_serve_up():
def test_cli_serve():

from nos.cli.cli import app_cli
from nos.tests.utils import NOS_TEST_DATA_DIR
from nos.test.utils import NOS_TEST_DATA_DIR

config_path = NOS_TEST_DATA_DIR / "hub/custom_model/config.yaml"
# Move to the test data directory
path = NOS_TEST_DATA_DIR / "hub/custom_model/config.yaml"
with path_ctx(config_path.parent):
serve_up_result = runner.invoke(app_cli, ["serve", "up", "-c", "config.yaml", "-d"])
assert serve_up_result.exit_code == 0

with path_ctx(path.parent):
result = runner.invoke(app_cli, ["serve", "-c", "config.yaml", "up"])
assert result.exit_code == 0
from nos.client import Client

# Wait for the server to be ready
client = Client()
client.WaitForServer()
assert client.IsHealthy()

# Tear down the model
serve_down_result = runner.invoke(app_cli, ["serve", "down", "--target", "custom_model"])
assert serve_down_result.exit_code == 0

0 comments on commit 87e21a4

Please sign in to comment.