0% found this document useful (0 votes)
6 views

LAB 1 – Network Automation Testing pyATS_0714c

This document outlines a lab activity focused on network automation testing using pyATS technology, including the exploration of testbed files and scripts. Participants will learn to update a testbed file to include an additional router and execute a pyATS script to analyze results. The lab involves connecting to devices, running tests, and reviewing the structure and functionality of pyATS classes and functions.

Uploaded by

Dúber Pérez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

LAB 1 – Network Automation Testing pyATS_0714c

This document outlines a lab activity focused on network automation testing using pyATS technology, including the exploration of testbed files and scripts. Participants will learn to update a testbed file to include an additional router and execute a pyATS script to analyze results. The lab involves connecting to devices, running tests, and reviewing the structure and functionality of pyATS classes and functions.

Uploaded by

Dúber Pérez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Discovery 1: Network

Automation Testing with pyATS


Introduction
In this lab, you will explore pyATS technology and update a pyATS testbed file and pyATS script.
During this activity, you will meet the following objectives:

 Explore the structure of a pyATS testbed file

 Run the pyATS script and review the results

 Explore the pyATS script main classes and functions

 Update the pyATS testbed file to include the R3 router in this lab

 Update the pyATS script file to include the R3 router in this lab

Topology
The topology for this lab includes three routers, R1, R2, and R3. These routers are connected to a
management network by the GigabitEthernet1 interface. Also, they connect through the
GigabitEthernet2 and GigabitEthernet3 interfaces.

Network Automation Testing with pyATS


Job Aid

Access Credentials Table

Device Credentials

Student-vm Username: Student


Password: 1234QWer

R1 Username: cisco
Password: cisco

R2 Username: cisco
Password: cisco

R3 Username: cisco
Password: cisco

Device Information Table

Device Description IP Address

R1 Cisco IOS XE router GigabitEthernet1: 172.21.1.21/24


GigabitEthernet2: 10.0.12.1/24
GigabitEthernet3: 10.0.13.1/24

Network Automation Testing with pyATS


Device Description IP Address

R2 Cisco IOS XE router GigabitEthernet1: 172.21.1.22/24


GigabitEthernet2: 10.0.12.2/24
GigabitEthernet3: 10.0.23.2/24

R3 Cisco IOS XE router GigabitEthernet1: 172.21.1.23/24


GigabitEthernet2: 10.0.13.3/24
GigabitEthernet3: 10.0.23.3/24

student-vm Ubuntu Ens160: 172.21.1.10/24

Network Automation Testing with pyATS


Task 1: Explore a pyATS Testbed and Script File
In this task, you will explore the structure of a pyATS testbed and script file.

Activity Procedure
Complete the following steps:
Step 1 Connect to the student-vm.

Navigate to topology page and click student-vm icon, login with credential
provided in Job Aid

Step 2 On student-vm start Visual Studio Code.

On the student-vm desktop, double-click Visual Studio Code icon.

Step 3 Open the pyATS testbed file pyats_ios_default.yaml and edit the file in the
main panel.

On the VS Code EXPLORER panel, click the pyATS testbed file


pyats_ios_default.yaml file to open and edit the file in the main panel.

Network Automation Testing with pyATS


Step 4 Review the two main sections of the YAML testbed file, testbed and topology,
notice there are two devices in this topology, R1 and R2.

Here is an example:

testbed:
name: pyATS_IOS_Example_Testbed
credentials:
default:
username: cisco
password: cisco
devices:
R1:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.21
port: 22
type: iosxe
os: iosxe
R2:
connections:
defaults:

Network Automation Testing with pyATS


class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.22
port: 22
type: iosxe
os: iosxe
topology:
R1:
interfaces:
GigabitEthernet1:
ipv4: 172.21.1.21/24
link: n1
type: ethernet
R2:
interfaces:
GigabitEthernet1:
ipv4: 172.21.1.22/24
link: n1
type: ethernet

Step 5 On the VS Code TERMINAL panel, activate the pyATS virtual environment
/pyats/. Then, change the working directory to pyats-ios directory.
Step 6 On the VS Code TERMINAL panel, use source /pyats/bin/activate command to
activate the pyATS virtual environment. Then, use cd pyats-ios/ command to
change the working directory to pyats-ios.

