Testbed-Topology

Testbed

Generate from Excel/CSV file

  • Generating from excel or csv file: pyats|genie create testbed file --path source.xls --output testbed/DC.yml

    • Option --encode-password will obfuscate the password. For better security, use secret string

  • https://pubhub.devnetcloud.com/media/genie-docs/docs/cli/genie_create.html

  • https://pubhub.devnetcloud.com/media/pyats-getting-started/docs/quickstart/manageconnections.html

# source.xls
hostname,ip,username,password,protocol,os
R1,10.10.10.1:222,admin,cisco,ssh,iosxe
R2,10.10.10.2:222,admin,,ssh,iosxr
R3,10.10.10.3:222,admin,,ssh,nxos
  • Sample generated testbed file, which can be manually created as well:

devices:
  R1:
    connections:
      cli:
        ip: 10.10.10.1
        port: 222
        protocol: ssh
    credentials:
      default:
        password: cisco
        username: admin
      enable:
        password: cisco
    os: iosxe
    type: iosxe
  R2:
    connections:
      cli:
        ip: 10.10.10.2
        port: 222
        protocol: ssh
    credentials:
      default:
        password: '%ASK{}'
        username: admin
      enable:
        password: '%ASK{}'
    os: iosxr
    type: iosxr
  R3:
    connections:
      cli:
        ip: 10.10.10.3
        port: 222
        protocol: ssh
    credentials:
      default:
        password: '%ASK{}'
        username: admin
      enable:
        password: '%ASK{}'
    os: nxos
    type: nxos

Generate testbed interactively

  • pyats create testbed interactive --output mytb.yaml --encode-password

Generate testbed from Python Dictionary

Validate Testbed file

Secret Strings

  • Secret strings (such as passwords) may be specified in an encoded form suitable for sharing with a wide audience, while ensuring that only authorized users are able to decode these strings into their plaintext form.

  • By default, pyATS secret strings are not cryptographically secure.

  • https://pubhub.devnetcloud.com/media/pyats/docs/utilities/secret_strings.html

Secure secret strings cryptographically

  1. Update Configuration file:

  1. Install the cryptography package: pip install cryptography

  2. Ensure permission to access configuration file is set correctly: chmod 600 ~/.pyats/pyats.conf

  3. Generate a cryptography key: pyats secret keygen

  4. Update configuration file

  1. Encode a password

  1. Decode encoded password

  1. Add encrypted password to testbed

  1. Check that passwords can be recovered from loaded testbed

Using Secret String Object

Customizing Connection

  • Allow users to tune unicon plugin behavior without the need for any code changes, several kinds of overrides may be made from the testbed YAML itself.

  • Connecting to a pyATS device via unicon ultimately results in a unicon Connection object being created. The following parameters are eligible for override under the arguments key in the testbed YAML connection block:

    • learn_hostname

    • prompt_recovery

    • init_exec_commands

    • init_config_commands

    • mit

    • log_stdout

    • debug

    • goto_enable

    • standby_goto_enable

  • By default, after logging in device, pyats will change terminal settings both in terminal and in config mode and also show output to stdout. To disable, used below config

Error Pattern Handling

  • c.execute('show interface invalid', error_pattern=['^% Invalid'])

  • Default error patterns:

  • Pass an empty list to avoide error pattern checking: c.execute('show command error', error_pattern=[])

Set Environment Variables for connection

  • uut.settings.ENV = {'MYENV': 'mystring'}

Set Terminal Size Settings

  • uut.settings.ENV = {'ROWS': 200, 'COLUMNS': 200}

Logging

  • Every unicon device connection Logger has 3 handlers.

  1. Screen Handler: This logs messages on stdout

  2. File Handler: This logs messages in file /tmp/--.log. This is default log file. To modify the file value, the logfile parameter can be used.

  3. pyATS TaskLog Handler: This logs messages in pyats TaskLog file

  • Log level of device output and service messages is INFO.

Change logfile when connecting

  • In unicon standalone mode:

  • With pyATS: dev.connect(logfile='user-provided-file')

Disable unicon device connection logging

  • Set logger level above logging.INFO.

Topology

  • Topology module is delivered as part of base pyATS installation in the form of a Python Package

  • Installation if needed: pip install pyats.topology

Device Object

  • Device objects represent any piece of physical and/or virtual hardware that constitutes an important part of a testbed topology.

    • Each device may belong to a testbed (added to a Testbed object)

    • Each device may host arbitrary number of interfaces (Interface objects)

    • Interface names must be unique within a device

Creating Topology

There are two ways to create a topology within your testscript:

  1. create each testbed object from topology module classes and craft their interconnects together manually (eg, by assigning interfaces to each device).

  2. create a YAML testbed description file, and load it using the topology loader function.

Reference

  • https://developer.cisco.com/netdevops/live

  • https://developer.cisco.com/pyats/

  • https://github.com/CiscoTestAutomation?utm_campaign=oyoutube-davidbombal&utm_source=oyoutube&utm_medium=davidbombal-video13

  • https://github.com/hpreston/netdevops_demos

  • Genie makes all your network automation wishes come true (most of them)! Hank Preston explains: https://www.youtube.com/watch?v=unOmwDsMj8k

  • pyATS Series - Parsing like a pro: https://xrdocs.io/programmability/tutorials/pyats-series-parsing-like-a-pro/

  • Parse Genie: https://developer.cisco.com/codeexchange/github/repo/clay584/parse_genie/

  • pyATS Tutorial for Beginners: https://www.rogerperkin.co.uk/network-automation/pyats/pyats-genie-tutorial/

  • Explore Genie: https://pubhub.devnetcloud.com/media/genie-docs/docs/cookbooks/explore.html

  • https://pubhub.devnetcloud.com/media/genie-docs/docs/overview/introduction.html

Last updated