-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Scrapli 'core' and platform migration #297
Conversation
Co-authored-by: Stefano Sasso <[email protected]>
* backdoor to reset VR * option to reset specific VMs
- Implement scrapli for telnet console and qemu monitor - Add scrapli for core funcs (wait_write, read_until, expect) - Add conditional use of scrapli via 'use_scrapli' var. Default is disabled - Add colours to logging - Log env vars - Log if transparent mgmt intf is in use - Log if scrapli is in use - Log overlay image creation - Log defined SMP and RAM
- Use Scrapli IOSXEDriver for config - Update install VM var name to 'cat8kv' from 'csr' - Fix installer class init so overlay image is only created once
- Remove license check - Send bootstrap config via day0/CVAC config (mounted file to cdrom) - Send startup config via Scrapli IOSXEDriver
- Use Scrapli IOSXEDriver for sending bootstrap and startup configs
- Use Scrapli IOSXRDriver to send bootstrap and startup configs
- Converts the qcow2 image into required vmdk format for vrnetlab via qemu-img.
- Use Scrapli IOSXRDriver for bootstrap and startup configs - Change class names to 'XRv9k' instead of 'XRv' - Explicitly wait for SDR baking to complete in install process - Remove call home/LC check
- Use NXOSDriver for bootstrap and startup configs
- Use NXOSDriver for bootstrap and startup configs
- Use IOSXEDriver for bootstrap and startup configs
- vios, csr, cat8kv, cat9kv -- add configuration saving - XRv, XRv9k -- log configuration saving
- Use scrapli community 'nokia_sros' platform - Remove wait_write clean_buffer override - Check if tftpboot conifg exists *before* opening Scrapli connection - Log command outputs with 'DEBUG_SCRAPLI' env var (defaults to false)
I rebased my branch to add the There is a current caveat with SROS. Please use my fork/branch of scrapli community. I have some minor changes to the regex to allow for BOF configuration prompt. Once cloned, please rebuild the base image with the Dockerfile in this PR branch. Once all has been tested and issues are ironed out I will make a PR to get this added in scrapli community. Of course as always I am open to/want feedback. If you want any explanations for anything please let me know! |
Did some tests on:
Everything worked as expected:
All tests were done with fully functional labs up to six nodes. Looks good, no Scrapli related issues so far (the log is a little chattier than before... ;-)). |
@tjbalzer Thanks for testing! For SROS there is an env var |
If the startup-configuration provided is classic then the default configuration engine will be set to classic mode. In this case the scrapli device variant should also be set to classic so the scrapli magic can do it's thing with the correct prompt matching.
Found two new issues in my setup (using SROS 24.10.R1): failing to apply default configsWhen "Applying basic SR OS configuration", it's still on bof exclusive mode, hence it's failing.
Fix suggestion: use quit-config instead of /.
bof commands fail when startup-config is classic
|
@kaelemc reverting f42e1 fixed "failing to apply default configs" only. I believe
|
@jcpvdm I'm not seeing this "failing to apply default configs". If you are still seeing it, let me know if Newest commit should fix some stuff when a classic startup config is used. Let me know how it works out. P.S. Thanks for testing! It's always appreciated. |
@hellt In the latest commit I've also reverted Edit: Force pushed as I had to fix the commit message :) |
As classic startup configurations are now supported for MD-CLI defaulting versions, the classic CLI will mean the default config engine is classic on node boot. In this commit all logic that determined when to send/not send config for classic versions is now replaced with a single 'classic_cfg' global variable. Most of the logic across the code had repeated statements checking if the version was <= 22 or magc. 'classic_cfg' is set to True in this case. Else it is False.
I see both issues are fixed in the last commit, but may have introduced a new one has @hellt mentioned above.
You don't see the issue even before reverting commit f42e1? Can you share the output from container logs? (make sure there is no configuration file present when booting) |
@jcpvdm I was mistaken, I observed the exact same behaviour as you reported. |
Looks good @kaelemc 👍 , my test cases passed |
Cool, thanks @jcpvdm ! |
This PR implements scrapli to the 'core' functions, and uses the driver for some platforms.
Changes
vrnetlab base image
A new vrnetlab 'base' image is added. This image should be used as the base for all migrated platforms.
It contains common pkgs preinstalled as well as Scrapli & Scrapli community.
Scrapli 'core'
The core now uses Scrapli's
Driver
for serial console and qemu monitor connections.Scrapli is imported in
vrnetlab.py
but will not throw an error if not found, which means scrapli and telnetlib may co-exist.Setting
use_scrapli
toTrue
in the class initializer will enable Scrapli for the serial console and qemu monitor connections.Core functions
wait_write
,expect
andread_until
now have Scrapli equivalents.wait_write
wait_write
can effectively still be used as normal. Inside the function ifuse_scrapli
was set to true then thewait_write_scrapli
function is run instead.wait_write_scrapli
replicates the functionality ofwait_write
, but using the Scrapli serial console connection instead of telnetlib.wait_write_scrapli
currently doesn't have support forcon
,clean_buffer
orhold
args.expect
expect
was part of telnetlib. The scrapli compatible version is thecon_expect
function.con_expect
aims to replicate the functionality oftelnetlib.expect
It accepts a list of byte-strings which are used for regex matching something on the console.
Like
telnetlib.expect
it will return the list index of the first thing that it matched, the re match object and the read console buffer up until the match (or timeout).Unlike telnetlib, the timeout is optional and
con_expect
will not block forever. Rather the timeout in this case is used for how long you wish to block for.My personal opinion is to not use the timeout/block, it makes behaviour less reliable.
read_until
read_until
was another function of telnetlib, the Scrapli compatible function iscon_read_until
. Generally this wasn't used directly in any nodes, but rather for thewait_write
function.con_read_until
will continously read and output the serial console buffer to stdout until the string it must match on is matched.It returns the entire buffer of the console read until the match.
By default
con_read_until
is blocking, however there is a timeout arg if the function should be required to timeout after some amount of time.Logging
Misc
These are fairly opinionated additions:
write_to_stdout
has been added. It's a simple helper function to write something to the stdout and flush the buffer so everything is written.The main usage is to print console output, the jusitifcation is because it looks uglier when console output is printed by the logger.
Another addition is the
format_bool_color
function. This is simply used to return text which is ANSI formatted in green or red depending on if some boolean is true or false.Migrated platforms
IOSXEDriver
NXOSDriver
NXOSDriver
IOSXRDriver
IOSXRDriver
nokia_sros
platform from Scrapli CommunityI plan to implement other platforms later down the line; time permitting.
Migration steps
There are two ways you can migrate:
Steps
ghcr.io/srl-labs/vrnetlab-base
as the base image.use_scrapli
toTrue
.self.tn.expect()
toself.con_expect()
and remove the timeout.self.write_to_stdout()
instead of trace or debug logging.self.tn.close()
toself.scrapli_tn.close()
Extra steps if migrating to Scrapli platform/driver
self.scrapli_tn
connection and open either manually or use the context manager (see XRv9k).self.scrapli_tn
connection, so the new driver uses the existing transport (seevIOS
)SCRAPLI_TIMEOUT
env var to let the user control the driver timeout.