published

Cisco DNA Center Automation with pyATS | Genie

This repository contains examples of how to get started with automating Cisco
DNA Center REST APIs in Cisco pyATS | Genie test framework.

Installation

To run this demo, you should follow the pyATS | Genie installation guide,
and have it installed in your Python virtual environment. Eg:

bash$ pip install pyats genie

API Diff using Genie CLI

Genie CLI is a powerful linux-based command-line utility offering Genie Python
functionality directly from a linux terminal. It requires no previous knowledge
of Python or network programming, making it a great way to start getting
acquainted with Genie.

This demo focuses on being able to take a snapshots of Cisco DNA Center's REST
API outputs, save to file, and use it later for comparison/difference analysis.

# snapshot rest apis related to: interface, isis and ospf
# and save to folder called "initial"
bash$ genie dnac interface isis ospf --testbed-file dna.yaml --output initial --via dnac:rest --device dnac

# now - if something changed, regardless of whether it was done intentionally # or not, you can take another snapshot, and compare it against your know-good states

# take the 2nd snapshot, save it into folder "modified" bash$ genie dnac interface isis ospf --testbed-file dna.yaml --output modified --via dnac:rest --device dnac

# do a diff between the two state snapshots bash$ genie diff initial modified # any differences will be displayed to screen

Northbound & Southbound Test Automation

The next example uses the power of Genie triggers & verification concept,
building on reusable testcases. Here's our test plan:

  1. Find an interface via device mgmt/vty and make sure description is the same as DNAC’s REST API output
  2. Change interface configuration on device: change description
  3. Verify it has been modified both in device and in DNAC 
  4. Restore configuration (remove description change)
  5. Verify everything is restored in both device and in DNAC

The code necessary to run this example is included in this repository.

bash$ pyats run job dnac_job.py --testbed-file dna.yaml --html-logs .

The generated HTML log files will be available in this folder.

Copyright (c) 2019 Cisco Systems, Inc. and/or its affiliates

Use Case

API Diff using Cisco pyATS | Genie CLI

Genie CLI is a powerful linux-based command-line utility offering Genie Python functionality directly from a linux terminal. It requires no previous knowledge of Python or network programming, making it a great way to start getting acquainted with Genie.

This demo focuses on being able to take a snapshots of Cisco DNA Center's REST API outputs, save to file, and use it later for comparison/difference analysis.

Use Cases:

  • comparing the REST API output of before/after configuration changes in Cisco DNA Center
  • keeping track of how your Cisco DNA Center and its managed device states changed over time programmatically
# snapshot rest apis related to: interface, isis and ospf# and save to folder called "initial"bash$ genie dnac interface isis ospf --testbed-file dna.yaml --output initial --via dnac:rest --device dnac# now - if something changed, regardless of whether it was done intentionally# or not, you can take another snapshot, and compare it against your know-good states# take the 2nd snapshot, save it into folder "modified"bash$ genie dnac interface isis ospf --testbed-file dna.yaml --output modified --via dnac:rest --device dnac# do a diff between the two state snapshotsbash$ genie diff initial modified# any differences will be displayed to screen

Northbound & Southbound Test Automation

This example focuses on building re-usable test cases with Genie, focusing on testing your Cisco DNA Center managed topology as a whole, with the ability to trigger changes on both Cisco DNA Center, and on your southbound managed devices, seeing the topology states converge, and validating whether the expected new state is reached.

Example

  1. Find an interface via device mgmt/vty and make sure description is the same as Cisco DNA Center’s REST API output
  2. Change interface configuration on device: change description
  3. Verify it has been modified both in device and in Cisco DNA Center
  4. Restore configuration (remove description change)
  5. Verify everything is restored in both device and in Cisco DNA Center

The code necessary to run this example is included in this repository.

bash$ pyats run job dnac_job.py --testbed-file dna.yaml --html-logs .

The generated HTML log files will be available in this folder.

View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.