Step 7 Run the pyats_ios.py script.

Network Automation Testing with pyATS


Use python pyats_ios.py command to run the script.

Step 8 In the Detailed Results section, take note of the main sections. Each section
corresponds to the pyATS classes that are defined in the pyATS script file. You
will analyze these classes in the following steps.
Here is an example:
+------------------------------------------------------------------------------+
| Detailed Results |
+------------------------------------------------------------------------------+
SECTIONS/TESTCASES RESULT
--------------------------------------------------------------------------------
.
|-- common_setup PASSED
| |-- check_topology PASSED
| |-- establish_connections PASSED
| | |-- Step 1: Connecting to ios device: R1 PASSED
| | `-- Step 2: Connecting to ios device: R2 PASSED
| `-- marking_interface_count_testcases PASSED
|-- PingTestcase[ios_name=R1] PASSED
| |-- setup PASSED
| |-- ping[destination=172.21.1.21] PASSED
| `-- ping[destination=172.21.1.22] PASSED
|-- PingTestcase[ios_name=R2] PASSED
| |-- setup PASSED
| |-- ping[destination=172.21.1.21] PASSED
| `-- ping[destination=172.21.1.22] PASSED
|-- VerifyInterfaceCountTestcase[device=R1] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED
|-- VerifyInterfaceCountTestcase[device=R2] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED

Network Automation Testing with pyATS


