Implement balance monitoring and notification for Selectel API integration
- Added support for balance tracking using `SELECTEL_API_TOKEN` in the configuration. - Introduced new balance notification logic in the local watchdog, alerting users on balance changes based on defined thresholds. - Updated documentation to include instructions for setting up balance notifications and the required environment variables. - Enhanced the `ready` and `session` modules to initialize balance state and handle notifications during GPU operations. - Refactored the CLI and related components to support the new balance monitoring features, ensuring a seamless user experience.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from gpu_rent.ready import ServiceCheck, _expected_services, verify_stack_local
|
||||
|
||||
|
||||
class _Cfg:
|
||||
enable_swarmui = True
|
||||
llm_runtime = "none"
|
||||
swarmui_local_port = 17801
|
||||
ollama_local_port = 17811
|
||||
llamacpp_local_port = 17812
|
||||
|
||||
|
||||
def test_expected_services_swarm_only():
|
||||
assert _expected_services(_Cfg()) == (True, False, False)
|
||||
|
||||
|
||||
def test_expected_services_llm_only():
|
||||
class C:
|
||||
enable_swarmui = False
|
||||
llm_runtime = "llamacpp"
|
||||
|
||||
assert _expected_services(C()) == (False, False, True)
|
||||
|
||||
|
||||
def test_verify_stack_local_empty_when_nothing():
|
||||
class C:
|
||||
enable_swarmui = False
|
||||
llm_runtime = "none"
|
||||
swarmui_local_port = 17801
|
||||
ollama_local_port = 17811
|
||||
llamacpp_local_port = 17812
|
||||
|
||||
logs: list[str] = []
|
||||
assert verify_stack_local(C(), logs.append, timeout=0.1) == []
|
||||
|
||||
|
||||
def test_verify_stack_local_fails_closed_port(monkeypatch):
|
||||
class C:
|
||||
enable_swarmui = False
|
||||
llm_runtime = "ollama"
|
||||
swarmui_local_port = 17801
|
||||
ollama_local_port = 17999
|
||||
llamacpp_local_port = 17812
|
||||
|
||||
monkeypatch.setattr("gpu_rent.ready._tcp_ok", lambda port, host="127.0.0.1", timeout=0.8: False)
|
||||
logs: list[str] = []
|
||||
try:
|
||||
verify_stack_local(C(), logs.append, timeout=0.3, poll_every=0.1)
|
||||
assert False, "expected CloudError"
|
||||
except Exception as exc:
|
||||
assert "ollama" in str(exc).lower() or "не отвечает" in str(exc)
|
||||
|
||||
|
||||
def test_service_check_dataclass():
|
||||
c = ServiceCheck("x", True, "ok", "vm")
|
||||
assert c.ok and c.where == "vm"
|
||||
Reference in New Issue
Block a user