Over recent weeks, my journey into network automation has led me to revisit key aspects of Python fundamentals, core principles of programmability, and diverse data models and architectures. As I delve into the capabilities of the pyATS framework for automation and testing, setting up a suitable and fully functional lab environment is a must.
Typically, this setup includes a Linux operating system (such as Ubuntu, Kali, or CentOS), Python version 3.6 or higher, access to network devices (routers, firewalls, access points, and switches) to be tested, and, of course, the pyATS framework with its library, Genie.
In this story, I will walk you through the process I used to set up a Linux environment on Windows 11 using Windows Subsystem for Linux (WSL). I'll cover everything from installation to configuration, ensuring you have all the tools you need to practice and excel in network automation using pyATS.
Initially developed for internal use by Cisco, pyATS was designed for rigorous testing processes before being released to the public. Today, it stands at the core of Cisco’s Test Automation Solution, used by thousands of engineers worldwide.
As per Cisco, pyATS is the de facto test framework for Cisco engineers across various platforms and functions. It powers millions of CI/CD, sanity, regression, scale, HA, and solution tests every month.
En plus, pyATS has been adopted by thousands of network engineers and developers globally, further proving its versatility and reliability.
There are several options to install pyATS on a computer, depending on your operating system and preferences. You can use pip
, or set up a virtual environment, install from source, or run it in a Docker container. Cisco DevNet also offers resources and tutorials for setting up pyATS, including sandbox environments for hands-on practice.
I decided to install it on Windows 11, my native OS. While running it on a Linux virtual machine is an option, the convenience of using Windows made it my preferred choice.
The Windows Subsystem for Linux (WSL) enables developers to install a Linux distribution and use Linux applications, utilities, and Bash command-line tools directly on Windows. This is achieved without the need for a traditional virtual machine or dual-boot setup, providing a seamless and efficient development experience.
Note: WSL is compatible with Windows 10 and above.
To get started, open Windows PowerShell or the command prompt with elevated privileges and enter the following command:
wsl –install
The command should install WSL and the Ubuntu distribution (default option), as you can see in the code below:
Your environment has been set up for using Node.js 20.12.2 (x64) and npm.
C:\Windows\System32>wsl --install
Downloading: Windows Subsystem for Linux 2.3.26
Installing: Windows Subsystem for Linux 2.3.26
Windows Subsystem for Linux 2.3.26 has been installed.
Installing Windows optional component: VirtualMachinePlatform
Deployment Image Servicing and Management tool Version: 10.0.26100.1252
Image Version: 10.0.26120.1912
Enabling feature(s) [100.0%] The operation completed successfully.
The requested operation is successful. Changes will not be effective until the system is rebooted.
Installing: Ubuntu Ubuntu has been installed. The requested operation is successful.
Changes will not be effective until the system is rebooted.
C:\Windows\System32>
After this step is complete, reboot your computer.
If no distribution is installed after setting up WSL, you may need to install a distribution manually.
During the first launch, you must create a username and set a password for your Ubuntu system. Follow the prompts to complete this setup.
Installing, this may take a few minutes...
Please create a default UNIX user account.
The username does not need to match your Windows username. For more information visit: https://aka.ms/wslusers
Enter new UNIX username: katshidev
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details. Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
Documentation: https://help.ubuntu.com Management: https://landscape.canonical.com Support: https://ubuntu.com/pro
System information as of Mon Nov 18 17:24:28 SAST 2024
System load: 0.0
Processes: 53
Usage of /: 0.1% of 1006.85GB
Users logged in: 0
Memory usage: 5%
IPv4 address for eth0: 172.20.249.39
Swap usage: 0%
This message is shown once a day. To disable it please create the /home/katshidev/.hushlogin file.
katshidev@EOC:~$
Then, run these two commands to update and upgrade your Linux packages. This ensures that all your Linux packages are up-to-date and ready for further installations.
katshidev@EOC:~$ sudo apt update && sudo apt upgrade
[sudo] password for katshidev:
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Get:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:4 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages [466 kB]
Get:5 http://archive.ubuntu.com/ubuntu noble-backports InRelease [126 kB]
Get:6 http://archive.ubuntu.com/ubuntu noble/universe amd64 Packages [15.0 MB]
Get:7 http://security.ubuntu.com/ubuntu noble-security/main Translation-en [98.1 kB]
Get:8 http://security.ubuntu.com/ubuntu noble-security/main amd64 Components [7196 B]
venv
Some limitations of WSL restrict the direct installation of Python packages globally. The best approach to overcome this is to create a virtual environment.
A virtual environment is an isolated workspace for Python projects. It allows you to manage dependencies and packages separately from the system-wide Python installation, ensuring each project has its own set of libraries without conflicts. This approach enables you to use different package versions for different projects seamlessly.
mkdir pyats_projects cd pyats_projects
venv
package is installed. This package will allow you to create virtual environments.apt install python3.12-venv
python3 -m venv myenv
source myenv/bin/activate
Now pyATS can be installed using the pip install pyats[full]
command 😄
(myenv) root@EOC:/home/katshidev/pyats_projects# pip install pyats[full]
Collecting pyats[full]
Downloading pyats-24.10-cp312-cp312-manylinux2014_x86_64.whl.metadata (4.6 kB)
Collecting packaging>=20.0 (from pyats[full])
Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
---output ommited---
Collecting pyats.log<24.11.0,>=24.10.0 (from pyats[full])
Downloading pyats.log-24.10-cp312-cp312-manylinux2014_x86_64.whl.metadata (3.4 kB)
---output ommited---
Collecting pluggy<2,>=1.5 (from pytest>=4.6->pytest-cov<5.0.0,>=4.0.0->pysnmp<6.2,>=6.1.4->genie.libs.sdk<24.11.0,>=24.10.0->genie<24.11.0,>=24.10.0->pyats[full])
Downloading pluggy-1.5.0-py3-none-any.whl.metadata (4.8 kB)
Downloading genie-24.10-cp312-cp312-manylinux2014_x86_64.whl (29.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 29.2/29.2 MB 366.9 kB/s eta 0:00:00
Downloading genie.libs.robot-24.10-py3-none-any.whl (11 kB)
Downloading genie.telemetry-24.10-py3-none-any.whl (70 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.2/70.2 kB 290.9 kB/s eta 0:00:00
Downloading genie.trafficgen-24.10-py3-none-any.whl (112 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 112.7/112.7 kB 417.5 kB/s eta 0:00:00
---output ommited---
Successfully installed
IxNetwork-9.30.2212.8
MarkupSafe-3.0.2
PrettyTable-3.12.0
aiofiles-24.1.0
aiohappyeyeballs-2.4.3
aiohttp-3.11.2
aiosignal-1.3.1
arrow-1.3.0
async-lru-2.0.4
attrs-24.2.0
backports.ssl-0.0.9
backports.ssl-match-hostname-3.7.0.1
bcrypt-4.2.0
binaryornot-0.4.4
certifi-2024.8.30
cffi-1.17.1
chardet-4.0.0
---output ommited---
yarl-1.17.2 (myenv)
root@EOC:/home/katshidev/pyats_projects#
After the installation process is complete, you can now verify it is successfully installed using the command pyats check
🙃
(myenv) root@EOC:/home/katshidev/pyats_projects# pyats check
/home/katshidev/pyats_projects/myenv/bin/pyats:5:
DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pyats.cli.main import main Usage: pyats <command> [options]
Commands: clean runs the provided clean file create create scripts and libraries from template develop Puts desired pyATS
packages into development mode diff Command to diff two snapshots saved to file or directory dnac Command to learn DNAC
features and save to file (Prototype) learn Command to learn device features and save to file logs command enabling log
archive viewing in local browser migrate utilities for migrating to future versions of pyATS parse Command to parse show
commands run runs the provided script and output corresponding results. secret utilities for working with secret strings.
shell enter Python shell, loading a pyATS testbed file and/or pickled data undevelop Removes desired pyATS packages from development
mode validate utilities that help to validate input files version commands related to version display and manipulation
General Options: -h, --help Show help Run 'pyats <command> --help' for more information on a command.
invalid choice: 'check' (choose from 'clean', 'create', 'develop', 'diff', 'dnac', 'learn', 'logs', 'migrate',
'parse', 'run', 'secret', 'shell', 'undevelop', 'validate', 'version')
(myenv) root@EOC:/home/katshidev/pyats_projects#
Mastering network automation with pyATS begins with a solid understanding of Python fundamentals and having a well-structured work environment. Using the Windows Subsystem for Windows 11, you can seamlessly integrate a Linux environment that supports the robust capabilities of pyATS and the Genie library. This setup empowers you to efficiently perform comprehensive tests and automation on various network devices.
pyATS has proven its versatility and reliability by becoming the de facto framework for network testing among thousands of engineers and developers worldwide. With several installation options, such as pip, virtual environments, and containers, setting up pyATS is easy and adaptable to different user and business requirements.
As the network automation market continues to grow, embracing such powerful tools will undoubtedly enhance your ability to manage and automate complex network environments. By following the steps outlined, you are now well-equipped to explore the full potential of pyATS, ultimately advancing your skills in network automation.