In this post, I want to show how I use PyATS/Robot frameworks and TextFSM to create simple tests to check the services/protocols for the Company ‘X’ virtual network.
Services/protocols were configured in DEV environment, the next step is creating automatic tests.
If you have not read the ‘Introduction’ post, it is a good starting point to understand what I will talk about.
In order not to write about the same thing, I leave links to useful resources that I used to understand how PyATS works.
pyATS provides the test framework foundation to the whole this ecosystem. It specializes in data-driven and reusable testing, and is engineered from ground up to be suitable for Agile, rapid development iterations.
Being highly-pluggable, pyATS is designed to enables developers start with small, simple and linear test cases, and scale towards large, complex and asynchronous test suites.
Overview about PyATS and demo.
PyATS uses the ‘Unicon framework’ to interact with devices that are described in the ‘testbed.yaml’ file.
Unicon supported platforms:
PyATS ‘testbed.yaml’ has the same meaning like Ansible ‘hosts file’.
testbed: name: IOS_Testbed tacacs: username: cisco passwords: tacacs: cisco devices: HQ-DIS1: os: ios type: IOSv connections: vty: protocol: ssh ip: 192.168.4.104 HQ-DIS2: os: ios type: IOSv connections: vty: protocol: ssh ip: 192.168.4.105
testbed: name: JUNOS_Testbed tacacs: username: cisco passwords: tacacs: Pa$$w0rd devices: vSRX-BR2-FW1: os: junos type: junos connections: vty: protocol: ssh ip: 192.168.4.113
testbed: name: VYOS_Testbed tacacs: username: vyos passwords: linux: vyos devices: VyOS-BR1-ED1: os: linux type: linux connections: vty: protocol: ssh ip: 192.168.4.111
AEtest (Automation Easy Testing) is the standard test engineering automation harness. It offers a simple and straight-forward way for users to define, execute and debug testcases and testscripts, serving as a basis for other testscript templates & engines.
To show how ‘Aetest test’ works, I recorded a short video.
The test task is to check the availability of ISP (22.214.171.124) and HQ-S1 (10.255.255.2) from HQ clients using ‘ping’ and ‘traceroute’.
class CommonSetup(aetest.CommonSetup): 0) Loading testbed 1) Connection to HQ clients which are described in the testbed.yaml file. 2) Setup static IP addresses to the HQ clients. сlass TESTCASE_1_PING_FROM_HQ_CLIENTS_TO_ISP(aetest.Testcase): 1) HQ-CX – ‘ping 126.96.36.199 –c 5’ to ISP class TESTCASE_2_PING_FROM_HQ_CLIENTS_TO_HQ_S1(aetest.Testcase): 1) HQ-CX – ‘ping 10.255.255.2 –c 5’ to HQ-S1 class TESTCASE_3_TRACEROUTE_FROM_HQ_CLIENTS_TO_ISP(aetest.Testcase): 1) HQ-CX – ‘trace 188.8.131.52’ to ISP class CommonCleanup(aetest.CommonCleanup): 1) Disconnect from HQ hosts
Also, I can run a test and get ‘html output’ using pyATS jobs.
RobotFramework is generic Python/Java test automation framework that focuses on acceptance test automation by through English-like keyword-driven test approach.
Example of Robot framework for Network Engineers:
It can be used in the conjunction with PyATS, for example:
That one Robot test combines two PyATS simple tests (connectivity_check) and (vlans_check).
The first one checks the availability of ISP (184.108.40.206) and HQ-S1 (10.255.255.2) from Company ‘x’ site clients (HQ-CX, BR1-C1, BR2-C1) as well as traceroute from HQ clients to ISP.
The second checks the existence of vlans (10,20,30,40) on the nodes (HQ-ACX and HQ-DISX).
Python module which implements a template based state machine for parsing semi-formatted text. Originally developed to allow programmatic access to information returned from the command line interface (CLI) of networking devices.
For (vlans_check) – I have used TextFSM, ntc template (cisco_ios_show_vlan.template ) to parse the output from devices.
PyATS has Genie (pyATS SDK),
This library package contains the open source implementations for:
Genie Ops: objects modelling the operational state of devices
Genie Conf: objects modelling the configuration of devices
Genie Robot: robot library layer, enabling Genie libs to be used in Robot Framework
Genie SDK: triggers and verifications (reusable testcases) implemented using Genie infrastructure.
Unfortunately, the project time is limited, I did not get the Genie and its libraries. Genie goes to future directions.
Also, Genie allows you to make a ‘snapshot’ of the network (working state) and after when there is a problem in the network to compare the outputs and find what is happened.
To sum up,
PyATS, Robot framework, Genie are very large and deep topics.
For my student project, I have covered a little what it is and how it works with simple examples.
One thing is for sure, the combination of all of them gives incredible flexibility to test an entire network.