Skip to content

Commit

Permalink
Updates to commit_confirm driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Aug 10, 2020
1 parent 8301637 commit f700494
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 94 deletions.
27 changes: 11 additions & 16 deletions napalm/base/base.py
Expand Up @@ -227,40 +227,35 @@ def commit_config(self, message="", commit_confirm=False, confirm_timeout=600):
"""
Commits the changes requested by the method load_replace_candidate or load_merge_candidate.
OS driver implementations that choose to support commit confirmation timers should cause
self.has_pending_commit to return True when a commit with rollback timer is in progress.
NAPALM drivers that support 'commit confirm' should cause self.has_pending_commit
to return True when a 'commit confirm' is in progress.
Implementations should raise an exception if commit_config is called multiple times while a
confirmation timer is pending.
'commit confirm' is pending.
:param message: Optional - configuration session commit message
:type message: str
:param commit_confirm: Optional - enable a commit confirmation timer
:param commit_confirm: Optional - the commit must be confirmed using the 'confirm_commit()'
method with confirm_timeout time (or the changes will be rolled back).
:type commit_confirm: bool
:param confirm_timeout: Optional - The # of seconds before the configuration must be
confirmed via the confirm_commit method before OS reverts back to the original
configuration. Driver implementations should use a default value of 600 seconds if this is
implemented for a target OS.
:param confirm_timeout: Optional - number of seconds before the configuration will be
rolled back (when using 'commit_confirm=True'). Drivers should use a default value of
600 seconds.
:type confirm_timeout: int
"""
raise NotImplementedError

def confirm_commit(self):
"""
Confirm the changes requested via commit_config when commit_confirm=True.
Should cause self.has_pending_commit to return False when done
"""
raise NotImplementedError
def confirm_commit_revert(self):
"""
Immediately abort/revert the commit without waiting for the confirm_timeout to expire.
Should cause self.has_pending_commi to return False when done
Should cause self.has_pending_commit to return False when done.
"""
raise NotImplementedError

def has_pending_commit(self):
"""
:return A boolean indicating if a pending commit exists when using a commit_confirm timer
:return Boolean indicating if a commit_config that needs confirmed is in process.
"""
raise NotImplementedError

Expand Down
74 changes: 0 additions & 74 deletions napalm/base/test/base.py
Expand Up @@ -153,80 +153,6 @@ def test_load_template(self):
self.device.discard_config()
self.assertTrue(diff != "")

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(commit_confirm=True, confirm_timeout=600)
self.device.confirm_commit()
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_and_commit_config_with_confirm_and_revert(self):
try:
self.device.load_replace_candidate(
filename="%s/new_good.conf" % self.vendor
)
self.device.commit_config(commit_confirm=True, confirm_timeout=600)
self.device.commit_revert()
except NotImplementedError:
raise SkipTest()

# Load original config which should be our reverted stated
self.device.load_replace_candidate(filename="%s/initial.conf" % self.vendor)

# The diff should be empty as the commit was aborted
diff = self.device.compare_config()

self.assertEqual(len(diff), 0)

def test_commit_config_with_confirm_for_pending_commit(self):
try:
self.device.load_replace_candidate(
filename="%s/new_good.conf" % self.vendor
)
self.device.commit_config(commit_confirm=True, confirm_timeout=600)
self.assertTrue(self.device.has_pending_commit())
self.device.commit_revert()
except NotImplementedError:
raise SkipTest()

# Load original config which should be our reverted stated
self.device.load_replace_candidate(filename="%s/initial.conf" % self.vendor)

# The diff should be empty as the commit was aborted
diff = self.device.compare_config()

self.assertEqual(len(diff), 0)

def test_commit_config_with_confirm_timeout_and_confirm_revert(self):
try:
self.device.load_replace_candidate(
filename="%s/new_good.conf" % self.vendor
)
self.device.commit_config(commit_confirm=True, confirm_timeout=600)
self.commit_confirm_revert()
except NotImplementedError:
raise SkipTest()

# Load original config which should be our reverted stated
self.device.load_replace_candidate(filename="%s/initial.conf" % self.vendor)

# The diff should be empty as the commit was aborted
diff = self.device.compare_config()

self.assertEqual(len(diff), 0)


class TestGettersNetworkDriver(object):
@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion napalm/ios/ios.py
Expand Up @@ -507,12 +507,13 @@ def commit_config(self, message="", commit_confirm=False, confirm_timeout=600):
"""
if commit_confirm is True:
raise NotImplementedError(
"Commit confirmation timer is not implemented on this platform"
"Commit confirm has not been implemented on this platform"
)
if message:
raise NotImplementedError(
"Commit message not implemented for this platform"
)

# Always generate a rollback config on commit
self._gen_rollback_cfg()

Expand Down
3 changes: 2 additions & 1 deletion napalm/iosxr/iosxr.py
Expand Up @@ -131,8 +131,9 @@ def compare_config(self):
def commit_config(self, message="", commit_confirm=False, confirm_timeout=600):
if commit_confirm is True:
raise NotImplementedError(
"Commit confirmation timer is not implemented on this platform"
"Commit confirm has not been implemented on this platform"
)

commit_args = {"comment": message} if message else {}
if self.replace:
self.device.commit_replace_config(**commit_args)
Expand Down
2 changes: 1 addition & 1 deletion napalm/junos/junos.py
Expand Up @@ -281,7 +281,7 @@ def commit_config(self, message="", commit_confirm=False, confirm_timeout=600):
"""Commit configuration."""
if commit_confirm is True:
raise NotImplementedError(
"Commit confirmation timer is not implemented on this platform"
"Commit confirm has not been implemented on this platform"
)
commit_args = {"comment": message} if message else {}
self.device.cu.commit(ignore_warning=self.ignore_warning, **commit_args)
Expand Down
2 changes: 1 addition & 1 deletion napalm/nxos/nxos.py
Expand Up @@ -217,7 +217,7 @@ def compare_config(self):
def commit_config(self, message="", commit_confirm=False, confirm_timeout=600):
if commit_confirm is True:
raise NotImplementedError(
"Commit confirmation timer is not implemented on this platform"
"Commit confirm has not been implemented on this platform"
)
if message:
raise NotImplementedError(
Expand Down

0 comments on commit f700494

Please sign in to comment.