fix: what bandit and the remaining lint rules found
- The five except Exception: pass (OMV version, smartctl per disk, /proc/mdstat, mdadm --detail, shared folder lookup) now log at debug level with the module logger (B110), so a swallowed failure leaves a trace. The returned data is unchanged. - The get_storage_services docstring example is wrapped to 100 columns.
This commit is contained in:
1 parent
6d82fad80a
commit
9fbbd17530
1 file changed
+20
-10
@@ -18,6 +18,7 @@ Tested against OpenMediaVault 6.x and 7.x (Debian Bullseye / Bookworm base).
|
||||
from __future__ import annotations
|
||||
|
||||
import json as _json
|
||||
import logging
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
@@ -34,6 +35,8 @@ from napalm_device_types.models import (
|
||||
)
|
||||
from napalm_linux.linux import LinuxDriver
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
"""NAPALM driver for OpenMediaVault NAS systems.
|
||||
@@ -78,7 +81,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
if ver:
|
||||
facts["os_version"] = f"OMV {ver}"
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("%s: OMV version not read: ignored", self.hostname, exc_info=True)
|
||||
return facts
|
||||
|
||||
# ── Physical disks ─────────────────────────────────────────────────────────
|
||||
@@ -172,7 +175,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
if rpm_m:
|
||||
rpm = int(rpm_m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("%s: smartctl for %s: ignored", self.hostname, name, exc_info=True)
|
||||
|
||||
result.append(
|
||||
PhysicalDiskDict(
|
||||
@@ -199,7 +202,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
if disk_name in line and re.match(r"^md\d+", line):
|
||||
return line.split(":")[0].strip()
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("%s: /proc/mdstat not read: ignored", self.hostname, exc_info=True)
|
||||
return ""
|
||||
|
||||
# ── md RAID pools ──────────────────────────────────────────────────────────
|
||||
@@ -266,7 +269,9 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
elif re.search(r"State\s*:.*(?:faulty|failed)", detail, re.IGNORECASE):
|
||||
status = "faulted"
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug(
|
||||
"%s: mdadm --detail for %s: ignored", self.hostname, md_name, exc_info=True
|
||||
)
|
||||
|
||||
result[md_name] = DiskPoolDict(
|
||||
name=md_name,
|
||||
@@ -446,11 +451,16 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
Example::
|
||||
|
||||
{
|
||||
"smb": {"name": "smb", "enabled": True, "running": True, "port": 445, "version": ""},
|
||||
"nfs": {"name": "nfs", "enabled": True, "running": True, "port": 2049, "version": ""},
|
||||
"ftp": {"name": "ftp", "enabled": False,"running": False, "port": 21, "version": ""},
|
||||
"ssh": {"name": "ssh", "enabled": True, "running": True, "port": 22, "version": ""},
|
||||
"rsync": {"name": "rsync", "enabled": False,"running": False, "port": 873, "version": ""},
|
||||
"smb": {"name": "smb", "enabled": True, "running": True,
|
||||
"port": 445, "version": ""},
|
||||
"nfs": {"name": "nfs", "enabled": True, "running": True,
|
||||
"port": 2049, "version": ""},
|
||||
"ftp": {"name": "ftp", "enabled": False, "running": False,
|
||||
"port": 21, "version": ""},
|
||||
"ssh": {"name": "ssh", "enabled": True, "running": True,
|
||||
"port": 22, "version": ""},
|
||||
"rsync": {"name": "rsync", "enabled": False, "running": False,
|
||||
"port": 873, "version": ""},
|
||||
}
|
||||
"""
|
||||
_SVC_MAP = [
|
||||
@@ -537,7 +547,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||
break
|
||||
return f"{mnt_dir}/{rel}".rstrip("/") if rel else mnt_dir
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("%s: shared folder %s: ignored", self.hostname, uuid, exc_info=True)
|
||||
return ""
|
||||
|
||||
def _smb_shares(self) -> dict[str, NASShareDict]:
|
||||
|
||||
Reference in new issue
Block a user