From 20dc2353f0a06483e4436a3bd64d648151738cbe Mon Sep 17 00:00:00 2001 From: Luca Salvatore Date: Thu, 11 Jul 2024 19:41:01 +0000 Subject: [PATCH 1/3] open tmp_cfgfil with w+ and fix seek --- napalm_srl/srl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/napalm_srl/srl.py b/napalm_srl/srl.py index b9e92e2..4e503bf 100644 --- a/napalm_srl/srl.py +++ b/napalm_srl/srl.py @@ -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") @@ -2295,7 +2295,9 @@ def commit_config(self, message='', revert_in=None): logging.info( f"Checkpoint 'NAPALM-{self.chkpoint_id}' created: {result}" ) if self._is_commit_pending(): + print("pending commit") try: + self.tmp_cfgfile.seek(0) json_config = json.load(self.tmp_cfgfile) if message: raise NotImplementedError("'message' not supported with JSON config") @@ -2311,6 +2313,7 @@ def commit_config(self, message='', revert_in=None): logging.error(e) raise CommitError(e) from e else: + print("no commit pending") return self._cli_commit(message,revert_in) def discard_config(self): @@ -2884,3 +2887,4 @@ def _dictToList(self, aDict): if isinstance(aDict[key], dict): aDict[key] = self._dictToList(aDict[key]) return aDict + From 920f427bb8538a52528a92893b057d2e8c652289 Mon Sep 17 00:00:00 2001 From: Luca Salvatore Date: Thu, 11 Jul 2024 19:47:49 +0000 Subject: [PATCH 2/3] removed debug pring statement --- napalm_srl/srl.py | 1 - 1 file changed, 1 deletion(-) diff --git a/napalm_srl/srl.py b/napalm_srl/srl.py index 4e503bf..a656323 100644 --- a/napalm_srl/srl.py +++ b/napalm_srl/srl.py @@ -2295,7 +2295,6 @@ def commit_config(self, message='', revert_in=None): logging.info( f"Checkpoint 'NAPALM-{self.chkpoint_id}' created: {result}" ) if self._is_commit_pending(): - print("pending commit") try: self.tmp_cfgfile.seek(0) json_config = json.load(self.tmp_cfgfile) From 4259ef86b8aac9f8bbe6e9d3b64a76e49c7268e8 Mon Sep 17 00:00:00 2001 From: Luca Salvatore Date: Thu, 11 Jul 2024 19:50:00 +0000 Subject: [PATCH 3/3] removed another debug print --- napalm_srl/srl.py | 1 - 1 file changed, 1 deletion(-) diff --git a/napalm_srl/srl.py b/napalm_srl/srl.py index a656323..d13eb0a 100644 --- a/napalm_srl/srl.py +++ b/napalm_srl/srl.py @@ -2312,7 +2312,6 @@ def commit_config(self, message='', revert_in=None): logging.error(e) raise CommitError(e) from e else: - print("no commit pending") return self._cli_commit(message,revert_in) def discard_config(self):