`-- common_cleanup PASSED
`-- disconnect PASSED
|-- Step 1: Disconnecting from ios device: R1 PASSED
`-- Step 2: Disconnecting from ios device: R2 PASSED
+------------------------------------------------------------------------------+
| Summary |
+------------------------------------------------------------------------------+
Number of ABORTED 0
Number of BLOCKED 0
Number of ERRORED 0
Number of FAILED 0
Number of PASSED 6
Number of PASSX 0
Number of SKIPPED 0
Total Number 6
Success Rate 100.0%
--------------------------------------------------------------------------------
(pyats) student@student-vm:~/pyats-ios-sample$

Step 9 On the VS Code, open the pyATS pyats_ios.py file.


On the VS Code EXPLORER panel, click the pyats_ios.py file to open.

Network Automation Testing with pyATS


Step 10 Review the pyats_ios.py file content and compare with the results that you
noted in the previous step.
As you review the pyats_ios.py file content, notice that each defined class
corresponds to each section of the results that you noted in the previous step.
Also, each function that is defined in the classes corresponds to subsections in the
previous result.
Step 11 Analyze the content of the common_setup class and save the name of class
member functions.
Here is an example:
#
# Common Setup Section
#
class common_setup(aetest.CommonSetup):
'''Common Setup Section

Defines subsections that performs configuration common to the entire script.

'''

@aetest.subsection
def check_topology(self, testbed, ios_names):
'''
check that we have at least two devices and a link between the devices
If so, mark the next subsection for looping.
'''

Network Automation Testing with pyATS


# abort/fail the testscript if no testbed was provided
if not testbed or not testbed.devices:
self.failed('No testbed was provided to script launch',
goto = ['exit'])

for ios_name in ios_names:


if ios_name not in testbed:
# abort/fail the testscript if no matching device was provided
self.failed('testbed needs to contain device
{ios_name}'.format(ios_name=ios_name,),goto = ['exit'])

# add them to testscript parameters


ios_device = testbed.devices[ios_name]
# get corresponding links
links = ios_device.links
# save link and ios_device as parameter
self.parent.parameters[ios_name] = {'ios': ios_device, 'links': links}
assert len(links) >= 1, 'require one link or more between devices'

@aetest.subsection
def establish_connections(self, steps, ios_names):
'''
establish connection to both devices
'''
for ios_name in ios_names:
with steps.start('Connecting to ios device: %s'%(ios_name)):
self.parent.parameters[ios_name]['ios'].connect()
# abort/fail the testscript if any device isn't connected
if not self.parent.parameters[ios_name]['ios'].connected:
self.failed('One of the devices could not be connected to',goto =
['exit'])

@aetest.subsection
def marking_interface_count_testcases(self, testbed):
'''
mark the VerifyInterfaceCountTestcase for looping.
'''
# ignore CML terminal_server

10

Network Automation Testing with pyATS


devices = [d for d in testbed.devices.keys() if 'terminal_server' not in d]

logger.info(banner('Looping VerifyInterfaceCountTestcase'
' for {}'.format(devices)))

# dynamic loop marking on testcase


aetest.loop.mark(VerifyInterfaceCountTestcase, device = devices)

Step 12 Based on your previous analysis, answer the following questions about member
functions of the common_setup class.

What action does the check_topology function take?


A) Checks if testbed file exists and if devices exist in testbed file.
B) Checks if testbed file exists, if devices exist in testbed file, and saves devices and
topology information.
C) Saves devices and topology information.
D) Creates the testbed file with devices and topology information
Answer (B)
What action does the establish_connections function take?
A) It connects to all devices and verifies if the connection succeeded.
B) It connects to all devices.
C) It checks for a connection to each device.
D) It checks if devices have connectivity between each other.
Answer (A)
What action does the marking_interface_count_testcases function take?
A) It gets device interfaces from the testbed file and pings the IP address.
B) It gets device interfaces from the testbed.
C) It gets device interfaces from the testbed file and saves them for future use.
D) It gets device interfaces and configures its IP address based on testbed file information.
Answer (C)

Step 13 Scroll through the pyats_ios.py file, analyze the contents of the PingTestcase
class and save the name of class member functions.

11

Network Automation Testing with pyATS


Here is an example:
#
# Ping Testcase: leverage dual-level looping
#
@aetest.loop(ios_name = ('R1', 'R2'))
class PingTestcase(aetest.Testcase):
'''Ping test'''

groups = ('basic', 'looping')

@aetest.setup
def setup(self, ios_name):
destination = []
for link in self.parent.parameters[ios_name]['links']:

# To get the link interfaces ip


for intf in link.interfaces:
parsed_dict = self.parent.parameters[intf.device.name]['ios'].\
parse('show ip interface brief')
intf_ip = parsed_dict['interface'][intf.name]['ip_address']
destination.append(intf_ip)

# apply loop to next section


aetest.loop.mark(self.ping, destination = destination)

@aetest.test
def ping(self, ios_name, destination):
'''
ping destination ip address from device

Sample of ping command result:

ping
Protocol [ip]:
Target IP address: 10.10.10.2
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: n

12

Network Automation Testing with pyATS


Sweep range of sizes [n]: n
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.10.10.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms

'''

try:
# store command result for later usage
result = self.parameters[ios_name]['ios'].ping(destination)

except Exception as e:
# abort/fail the testscript if ping command returns any exception
# such as connection timeout or command failure
self.failed('Ping {} from device {} failed with error: {}'.format(
destination,
device,
str(e),
),
goto = ['exit'])
else:
# extract success rate from ping result with regular expression
match = re.search(r'Success rate is (?P<rate>\d+) percent', result)
success_rate = match.group('rate')
# log the success rate
logger.info(banner('Ping {} with success rate of {}%'.format(
destination,
success_rate,
)
)
)

Step 14 Based on your previous analysis, answer the following questions about member
functions of the pingTestcase class.

What action does the setup function take?


A) It gets a destination array with all IPs associated to a device.
B) It gets a destination array with all IPs associated to links connected to a device.

13

Network Automation Testing with pyATS


C) It gets a destination array with all links connected to a device.
D) It gets a destination array with connection objects to each device.
Answer (B)
What action does the ping function take?
A) It pings the destination.
B) It pings the destination and waits for ping success.
C) It pings the destination and reports the success rate.
D) It pings the destination and, if successful, performs a traceroute.
Answer (C)
Step 15 Scroll down on the pyats_ios.py file, analyze the content of the
VerifyInterfaceCountTestcase class and save the name of class member
functions.
Here is an example:
#
# Verify Interface Count Testcase
#
class VerifyInterfaceCountTestcase(aetest.Testcase):
'''Verify interface count test'''

groups = ('basic', 'looping')

@aetest.test
def extract_interface_count(self, device):
'''
extract interface counts from `show version`

Sample of show version command result:

show version
Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version
15.6(2)T, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Tue 22-Mar-16 16:19 by prod_rel_team

ROM: Bootstrap program is IOSv

14

Network Automation Testing with pyATS


ios2 uptime is 1 hour, 17 minutes
System returned to ROM by reload
System image file is "flash0:/vios-adventerprisek9-m"
Last reload reason: Unknown reason

<....>

Cisco IOSv (revision 1.0) with with 484609K/37888K bytes of memory.


Processor board ID 9QTSICFAZS7Q2I61N8WNZ
2 Gigabit Ethernet interfaces
DRAM configuration is 72 bits wide with parity disabled.
256K bytes of non-volatile configuration memory.
2097152K bytes of ATA System CompactFlash 0 (Read/Write)
0K bytes of ATA CompactFlash 1 (Read/Write)
0K bytes of ATA CompactFlash 2 (Read/Write)
10080K bytes of ATA CompactFlash 3 (Read/Write)

Configuration register is 0x0

'''

try:
# store execution result for later usage
result = self.parameters[device]['ios'].execute('show version')

except Exception as e:
# abort/fail the testscript if show version command returns any
# exception such as connection timeout or command failure
self.failed('Device {} \'show version\' failed: {}'.format(device,
str(e)),
goto = ['exit'])
else:
# extract interfaces counts from `show version`
match = re.search(r'(?P<ethernet>\d+) Gigabit Ethernet interfaces\r\n',
result)
ethernet_intf_count = int(match.group('ethernet'))
# log the interface counts

15

Network Automation Testing with pyATS


logger.info(banner('\'show version\' returns {} ethernet interfaces'
.format(
ethernet_intf_count

)
)
)
# add them to testcase parameters
self.parameters.update(ethernet_intf_count = ethernet_intf_count,
serial_intf_count = 0)

@aetest.test
def verify_interface_count(self, device, ethernet_intf_count = 0,
serial_intf_count = 0):
'''
verify interface counts with `show ip interface brief`

Sample of show ip interface brief command result:

show ip interface brief


Interface IP-Address OK? Method Status
Protocol
GigabitEthernet0/0 unassigned YES unset administratively down
down
GigabitEthernet0/1 10.10.10.2 YES manual up
up
'''

try:
# store execution result for later usage
result = self.parameters[device]['ios'].execute('show ip interface
brief')

except Exception as e:
# abort/fail the testscript if show ip interface brief command
# returns any exception such as connection timeout or command
# failure
self.failed('Device {} \'show ip interface brief\' failed: '
'{}'.format(device, str(e)),
goto = ['exit'])

16

Network Automation Testing with pyATS


else:
# extract ethernet interfaces
ethernet_interfaces = re.finditer(r'\r\nGigabitEthernet\d+\s+', result)
# total number of ethernet interface
len_ethernet_interfaces = len(tuple(ethernet_interfaces))

# log the ethernet interface counts


logger.info(banner('\'show ip interface brief\' returns {} ethernet'
' interfaces'.format(len_ethernet_interfaces)))

# compare the ethernet interface count between


# `show ip interface brief` and `show version`
assert len_ethernet_interfaces == ethernet_intf_count

Step 16 Based on your previous analysis, provide the correct answer to the following
question about member functions of the VerifyInterfaceCountTestcase class.
What action does the extract_interface_count function take?
A) It gets the device interface number from the show version command.
B) It gets the device interface number from the show ip interface brief command.
C) It gets the device interface number from the show interface description command.
D) It gets the device interface number from the show inventory command.
Answer (A)

What action does the verify_interface_count function take?


A) It gets the device interface number from the show version command.
B) It gets the device interface number from the show ip interface brief command.
C) It gets the device interface number from the show interface description command.
D) It gets the device interface number from the show inventory command.
Answer (B)
Step 17 Scroll down on the pyats_ios.py file, analyze the content of the
common_cleanup class and save the name of class member functions.
Here is an example:
#
# Disconnect from ios routers

17

Network Automation Testing with pyATS


#
class common_cleanup(aetest.CommonCleanup):
'''disconnect from ios routers'''

@aetest.subsection
def disconnect(self, steps, ios_names):
'''disconnect from both devices'''
for ios_name in ios_names:
with steps.start('Disconnecting from ios device: %s'%(ios_name)):
self.parameters[ios_name]['ios'].disconnect()
if self.parameters[ios_name]['ios'].connected:
# abort/fail the testscript if device connection still exists
self.failed('One of the devices could not be disconnected from',
goto = ['exit'])

Step 18 Based on your previous analysis, provide the correct answer to the following
question about member functions of the common_cleanup class.
What action does the disconnect function take?
A) It disconnects from all devices.
B) It disconnects from all devices and verify disconnection was successful.
C) It disconnects from all devices and connect to again.
D) It disconnects from all devices and waits until connections reestablish.
Answer (B)

Activity Verification
You have completed this task when you obtain the following results:
 You successfully reviewed the pyATS testbed file.
 You successfully reviewed the pyATS script file.
 You successfully ran the pyATS script file.

18

Network Automation Testing with pyATS


Task 2: Update pyATS Testbed and Script Files
In this task, you will update the pyATS testbed and script files.

Activity Procedure
Complete the following steps:
Step 1 On the VS Code, Edit the testbed file.
On the VS Code EXPLORER panel, click the pyats_ios_default.yaml file.

Step 2 In testbed file, in the topology section, add a second link between R1 and R2.
Use information provided in Job Aid.

Note: Be careful with spaces in the YAML file, as spaces in YAML files must be formatted properly.

Compare your testbed file with the following YAML file:


Interface GigabitEthernet2 on R1 topology:
GigabitEthernet2:
ipv4: 10.0.12.1/24
link: n2
type: ethernet

Interface GigabitEthernet2 on R2 topology:

19

Network Automation Testing with pyATS


GigabitEthernet2:
ipv4: 10.0.12.2/24
link: n2
type: ethernet

Step 3 Verify that your testbed file is equal to the following YAML file. Then, save your
changes.

testbed:
name: pyATS_IOS_Example_Testbed
credentials:
default:
username: cisco
password: cisco
devices:
R1:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.21
port: 22
type: iosxe
os: iosxe
R2:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.22
port: 22
type: iosxe
os: iosxe
topology:
R1:

20

Network Automation Testing with pyATS


interfaces:
GigabitEthernet1:
ipv4: 172.21.1.21/24
link: n1
type: ethernet
GigabitEthernet2:
ipv4: 10.0.12.1/24
link: n2
type: ethernet
R2:
interfaces:
GigabitEthernet1:
ipv4: 172.21.1.22/24
link: n1
type: ethernet
GigabitEthernet2:
ipv4: 10.0.12.2/24
link: n2
type: ethernet

On VS Code, click the File menu and click Save to save your changes.
Step 4 On VS Code, run the pyats_ios.py script.
On VS Code, use python pyats_ios.py command.

Step 5 From the Detailed Results section, notice that pyATS automatically discovered
the new link between R1 and R2 and includes the IP addresses for the interfaces
in the ping test.
Here is an example:
+------------------------------------------------------------------------------+
| Detailed Results |
+------------------------------------------------------------------------------+
SECTIONS/TESTCASES RESULT
--------------------------------------------------------------------------------
.
|-- common_setup PASSED
| |-- check_topology PASSED

21

Network Automation Testing with pyATS


| |-- establish_connections PASSED
| | |-- Step 1: Connecting to ios device: R1 PASSED
| | `-- Step 2: Connecting to ios device: R2 PASSED
| `-- marking_interface_count_testcases PASSED
|-- PingTestcase[ios_name=R1] PASSED
| |-- setup PASSED
| |-- ping[destination=172.21.1.21] PASSED
| |-- ping[destination=172.21.1.22] PASSED
| |-- ping[destination=10.0.12.1] PASSED
| `-- ping[destination=10.0.12.2] PASSED
|-- PingTestcase[ios_name=R2] PASSED
| |-- setup PASSED
| |-- ping[destination=172.21.1.21] PASSED
| |-- ping[destination=172.21.1.22] PASSED
| |-- ping[destination=10.0.12.1] PASSED
| `-- ping[destination=10.0.12.2] PASSED
|-- VerifyInterfaceCountTestcase[device=R1] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED
|-- VerifyInterfaceCountTestcase[device=R2] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED
`-- common_cleanup PASSED
`-- disconnect PASSED
|-- Step 1: Disconnecting from ios device PASSED
`-- Step 2: Disconnecting from ios device PASSED
+------------------------------------------------------------------------------+
| Summary |
+------------------------------------------------------------------------------+
Number of ABORTED 0
Number of BLOCKED 0
Number of ERRORED 0
Number of FAILED 0

