Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Added commit confirm functionality #213

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion napalm_base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,26 @@ def compare_config(self):
"""
raise NotImplementedError

def commit_config(self):
def commit_config(self, confirmed=0):
"""
Commits the changes requested by the method load_replace_candidate or load_merge_candidate.

If you are operating on remote devices without out of band network access and/or there \
is a risk that you could lose access to your device after commit, you can use commit \
confirmed functionality. You have to provide an additional argument (confirmed). \
It defines how long (in minutes) device will wait for your confirmation. \
You can confirm the change by executing commit_confirm(). A device will rollback \
changes by itself if confirmation is not sent or confirmation message can not \
reach the device. For example, device will wait 5 minutes for confirmation, \
after that changes will be reverted::

:param confirmed: Number of minutes until rollback. Don't revert if 0.
"""
raise NotImplementedError

def commit_confirm(self):
"""
Confirm pending commit.
"""
raise NotImplementedError

Expand Down
17 changes: 17 additions & 0 deletions napalm_base/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ def test_replacing_and_committing_config(self):

self.assertEqual(len(diff), 0)

def test_replacing_and_committing_config_with_confirm(self):
try:
self.device.load_replace_candidate(filename='%s/new_good.conf' % self.vendor)
self.device.commit_config(confirmed=60)
self.device.commit_confirm()
except NotImplementedError:
raise SkipTest()

# The diff should be empty as the configuration has been committed already
diff = self.device.compare_config()

# Reverting changes
self.device.load_replace_candidate(filename='%s/initial.conf' % self.vendor)
self.device.commit_config()

self.assertEqual(len(diff), 0)

def test_replacing_config_with_typo(self):
result = False
try:
Expand Down