Skip to content

Commit

Permalink
Merge pull request #69 from jbemmel/fix-commit-error-handling
Browse files Browse the repository at this point in the history
Fix error handling for commit errors and raise rollback exception
  • Loading branch information
jbemmel authored Oct 29, 2023
2 parents 5f2da2d + fdd6e54 commit e8e24f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ NAPALM integration is validated with a minimum of Nokia Service Router Operating
6) For testing, please refer to [Test Document](https://github.com/napalm-automation-community/napalm-sros/blob/master/README_TEST.md)

#### **Components Version**
1) Python - 3.6
1) Python - 3.8 or higher
2) ncclient >= 0.6.13
3) paramiko >= 2.11.0
4) NAPALM >= 3.4.1
4) NAPALM >= 4.0.0

##### **Note**
This version of the driver leverages Nokia’s defined YANG models for configuration and state trees for the SROS platform. While SROS also support limited configuration and state retrieval using openconfig standard models, the NAPALM driver does not support configuration or state retrieval of openconfig data models.
This version of the driver leverages Nokia’s defined YANG models for configuration and state trees for the SROS platform. While SROS also supports limited configuration and state retrieval using openconfig standard models, the NAPALM driver does not support configuration or state retrieval of openconfig data models.

#### License
This project is licensed under the Apache-2.0 license - see the [LICENSE](LICENSE) file.
19 changes: 10 additions & 9 deletions napalm_sros/sros.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import json
import time
import re
import logging
import datetime
import traceback
import xmltodict
Expand All @@ -41,6 +40,8 @@
SessionLockedException,
MergeConfigException,
ReplaceConfigException,
CommitError,
CommandErrorException,
)
from napalm.base.helpers import convert, ip, as_number
import napalm.base.constants as C
Expand Down Expand Up @@ -295,14 +296,14 @@ def _find_txt(self, xml_tree, path, default="", namespaces=None):
value = xpath_result
else:
if xpath_applied == "":
logging.error(
log.error(
"Unable to find the specified-text-element/XML path: %s in \
the XML tree provided. Total Items in XML tree: %d "
% (path, xpath_length)
)
except Exception as e: # in case of any exception, returns default
print("Error while finding text in xml: {}".format(e))
logging.error("Error while finding text in xml: %s" % traceback.format_exc())
log.error("Error while finding text in xml: %s" % traceback.format_exc())
value = default
return str(value)

Expand All @@ -323,7 +324,7 @@ def is_alive(self):
return is_alive_dict
except Exception as e: # in case of any exception, returns default
print("Error occurred in is_alive method: {}".format(e))
logging.error("Error occurred in is_alive: %s" % traceback.format_exc())
log.error("Error occurred in is_alive: %s" % traceback.format_exc())

def discard_config(self):
"""
Expand All @@ -345,14 +346,13 @@ def commit_config(self, message="", revert_in=None):
# If error while performing commit, return the error
error = ""
for item in buff.split("\n"):
if self.cmd_line_pattern_re.search(item):
continue
if any(match.search(item) for match in self.terminal_stderr_re):
row = item.strip()
row_list = row.split(": ")
error += row_list[2]
if error:
print("Error while commit: ", error)
log.error(f"Error during commit: {error}")
raise CommitError(error)
elif self.fmt == "xml":
self.conn.commit()
if not self.lock_disable and not self.session_config_lock:
Expand All @@ -375,8 +375,8 @@ def rollback(self):
row_list = row.split(": ")
error += row_list[2]
if error:
print("Error while rollback: ", error)
break
log.error(f"Error during rollback: {error}")
raise CommandErrorException(error)

def compare_config(self):
"""
Expand Down Expand Up @@ -551,6 +551,7 @@ def load_replace_candidate(self, filename=None, config=None):
if buff is not None:
for item in buff.split("\n"):
if any(match.search(item) for match in self.terminal_stderr_re):
log.error( f"Replace issue: {item}" )
raise ReplaceConfigException("Replace issue: %s", item)
else:
raise ReplaceConfigException("Timeout during load_replace_candidate")
Expand Down

0 comments on commit e8e24f0

Please sign in to comment.