22

Network Automation Testing with pyATS


Number of PASSED 6
Number of PASSX 0
Number of SKIPPED 0
Total Number 6
Success Rate 100.0%
--------------------------------------------------------------------------------
(pyats) student@student-vm:~/pyats-ios-sample$

Step 6 In the VS Code editor panel, edit the testbed file to add a new router, R3. Also,
edit the topology section to include a link between R3 and the R1 and R2 routers.
Use information provided in Job Aid.

Note Be careful with spaces in the YAML file, as spaces in YAML files must be formatted
properly.

Compare your testbed file with the following YAML file:


R3 definition in testbed section:
R3:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.23
port: 22
type: iosxe
os: iosxe

Interface GigabitEthernet3 on R1 topology section:


GigabitEthernet3:
ipv4: 10.0.13.1/24
link: n3
type: ethernet

Interface GigabitEthernet3 on R2 topology section:


GigabitEthernet3:

23

Network Automation Testing with pyATS


ipv4: 10.0.23.1/24
link: n4
type: ethernet

R3 definition in topology section:


R3:
interfaces:
GigabitEthernet1:
ipv4: 172.21.1.23/24
link: n1
type: ethernet
GigabitEthernet2:
ipv4: 10.0.13.2/24
link: n3
type: ethernet
GigabitEthernet3:
ipv4: 10.0.23.2/24
link: n4
type: ethernet

