fix: what bandit and the remaining lint rules found
- set_interface: the except Exception: pass around reading the old untagged VLANs now logs at debug level (B110), with a module logger. - nosec for the empty password field of get_users (B105, now a named constant); a false positive. - Two docstrings quoting tabular device output keep their lines (noqa E501); a long docstring and an error message are shortened or split; the unused duplex column is named _duplex. - tests: a get_facts test named SHOW_INTERFACE, which does not exist; it is SHOW_INTERFACE_STATUS. raise ... from exc.
This commit is contained in:
1 parent
e53a4b4cc6
commit
bef2f23ab2
3 files changed
+16
-9
No files matched your search
@@ -18,6 +18,7 @@ Netmiko device_type: ``tplink_jetstream``
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import Any, ClassVar
|
||||
|
||||
@@ -38,6 +39,11 @@ from napalm_device_types.ssh_host_keys import HostKeyCheck, SshHostKeyMismatch
|
||||
from netmiko import ConnectHandler
|
||||
from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
#: get_users' password field: the switch never shows a password, so it stays empty.
|
||||
_PASSWORD_NOT_SHOWN = "" # nosec B105
|
||||
|
||||
|
||||
class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
"""NAPALM driver for TP-Link Jetstream managed switches."""
|
||||
@@ -372,7 +378,7 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
|
||||
Port State Speed Duplex FlowCtrl Description
|
||||
Gi1/0/1 Enable Auto Auto Disable uplink
|
||||
"""
|
||||
""" # noqa: E501 - recorded device output keeps its lines
|
||||
jumbo_out = self._send_command("show jumbo")
|
||||
global_mtu = 1518
|
||||
m = re.search(r"(\d+)", jumbo_out)
|
||||
@@ -446,7 +452,7 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
)
|
||||
if not match:
|
||||
continue
|
||||
port, status, speed, duplex, _, _, _, _, description = (
|
||||
port, status, speed, _duplex, _, _, _, _, description = (
|
||||
match.group(1),
|
||||
match.group(2),
|
||||
match.group(3),
|
||||
@@ -703,7 +709,7 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
Port Device ID Port ID management address Port Description System Name
|
||||
---- ------------ -------- ------------------ ---------------- -----------
|
||||
Gi1/0/9 64:E8:81:E1:29:00 2 10.7.0.10 2 swt-l0-1-10
|
||||
"""
|
||||
""" # noqa: E501 - recorded device output keeps its lines
|
||||
neighbors: dict[str, list[dict]] = {}
|
||||
for row in self._get_lldp_table():
|
||||
neighbors.setdefault(row["local_port"], []).append(
|
||||
@@ -1026,7 +1032,7 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
|
||||
@staticmethod
|
||||
def _to_cli_interface(port: str) -> str:
|
||||
"""Convert abbreviated port name (e.g. ``Gi1/0/1``) to CLI form (``gigabitEthernet 1/0/1``)."""
|
||||
"""Convert a short port name (``Gi1/0/1``) to CLI form (``gigabitEthernet 1/0/1``)."""
|
||||
_PREFIX_MAP = {
|
||||
"gi": "gigabitEthernet",
|
||||
"te": "ten-gigabitEthernet",
|
||||
@@ -1150,7 +1156,8 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
"""
|
||||
if self._backup_config is None:
|
||||
raise CommandErrorException(
|
||||
"No backup configuration available – commit_config has not been called in this session."
|
||||
"No backup configuration available – "
|
||||
"commit_config has not been called in this session."
|
||||
)
|
||||
|
||||
current = self._send_command("show running-config")
|
||||
@@ -1423,7 +1430,7 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
# Map TP-Link roles to NAPALM privilege levels (1-15)
|
||||
level = 15 if role == "admin" else 1
|
||||
|
||||
users[username] = {"level": level, "password": "", "sshkeys": []}
|
||||
users[username] = {"level": level, "password": _PASSWORD_NOT_SHOWN, "sshkeys": []}
|
||||
|
||||
return users
|
||||
|
||||
@@ -1618,7 +1625,7 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
|
||||
if interface in vlan_info.get("untagged", []) and vid_str != new_vid:
|
||||
old_untagged_vlans.append(vid_str)
|
||||
except Exception:
|
||||
pass
|
||||
logger.debug("reading the old untagged VLANs: ignored", exc_info=True)
|
||||
|
||||
self._enter_config_mode()
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user