Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/pip/types-requests-2.32.0.2024…
Browse files Browse the repository at this point in the history
…0712
  • Loading branch information
ktbyers authored Feb 20, 2025
2 parents f976632 + d21c466 commit 7063899
Show file tree
Hide file tree
Showing 67 changed files with 2,423 additions and 2,694 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ docs/_static/
.venv
.vscode
.devcontainer
.python-version

env
*.swp
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
urllib3==2.2.1 # https://github.com/readthedocs/readthedocs.org/issues/10290
urllib3==2.2.2 # https://github.com/readthedocs/readthedocs.org/issues/10290
sphinx==7.3.7
sphinx-rtd-theme==2.0.0
invoke==2.2.0
jinja2==3.1.4
MarkupSafe==2.1.5
pytest==8.2.1
ansible==9.6.0
ansible==9.6.1
15 changes: 13 additions & 2 deletions napalm/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,23 @@ def get_ntp_servers(self) -> Dict[str, models.NTPServerDict]:
"""
Returns the NTP servers configuration as dictionary.
The keys of the dictionary represent the IP Addresses of the servers.
Inner dictionaries do not have yet any available keys.
Inner dictionaries MAY contain information regarding per-server configuration.
Example::
{
'192.168.0.1': {},
'192.168.0.1':
{
'address': '192.168.0.1',
'port': 123,
'version': 4,
'association_type': 'SERVER',
'iburst': False,
'prefer': False,
'network_instance': 'default',
'source_address': '192.0.2.1',
'key_id': -1,
},
'17.72.148.53': {},
'37.187.56.220': {},
'162.158.20.18': {}
Expand Down
20 changes: 13 additions & 7 deletions napalm/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@
},
)

BGPStateAdressFamilyDict = TypedDict(
"BGPStateAdressFamilyDict",
BGPStateAddressFamilyDict = TypedDict(
"BGPStateAddressFamilyDict",
{"received_prefixes": int, "accepted_prefixes": int, "sent_prefixes": int},
)

Expand All @@ -203,7 +203,7 @@
"is_enabled": bool,
"description": str,
"uptime": int,
"address_family": Dict[str, BGPStateAdressFamilyDict],
"address_family": Dict[str, BGPStateAddressFamilyDict],
},
)

Expand All @@ -223,16 +223,22 @@

NTPPeerDict = TypedDict(
"NTPPeerDict",
{
# will populate it in the future wit potential keys
},
{},
total=False,
)

NTPServerDict = TypedDict(
"NTPServerDict",
{
# will populate it in the future wit potential keys
"address": str,
"port": int,
"version": int,
"association_type": str,
"iburst": bool,
"prefer": bool,
"network_instance": str,
"source_address": str,
"key_id": int,
},
total=False,
)
Expand Down
8 changes: 6 additions & 2 deletions napalm/base/test/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ def test_get_ntp_peers(self, test_case):

for peer, peer_details in get_ntp_peers.items():
assert isinstance(peer, str)
assert helpers.test_model(models.NTPPeerDict, peer_details)
assert helpers.test_model(
models.NTPPeerDict, peer_details, allow_subset=True
)

return get_ntp_peers

Expand All @@ -323,7 +325,9 @@ def test_get_ntp_servers(self, test_case):

for server, server_details in get_ntp_servers.items():
assert isinstance(server, str)
assert helpers.test_model(models.NTPServerDict, server_details)
assert helpers.test_model(
models.NTPServerDict, server_details, allow_subset=True
)

return get_ntp_servers

Expand Down
19 changes: 12 additions & 7 deletions napalm/base/test/helpers.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
"""Several methods to help with the tests."""


def test_model(model, data):
def test_model(model, data, allow_subset=False):
"""Return if the dictionary `data` complies with the `model`."""
# Access the underlying schema for a TypedDict directly
model = model.__annotations__
same_keys = set(model.keys()) == set(data.keys())
annotations = model.__annotations__
if allow_subset:
same_keys = set(data.keys()) <= set(annotations.keys())
source = data
else:
same_keys = set(annotations.keys()) == set(data.keys())
source = annotations

if not same_keys:
print(
"model_keys: {}\ndata_keys: {}".format(
sorted(model.keys()), sorted(data.keys())
sorted(annotations.keys()), sorted(data.keys())
)
)

correct_class = True
for key, instance_class in model.items():
correct_class = isinstance(data[key], instance_class) and correct_class
for key in source.keys():
correct_class = isinstance(data[key], annotations[key]) and correct_class
if not correct_class:
print(
"key: {}\nmodel_class: {}\ndata_class: {}".format(
key, instance_class, data[key].__class__
key, annotations[key], data[key].__class__
)
)

Expand Down
Loading

0 comments on commit 7063899

Please sign in to comment.