фикс парсинга 3

This commit is contained in:
dv 2026-04-15 17:30:38 +03:00
parent b64198235d
commit d9f62717ce
2 changed files with 70 additions and 53 deletions

View file

@ -158,7 +158,10 @@ def parse_slave_check(config_text: str, master_ip: str, host: str) -> tuple[bool
(is_slave, identifier, config_text) config_text is passed through unchanged. (is_slave, identifier, config_text) config_text is passed through unchanged.
""" """
parser = RawConfigParser(strict=False) parser = RawConfigParser(strict=False)
try:
parser.read_string(config_text) parser.read_string(config_text)
except _cp.Error as exc:
logger.warning("[discovery] Config parse warning for %s: %s", host, exc)
linking_cls = parser.get("plugin:linking", "cls", fallback="") linking_cls = parser.get("plugin:linking", "cls", fallback="")
linking_uri = parser.get("plugin:linking", "uri", fallback="") linking_uri = parser.get("plugin:linking", "uri", fallback="")
identifier = parser.get("caps.rack", "identifier", fallback="").strip() identifier = parser.get("caps.rack", "identifier", fallback="").strip()

View file

@ -692,6 +692,7 @@ async def _discover_slave_racks(
logger.info("[discovery] Checking slave candidate %s...", candidate_ip) logger.info("[discovery] Checking slave candidate %s...", candidate_ip)
await _emit("disc_action", {"message": f"Проверяем слейв-кандидата {candidate_ip}..."}) await _emit("disc_action", {"message": f"Проверяем слейв-кандидата {candidate_ip}..."})
try:
slave_config = await fetch_slave_config(candidate_ip, ssh_port, ssh_options, config_path) slave_config = await fetch_slave_config(candidate_ip, ssh_port, ssh_options, config_path)
is_slave = False is_slave = False
slave_identifier = "" slave_identifier = ""
@ -733,7 +734,7 @@ async def _discover_slave_racks(
for found in slave_devices: for found in slave_devices:
await _upsert_plugin_device( await _upsert_plugin_device(
db, obj, found, db, obj, found,
external_id="", # not used for slaves (is_slave=True path) external_id="",
rack_id_mapping={}, rack_id_mapping={},
result=result, result=result,
slave_rack_id=slave_rack_id, slave_rack_id=slave_rack_id,
@ -744,6 +745,11 @@ async def _discover_slave_racks(
await db.flush() await db.flush()
except Exception as exc: except Exception as exc:
result.errors.append(f"Flush error after slave {candidate_ip}: {exc}") result.errors.append(f"Flush error after slave {candidate_ip}: {exc}")
logger.error("[discovery] Flush error after slave %s: %s", candidate_ip, exc)
except Exception as exc:
result.errors.append(f"Slave candidate {candidate_ip}: {exc}")
logger.error("[discovery] Error processing slave candidate %s: %s", candidate_ip, exc, exc_info=True)
async def _ensure_slave_rack( async def _ensure_slave_rack(
@ -875,7 +881,11 @@ async def _discover_mikrotik(
ip=mikrotik_ip, hostname="mikrotik", action="ERROR", reason=str(exc), ip=mikrotik_ip, hostname="mikrotik", action="ERROR", reason=str(exc),
category="router", role="other", category="router", role="other",
)) ))
try:
await db.flush() await db.flush()
except Exception as exc:
result.errors.append(f"Flush error after mikrotik upsert: {exc}")
logger.error("[discovery] Flush error after mikrotik: %s", exc)
async def _discover_proxmox( async def _discover_proxmox(
@ -934,7 +944,11 @@ async def _discover_proxmox(
ip=proxmox_ip, hostname=hostname, action="ERROR", reason=str(exc), ip=proxmox_ip, hostname=hostname, action="ERROR", reason=str(exc),
category="vm", role="other", category="vm", role="other",
)) ))
try:
await db.flush() await db.flush()
except Exception as exc:
result.errors.append(f"Flush error after proxmox upsert: {exc}")
logger.error("[discovery] Flush error after proxmox: %s", exc)
# ── Summary logging ─────────────────────────────────────────────────────────── # ── Summary logging ───────────────────────────────────────────────────────────