Skip to content

Commit

Permalink
Adding arguments to support commit_confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Nov 19, 2017
1 parent 8482197 commit 22630f3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
9 changes: 8 additions & 1 deletion napalm/base/base.py
Expand Up @@ -178,12 +178,19 @@ def compare_config(self):
"""
raise NotImplementedError

def commit_config(self):
def commit_config(self, confirmed=None):
"""
Commits the changes requested by the method load_replace_candidate or load_merge_candidate.
:param confirmed (optional): Number of minutes until rollback occurs. Default is None \
(no confirmation).
"""
raise NotImplementedError

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

def discard_config(self):
"""
Discards the configuration loaded into the candidate.
Expand Down
17 changes: 17 additions & 0 deletions napalm/base/test/base.py
Expand Up @@ -69,6 +69,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=5)
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
4 changes: 3 additions & 1 deletion napalm/eos/eos.py
Expand Up @@ -187,8 +187,10 @@ def compare_config(self):

return result.strip()

def commit_config(self):
def commit_config(self, confirmed=None):
"""Implementation of NAPALM method commit_config."""
if confirmed is not None:
raise NotImplementedError
commands = []
commands.append('copy startup-config flash:rollback-0')
commands.append('configure session {}'.format(self.config_session))
Expand Down
5 changes: 4 additions & 1 deletion napalm/ios/ios.py
Expand Up @@ -388,12 +388,15 @@ def _commit_hostname_handler(self, cmd):
self.device.set_base_prompt()
return output

def commit_config(self):
def commit_config(self, confirmed=None):
"""
If replacement operation, perform 'configure replace' for the entire config.
If merge operation, perform copy <file> running-config.
"""
if confirmed is not None:
raise NotImplementedError

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

Expand Down
5 changes: 4 additions & 1 deletion napalm/iosxr/iosxr.py
Expand Up @@ -145,7 +145,10 @@ def compare_config(self):
else:
return self.device.compare_config().strip()

def commit_config(self):
def commit_config(self, confirmed=None):
if confirmed is not None:
raise NotImplementedError

if self.replace:
self.device.commit_replace_config()
else:
Expand Down
4 changes: 3 additions & 1 deletion napalm/junos/junos.py
Expand Up @@ -234,8 +234,10 @@ def compare_config(self):
else:
return diff.strip()

def commit_config(self):
def commit_config(self, confirmed=None):
"""Commit configuration."""
if confirmed is not None:
raise NotImplementedError
self.device.cu.commit(ignore_warning=self.ignore_warning)
if not self.config_lock:
self._unlock()
Expand Down
5 changes: 4 additions & 1 deletion napalm/nxos/nxos.py
Expand Up @@ -323,7 +323,10 @@ def _load_config(self):
raise ReplaceConfigException(rollback_result['msg'])
return True

def commit_config(self):
def commit_config(self, confirmed=None):
if confirmed is not None:
raise NotImplementedError

if self.loaded:
self.backup_file = 'config_' + str(datetime.now()).replace(' ', '_')
self._save_config(self.backup_file)
Expand Down
5 changes: 4 additions & 1 deletion napalm/nxos_ssh/nxos_ssh.py
Expand Up @@ -672,7 +672,10 @@ def _load_cfg_from_checkpoint(self):
return False
return True

def commit_config(self):
def commit_config(self, confirmed=None):
if confirmed is not None:
raise NotImplementedError

if self.loaded:
self.backup_file = 'config_' + str(datetime.now()).replace(' ', '_')
# Create Checkpoint from current running-config
Expand Down

0 comments on commit 22630f3

Please sign in to comment.