Skip to content

Commit c1fbdb3

Browse files
authored
Fix RuntimeError('dictionary keys changed during iteration') (#59)
* Fix RuntimeError('dictionary keys changed during iteration') * change clab management network configuration * fix ipv4 management subnet * fix ipv4 management subnet; delete clab.bak
1 parent 8af98b2 commit c1fbdb3

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

.clab/ci-topology.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
22
name: napalm-ci_cd
33

4+
mgmt:
5+
network: clab_mgmt
6+
ipv4-subnet: 172.20.20.0/24
7+
ipv6-subnet: 2001:172:20:20::/64
8+
49
topology:
510
kinds:
611
srl:

napalm_srl/srl.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,15 +2874,23 @@ def _decodeVal(self, val):
28742874
)
28752875

28762876
def _dictToList(self, aDict):
2877-
for key in aDict.keys():
2877+
keys_to_update = {}
2878+
keys_to_delete = []
2879+
2880+
for key in list(aDict.keys()): # Use list() to avoid modifying during iteration
28782881
if key.startswith("___"):
2879-
aDict[key[3:]] = [
2882+
keys_to_update[key[3:]] = [
28802883
self._dictToList(val) if isinstance(val, dict) else val
28812884
for val in aDict[key].values()
28822885
]
2883-
del aDict[key]
2884-
else:
2885-
if isinstance(aDict[key], dict):
2886-
aDict[key] = self._dictToList(aDict[key])
2886+
keys_to_delete.append(key) # Mark for deletion
2887+
elif isinstance(aDict[key], dict):
2888+
aDict[key] = self._dictToList(aDict[key])
2889+
2890+
# Apply updates outside the loop
2891+
aDict.update(keys_to_update)
2892+
for key in keys_to_delete:
2893+
del aDict[key]
2894+
28872895
return aDict
28882896

0 commit comments

Comments
 (0)