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

Add commit confirmed feature #124

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Conversation

mirceaulinic
Copy link
Member

Based on the suggestions from #121, submitting this changes to try an implementation for commit confirmed.

For load_merge, when confirmed is required, a candidate config file is saved on the flash that is used afterwards to replace and schedule the rollback time.

@mirceaulinic
Copy link
Member Author

mirceaulinic commented Mar 15, 2017

I have tested and it seems to work as expected:

>>> i.load_merge_candidate(config='ntp server 1.2.3.6')
>>> i.commit_config(confirmed=1)

produces the logs:

*Mar 15 15:31:36.052: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_BACKUP: Backing up current running config to bootflash:archive-Mar-15-15-31-36.011-15
*Mar 15 15:31:36.062: Rollback:Acquired Configuration lock.
*Mar 15 15:31:36.081: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_START_ABSTIMER: User: napalm(Priv: 15, View: 0): Scheduled to rollback to config bootflash:archive-Mar-15-15-31-36.011-15 in 1 minutes
*Mar 15 15:31:36.081: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_WARNING_ABSTIMER: System will rollback to config bootflash:archive-Mar-15-15-31-36.011-15 in one minute. Enter "configure confirm" if you wish to keep what you've configured
*Mar 15 15:32:36.081: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_ROLLBACK_START: Start rolling to: bootflash:archive-Mar-15-15-31-36.011-15
*Mar 15 15:32:36.093: Rollback:Acquired Configuration lock.

And indeed reverted the change I requested.

Confirming the commit:

>>> i.load_merge_candidate(config='ntp server 1.2.3.6')
>>> i.commit_config(confirmed=1)
>>> i.commit_confirm()

produces the logs:

*Mar 15 15:34:16.442: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_BACKUP: Backing up current running config to bootflash:archive-Mar-15-15-34-16.400-16
*Mar 15 15:34:16.446: Rollback:Acquired Configuration lock.
*Mar 15 15:34:16.465: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_START_ABSTIMER: User: napalm(Priv: 15, View: 0): Scheduled to rollback to config bootflash:archive-Mar-15-15-34-16.400-16 in 1 minutes
*Mar 15 15:34:16.467: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_WARNING_ABSTIMER: System will rollback to config bootflash:archive-Mar-15-15-34-16.400-16 in one minute. Enter "configure confirm" if you wish to keep what you've configured
*Mar 15 15:34:17.329: %PARSER-4-BADCFG: Unexpected end of configuration file.

*Mar 15 15:34:20.244: %SYS-5-CONFIG_I: Configured from console by napalm on vty1 (172.31.13.136)
*Mar 15 15:34:25.842: %ARCHIVE_DIFF-5-ROLLBK_CNFMD_CHG_CONFIRM: User: napalm: Confirm the configuration change

and saved the running config.

@dbarrosop
Copy link
Member

LGTM but I will defer to @ktbyers as he is our resident expert on everything ios.

@@ -354,6 +354,8 @@ def commit_config(self):
raise ReplaceConfigException("Candidate config file does not exist")
if self.auto_rollback_on_error:
cmd = 'configure replace {} force revert trigger error'.format(cfg_file)
elif confirmed:
cmd = 'configure replace bootflash:{} force time {}'.format(cfg_file, confirmed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hard-code the file system bootflash. The cfg_file variable already has the file_system which either gets auto detected or set by optional_args.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have hardcoded as I have noticed that it wasn't able to detect the file system and for this command it seems that is mandatory -- but I will double check this & fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Netmiko should automatically try to autodectect by doing a dir. If this fails, however, you can still set it using NAPALM optional_args.

We should create an issue, however, if you are seeing this fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The autodetect happens right as part of the open code in the NAPALM code (IIRC).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most probably I missed something. I will check.

# Replace running config with the rollback config
# And schedule the revert time
# If not confirmed, it will go back to the current running-config state
cmd = 'configure replace bootflash:{} force time {}'.format(self.rollback_cfg,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hard-code file system. Use _gen_full_path(self.rollback_cfg) to generate full path using file-system bound to object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should ensure that the rollback_cfg exactly matches running config at this point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably copy it just before to be sure?

Copy link
Contributor

@ktbyers ktbyers Mar 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about copy and then make sure no diffs (and throw an error if differences are found).

pynet-rtr1#copy system:running-config flash:rollback_config.txt
pynet-rtr1#show archive config differences system:running-config flash:rollback_config.txt
!Contextual Config Diffs:
!No changes were found

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense to me... didn't know about this command (as many other tricks I have discovered reading the code 😄 ).

@ktbyers
Copy link
Contributor

ktbyers commented Mar 16, 2017

@mirceaulinic Nice! I added some comments (mainly pertaining to the hard-coding of the file system).

Also I would like to test this prior to merging.

@ktbyers
Copy link
Contributor

ktbyers commented Mar 16, 2017

We also need unit tests for this on real devices (i.e. not the mocked unit tests / the real unit tests).

@mirceaulinic
Copy link
Member Author

I have tested this on a 2811 so I can run the tests after we implement them, no problem.

@ktbyers
Copy link
Contributor

ktbyers commented Mar 18, 2017

Yes, I will probably try to work on the tests also...though it might be the end of next week.

@ktbyers
Copy link
Contributor

ktbyers commented Oct 24, 2017

This will be reimplemented post-reunification.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants