Giter Site home page Giter Site logo

ciscodevnet / pyats-ios-sample Goto Github PK

View Code? Open in Web Editor NEW
26.0 25.0 13.0 38 KB

pyATS Example script for Cisco IOS Testbed

Home Page: https://developer.cisco.com/site/pyats/

License: Apache License 2.0

Python 98.54% Makefile 0.75% Shell 0.72%
pyats cisco test-automation pyats-examples cisco-ios ccna ccie ccnp routers

pyats-ios-sample's Introduction

pyats-ios-sample

Introduction

This repo provides a demonstration of Cisco pyATS with a NetDevOps style workflow.

Requirements

  • Python 2.7
  • 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/kecorbin/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

Verify

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!

pyATS details

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.

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/

pyats-ios-sample's People

Contributors

annegentle avatar eckelcu avatar kecorbin avatar lsheikal avatar simingy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyats-ios-sample's Issues

virl up on Multi-IOS Cisco Test Network devbox fails due to a LOCALE exception

Issue Description

Executing command virl up in the pyats-ios-sample directory causes the command execution to fail due to an exception. More specifically a Language Locale exception:

(py3venv) [developer@devbox pyats-ios-sample]$ virl up
Exception raised while running your command
Please re-run as 'virl --debug ...' and collect the output before opening an issue
Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/python3/ for mitigation steps.

This system lists a couple of UTF-8 supporting locales that you can pick from. The following suitable locales were discovered: aa_DJ.utf8, aa_ER.utf8, aa_ET.utf8, af_ZA.utf8, am_ET.utf8, an_ES.utf8, ar_AE.utf8, ar_BH.utf8, ar_DZ.utf8, ar_EG.utf8, ar_IN.utf8, ar_IQ.utf8, ar_JO.utf8, ar_KW.utf8, ar_LB.utf8, ar_LY.utf8, ar_MA.utf8, ar_OM.utf8, ar_QA.utf8, ar_SA.utf8, ar_SD.utf8, ar_SY.utf8, ar_TN.utf8, ar_YE.utf8, as_IN.utf8, ast_ES.utf8, ayc_PE.utf8, az_AZ.utf8, be_BY.utf8, bem_ZM.utf8, ber_DZ.utf8, ber_MA.utf8, bg_BG.utf8, bho_IN.utf8, bn_BD.utf8, bn_IN.utf8, bo_CN.utf8, bo_IN.utf8, br_FR.utf8, brx_IN.utf8, bs_BA.utf8, byn_ER.utf8, ca_AD.utf8, ca_ES.utf8, ca_FR.utf8, ca_IT.utf8, crh_UA.utf8, cs_CZ.utf8, csb_PL.utf8, cv_RU.utf8, cy_GB.utf8, da_DK.utf8, de_AT.utf8, de_BE.utf8, de_CH.utf8, de_DE.utf8, de_LU.utf8, doi_IN.utf8, dv_MV.utf8, dz_BT.utf8, el_CY.utf8, el_GR.utf8, en_AG.utf8, en_AU.utf8, en_BW.utf8, en_CA.utf8, en_DK.utf8, en_GB.utf8, en_HK.utf8, en_IE.utf8, en_IN.utf8, en_NG.utf8, en_NZ.utf8, en_PH.utf8, en_SG.utf8, en_US.utf8, en_ZA.utf8, en_ZM.utf8, en_ZW.utf8, es_AR.utf8, es_BO.utf8, es_CL.utf8, es_CO.utf8, es_CR.utf8, es_CU.utf8, es_DO.utf8, es_EC.utf8, es_ES.utf8, es_GT.utf8, es_HN.utf8, es_MX.utf8, es_NI.utf8, es_PA.utf8, es_PE.utf8, es_PR.utf8, es_PY.utf8, es_SV.utf8, es_US.utf8, es_UY.utf8, es_VE.utf8, et_EE.utf8, eu_ES.utf8, fa_IR.utf8, ff_SN.utf8, fi_FI.utf8, fil_PH.utf8, fo_FO.utf8, fr_BE.utf8, fr_CA.utf8, fr_CH.utf8, fr_FR.utf8, fr_LU.utf8, fur_IT.utf8, fy_DE.utf8, fy_NL.utf8, ga_IE.utf8, gd_GB.utf8, gez_ER.utf8, gez_ET.utf8, gl_ES.utf8, gu_IN.utf8, gv_GB.utf8, ha_NG.utf8, he_IL.utf8, hi_IN.utf8, hne_IN.utf8, hr_HR.utf8, hsb_DE.utf8, ht_HT.utf8, hu_HU.utf8, hy_AM.utf8, ia_FR.utf8, id_ID.utf8, ig_NG.utf8, ik_CA.utf8, is_IS.utf8, it_CH.utf8, it_IT.utf8, iu_CA.utf8, iw_IL.utf8, ja_JP.utf8, ka_GE.utf8, kk_KZ.utf8, kl_GL.utf8, km_KH.utf8, kn_IN.utf8, ko_KR.utf8, kok_IN.utf8, ks_IN.utf8, ku_TR.utf8, kw_GB.utf8, ky_KG.utf8, lb_LU.utf8, lg_UG.utf8, li_BE.utf8, li_NL.utf8, lij_IT.utf8, lo_LA.utf8, lt_LT.utf8, lv_LV.utf8, mag_IN.utf8, mai_IN.utf8, mg_MG.utf8, mhr_RU.utf8, mi_NZ.utf8, mk_MK.utf8, ml_IN.utf8, mn_MN.utf8, mni_IN.utf8, mr_IN.utf8, ms_MY.utf8, mt_MT.utf8, my_MM.utf8, nb_NO.utf8, nds_DE.utf8, nds_NL.utf8, ne_NP.utf8, nhn_MX.utf8, niu_NU.utf8, niu_NZ.utf8, nl_AW.utf8, nl_BE.utf8, nl_NL.utf8, nn_NO.utf8, nr_ZA.utf8, nso_ZA.utf8, oc_FR.utf8, om_ET.utf8, om_KE.utf8, or_IN.utf8, os_RU.utf8, pa_IN.utf8, pa_PK.utf8, pap_AN.utf8, pl_PL.utf8, ps_AF.utf8, pt_BR.utf8, pt_PT.utf8, ro_RO.utf8, ru_RU.utf8, ru_UA.utf8, rw_RW.utf8, sa_IN.utf8, sat_IN.utf8, sc_IT.utf8, sd_IN.utf8, se_NO.utf8, shs_CA.utf8, si_LK.utf8, sid_ET.utf8, sk_SK.utf8, sl_SI.utf8, so_DJ.utf8, so_ET.utf8, so_KE.utf8, so_SO.utf8, sq_AL.utf8, sq_MK.utf8, sr_ME.utf8, sr_RS.utf8, ss_ZA.utf8, st_ZA.utf8, sv_FI.utf8, sv_SE.utf8, sw_KE.utf8, sw_TZ.utf8, szl_PL.utf8, ta_IN.utf8, ta_LK.utf8, te_IN.utf8, tg_TJ.utf8, th_TH.utf8, ti_ER.utf8, ti_ET.utf8, tig_ER.utf8, tk_TM.utf8, tl_PH.utf8, tn_ZA.utf8, tr_CY.utf8, tr_TR.utf8, ts_ZA.utf8, tt_RU.utf8, ug_CN.utf8, uk_UA.utf8, unm_US.utf8, ur_IN.utf8, ur_PK.utf8, ve_ZA.utf8, vi_VN.utf8, wa_BE.utf8, wae_CH.utf8, wal_ET.utf8, wo_SN.utf8, xh_ZA.utf8, yi_US.utf8, yo_NG.utf8, yue_HK.utf8, zh_CN.utf8, zh_HK.utf8, zh_SG.utf8, zh_TW.utf8, zu_ZA.utf8

