Refactor backend: Split models and proxmox_client into modules, add alembic
Some checks failed
Backend Tests / pytest (Python 3.12) (push) Failing after 2m27s

This commit is contained in:
2026-06-13 03:53:27 +05:00
parent 8a879f36fa
commit bfd92102cf
54 changed files with 6026 additions and 5137 deletions

View File

@@ -14,7 +14,7 @@ from loguru import logger
from ..db import SessionLocal
from ..models import BackupJob, ProxmoxServer
from ..proxmox_client import ProxmoxClient
from ..proxmox import ProxmoxClient
# Singleton scheduler instance

View File

@@ -64,7 +64,7 @@ def _fetch_server_resources_with_nodes(server) -> dict:
Pull VMs + containers + per-node CPU/RAM/Disk status + cached RRD slices.
Runs in a thread pool — safe to block.
"""
from ..proxmox_client import get_proxmox_resources
from ..proxmox import get_proxmox_resources
from ..api.proxmox._helpers import _get_proxmox_client
base: dict = {

View File

@@ -20,6 +20,15 @@ def utcnow() -> datetime:
return datetime.now(timezone.utc)
def make_tz_aware(dt: Optional[datetime]) -> Optional[datetime]:
"""Ensure datetime is timezone-aware. Defaults to UTC if naive."""
if dt is None:
return None
if dt.tzinfo is None:
return dt.replace(tzinfo=timezone.utc)
return dt
class SecurityService:
"""Service for security operations"""
@@ -103,7 +112,7 @@ class SecurityService:
# Compare timezone-aware datetimes
now = utcnow()
if blocked.expires_at and blocked.expires_at > now:
if blocked.expires_at and make_tz_aware(blocked.expires_at) > now:
return True, blocked.reason
# Block expired, remove it
@@ -305,7 +314,7 @@ class SecurityService:
# Check expiration
# Compare timezone-aware datetimes
now = utcnow()
if session.expires_at < now:
if make_tz_aware(session.expires_at) < now:
session.is_active = False
db.commit()
return None
@@ -403,7 +412,7 @@ class SecurityService:
return False, None
# Compare timezone-aware datetimes
if user.locked_until > utcnow():
if make_tz_aware(user.locked_until) > utcnow():
return True, user.locked_until
return False, None

View File

@@ -17,12 +17,12 @@ def utcnow() -> datetime:
try:
from backend.app.db import SessionLocal
from backend.app.models import TaskQueue, ProxmoxServer, User
from backend.app.proxmox_client import ProxmoxClient
from backend.app.proxmox import ProxmoxClient
from backend.app.websocket_manager import broadcast_task_update
except ImportError:
from app.db import SessionLocal
from app.models import TaskQueue, ProxmoxServer, User
from app.proxmox_client import ProxmoxClient
from app.proxmox import ProxmoxClient
from app.websocket_manager import broadcast_task_update