LAB 1-Network Automation Testing pyATS - 62722
LAB 1-Network Automation Testing pyATS - 62722
Topology
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 to each other through the
GigabitEthernet2 and GigabitEthernet3 interfaces.
Job Aid
Device Credentials
R1 Username: cisco
Password: cisco
R2 Username: cisco
Password: cisco
R3 Username: cisco
Password: cisco
GigabitEthernet3: 10.0.23.2/24
Activity Procedure
Complete the following steps:
Step 1 Connect to the Jumpbox PC.
Step 2 On the Jumpbox destop, start Visual Studio Code by double-clicking its icon.
Step 3 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.
Step 4 As you review the content of the YAML testbed file, notice the two main sections
testbed and topology. Also, notice the two devices in this topology, R1 and R2.
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:
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, active the pyats virtual environment with the
source /pyats/bin/activate command. Then change the working directory to
pyats-ios with the cd pyats-ios/ command.
Step 6 Run the pyats_ios.py script with the command python pyats_ios.py.
Step 7 On the Detailed Results section, take note of the main sections. Each section
corresponds to pyATS classes that are defined in the pyATS script file. You will
review these classes in the following steps.
+------------------------------------------------------------------------------+
| Detailed Results |
+------------------------------------------------------------------------------+
SECTIONS/TESTCASES RESULT
--------------------------------------------------------------------------------
+------------------------------------------------------------------------------+
| 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
--------------------------------------------------------------------------------
(pyats) student@student-vm:~/pyats-ios-sample$
Step 8 On the VS Code EXPLORER panel, open the pyATS script file by clicking
pyats_ios.py.
Step 9 As you review the content of the script, notice that each defined class
corresponds to each section of the results that you noted in the previous step.
Also, each function defined in these classes corresponds to subsections in the
previous result.
Step 10 Review the content of common_setup class.
#
class common_setup(aetest.CommonSetup):
'''
@aetest.subsection
'''
check that we have at least two devices and a link between the devices
'''
goto = ['exit'])
links = ios_device.links
@aetest.subsection
'''
'''
self.parent.parameters[ios_name]['ios'].connect()
if not self.parent.parameters[ios_name]['ios'].connected:
@aetest.subsection
'''
'''
logger.info(banner('Looping VerifyInterfaceCountTestcase'
Step 11 Based on your previous revision, provide a brief description of the following
member functions of common_setup class.
check_topology: _________________________________________________________
________________________________________________________________________
establish_connections:____________________________________________________
________________________________________________________________________
marking_interface_count_testcases:_________________________________________
________________________________________________________________________
Step 12 Scroll down the script file and analize the contents of the PingTestcase class.
class PingTestcase(aetest.Testcase):
'''Ping test'''
destination = []
parsed_dict = self.parent.parameters[intf.device.name]['ios'].\
intf_ip = parsed_dict['interface'][intf.name]['ip_address']
destination.append(intf_ip)
@aetest.test
'''
ping
Protocol [ip]:
!!!!!
'''
try:
result = self.parameters[ios_name]['ios'].ping(destination)
# result = self.parameters[device].ping(destination)
except Exception as e:
destination,
device,
str(e),
),
goto = ['exit'])
else:
success_rate = match.group('rate')
destination,
success_rate,
Step 13 Based on your previous revision, provide a brief description of the following
member functions of the pingTestcase class.
setup: __________________________________________________________________
________________________________________________________________________
ping:____________________________________________________________________
________________________________________________________________________
Step 14 Scroll down on the pyATS script file and analyze the contents of the
VerifyInterfaceCountTestcase class.
class VerifyInterfaceCountTestcase(aetest.Testcase):
@aetest.test
def extract_interface_count(self, device):
'''
show version
<....>
'''
try:
except Exception as e:
str(e)),
goto = ['exit'])
else:
ethernet_intf_count = int(match.group('ethernet'))
ethernet_intf_count
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):
'''
'''
try:
except Exception as e:
# failure
'{}'.format(device, str(e)),
goto = ['exit'])
else:
ethernet_interfaces = re.finditer(r'\r\nGigabitEthernet\d+\s+',
result)
len_ethernet_interfaces = len(tuple(ethernet_interfaces))
' interfaces'.format(len_ethernet_interfaces)))
extract_interface_count: ___________________________________________________
________________________________________________________________________
verify_interface_count:____________________________________________________
________________________________________________________________________
Step 16 Scroll down on the script file and analyze the content of the common_cleanup
class.
class common_cleanup(aetest.CommonCleanup):
@aetest.subsection
self.parameters[ios_name]['ios'].disconnect()
if self.parameters[ios_name]['ios'].connected:
goto = ['exit'])
Activity Verification
You have completed this task when you obtain the following results:
Successfully review the pyATS testbed file.
Successfully review the pyATS script file.
Successfully run the pyATS script file.
Activity Procedure
Complete the following steps:
Step 1 On the VS Code EXPLORER panel, click the pyats_ios_default.yaml file.
Step 2 In the topology section, add a second link between R1 and R2. When you finish,
compare your testbed file with the following YAML file:
Interfece GigabitEthernet2 on R1 topology:
GigabitEthernet2:
ipv4: 10.0.12.1/24
link: n2
type: ethernet
Step 3 Verify that your testbed file is equal to the following YAML file. Then press
Ctrl + S to 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:
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
Step 1 On VS Code, run the pyats_ios.py script with the python pyats_ios.py
command.
Step 1 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.
+------------------------------------------------------------------------------+
| Detailed Results |
+------------------------------------------------------------------------------+
SECTIONS/TESTCASES RESULT
--------------------------------------------------------------------------------
+------------------------------------------------------------------------------+
| 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
--------------------------------------------------------------------------------
(pyats) student@student-vm:~/pyats-ios-sample$
Step 2 On the VS Code main 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.
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
Step 3 Verify that your testbed file is equal to the following YAML file. Then press
Ctrl + S to 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
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:
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
Step 4 On the VS Code EXPLORER panel, click the pyats_ios.py file to open the mail
panel.
Step 5 Edit line number 135 to include the R3 router in the loop.
class PingTestcase(aetest.Testcase):
'''Ping test'''
Step 6 Edit line number 338 to include the R3 router name in the ios_name variable.
# parse args
Step 1 After you update the script, press Ctrl + S to save your changes.
Step 2 On VS Code, run the pyats_ios.py script with the python pyats_ios.py
command.
Step 3 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.
+------------------------------------------------------------------------------+
| Detailed Results |
+------------------------------------------------------------------------------+
SECTIONS/TESTCASES RESULT
--------------------------------------------------------------------------------
+------------------------------------------------------------------------------+
| Summary |
+------------------------------------------------------------------------------+
Number of ABORTED 0
Number of BLOCKED 0
Number of ERRORED 0
Number of FAILED 0
Number of PASSED 8
Number of PASSX 0
Number of SKIPPED 0
Total Number 8
--------------------------------------------------------------------------------
(pyats) student@student-vm:~/pyats-ios-sample$
Activity Verification
You have completed this task when you obtain the following results:
Successfully update the pyATS testbed file.
Successfully update the pyATS script file.
Successfully run the pyATS script file.