Step 7 Verify that your testbed file is equal to the following YAML file. Then save your
changes.

testbed:
name: pyATS_IOS_Example_Testbed
credentials:
default:
username: cisco
password: cisco
devices:
R1:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.21

24

Network Automation Testing with pyATS


port: 22
type: iosxe
os: iosxe
R2:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.22
port: 22
type: iosxe
os: iosxe
R3:
connections:
defaults:
class: 'unicon.Unicon'
a:
protocol: ssh
ip: 172.21.1.23
port: 22
type: iosxe
os: iosxe
topology:
R1:
interfaces:
GigabitEthernet1:
ipv4: 172.21.1.21/24
link: n1
type: ethernet
GigabitEthernet2:
ipv4: 10.0.12.1/24
link: n2
type: ethernet
GigabitEthernet3:
ipv4: 10.0.13.1/24
link: n3
type: ethernet
R2:

25

Network Automation Testing with pyATS


interfaces:
GigabitEthernet1:
ipv4: 172.21.1.22/24
link: n1
type: ethernet
GigabitEthernet2:
ipv4: 10.0.12.2/24
link: n2
type: ethernet
GigabitEthernet3:
ipv4: 10.0.23.1/24
link: n4
type: ethernet
R3:
interfaces:
GigabitEthernet1:
ipv4: 172.21.1.23/24
link: n1
type: ethernet
GigabitEthernet2:
ipv4: 10.0.13.2/24
link: n3
type: ethernet
GigabitEthernet3:
ipv4: 10.0.23.2/24
link: n4
type: ethernet

