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
|
from __future__ import annotations
|
||||||
|
|
||||||
import json as _json
|
import json as _json
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -34,6 +35,8 @@ from napalm_device_types.models import (
|
|||||||
)
|
)
|
||||||
from napalm_linux.linux import LinuxDriver
|
from napalm_linux.linux import LinuxDriver
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
||||||
"""NAPALM driver for OpenMediaVault NAS systems.
|
"""NAPALM driver for OpenMediaVault NAS systems.
|
||||||
@@ -78,7 +81,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
|||||||
if ver:
|
if ver:
|
||||||
facts["os_version"] = f"OMV {ver}"
|
facts["os_version"] = f"OMV {ver}"
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
logger.debug("%s: OMV version not read: ignored", self.hostname, exc_info=True)
|
||||||
return facts
|
return facts
|
||||||
|
|
||||||
# ── Physical disks ─────────────────────────────────────────────────────────
|
# ── Physical disks ─────────────────────────────────────────────────────────
|
||||||
@@ -172,7 +175,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
|||||||
if rpm_m:
|
if rpm_m:
|
||||||
rpm = int(rpm_m.group(1))
|
rpm = int(rpm_m.group(1))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
logger.debug("%s: smartctl for %s: ignored", self.hostname, name, exc_info=True)
|
||||||
|
|
||||||
result.append(
|
result.append(
|
||||||
PhysicalDiskDict(
|
PhysicalDiskDict(
|
||||||
@@ -199,7 +202,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
|||||||
if disk_name in line and re.match(r"^md\d+", line):
|
if disk_name in line and re.match(r"^md\d+", line):
|
||||||
return line.split(":")[0].strip()
|
return line.split(":")[0].strip()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
logger.debug("%s: /proc/mdstat not read: ignored", self.hostname, exc_info=True)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# ── md RAID pools ──────────────────────────────────────────────────────────
|
# ── md RAID pools ──────────────────────────────────────────────────────────
|
||||||
@@ -266,7 +269,9 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
|||||||
elif re.search(r"State\s*:.*(?:faulty|failed)", detail, re.IGNORECASE):
|
elif re.search(r"State\s*:.*(?:faulty|failed)", detail, re.IGNORECASE):
|
||||||
status = "faulted"
|
status = "faulted"
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
logger.debug(
|
||||||
|
"%s: mdadm --detail for %s: ignored", self.hostname, md_name, exc_info=True
|
||||||
|
)
|
||||||
|
|
||||||
result[md_name] = DiskPoolDict(
|
result[md_name] = DiskPoolDict(
|
||||||
name=md_name,
|
name=md_name,
|
||||||
@@ -446,11 +451,16 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
|||||||
Example::
|
Example::
|
||||||
|
|
||||||
{
|
{
|
||||||
"smb": {"name": "smb", "enabled": True, "running": True, "port": 445, "version": ""},
|
"smb": {"name": "smb", "enabled": True, "running": True,
|
||||||
"nfs": {"name": "nfs", "enabled": True, "running": True, "port": 2049, "version": ""},
|
"port": 445, "version": ""},
|
||||||
"ftp": {"name": "ftp", "enabled": False,"running": False, "port": 21, "version": ""},
|
"nfs": {"name": "nfs", "enabled": True, "running": True,
|
||||||
"ssh": {"name": "ssh", "enabled": True, "running": True, "port": 22, "version": ""},
|
"port": 2049, "version": ""},
|
||||||
"rsync": {"name": "rsync", "enabled": False,"running": False, "port": 873, "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 = [
|
_SVC_MAP = [
|
||||||
@@ -537,7 +547,7 @@ class OpenMediaVaultDriver(StorageDriver, LinuxDriver):
|
|||||||
break
|
break
|
||||||
return f"{mnt_dir}/{rel}".rstrip("/") if rel else mnt_dir
|
return f"{mnt_dir}/{rel}".rstrip("/") if rel else mnt_dir
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
logger.debug("%s: shared folder %s: ignored", self.hostname, uuid, exc_info=True)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _smb_shares(self) -> dict[str, NASShareDict]:
|
def _smb_shares(self) -> dict[str, NASShareDict]:
|
||||||
|
|||||||
Reference in new issue
Block a user