фикс прошлого

This commit is contained in:
dv 2026-04-10 13:46:15 +03:00
parent 2f3edb680a
commit 67f440682f
3 changed files with 24 additions and 8 deletions

View file

@ -17,12 +17,6 @@ logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)
from app.config import settings # noqa: E402
if not settings.SQLALCHEMY_LOG:
logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING)
logging.getLogger("sqlalchemy.pool").setLevel(logging.WARNING)
logging.getLogger("sqlalchemy.dialects").setLevel(logging.WARNING)
@asynccontextmanager
async def lifespan(app: FastAPI):

View file

@ -1,3 +1,5 @@
import logging
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from app.config import settings
@ -8,6 +10,10 @@ engine = create_async_engine(
pool_pre_ping=True,
)
if not settings.SQLALCHEMY_LOG:
for _log_name in ("sqlalchemy.engine", "sqlalchemy.pool", "sqlalchemy.dialects", "sqlalchemy.orm"):
logging.getLogger(_log_name).setLevel(logging.WARNING)
AsyncSessionLocal = async_sessionmaker(
bind=engine,
class_=AsyncSession,

View file

@ -462,7 +462,18 @@ async def _autodetect_db_from_server_multi(
async def _ssh_run_multi(host: str, port: int, options: list, command: str, timeout: int = 15) -> str:
"""Try multiple SSH auth options to run a command; return stdout on success or raise."""
last_exc: Exception = Exception("No auth options provided")
for opt in options:
for i, opt in enumerate(options):
if opt.type == "key":
logger.info(
"[ssh_discovery] SSH attempt %d/%d for %s — key: user=%s key_path=%s",
i + 1, len(options), host, opt.username, opt.key_path,
)
else:
masked = (opt.password[:1] + "***" + opt.password[-1:]) if len(opt.password) > 2 else "***"
logger.info(
"[ssh_discovery] SSH attempt %d/%d for %s — password: user=%s password=%s",
i + 1, len(options), host, opt.username, masked,
)
try:
connect_kwargs: dict = dict(
host=host, port=port, username=opt.username,
@ -475,10 +486,11 @@ async def _ssh_run_multi(host: str, port: int, options: list, command: str, time
connect_kwargs["password"] = opt.password
async with asyncssh.connect(**connect_kwargs) as conn:
result = await asyncio.wait_for(conn.run(command, check=True), timeout=timeout)
logger.info("[ssh_discovery] SSH auth succeeded for %s with %s(%s)", host, opt.type, opt.username)
return result.stdout
except Exception as exc:
last_exc = exc
logger.debug(f"[ssh_discovery] Auth {opt.type}/{opt.username} failed for {host}: {exc}")
logger.info("[ssh_discovery] SSH auth failed for %s with %s(%s): %s", host, opt.type, opt.username, exc)
raise last_exc
@ -700,6 +712,10 @@ async def discover_via_ssh(
# Step 1: get rack hosts from object's DB
await _emit("disc_action", {"message": "Получение списка стоек из БД..."})
logger.info(
"[ssh_discovery] Connecting to object DB: host=%s port=%s dbname=%s user=%s table=%s via_tunnel=%s",
db_host, db_port, db_name, db_user, db_table, obj.db_via_tunnel,
)
try:
rack_hosts = await _get_rack_hosts_direct(
host=db_host,