pyATS Tutorial for Beginners | Getting started with Genie & pyATS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to this video on pi ats uh my name is roger perkin i'm a network and security consultant based in the uk um i'm ccie 5038 and for the last few years i've been into network automation and programmability and a tool which i've not yet got to grips with is pi ats and so i thought it's about time that i did so i've written a tutorial on my website which is roger perkin.co.uk that's that post here which i'm following along so i'll put the description in the link so you can follow through this and this is a very simple tutorial where we use pi ats and genie to test a simple lab network that i've got set up now pi ats is cisco's in-house cisco python testing framework it was made open source a few years ago and released the community and it's what they use to test all the code releases uh on all the routers which is all the ios is xc nexus platforms and the genie element of this pi ats genie which you often hear used together genie is the library that contains all the knowledge of network operations which works on top of pi ats so pi ats and junior are often talked about together but together they make up a very powerful network testing application so let's get straight into this first of all we need to install pi ats and to do that i'm using an ubuntu 20 machine here and i i've got the tutorial on the side now it i would recommend that you do this in a virtual environment if you don't know about python virtual environments uh just there there's a link uh python virtual environment tutorial that will tell you all about virtual environments but basically what a virtual environment is is another like a protected area of your operating system where you can install a different version of python and different applications so let's do that now so as i said here's my terminal so i'm just going to go in here and i've got a folder called vms where i put all my virtual environments i'm going to make a directory in here called pi ats and then we're going to go into the directory and you can follow along here and then i'm going to create a virtual environment within that directory which is python 3 minus m bm and a dot so that's now created this virtual environment and then now we need to activate that virtual environment activate so now you can see that my prompt has changed here and it's now i've got a bracket here which is showing pi ats so that means i'm running in the virtual environment and then within this virtual environment if i do a pip freeze you can see that i don't have any packages installed at all so this is a completely clean area where i can do what i like so to install pi ats we just do pip install and then if we do pi ats and then this square bracket full this actually installs a a full version of pi 80s oh no i mistyped that let's just copy this so you can just copy these commands straight from the blog post okay so that you can just do a pip in store pi ats but if you do the pi uh pip and store paint yes full you get a lot more goodies which we're not going to dig into with this video but probably will do in later tutorials so this is now going to download everything and the benefit of doing this within a virtual environment is i know that everything's coming down clean and i'm starting from a clean slate now interestingly this installs an awful lot of stuff so at some point in time you will see it there it is um it's it's currently installing ansible um ansible and pi ats can be used together that's another video so there's there's tons of stuff in here um we're only literally going to scratch the surface and if you are interested in ansible and want to do that i do have a a course um unanswerable for network engineers there'll be a link for that in the uh the video now i did have a few issues when i installed this last time which we can go through so this is why i'm doing this now because we can see everything so even though i've run a python virtual environment it's saying we've got a few incompatible things so let's just make a note of them so this is saying that we've got ginger 2 requirements but i've got ginger 2 3 0 1 but it only wants ginger 2 211 okay so what i'm gonna have to do is just once this is done just install these specific versions that it wants and you can see now we're doing a big ansible install i'm just going to pause the video while this ansible bit finishes and then we can catch up when that's done okay so that's done there and what you should do once this is installed um is do a pi ats version check which is just there so that's pi ats version check now i suspect this is going to fail as we've got these requirements that are quite wrong so this is saying that it wants ginger 2 11 3 and as i've seen from the errors earlier which i caught this says i've got ginger three so this is the version of ginger that we actually want so i'm just gonna pop that in there and just do a look three in store and then the other requirement was markup safe one one one reinstall now this might vary for you depending on where you're installing it um and then it also wants this i'm just so what i've done is i've just copied the uh the log here of where it went wrong and i'm just one by one just installing the exact requirements that it wants so now we should be good to go so pi ats version check perfect okay so we are up and running now so i've got pi ats installed and the current version is 21.4 and i'm running python 3.8.5 okay so let's move this over here a bit more so the next thing we have to do is set up what they call a pi ats testbed file so because pi ats is going to go out and connect to your network environment you need to tell it where those devices are so to create the testbed file it's just a yaml file um and when it's done it will look like that so it's that's all it is is a yaml file that just says the name of the device and the connections and the passwords that's that's about it so i would advise the best thing to do is to create one and then depending on how many devices you've got you'll see what happens now so if we just take this so it says here the command is genie create testbed interactive and then the output to a file called testbed1.yaml okay so that's fine so before we do that i'm just going to move myself into my network programmability folder so you'll see why in a second so i can see everything that's going on pi ats so i've created a folder uh just called piots so we can see where everything is and then if if you want to this is going to be on github so you can see all the code so the command was genie create testbed interactive output testbed1.yaml so what this is going to do is start the interactive oh that's two dashes two dashes oh oh don't that's dash dash need to fix that so it's uh genie create test bed interactive dash dash output and then the the name of the file testbed1.yaml now this will start an autumn oh my goodness what's going on here i'm just going to type this just to make sure genie create test bed interactive dash dash output test bed one dot yaml there we go that's right double i think it's the uh the double dash in here i'll amend that post so it's um genie create testbed interactive dash dash output and then the name of the yaml file so this says do all devices have the same username yes they do put in the username roger do all the devices have the same password yes they do my super secret password same password again and then here's where you start putting in the device name so this is device hostname so this is csr-1 and the ip of this is 192.168.1 and it's ssh and it's ios add another device csr2 192.168.1.222 ssh ios now you can see that this is going to become quite painful if you have to do 100 devices in here so what i would suggest is that you do one or two uh finish it with a no so that's created the testbed.yaml file and now if we look in my folder so in my pierre ts folder we've now got this testbed1.yaml file and you can see it's a very simple format it's just yaml it's called devices and then each one is listed with connections cli iprotocol and then the username and passwords so if you want to add more devices into this file then you can simply just copy this and add them underneath so that would be what i would recommend that's the simplest way to tackle that so we've now got a file called the testbed file which is defining our devices now i'll show you as well i'm running this on even g i've got a few routers here but just for this tutorial we've got csr1 and csr2 they're running here and i'm just running ospf between the two devices so that's what is happening in the background so now we've got the testbed file we're going to run our first test and we're going to tell genie to learn everything it needs to know about ospf so we're going to run this command genie learn ospf now within the genie library this is the beauty of using pie ts in genie all the hard work has already been done for you by cisco so they have put in all the commands that you need to know to be able to interrogate this network for everything relating to ospf so if i say junior learn ospf and we're saying test bed file and it's test bed output and then this is asking us where to put it so it's going to be a folder so i'm going to put ospf 1 here and these dashes are yeah i need to check the formatting that's actually a double dash and that's a double dash it's putting them together it's annoying so now this has gone through and you can see this is said learning ospf on devices csr1 and csr2 and it connected to csr1 and it logged it and it learned all about rfpf so let's go back into that folder so now we can see i've got a folder here called ospf1 so if i go into that folder there's a ton of information in here now this just says the connection info which is nothing too exciting but here this is where we can see what happened so what it did is it logged on to csr1 and it did show ipo spf and it got all this output and tons and tons of output everything you need to know about ospf and then it's created this file which is every ospf interface the links far too much information to be able to go through with your own eyes but everything about this ospf network is now contained in this ospf folder so what's the beauty of that well what we're going to do now is we have a baseline so this is a normal operating network i've got a peering between the two routers so what i would do now is let's break the network so it's going to bring down so this is csr1 so let's say that someone has made a change in the evening and so let's go into gigabit one so this is the connecting link to the other period so before i do that let's just uh i'll validate here show ipo spf neighbors so you can see i've got a neighbor to gigabit 1 2 csr2 so i'm going to shut down gi 1 shot so that's going to break the ospf relationship ospf has gone down so that was our change that was done in the middle of the night that nobody knows about and then we're going to learn the network again so let's go and say this time genie learn ospf testbed file testbed 1 output and this time we're going to put it into another folder called ospf2 so again now it's going off it's connecting to the devices and it's learning everything about ospf so now we've got two files two folders with all the information about ospf the first one which was our working state and our second one ospf2 which contains the information and the key to why our network is now broken so this is very simple with two routers but imagine if this was your entire network and this was 500 routers and someone had make made a change somewhere and you didn't know where that was so you could run this and this is going to drill right in and tell exactly what's changed so now between the two folders we're going to do a diff so i'm going to say pi ats diff ospf 1 and then ospf2 so that's saying please go into those two folders and tell me the differences between the two so that's popped up and this says right i found a diff um we found two diffs um one ospf 1 csr1 and 2. so if we now open this up we can see i've now got this diff file here i've got two diff files so i've got a diff for csr1 and within that diff we've got all these minuses which means nothing has changed and then there's this plus here so this one says enable is false so that's telling me that gigabit ethernet one which was previously enabled is now been changed to not enabled and if we go into csr2 what does that report yeah so there's nothing in there so what we've got is the the fact that that interface has changed so that tells us that the difference on the network the change that has broken our ospf is the fact that this interface gigabit ethernet 1 is now not enabled now this is literally scratching the surface with what pi ats can do there are tons and tons of more features in it at the bottom here there's an hour long video from devops live that shows you how to go into pi ats i would highly recommend that you go into this give it a try see what you can make of it and if you're following along here um i need to fix this just be careful that this isn't a dash this is two dashes that just go in there so i hope that's been helpful to you i hope you've learned a bit about pi ats and genie as i said my name is roger perkin and if you are interested in this stuff and network automation in general please check out my courses i've got ansible and narnia and um some get course coming soon all the links for that are in the description so thanks for watching and any questions just ping a comment and i will do my best to answer it thank you
Info
Channel: Roger Perkin
Views: 1,509
Rating: 5 out of 5
Keywords: roger perkin, pyats tutorial, pyats, pyats genie, what is pyats, genie pyats, install pyats, pyats learn, pyats installation, pyats getting started, pyats and genie, cisco pyats genie, pyats python, pyats & genie example, pyats example, pyats framework, pyats testbed file, network automation, python, python virtual environment, python venv
Id: 1Ba_BRyHxSo
Channel Id: undefined
Length: 21min 30sec (1290 seconds)
Published: Fri May 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.