Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eos config_session not cleared if discard failed #1921

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/support/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ ____________________________________
* :code:`eos_fn0039_config` (eos) - Transform old style configuration to the new style, available beginning with EOS release 4.23.0, as per FN 0039. Beware
that enabling this option will change the configuration you're loading through NAPALM. Default: ``False`` (won't change your configuration commands).
.. versionadded:: 3.0.1
* :code:`force_cfg_session_invalid` (eos) - Force the config_session to be cleared in case of issues, like `discard_config` failure. (default: ``False``)

The transport argument
______________________
Expand Down
14 changes: 12 additions & 2 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
Optional args:
* lock_disable (True/False): force configuration lock to be disabled (for external lock
management).
* force_cfg_session_invalid (True/False): force invalidation of the config session
in case of failure.
* enable_password (True/False): Enable password for privilege elevation
* eos_autoComplete (True/False): Allow for shortening of cli commands
* transport (string): transport, eos_transport is a fallback for compatibility.
Expand Down Expand Up @@ -134,6 +136,10 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
# Define locking method
self.lock_disable = self.optional_args.pop("lock_disable", False)

self.force_cfg_session_invalid = self.optional_args.pop(
"force_cfg_session_invalid", False
)

# eos_transport is there for backwards compatibility, transport is the preferred method
transport = self.optional_args.get(
"transport", self.optional_args.get("eos_transport", "https")
Expand All @@ -150,7 +156,6 @@ def _process_optional_args_ssh(self, optional_args):
self.netmiko_optional_args = netmiko_args(optional_args)

def _process_optional_args_eapi(self, optional_args):

# Parse pyeapi transport class
self.transport_class = self._parse_transport(self.transport)

Expand Down Expand Up @@ -543,7 +548,12 @@ def confirm_commit(self):
def discard_config(self):
"""Implementation of NAPALM method discard_config."""
if self.config_session is not None:
commands = [f"configure session {self.config_session} abort"]
config_session = self.config_session

if self.force_cfg_session_invalid:
self.config_session = None

commands = [f"configure session {config_session} abort"]
self._run_commands(commands, encoding="text")
self.config_session = None

Expand Down