M3 – Network tests, PyATS/Robot framework/TextFSM, week 16

Greetings!

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

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.

https://developer.cisco.com/docs/pyats/#!introduction/pyats-genie

Overview about PyATS and demo.

Docs:


https://pubhub.devnetcloud.com/media/pyats/docs/overview/index.html

Learning labs:


https://katacoda.com/kecorbin

https://developer.cisco.com/learning/lab/intro-to-pyats/step/1

Examples:


https://github.com/kecorbin/pyats-network-checks

https://github.com/kecorbin/pyats-ios-sample


PyATS uses the ‘Unicon framework’ to interact with devices that are described in the ‘testbed.yaml’ file.

Unicon supported platforms:

https://pubhub.devnetcloud.com/media/pyats-packages/docs/unicon/user_guide/introduction.html#supported-platforms

PyATS ‘testbed.yaml’ has the same meaning like Ansible ‘hosts file’.

https://pubhub.devnetcloud.com/media/pyats/docs/topology/concept.html#topology-concept

https://pubhub.devnetcloud.com/media/pyats/docs/topology/schema.html


Example (ios_testbed.yaml):

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

Example (junos_testbed.yaml):

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

Example (vyos_testbed.yaml)

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

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.

https://pubhub.devnetcloud.com/media/pyats/docs/aetest/introduction.html

Script Structure

https://pubhub.devnetcloud.com/media/pyats/docs/aetest/structure.html


To show how ‘Aetest test’ works, I recorded a short video.

The test task is to check the availability of ISP (8.8.8.8) and HQ-S1 (10.255.255.2) from HQ clients using ‘ping’ and ‘traceroute’.


Description:

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 8.8.8.8 –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 8.8.8.8’ to ISP

class CommonCleanup(aetest.CommonCleanup):

1) Disconnect from HQ hosts

Also, I can run a test and get ‘html output’ using pyATS jobs.

https://pubhub.devnetcloud.com/media/pyats/docs/easypy/jobfile.html#easypy-jobfile

Example,


Robot framework

RobotFramework is generic Python/Java test automation framework that focuses on acceptance test automation by through English-like keyword-driven test approach.

https://pubhub.devnetcloud.com/media/pyats/docs/robot/index.html

https://robotframework.org/

Example of Robot framework for Network Engineers:

https://github.com/permitanyany/robotframework

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 (8.8.8.8) 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).


TextFSM

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.

https://github.com/google/textfsm

Examples,

http://gratuitousarp.info/a-quick-example-of-using-textfsm-to-parse-data-from-cisco-show-commands/

https://codingpackets.com/blog/textfsm-getting-started/


For (vlans_check) – I have used TextFSM, ntc template (cisco_ios_show_vlan.template ) to parse the output from devices.

https://github.com/networktocode/ntc-templates/blob/master/templates/cisco_ios_show_vlan.template


PyATS has Genie (pyATS SDK),


https://pubhub.devnetcloud.com/media/pyats-packages/docs/genie/index.html

Genie libs

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.

https://github.com/CiscoTestAutomation/genielibs

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.

More information:


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.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: