fix: rescue gcp ollama through proxy
All checks were successful
CD Pipeline / deploy (push) Successful in 1m9s

This commit is contained in:
OoO
2026-06-18 12:13:38 +08:00
parent 9bafa73ffc
commit ee50e440ce
6 changed files with 91 additions and 6 deletions

View File

@@ -75,6 +75,31 @@ def test_resolve_falls_back_on_request_exception():
assert host == 'http://fallback.example:11434'
def test_resolve_uses_primary_proxy_rescue_before_secondary():
"""正式主機直連 GCP-A 不通時,先走 110 primary proxy再考慮 GCP-B。"""
from services import ollama_service as oss
fake_ok = MagicMock(status_code=200)
seen_urls = []
def fake_get(url, timeout=None):
seen_urls.append(url)
if url == f"{oss.OLLAMA_HOST_PRIMARY}/api/version":
raise Exception("primary direct timeout")
if url == f"{oss.OLLAMA_HOST_PRIMARY_PROXY}/api/version":
return fake_ok
raise AssertionError(f"should not reach {url}")
with patch('services.ollama_service.requests.get', side_effect=fake_get):
host = oss.resolve_ollama_host()
assert host == oss.OLLAMA_HOST_PRIMARY_PROXY
assert seen_urls == [
f"{oss.OLLAMA_HOST_PRIMARY}/api/version",
f"{oss.OLLAMA_HOST_PRIMARY_PROXY}/api/version",
]
# ═══════════════════════════════════════════════════════════════════════════
# B4 — mark_unhealthy 行為
# ═══════════════════════════════════════════════════════════════════════════