style: ruff format and the lint rules of the driver standard
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM driver uses (E, F, I, UP, B at line length 100, Python 3.10). What ruff cannot fix comes in the next commit.
This commit is contained in:
1 parent
8145a9f479
commit
b23967417c
3 files changed
+62
-34
No files matched your search
+45
-26
@@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
@@ -44,7 +43,6 @@ from fritzconnection.core.exceptions import (
|
|||||||
FritzServiceError,
|
FritzServiceError,
|
||||||
)
|
)
|
||||||
from napalm.base.exceptions import ConnectionClosedException, ConnectionException
|
from napalm.base.exceptions import ConnectionClosedException, ConnectionException
|
||||||
|
|
||||||
from napalm_device_types import FingerprintRule, ResidentialGatewayDriver
|
from napalm_device_types import FingerprintRule, ResidentialGatewayDriver
|
||||||
from napalm_device_types.models import (
|
from napalm_device_types.models import (
|
||||||
HostDict,
|
HostDict,
|
||||||
@@ -345,10 +343,18 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
result["dsl_downstream_max_rate"] = int(_to_float(info.get("NewDownstreamMaxRate")))
|
result["dsl_downstream_max_rate"] = int(_to_float(info.get("NewDownstreamMaxRate")))
|
||||||
result["dsl_upstream_max_rate"] = int(_to_float(info.get("NewUpstreamMaxRate")))
|
result["dsl_upstream_max_rate"] = int(_to_float(info.get("NewUpstreamMaxRate")))
|
||||||
# SNR margins and attenuation are stored as dB×10 by TR-064
|
# SNR margins and attenuation are stored as dB×10 by TR-064
|
||||||
result["dsl_downstream_noise_margin"] = int(_to_float(info.get("NewDownstreamNoiseMargin")))
|
result["dsl_downstream_noise_margin"] = int(
|
||||||
result["dsl_upstream_noise_margin"] = int(_to_float(info.get("NewUpstreamNoiseMargin")))
|
_to_float(info.get("NewDownstreamNoiseMargin"))
|
||||||
result["dsl_downstream_attenuation"] = int(_to_float(info.get("NewDownstreamAttenuation")))
|
)
|
||||||
result["dsl_upstream_attenuation"] = int(_to_float(info.get("NewUpstreamAttenuation")))
|
result["dsl_upstream_noise_margin"] = int(
|
||||||
|
_to_float(info.get("NewUpstreamNoiseMargin"))
|
||||||
|
)
|
||||||
|
result["dsl_downstream_attenuation"] = int(
|
||||||
|
_to_float(info.get("NewDownstreamAttenuation"))
|
||||||
|
)
|
||||||
|
result["dsl_upstream_attenuation"] = int(
|
||||||
|
_to_float(info.get("NewUpstreamAttenuation"))
|
||||||
|
)
|
||||||
except _OPTIONAL_SERVICE_ERRORS:
|
except _OPTIONAL_SERVICE_ERRORS:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -455,7 +461,12 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
ext_ip = self._call(svc, "GetExternalIPAddress").get("NewExternalIPAddress", "")
|
ext_ip = self._call(svc, "GetExternalIPAddress").get("NewExternalIPAddress", "")
|
||||||
wan_service_used = svc
|
wan_service_used = svc
|
||||||
break
|
break
|
||||||
except (FritzArrayIndexError, FritzServiceError, FritzActionError, FritzConnectionException):
|
except (
|
||||||
|
FritzArrayIndexError,
|
||||||
|
FritzServiceError,
|
||||||
|
FritzActionError,
|
||||||
|
FritzConnectionException,
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
@@ -494,7 +505,9 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
index = 0
|
index = 0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
entry = self._call(service, "GetGenericPortMappingEntry", NewPortMappingIndex=index)
|
entry = self._call(
|
||||||
|
service, "GetGenericPortMappingEntry", NewPortMappingIndex=index
|
||||||
|
)
|
||||||
except (FritzArrayIndexError, FritzConnectionException):
|
except (FritzArrayIndexError, FritzConnectionException):
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -530,15 +543,21 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
except (FritzArrayIndexError, FritzConnectionException, FritzActionError):
|
except (FritzArrayIndexError, FritzConnectionException, FritzActionError):
|
||||||
break
|
break
|
||||||
proto_num = int(ph.get("NewProtocol", 0) or 0)
|
proto_num = int(ph.get("NewProtocol", 0) or 0)
|
||||||
proto = "TCP6" if proto_num == 6 else ("UDP6" if proto_num == 17 else str(proto_num))
|
proto = (
|
||||||
forwards.append({
|
"TCP6"
|
||||||
"name": ph.get("NewPinholeDescription", ""),
|
if proto_num == 6
|
||||||
"protocol": proto,
|
else ("UDP6" if proto_num == 17 else str(proto_num))
|
||||||
"external_port": int(ph.get("NewRemotePort", 0) or 0),
|
)
|
||||||
"internal_ip": ph.get("NewInternalIPAddress", ""),
|
forwards.append(
|
||||||
"internal_port": int(ph.get("NewInternalPort", 0) or 0),
|
{
|
||||||
"enabled": True,
|
"name": ph.get("NewPinholeDescription", ""),
|
||||||
})
|
"protocol": proto,
|
||||||
|
"external_port": int(ph.get("NewRemotePort", 0) or 0),
|
||||||
|
"internal_ip": ph.get("NewInternalIPAddress", ""),
|
||||||
|
"internal_port": int(ph.get("NewInternalPort", 0) or 0),
|
||||||
|
"enabled": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
index += 1
|
index += 1
|
||||||
except _OPTIONAL_SERVICE_ERRORS:
|
except _OPTIONAL_SERVICE_ERRORS:
|
||||||
pass
|
pass
|
||||||
@@ -552,9 +571,9 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
``Hosts1.GetHostNumberOfEntries`` entries.
|
``Hosts1.GetHostNumberOfEntries`` entries.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
count = int(self._call("Hosts1", "GetHostNumberOfEntries").get(
|
count = int(
|
||||||
"NewHostNumberOfEntries", 0
|
self._call("Hosts1", "GetHostNumberOfEntries").get("NewHostNumberOfEntries", 0) or 0
|
||||||
) or 0)
|
)
|
||||||
except _OPTIONAL_SERVICE_ERRORS:
|
except _OPTIONAL_SERVICE_ERRORS:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -631,9 +650,9 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
for service in self._wlan_services():
|
for service in self._wlan_services():
|
||||||
try:
|
try:
|
||||||
ssid = self._call(service, "GetInfo").get("NewSSID", "")
|
ssid = self._call(service, "GetInfo").get("NewSSID", "")
|
||||||
total = int(self._call(service, "GetTotalAssociations").get(
|
total = int(
|
||||||
"NewTotalAssociations", 0
|
self._call(service, "GetTotalAssociations").get("NewTotalAssociations", 0) or 0
|
||||||
) or 0)
|
)
|
||||||
except _OPTIONAL_SERVICE_ERRORS:
|
except _OPTIONAL_SERVICE_ERRORS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -680,9 +699,9 @@ class FritzBoxDriver(ResidentialGatewayDriver):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
clients = int(self._call(service, "GetTotalAssociations").get(
|
clients = int(
|
||||||
"NewTotalAssociations", 0
|
self._call(service, "GetTotalAssociations").get("NewTotalAssociations", 0) or 0
|
||||||
) or 0)
|
)
|
||||||
except _OPTIONAL_SERVICE_ERRORS:
|
except _OPTIONAL_SERVICE_ERRORS:
|
||||||
clients = 0
|
clients = 0
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -48,7 +48,14 @@ include = ["napalm_fritzbox*"]
|
|||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
line-length = 100
|
line-length = 100
|
||||||
target-version = "py39"
|
target-version = "py310"
|
||||||
|
|
||||||
|
[tool.ruff.lint]
|
||||||
|
select = ["E", "F", "I", "UP", "B"]
|
||||||
|
|
||||||
|
[tool.ruff.lint.per-file-ignores]
|
||||||
|
# Recorded device output keeps its lines.
|
||||||
|
"tests/**" = ["E501"]
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
testpaths = ["tests"]
|
testpaths = ["tests"]
|
||||||
@@ -6,7 +6,6 @@ import pytest
|
|||||||
from fritzconnection.core.exceptions import (
|
from fritzconnection.core.exceptions import (
|
||||||
FritzActionError,
|
FritzActionError,
|
||||||
FritzArrayIndexError,
|
FritzArrayIndexError,
|
||||||
FritzServiceError,
|
|
||||||
)
|
)
|
||||||
from napalm.base.exceptions import ConnectionClosedException, ConnectionException
|
from napalm.base.exceptions import ConnectionClosedException, ConnectionException
|
||||||
|
|
||||||
@@ -135,9 +134,9 @@ DSL_INFO = {
|
|||||||
"NewDownstreamMaxRate": 120000,
|
"NewDownstreamMaxRate": 120000,
|
||||||
"NewUpstreamMaxRate": 50000,
|
"NewUpstreamMaxRate": 50000,
|
||||||
"NewDownstreamNoiseMargin": 120, # 12.0 dB
|
"NewDownstreamNoiseMargin": 120, # 12.0 dB
|
||||||
"NewUpstreamNoiseMargin": 80, # 8.0 dB
|
"NewUpstreamNoiseMargin": 80, # 8.0 dB
|
||||||
"NewDownstreamAttenuation": 150, # 15.0 dB
|
"NewDownstreamAttenuation": 150, # 15.0 dB
|
||||||
"NewUpstreamAttenuation": 90, # 9.0 dB
|
"NewUpstreamAttenuation": 90, # 9.0 dB
|
||||||
}
|
}
|
||||||
|
|
||||||
DSL_STATS = {
|
DSL_STATS = {
|
||||||
@@ -639,7 +638,8 @@ class TestPPPoEInterface:
|
|||||||
class TestAutoMaxBitRate:
|
class TestAutoMaxBitRate:
|
||||||
def test_lan_speed_zero_when_auto(self, driver):
|
def test_lan_speed_zero_when_auto(self, driver):
|
||||||
driver.fc.call_action.side_effect = lambda svc, act, **kw: (
|
driver.fc.call_action.side_effect = lambda svc, act, **kw: (
|
||||||
LAN_INFO_AUTO_RATE if (svc, act) == ("LANEthernetInterfaceConfig1", "GetInfo")
|
LAN_INFO_AUTO_RATE
|
||||||
|
if (svc, act) == ("LANEthernetInterfaceConfig1", "GetInfo")
|
||||||
else _call_action(svc, act, **kw)
|
else _call_action(svc, act, **kw)
|
||||||
)
|
)
|
||||||
interfaces = driver.get_interfaces()
|
interfaces = driver.get_interfaces()
|
||||||
@@ -690,7 +690,8 @@ class TestGetSystemConfig:
|
|||||||
|
|
||||||
def test_firmware_not_available_when_none(self, driver):
|
def test_firmware_not_available_when_none(self, driver):
|
||||||
driver.fc.call_action.side_effect = lambda svc, act, **kw: (
|
driver.fc.call_action.side_effect = lambda svc, act, **kw: (
|
||||||
UI_INFO_NO_UPDATE if (svc, act) == ("UserInterface1", "X_AVM-DE_GetInfo")
|
UI_INFO_NO_UPDATE
|
||||||
|
if (svc, act) == ("UserInterface1", "X_AVM-DE_GetInfo")
|
||||||
else _call_action(svc, act, **kw)
|
else _call_action(svc, act, **kw)
|
||||||
)
|
)
|
||||||
assert driver.get_system_config()["firmware_update_available"] is False
|
assert driver.get_system_config()["firmware_update_available"] is False
|
||||||
@@ -730,8 +731,9 @@ class TestIPv6Pinholes:
|
|||||||
def test_pinholes_are_not_reported_as_nat_translations(self, driver):
|
def test_pinholes_are_not_reported_as_nat_translations(self, driver):
|
||||||
"""A pinhole opens the firewall for a globally routable address; there
|
"""A pinhole opens the firewall for a globally routable address; there
|
||||||
is nothing to translate."""
|
is nothing to translate."""
|
||||||
assert all(":" not in t["inside_local"].rsplit(":", 1)[0]
|
assert all(
|
||||||
for t in driver.get_nat_translations())
|
":" not in t["inside_local"].rsplit(":", 1)[0] for t in driver.get_nat_translations()
|
||||||
|
)
|
||||||
|
|
||||||
def test_no_pinholes_without_ipv6_service(self, driver):
|
def test_no_pinholes_without_ipv6_service(self, driver):
|
||||||
del driver.fc.services["WANIPv6Firewall1"]
|
del driver.fc.services["WANIPv6Firewall1"]
|
||||||
|
|||||||
Reference in new issue
Block a user