From dca7a3ea70222ca7811a2af156d36895b63942f3 Mon Sep 17 00:00:00 2001 From: kderynski Date: Fri, 17 Feb 2017 12:15:18 +0100 Subject: [PATCH 1/3] Added commit confirm functionality Commit confirm added to napalm base. It introduces new optional argument in commit_config method and new method commit_confirm for confirmation pending commit. --- napalm_base/base.py | 10 +++++++++- napalm_base/test/base.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/napalm_base/base.py b/napalm_base/base.py index 01e1aa69..f854645c 100644 --- a/napalm_base/base.py +++ b/napalm_base/base.py @@ -166,9 +166,17 @@ def compare_config(self): """ raise NotImplementedError - def commit_config(self): + def commit_config(self, revert_in=0): """ Commits the changes requested by the method load_replace_candidate or load_merge_candidate. + + :param revert_in: Number of seconds until rollback. Don't revert if 0. + """ + raise NotImplementedError + + def commit_confirm(self): + """ + Confirm pending commit. """ raise NotImplementedError diff --git a/napalm_base/test/base.py b/napalm_base/test/base.py index 1760198d..4d6c4395 100644 --- a/napalm_base/test/base.py +++ b/napalm_base/test/base.py @@ -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(revert_in=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: From 4e42653618f90ae1e1bfa231a7ec29af037b19fc Mon Sep 17 00:00:00 2001 From: kderynski Date: Thu, 2 Mar 2017 15:24:03 +0100 Subject: [PATCH 2/3] Name of argument and time unit have changed. --- napalm_base/base.py | 4 ++-- napalm_base/test/base.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/napalm_base/base.py b/napalm_base/base.py index f854645c..edc04529 100644 --- a/napalm_base/base.py +++ b/napalm_base/base.py @@ -166,11 +166,11 @@ def compare_config(self): """ raise NotImplementedError - def commit_config(self, revert_in=0): + def commit_config(self, confirmed=0): """ Commits the changes requested by the method load_replace_candidate or load_merge_candidate. - :param revert_in: Number of seconds until rollback. Don't revert if 0. + :param confirmed: Number of minutes until rollback. Don't revert if 0. """ raise NotImplementedError diff --git a/napalm_base/test/base.py b/napalm_base/test/base.py index 4d6c4395..41dba9e4 100644 --- a/napalm_base/test/base.py +++ b/napalm_base/test/base.py @@ -62,7 +62,7 @@ def test_replacing_and_committing_config(self): 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(revert_in=60) + self.device.commit_config(confirmed=60) self.device.commit_confirm() except NotImplementedError: raise SkipTest() From 7363f3b6bc863325361c459e2b647c15a36463db Mon Sep 17 00:00:00 2001 From: kderynski Date: Wed, 8 Mar 2017 15:56:53 +0100 Subject: [PATCH 3/3] Extended description added to commit_config doctoring. --- napalm_base/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/napalm_base/base.py b/napalm_base/base.py index edc04529..4922e0d6 100644 --- a/napalm_base/base.py +++ b/napalm_base/base.py @@ -170,6 +170,15 @@ 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