Click discovered that you exported a UTF-8 locale but the locale system could not pick up from it because it does not exist. The exported locale is 'en_US.UTF-8' but it is not supported
(py3venv) [developer@devbox pyats-ios-sample]$

Steps to reproduce

  1. Reserve a Multi-IOS Cisco Test Network Sandbox
  2. Connect to VPN
  3. Connect to devbox using provided username and password
  4. Create a directory 'code' and change into it (mkdir code && cd code)
  5. Copy the pyATS IOS Sample Repo (git clone https://github.com/CiscoDevNet/pyats-ios-sample.git)
  6. Change to pyats-ios-sample directory by executing cd pyats-ios-sample/
  7. Execute virl up command and the error in the issue description should re-produce

Workaround

I don't necessarily think this is a pyATS bug/issue, more likely related to the dependency library click, however, to allow the program to execute as expected the following variables should be exported:
export LC_ALL="en_US.utf-8"
export LANG="en_US.utf-8"

Then execute virl up as normal and the program continues without exception:

(py3venv) [developer@devbox pyats-ios-sample]$ export LC_ALL="en_US.utf-8"
(py3venv) [developer@devbox pyats-ios-sample]$ export LANG="en_US.utf-8"
(py3venv) [developer@devbox pyats-ios-sample]$ virl up
Creating default environment from topology.virl
Localizing rsa modulus 768 with: rsa modulus 1024
(py3venv) [developer@devbox pyats-ios-sample]$

Sharing/reporting this so that other users are aware and know how to work around the problem.
Thanks,
Veprim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.