Prod upgrade fixes: profiler compatibility with new FastAPI, pinned dependencies
- profiler: Literal instead of Query(enum=...) (broke on FastAPI 0.162) - pin fastapi/starlette/uvicorn/pydantic for the profiler, upper bounds for APP_CORE - health check: show the service log when an HTTP check fails - update.sh: the "before" version comes from deploy.state - migrate.py: hint about OVPMON_*_DB_PATH when the default database is missing - docs: --source --no-pull mode, dependency pinning, PIP_CONSTRAINT - tests: new test for the section parameter, fixed test_server_process.py Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1bbf9b7cc1
commit
79c950f8f7
14 files changed
+156
-38
No files matched your search
@@ -37,6 +37,9 @@ def main(argv=None):
|
||||
if st.too_new:
|
||||
raise migrations._too_new_error(st)
|
||||
print(f"Database: {db_path}" + ("" if st.exists else " (does not exist yet)"))
|
||||
if not st.exists and not args.db:
|
||||
print("Hint: the default database was used; for an installed system set OVPMON_PROFILER_DB_PATH "
|
||||
"(see /etc/ovpmon/env) or pass --db PATH")
|
||||
if args.check:
|
||||
print(f"Schema version: {st.current} (latest known: {migrations.latest_version()})")
|
||||
if not st.pending:
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
fastapi
|
||||
uvicorn
|
||||
fastapi==0.143.3
|
||||
starlette==1.8.0
|
||||
uvicorn==0.54.0
|
||||
pydantic==2.14.1
|
||||
sqlalchemy
|
||||
psutil
|
||||
python-multipart
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Literal, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from database import get_db
|
||||
@@ -13,7 +15,7 @@ router = APIRouter(dependencies=[Depends(verify_token)])
|
||||
|
||||
@router.get("/config", response_model=ConfigResponse)
|
||||
def get_config(
|
||||
section: str = Query(None, enum=["server", "pki"]),
|
||||
section: Optional[Literal["server", "pki"]] = Query(None),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
response = ConfigResponse()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# The DB path must be set before database.py is imported (via main)
|
||||
_tmp = tempfile.TemporaryDirectory()
|
||||
os.environ["OVPMON_PROFILER_DB_PATH"] = os.path.join(_tmp.name, "test.db")
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
from utils.auth import verify_token
|
||||
|
||||
app.dependency_overrides[verify_token] = lambda: {"sub": "test"}
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_config_section_values():
|
||||
r = client.get("/api/config", params={"section": "server"})
|
||||
assert r.status_code == 200 and r.json()["server"] and not r.json().get("pki")
|
||||
assert client.get("/api/config", params={"section": "pki"}).status_code == 200
|
||||
assert client.get("/api/config").status_code == 200
|
||||
assert client.get("/api/config", params={"section": "bogus"}).status_code == 422
|
||||
@@ -1,33 +1,27 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
# The DB path must be set before database.py is imported (via main)
|
||||
_tmp = tempfile.TemporaryDirectory()
|
||||
os.environ["OVPMON_PROFILER_DB_PATH"] = os.path.join(_tmp.name, "test.db")
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add project root to sys.path
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
from utils.auth import verify_token
|
||||
|
||||
app.dependency_overrides[verify_token] = lambda: {"sub": "test"}
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_get_stats():
|
||||
response = client.get("/server/process/stats")
|
||||
print(f"Stats response status: {response.status_code}")
|
||||
print(f"Stats response body: {response.json()}")
|
||||
response = client.get("/api/server/process/stats")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "pid" in data
|
||||
assert "cpu_percent" in data
|
||||
assert "memory_mb" in data
|
||||
|
||||
def test_control_invalid():
|
||||
response = client.post("/server/process/invalid_action")
|
||||
print(f"Invalid action response: {response.status_code}")
|
||||
assert response.status_code == 400
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Running API tests...")
|
||||
try:
|
||||
test_get_stats()
|
||||
test_control_invalid()
|
||||
print("Tests passed!")
|
||||
except Exception as e:
|
||||
print(f"Tests failed: {e}")
|
||||
def test_control_invalid():
|
||||
response = client.post("/api/server/process/invalid_action")
|
||||
assert response.status_code == 400
|
||||
Reference in new issue
Block a user