On VS Code, click the File menu and click Save to save your changes.
Step 8 On the VS Code, open the pyats_ios.py file.
On the VS Code EXPLORER panel, click the pyats_ios.py file to open the main
panel.

26

Network Automation Testing with pyATS


Step 9 Edit line number 135 to include the R3 router in the loop.
Here is an example:
#
# Ping Testcase: leverage dual-level looping
#
@aetest.loop(ios_name = ('R1', 'R2', 'R3'))
class PingTestcase(aetest.Testcase):
'''Ping test'''

Step 10 Edit line number 338 to include the R3 router name in the ios_name variable.
Here is an example:
from ats.topology import loader
parser = argparse.ArgumentParser(description = "standalone parser")
parser.add_argument('--ios', dest = 'ios_names', type = list, default = ['R1',
'R2', 'R3'])
parser.add_argument('--testbed', dest = 'testbed', type = loader.load, default =
'pyats_ios_default.yaml')
# parse args

Step 11 After updating the pyats_ios.py file, on VS Code, save your changes.
On VS Code, click the File menu and select Save to save your changes.
Step 12 In the VS Code terminal, run the pyats_ios.py script.
In the VS Code terminal, use the python pyats_ios.py command to run the
pyats_ios.py script.

27

Network Automation Testing with pyATS


