- Removed deprecated console usage in favor of structured logging functions for error handling and user prompts. - Enhanced CLI prompts for LLM runtime and preset selection, utilizing menu helpers for better user interaction. - Updated GPU pool scanning output with improved formatting and error indication for clarity. - Refactored setup wizard to streamline LLM runtime and preset configuration, ensuring a more intuitive setup process. - Improved documentation and user feedback in CLI outputs to enhance overall usability.
62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
from gpu_rent.inventory import FlavorInfo
|
|
from gpu_rent.ux import prompt_server_plan
|
|
from gpu_rent.varsfile import parse_vars_file, upsert_vars
|
|
|
|
|
|
def _cfg_stub(monkeypatch, data_gb: int = 100):
|
|
monkeypatch.setenv("OS_AUTH_URL", "https://example.invalid/identity/v3")
|
|
monkeypatch.setenv("OS_USER_DOMAIN_NAME", "999")
|
|
monkeypatch.setenv("OS_USERNAME", "svc")
|
|
monkeypatch.setenv("OS_PASSWORD", "secret")
|
|
monkeypatch.setenv("OS_PROJECT_ID", "proj")
|
|
monkeypatch.setenv("OS_REGION_NAME", "ru-7")
|
|
monkeypatch.setenv("GPU_RENT_AZ", "ru-7a")
|
|
monkeypatch.setenv("DATA_VOLUME_SIZE_GB", str(data_gb))
|
|
from gpu_rent.config import load_config
|
|
|
|
return load_config(require_auth=True)
|
|
|
|
|
|
def test_prompt_server_plan_with_ranked(monkeypatch, tmp_path):
|
|
cfg = _cfg_stub(monkeypatch)
|
|
monkeypatch.setattr("gpu_rent.paths.app_root", lambda: tmp_path)
|
|
f1 = FlavorInfo(
|
|
id="a", name="small", vcpus=4, ram_mb=16384, disabled=False, extra={}, label="4090-24"
|
|
)
|
|
f2 = FlavorInfo(
|
|
id="b", name="big", vcpus=12, ram_mb=65536, disabled=False, extra={}, label="4090-48"
|
|
)
|
|
|
|
monkeypatch.setattr(
|
|
"gpu_rent.ux.list_ranked_flavors",
|
|
lambda flavors, cfg: [f1, f2],
|
|
)
|
|
answers = iter(["2", "200", "2"])
|
|
|
|
def ask(msg: str, default: str = "") -> str:
|
|
return next(answers)
|
|
|
|
remembered: list[bool] = []
|
|
|
|
plan = prompt_server_plan(
|
|
cfg,
|
|
["x"],
|
|
picked=f1,
|
|
spot=True,
|
|
ask=ask,
|
|
confirm=lambda m: remembered.append(True) or False,
|
|
)
|
|
assert plan.flavor.id == "b"
|
|
assert plan.data_gb == 200
|
|
assert plan.spot is False
|
|
assert remembered
|
|
|
|
|
|
def test_upsert_vars(tmp_path):
|
|
path = tmp_path / "gpu-rent.vars"
|
|
path.write_text("# c\nLLM_RUNTIME=none\n", encoding="utf-8")
|
|
upsert_vars(path, {"LLM_RUNTIME": "llamacpp", "DATA_VOLUME_SIZE_GB": "200"})
|
|
data = parse_vars_file(path)
|
|
assert data["LLM_RUNTIME"] == "llamacpp"
|
|
assert data["DATA_VOLUME_SIZE_GB"] == "200"
|