Package: netests
Netests.iodylan.hamel@protonmail.com- June 2020 - CopyrightDocumentationhttps://www.netests.io/How to use ??This tool contains two modes :Integrity & Sanity checksCLIIntegrity & Sanity checksThe idea of this project is to offer a test platform for the network to allow engineers to perform tests without having to write python code (or other languages :smile:).In addition, this platform does not consider the OS, it is possible to run tests on Cisco, Cumulus, Juniper devices without changing the data structure.Define inventoryYou have to create a Nornir or an Ansible inventory (Example based on an Ansible Inventory)hostsfile.[leaf]leaf01# Cumulus Networksleaf02# Cisco Nexus 9kleaf03# Arista vEOSleaf04# Juniper Networksleaf05# Cisco IOS[spine]spine01# Cumulus Networksspine02# Extreme Networks VSPspine03# Cisco IOS-XRDefine device parameters inhost_vars/inventory_hostname.ymlfileshostname:10.0.5.202platform:linux# <<=== specify device OS (Cumulus Linux)username:adminpassword:Ci$co123connexion:ssh# <<=== specify connexion method - check supported protocolsport:22hostname:10.0.5.204platform:junos# <<=== specify device OS (Juniper)username:rootpassword:Jun1p3rconnexion:netconf# <<=== specify connexion method - check supported protocolsport:830hostname:10.0.5.203platform:eos# <<=== specify device OS (Arista)username:adminpassword:admin123connexion:api# <<=== specify connexion method - check supported protocolsport:443Define testsTests are defined in the filenetests.yml. In this file you can define which test will be executed.config:nornir_cfg:./nornir/config_ansible.ymlinventory:./inventory/ansible/hostsprotocols:bgp:test:falsecdp:test:falselldp:test:truefacts:test:falseping:test:falseIntruth_vars/you need to define the configuration that you want on your production devices.Exemple  :There are three ways to define variables :For a specific host - define your configuration intruth_vars/hosts/hostname/protocol.ymlLLDP configuration-local_name:leaf03local_port:Ethernet1neighbor_mgmt_ip:192.168.1.148neighbor_name:cumulusneighbor_os:Cumulus Linux version 4.0.0neighbor_port:swp1neighbor_type:["Bridge","Router"]Will test that the neighbor on the portEthernet1is a device namedcumulusand the connexion is on the portswp1.For all hosts defined in a group - such asspines- define intruth_vars/groups/group/protocol.ymlGroup isspine-arista.
Facts configurationdomain:dh.localversion:4.24.0FWill test if all devices linked to this group hasdh.localas domain name,4.24.0Fas version.for all devices - definetruth_vars/all/{{ protocol }}.ymldomain: dh.localWill test if all devices in your inventory have t domaindh.local.The script will connect on each devices, retrieveinformations and campre them with the data define in yourtruth_vars/(source of truth).If the informations are the same the tests is OK :smile:Run the script./netests.py-x-iinventory/ansible/hosts-anetests.yml[netests-base_run.py](ping)isworking=True# -x / Define that you will use an Ansible inventory# -i / Path to your Ansible inventory# -a / Path to your netests configuration file (default is netests.yml)Netests-CLIYou can get some informations regarding you network configuration directly from the CLI.This tool will use your Ansible/Nornir/Netbox Inventory. For example :[leaf]leaf01
leaf02
leaf03
leaf04
leaf05[spine]spine01
spine02
spine03Run the CLI tool⚡./netests.py-x-iinventory/ansible/hosts-anetests.yml-t
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
WelcometoNetestsCLI
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Get HELP> help
+------------------------------------------------------------+
|                       Netests Help                         |
+------------------------------------------------------------+
| [help]      Display help                                   |
| [select]    Select devices on which on action will be exec |
| [unselect]  Remove a device from the selected              |
| [selected]  Show devices currently selected                |
| [get xx]   Get XX protocols informations                   |
| [options]   Set arguments that will retrieve for a Protocol|
| [more xx]  Show XX Protocol class arguments selected       |
| [show xx]  Show XX Protocol class arguments                |
| [print yy]  Show YY devices informations                   |
| [compare yy xx]  Compare device config with source of truth|
| [exit]  Quit Netests CLI                                   |
+------------------------------------------------------------+Get help for a specific command> help options
+------------------------------------------------------------+
|                 Netests - Options Commands                 |
+------------------------------------------------------------+
| This command is used to define which parameter will be     |
| retrieve for a protocol.                                   |
| It is possible to get a subset of protocols parameters.    |
| Format :                                                   |
|   > options  {{ protocol }}  {{ classArg1,classArg2  }}    |
|   (To get all protocols parameters use the 'show' command) |
|                                                            |
| Examples :                                                 |
|   > options vrf vrf_name,rd,rt_imp,rt_exp                  |
+------------------------------------------------------------+Print hosts defined in your inventory :{   'leaf01': {   'connexion': 'ssh',
                  'hostname': '172.16.194.51',
                  'platform': 'linux',
                  'port': 22},
    'leaf02': {   'connexion': 'api',
                  'hostname': 'sbx-nxos-mgmt.cisco.com',
                  'platform': 'nxos',
                  'port': 443},
    'leaf04': {   'connexion': 'netconf',
                  'hostname': '66.129.235.11',
                  'platform': 'junos',
                  'port': 40002},
    'leaf05': {   'connexion': 'ssh',
                  'hostname': 'ios-xe-mgmt.cisco.com',
                  'platform': 'ios',
                  'port': 8181}}Select devicesAt the beginning if you use a command to get some network informations, nothing will happend. The reason is that no device is selected.>getvrf[[netests-get_vrf]]nodeviceselected.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