Step 13 From the Detailed Results section, notice that pyATS automatically discovered
the new link between R1 and R2 and includes the IP addresses for the interfaces
in the ping test.
Here is an example:

+------------------------------------------------------------------------------+
| Detailed Results |
+------------------------------------------------------------------------------+
SECTIONS/TESTCASES RESULT
--------------------------------------------------------------------------------
.
|-- common_setup PASSED
| |-- check_topology PASSED
| |-- establish_connections PASSED
| | |-- Step 1: Connecting to ios device: R1 PASSED
| | |-- Step 2: Connecting to ios device: R2 PASSED
| | `-- Step 3: Connecting to ios device: R3 PASSED
| `-- marking_interface_count_testcases PASSED
|-- PingTestcase[ios_name=R1] PASSED
| |-- setup PASSED
| |-- ping[destination=10.0.13.1] PASSED
| |-- ping[destination=10.0.13.2] PASSED
| |-- ping[destination=10.0.12.1] PASSED
| |-- ping[destination=10.0.12.2] PASSED
| |-- ping[destination=172.21.1.21] PASSED
| |-- ping[destination=172.21.1.22] PASSED
| `-- ping[destination=172.21.1.23] PASSED
|-- PingTestcase[ios_name=R2] PASSED
| |-- setup PASSED
| |-- ping[destination=10.0.12.1] PASSED
| |-- ping[destination=10.0.12.2] PASSED

28

Network Automation Testing with pyATS


| |-- ping[destination=172.21.1.21] PASSED
| |-- ping[destination=172.21.1.22] PASSED
| |-- ping[destination=172.21.1.23] PASSED
| |-- ping[destination=10.0.23.1] PASSED
| `-- ping[destination=10.0.23.2] PASSED
|-- PingTestcase[ios_name=R3] PASSED
| |-- setup PASSED
| |-- ping[destination=10.0.13.1] PASSED
| |-- ping[destination=10.0.13.2] PASSED
| |-- ping[destination=172.21.1.21] PASSED
| |-- ping[destination=172.21.1.22] PASSED
| |-- ping[destination=172.21.1.23] PASSED
| |-- ping[destination=10.0.23.1] PASSED
| `-- ping[destination=10.0.23.2] PASSED
|-- VerifyInterfaceCountTestcase[device=R1] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED
|-- VerifyInterfaceCountTestcase[device=R2] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED
|-- VerifyInterfaceCountTestcase[device=R3] PASSED
| |-- extract_interface_count PASSED
| `-- verify_interface_count PASSED
`-- common_cleanup PASSED
`-- disconnect PASSED
|-- Step 1: Disconnecting from ios device: R1 PASSED
|-- Step 2: Disconnecting from ios device: R2 PASSED
`-- Step 3: Disconnecting from ios device: R3 PASSED
+------------------------------------------------------------------------------+
| Summary |
+------------------------------------------------------------------------------+
Number of ABORTED 0
Number of BLOCKED 0

29

Network Automation Testing with pyATS


Number of ERRORED 0
Number of FAILED 0
Number of PASSED 8
Number of PASSX 0
Number of SKIPPED 0
Total Number 8
Success Rate 100.0%
--------------------------------------------------------------------------------
(pyats) student@student-vm:~/pyats-ios-sample$

Activity Verification
You have completed this task when you obtain the following results:
 You successfully updated the pyATS testbed file.
 You successfully updated the pyATS script file.
 You successfully ran the pyATS script file.

30

Network Automation Testing with pyATS

You might also like