Skip to content

Commit

Permalink
Merge pull request #55 from lucasalvatore/dev
Browse files Browse the repository at this point in the history
open tmp_cfgfil with w+ and fix seek
  • Loading branch information
jbemmel authored Jul 15, 2024
2 parents 5cf6abd + 4259ef8 commit 8af98b2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion napalm_srl/srl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2264,7 +2264,7 @@ def _load_candidate(self,filename,config,is_replace):
else:
cfg = { 'replaces' if is_replace else 'updates': [ { 'path': '/', 'value': cfg } ] }

self.tmp_cfgfile = tempfile.TemporaryFile(mode='w')
self.tmp_cfgfile = tempfile.TemporaryFile(mode='w+')
json.dump(cfg, self.tmp_cfgfile, sort_keys=True)
self.tmp_cfgfile.seek(0) # Prepare for reading back
return "JSON candidate config loaded for " + ("replace" if is_replace else "merge")
Expand Down Expand Up @@ -2296,6 +2296,7 @@ def commit_config(self, message='', revert_in=None):

if self._is_commit_pending():
try:
self.tmp_cfgfile.seek(0)
json_config = json.load(self.tmp_cfgfile)
if message:
raise NotImplementedError("'message' not supported with JSON config")
Expand Down Expand Up @@ -2884,3 +2885,4 @@ def _dictToList(self, aDict):
if isinstance(aDict[key], dict):
aDict[key] = self._dictToList(aDict[key])
return aDict

0 comments on commit 8af98b2

Please sign in to comment.