@EndGET
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-You have to select devices on which one you would get informationsSelect all devices in the inventory>select*
@Followingsdeviceswillbeaddedtothelist:
@['leaf01','leaf02','leaf03','leaf04','leaf05','spine01','spine02','spine03']Select only a subset of devices> select leaf01,spine03
@Followings devices will be added to the list :
@['leaf01', 'spine03']Print selected devices> selected
@Followings devices are selected :
@['leaf01', 'leaf02', 'leaf04', 'leaf05']Execute GETRun the commandgetand the protocols that you would like retrieve.>selectleaf01,spine03
@Followingsdeviceswillbeaddedtothelist:
@['leaf01','spine03']>getvrf
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
>>>>>spine03{'ListVRF':[{'VRF':{'exp_targ':'NOT_SET','imp_targ':'NOT_SET','l3_vni':'NOT_SET','rd':'NOT_SET','rt_exp':'NOT_SET','rt_imp':'NOT_SET','vrf_id':'NOT_SET','vrf_name':'MGMT_VRF','vrf_type':'NOT_SET'}},{'VRF':{'exp_targ':'NOT_SET','imp_targ':'NOT_SET','l3_vni':'NOT_SET','rd':'NOT_SET','rt_exp':'65000:1','rt_imp':'65000:1','vrf_id':'NOT_SET','vrf_name':'EXTERNAL_PEERING','vrf_type':'NOT_SET'}}]}*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
>>>>>leaf01{'ListVRF':[{'VRF':{'exp_targ':'NOT_SET','imp_targ':'NOT_SET','l3_vni':'NOT_SET','rd':'NOT_SET','rt_exp':'NOT_SET','rt_imp':'NOT_SET','vrf_id':'1001','vrf_name':'mgmt','vrf_type':'NOT_SET'}}]}*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
@EndGET
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Compare config withtruth_vars/> compare facts
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
{   'Facts': {   'base_mac': 'NOT_SET',
                 'build': 'fc2',
                 'domain': 'NOT_SET',
                 'hostname': 'csr1000v',
                 'interfaces_lst': [   'GigabitEthernet1',
                                       'GigabitEthernet2',
                                       'GigabitEthernet3',
                                       'Loopback3',
                                       'Loopback1234',
                                       'Loopback9009'],
                 'memory': '8113280',
                 'model': 'CSR1000V',
                 'serial': '9OOFTICVAFM',
                 'vendor': 'Cisco',
                 'version': '16.9.3'}}
[netests - compare_facts] Key infos_data is missingfor leaf05 or no Facts data has been found.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
@The following devices have the same configuration that defined in the source of truth :
@[leaf05].
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
>ScreenshotContributorDylan Hamel -dylan.hamle@protonmail.com