fix: what bandit and the remaining lint rules found

- The six except Exception: pass (REST logout, the extra-ports lookup, the
  per-port detail in get_interfaces, closing CLI and REST sessions) now log
  at debug level (B110), so a swallowed failure leaves a trace.
- nosec for comparing a reported address with 0.0.0.0 (B104) and for the
  empty password field of get_users (B105, now a named constant); both are
  false positives.
- A long error message is split into adjacent f-strings; the unused ARP
  entry type is named _entry_type.
- tests: the failed-open test expects ConnectionException instead of any
  Exception; raise ... from exc.
This commit is contained in:
Christian Manivong committed 2026-10-23 08:34:55 +02:00
1 parent c2a788fa7a
commit fc24495b83
5 files changed
+19 -13

No files matched your search

+6 -5
View File
@@ -238,7 +238,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
try:
self._device.disconnect()
except Exception:
pass
logger.debug("closing the CLI session: ignored", exc_info=True)
self._device = None
self._transport = None
@@ -556,7 +556,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
if detail.get("description"):
ifaces[port]["description"] = detail["description"]
except Exception:
pass
logger.debug("show interfaces %s: ignored", port, exc_info=True)
# The CLI lists member ports only ("3-Trk3"); the trunk gets its own row.
return add_lag_interfaces(ifaces)
@@ -643,7 +643,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
try:
self._api._session.close()
except Exception:
pass
logger.debug("closing the REST session: ignored", exc_info=True)
running = self._get_config_via_ssh()
return {"running": running, "startup": "", "candidate": ""}
@@ -971,7 +971,8 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
resp = self._api.put(f"ports/{interface}", json=patch)
if not resp.ok:
raise ConnectionException(
f"set_interface({interface}): ports PUT HTTP {resp.status_code} – {resp.text[:200]}"
f"set_interface({interface}): ports PUT HTTP {resp.status_code} – "
f"{resp.text[:200]}"
)
mode = config.get("mode")
if mode == "trunk":
@@ -1286,7 +1287,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
try:
self._device.disconnect()
except Exception: # noqa: BLE001 - closing a temporary session
pass
logger.debug("closing the temporary CLI session: ignored", exc_info=True)
self._api, self._device, self._transport = old_api, old_device, old_transport
def _snmp_configure_cli(self, settings: dict[str, Any]) -> dict[str, Any]: