Skip to content

Commit

Permalink
Fix RuntimeError('dictionary keys changed during iteration') (#59)
Browse files Browse the repository at this point in the history
* Fix RuntimeError('dictionary keys changed during iteration')

* change clab management network configuration

* fix ipv4 management subnet

* fix ipv4 management subnet; delete clab.bak
  • Loading branch information
samuelbarata authored Feb 9, 2025
1 parent 8af98b2 commit c1fbdb3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .clab/ci-topology.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
name: napalm-ci_cd

mgmt:
network: clab_mgmt
ipv4-subnet: 172.20.20.0/24
ipv6-subnet: 2001:172:20:20::/64

topology:
kinds:
srl:
Expand Down
20 changes: 14 additions & 6 deletions napalm_srl/srl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2874,15 +2874,23 @@ def _decodeVal(self, val):
)

def _dictToList(self, aDict):
for key in aDict.keys():
keys_to_update = {}
keys_to_delete = []

for key in list(aDict.keys()): # Use list() to avoid modifying during iteration
if key.startswith("___"):
aDict[key[3:]] = [
keys_to_update[key[3:]] = [
self._dictToList(val) if isinstance(val, dict) else val
for val in aDict[key].values()
]
del aDict[key]
else:
if isinstance(aDict[key], dict):
aDict[key] = self._dictToList(aDict[key])
keys_to_delete.append(key) # Mark for deletion
elif isinstance(aDict[key], dict):
aDict[key] = self._dictToList(aDict[key])

# Apply updates outside the loop
aDict.update(keys_to_update)
for key in keys_to_delete:
del aDict[key]

return aDict

0 comments on commit c1fbdb3

Please sign in to comment.