Skip to content

kecorbin/pyats-ios-sample

 
 

Repository files navigation

pyats-ios-sample

Introduction

This repo contains a full test script in pyATS with local libraries that connects to a testbed of IOS devices, and runs various test cases that parses command outputs, collects router information, and report them in log.

Requirements

  • Python 3.x
  • Docker

Workflow

Make sure virl cli is configured

export VIRL_HOST=myvirlserver.change.me

Clone this repo / create virtualenv / install requirements

git clone https://github.com/CiscoDevNet/pyats-ios-sample
cd pyats-ios-sample
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

Launch topology

virl up

It may take a minute to boot the nodes, make sure that you allow enough time for the topology to boot. This can be verified using the virl ls and virl nodes commands

Sample outputs

virl ls

Running Simulations
╒═════════════════════════════════╤══════════╤════════════════════════════╤═══════════╕
│ Simulation                      │ Status   │ Launched                   │ Expires   │
╞═════════════════════════════════╪══════════╪════════════════════════════╪═══════════╡
│ pyats-ios-sample_default_UbI56G │ ACTIVE   │ 2017-12-13T22:02:36.810310 │           │
╘═════════════════════════════════╧══════════╧════════════════════════════╧═══════════╛

virl nodes


    Here is a list of all the running nodes

╒═══════════╤══════════╤═════════╤═════════════╤════════════╤══════════════════════╤════════════════════╕
│ Node      │ Type     │ State   │ Reachable   │ Protocol   │ Management Address   │ External Address   │
╞═══════════╪══════════╪═════════╪═════════════╪════════════╪══════════════════════╪════════════════════╡
│ ~mgmt-lxc │ mgmt-lxc │ ACTIVE  │ REACHABLE   │ ssh        │ 10.255.0.154         │ 10.94.238.236      │
├───────────┼──────────┼─────────┼─────────────┼────────────┼──────────────────────┼────────────────────┤
│ ios2      │ IOSv     │ ACTIVE  │ UNREACHABLE │ telnet     │ 10.255.0.156         │ N/A                │
├───────────┼──────────┼─────────┼─────────────┼────────────┼──────────────────────┼────────────────────┤
│ ios1      │ IOSv     │ ACTIVE  │ UNREACHABLE │ telnet     │ 10.255.0.155         │ N/A                │
╘═══════════╧══════════╧═════════╧═════════════╧════════════╧══════════════════════╧════════════════════╛

Generate pyATS testbed inventory

The virlutils package provides us an easy way of dynamically generating a testbed definition with the accurate connectivity information for the simulation.

virl generate pyats

Testbed Credentials

The generated testbed will look to the execution environment to provide credentials, make sure these are set in either your local environment, or docker container.

tacacs:
    username: "%ENV{PYATS_USERNAME}"
passwords:
    tacacs: "%ENV{PYATS_PASSWORD}"
    enable: "%ENV{PYATS_AUTH_PASS}"
    line: "%ENV{PYATS_PASSWORD}"

You can set these like such

export PYATS_USERNAME=cisco
export PYATS_PASSWORD=cisco
export PYATS_AUTH_PASS=cisco

Test Cases

Launch pyATS test suite

make test

Sample output

2017-12-13T23:01:17: %EASYPY-INFO: +------------------------------------------------------------------------------+
2017-12-13T23:01:17: %EASYPY-INFO: |                             Task Result Summary                              |
2017-12-13T23:01:17: %EASYPY-INFO: +------------------------------------------------------------------------------+
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example.commonSetup                                    PASSED
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example.PingTestcase[device=ios1]                      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example.PingTestcase[device=ios2]                      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example.VerifyInterfaceCountTestcase[device=ios1]      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example.VerifyInterfaceCountTestcase[device=ios2]      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example.commonCleanup                                  PASSED
2017-12-13T23:01:17: %EASYPY-INFO:
2017-12-13T23:01:17: %EASYPY-INFO: +------------------------------------------------------------------------------+
2017-12-13T23:01:17: %EASYPY-INFO: |                             Task Result Details                              |
2017-12-13T23:01:17: %EASYPY-INFO: +------------------------------------------------------------------------------+
2017-12-13T23:01:17: %EASYPY-INFO: __task1: pyats_ios_example
2017-12-13T23:01:17: %EASYPY-INFO: |-- commonSetup                                                           PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |-- check_topology                                                    PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |-- establish_connections                                             PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |   |-- Step 1: Connecting to Router-1                                PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |   `-- Step 2: Connecting to Router-2                                PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   `-- marking_interface_count_testcases                                 PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |-- PingTestcase[device=ios1]                                             PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |-- ping[destination=10.10.10.1]                                      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   `-- ping[destination=10.10.10.2]                                      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |-- PingTestcase[device=ios2]                                             PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |-- ping[destination=10.10.10.1]                                      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   `-- ping[destination=10.10.10.2]                                      PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |-- VerifyInterfaceCountTestcase[device=ios1]                             PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |-- extract_interface_count                                           PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   `-- verify_interface_count                                            PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |-- VerifyInterfaceCountTestcase[device=ios2]                             PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   |-- extract_interface_count                                           PASSED
2017-12-13T23:01:17: %EASYPY-INFO: |   `-- verify_interface_count                                            PASSED
2017-12-13T23:01:17: %EASYPY-INFO: `-- commonCleanup                                                         PASSED
2017-12-13T23:01:17: %EASYPY-INFO:     `-- disconnect                                                        PASSED
2017-12-13T23:01:17: %EASYPY-INFO:         |-- Step 1: Disconnecting from Router-1                           PASSED
2017-12-13T23:01:17: %EASYPY-INFO:         `-- Step 2: Disconnecting from Router-2                           PASSED
2017-12-13T23:01:17: %EASYPY-INFO: No SMTP server information configured, ignoring sending notification email.
2017-12-13T23:01:17: %EASYPY-INFO: Done!

General Information

Arguments

This script requires one script argument testbed to be passed in when run under standalone execution for demonstration purposes. testbed: the path to testbed yaml file

This script requires one script argument testbed_file and two optional script argument ios1 and ios2 to be passed in when run under easypy for demonstration purposes.

testbed_file: the path to testbed yaml file
ios1: the device name defined in the testbed yaml file, if modified
ios2: the device name defined in the testbed yaml file, if modified

Topology


    +-------------+                                      +-------------+
    |             |                                      |             |
    |    ios1     | ------------------------------------ |    ios2     |
    |             |          Gig0/1 <-> Gig0/1           |             |
    +-------------+                                      +-------------+

Testing

This script performs the following tests for demonstration purposes.

  • router connection: basic device connection test
  • ping command: basic device ping test; logs ping result.
  • interface count verification
    • execute show version command: basic command execution and data parsing; extract ethernet and serial interface counts; logs interface counts.
    • execute show ip interface brief command: basic command execution and data parsing; extract all ethernet and serial interfaces; logs number of interface counts.
    • verify ethernet and serial interface counts from above commands.
  • router disconnect: basic device disconnect test

Examples

# to run under standalone execution
$ python pyats_ios_example.py --testbed pyats_ios_example.yaml

# to run under easypy
$ easypy pyats_ios_example_job.py -testbed_file pyats_ios_example.yaml

References: For the complete and up-to-date user guide on pyATS, visit: https://developer.cisco.com/site/pyats/docs/

About

pyATS Example script for Cisco IOS Testbed

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.5%
  • Other 1.5%