SlideShare uma empresa Scribd logo
1 de 61
Is the Network Ready for Use?
An automated testing approach using pytest
Jeremy Schulman
Heading up Network Automation at MLB
2019 - October - NANOG 77
@nwkautomaniac
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
About Me
● Jeremy Schulman
○ Software engineer, sales & systems engineer, ...
○ 20 yrs @ Vendors
○ Now @ Major League Baseball
● @nwkautomaniac - Est. 2012
● 100% focused on network automation
● Open-source & community contributor
2
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
About this Tutorial
● Motivation for “Network Ready for Use”
● General testing concepts
● pytest to automate network tests
● Live coding tutorials
● Q & A
3
https://github.com/jeremyschulman/nanog77-nrfu-tutorial
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
About You
● You have a working knowledge of Python
● You are a Network Engineer working on
automation projects
● You are a Developer / DevOps working with
Network Engineers
4
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
About pytest
pytest is an open-source software testing
framework used by software developers to test
their code
5
http://pytest.org
● We are going to treat the network as our “code”
● We are going to use pytest to validate operational
states of the network
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Network Ready For Use
Does the actual operating states of the network
match the expected outcomes based on the design?
Motivation
DESIGN BUILD DEPLOY VALIDATE
Workflow
Lifecycle
NRFU !
6
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Motivating Use-Case
New building network
● Consist of hundreds of network devices
● Multiple floors, multiple rooms per floor
● 3rd-party installing equipment
● 3rd-party (different) installing structured cabling
● Staggered installation schedule over multiple weeks
7
Use automated testing to run audits
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Network Ready For Use - Phase 1
NRFU testing to validate physical installation
● Devices on-boarded into management system
● Optics installed properly
● Cabling installed properly
8
DONE = network is ready for use for NETENG to
deploy network services
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Network Ready for Use - Phase 2
NRFU audit to validate network services are
operating correctly
● LACP, MLAG, BGP, VXLAN, …
9
DONE = network is ready for use for other teams
to deploy their equipment
● VoIP, IPTV, InfoSec, Building Management, etc.
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
The Installation & Cabling Plan
We provide spreadsheets to the installation teams:
10
Phase-1
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Audit Criteria
Transceivers
○ For each interface is the correct transceiver installed?
○ Are transceivers only present where expected?
Interface Status
○ For each interface is the operational state as expected?
○ Are unused interfaces placed in a shutdown state?
Cabling
○ Is LLDP reporting the remote system/interface as expected?
○ Are any unexpected connections present?
11
Phase-1
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
NRFU Audit Reporting
We produce an audit report so we can pinpoint corrective
actions for the installation team, for example:
12
Phase-1
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
NRFU Dashboard Report
13
Not Done!
● 11 devices not tested
● 275 test failures
● Failures prioritized
Phase-1
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Automated Approach Required
● Total devices > 300
● Building with multiple
floors / rooms
● Mixture of different
hardware devices
● Mixture of transceiver
types; SMF, MMF, and
CAT6 cabling
14
Test Case Number of Tests
Transceiver check 4,248
Interface status check 16,688
Cabling check 2,046
Total 22,982
Audit Scope and Scale
Based on the campus design, almost 23K test-
cases covered by NRFU:
Phase-1
Screenshots
using pytest
Showcasing both command-line
and WebUI reports
15
http://pytest.org
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
pytest run for a given device
16
PASS
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
pytest run for a given device
17
FAIL
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
pytest run for a given device
18
FAILFAIL
Live Demo
19
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Recap
20
● pytest can be used to execute specific test cases
against specific devices
● Test cases are parameterized
● Test cases uniquely named can be filtered
based on these names
● Use CLI to show brief PASS / FAIL output
● Use HTML to show more actionable failure information
General Testing
Concepts
21
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Testing
22
Testing is a means to provide a metric of quality
and completeness.
We are using testing to answer the question:
Is the network ready for use?
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Test Coverage
Test coverage is the metric that measures the
amount of testing performed by a set of tests
over a collection of Devices Under Test (DUTs)
23
Total number of DUTs that
are online and can be measured
vs.
The total number of DUTs
For each DUT, the total number of
test cases PASSING
vs.
The total number of DUT test cases
Done ?
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Test Coverage
For each Device Under Test (DUT) we need to
identify the specific test cases for each of the
test functions.
24
Test Function Number of Test-cases
test_optic_inventory 30
test_interface_status 36
test_cabling 34
Total 100
For example, “switch-2105” in our
network requires the following
number of test cases per test
function.
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Crafting Test-cases
A test case is generally represented
as a record of structured data.
Each device, e.g. “switch-2105” will
have a JSON file per test function,
e.g. “cabling”, containing a list of test
cases.
Each unique test case is a specific
dictionary in this list.
25
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
DUT Actual Data
The test function will need to examine the
DUT actual data and apply the logic to
compare it with the test-case data.
The test function for this tutorial will be tightly
coupled to the DUT actual data, i.e. specific to
this device/NOS. An example JSON body is
shown.
The test function will extract the specific fields
and perform the validation logic.
26
Example Arista EOS via eAPI
show lldp neighbors
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Putting it Together
27
Test function
DUT
Actual Data
Test case
PASS
FAIL
All expected
outcomes are met
without exception
Expected outcomes
not met due to one
or more exceptions
Data obtained originating
from the device under test
Data used to parameterize
the test and identify
expected outcomes
Logic to determine if the
actual data meets the
expected outcomes of the
test-case
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Testing Considerations
Separate the “What” from the “How”
Actual data
How does the test obtain the DUT data?
Test-cases
How are these test-cases created?
How are these test-cases stored?
How does test get these test-cases?
28
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Obtaining DUT Actual Data
● Open a session directly to the device, e.g. using Netmiko,
pyEAPI, etc.
● Use a controller-server that aggregates many devices
● Use a database that is populated by yet another
software system
● Normalizing data from multiple vendors
29
… always based on your specific constraints
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Obtaining Test-Cases
30
● Write a program to generate test-case data based on
some other Source-of-Truth system(s), which could be
○ One or more spreadsheets
○ From an internal database system
○ From other SoT systems like NetBox
… always based on your specific constraints
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Test Functions
Writing tightly-coupled test functions … is OK
The test functions uses the DUT actual data
If the test function is written to use a specific
DUT output format, then it is tightly-coupled to that DUT
Same is true for the structure and/or content of the test-case
31
Decisions around abstractions, normalizing data, etc.,
are specific to your specific constraints
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Recap
● Test coverage is a collection of test functions
● Test functions are run with multiple test-cases
● Test functions OK to be tightly coupled to DUT
○ Test-case structure not tightly coupled
○ Test-case data tightly coupled to DUT
32
There are no “right answers” only “right now answers”
Introduction to
pytest
33
http://pytest.org
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
pytest Tutorial
34
● Basic project setup
● Writing test functions
● Writing test function fixtures
● Writing parameterized test-cases
● Running pytest to filter test cases
● Creating HTML reports
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Installing pytest
35
(venv)$ pip install pytest
(venv)$ pip install pytest-html
Recommend installing into virtualenv
http://plugincompat.herokuapp.com/
Almost 700 pytest plugins listed:
Live Demo
36
“NRFU” pytest
Coding Tutorials
37
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
NRFU Tutorials
38
1. Create custom pytest options
2. Initially verify the device is online
3. Running test-functions
a. Provide device instance to test-functions
b. Load device specific test-cases
c. Using “bulk-data” type device commands
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Testing Strategy
39
Device
NRFU Library of Functions
nrfupytesteos
Load DUT test-cases JSON file
Get Actual Data pyEAPI
The
NetworkTest Function
Each pytest Test File (python module)
pytest ● Test one device per pytest run
● Write one test file per test function
● Each device has directory of JSON
files, each per test function
testcases/switch-21.bld1
├── testcases-cabling.json
├── testcases-interface-status.json
└── testcases-optic-inventory.json
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Create Custom pytest Options
40
I want to tell pytest the device I want to run tests
against. I need to provide the device hostname
and also the directory that has the test-case files.
$ pytest 
--nrfu-device switch-21.bld1 
--nrfu-testcases /opt/nrfu/testcases/switch-21.bld1 
<other pytest options>
what
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Create Custom pytest Options
41
Write a pytest_addoption hook function to
add your custom options:
how
conftest.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Initially Verify Device Online
42
Once I give pytest the device information, I want
pytest to first ensure the device is online before I
start running any tests.
$ pytest --nrfu-device switch-111.bld2 <...>
Exit: Unable to connect to device switch-111.bld2
!!!!!!!!! _pytest.outcomes.Exit: Unable to connect to device switch-111.bld2 !!!!!!!!!!
what
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Initially Verify Device Online
43
Write a pytest_sessionstart hook function
to run code before any tests are executed:
how
conftest.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Provide the device to test functions
I will need to provide the device object to my test
function so that I can retrieve the actual data from the
device.
44
what
test_cabling.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Provide the device to test-cases
Create a function called device() in
conftest.py and as a session level fixture.
This function will be run only once.
45
how
conftest.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Load device specific test-cases
I need to use test-cases that are specific to the
device under test. Using the CLI option I
provided, load the test-case file to parameterize
the test cases to the test functions
46
$ pytest 
--nrfu-testcases /opt/nrfu/testcases/switch-21.bld1 
<...>
what
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Load device specific test-cases
I want to see each test case instance reported.
For example, cabling test shows the expected
remote device and interface:
47
what
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Load device specific test-cases
Write the test function to uses a fixture, in this
example called testcase. This fixture needs to
be parameterized using a JSON file.
48
how
test_cabling.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Load device specific test-cases
write the pytest_generate_tests hook
function, in the same python file containing the
test case function:
49
how
test_cabling.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Load device specific test-cases
Use parametrize to dynamically load the
testcase fixture values from any source, a
JSON file in this example:
50
how
test_cabling.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Load device specific test-cases
parametrize takes the fixture name as a string.
This value must match the same argument name
used by the test function.
51
how
test_cabling.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Generating test-cases names
52
how
test_cabling.py
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Recap: device specific test-cases
The coding shown in the previous slides will result
in pytest running the test function multiple times,
each with the specific test name
53
what
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Use “bulk-data” device results
In some cases I need to run a device command
that will contain the results for many test-cases.
For example I must use the “show inventory”
command to obtain the transceiver data. That
command does not allow me to get data for one
interface at a time.
54
what
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Use “bulk-data” device results
Define a module level fixture to return the bulk-
data. A module fixture will be called only once
per python test-function module.
55
how
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Use “bulk-data” device results
56
how
test_optics.py
Recapping Tutorial
57
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Summary
58
● pytest can be used to automate network testing
● pytest has a large community & catalog of plugins
● Useful for both “greenfield” and “brownfield” scenarios
● You still need to write your own test functions
● You still need to determine your testing strategy
Opportunity for Networking community
Copyright © 2019 - Jeremy Schulman - All Rights Reserved
Reference Links
https://twitter.com/pytestdotorg
● https://github.com/jeremyschulman/nanog77-nrfu-tutorial
● http://www.pytest.org
● http://www.pytest.org/en/latest/#documentation
● https://docs.pytest.org/en/latest/talks.html
● https://docs.pytest.org/en/latest/parametrize.html
● https://docs.pytest.org/en/latest/fixture.html#fixture-parametrize
59
https://pythontesting.net/
Podcasts, Blogs, and much
more at:
Q & A
60
Thank you!
61
Jeremy Schulman
@nwkautomaniac

Mais conteúdo relacionado

Mais procurados

機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)
機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)
機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)Hadoop / Spark Conference Japan
 
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery BlueHat Security Conference
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkSergey Petrunya
 
VictoriaLogs: Open Source Log Management System - Preview
VictoriaLogs: Open Source Log Management System - PreviewVictoriaLogs: Open Source Log Management System - Preview
VictoriaLogs: Open Source Log Management System - PreviewVictoriaMetrics
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction Robert Reiz
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional WorldDebasish Ghosh
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughThomas Graf
 
KubeCon + CloudNative Con NA 2021 | A New Generation of NATS
KubeCon + CloudNative Con NA 2021 | A New Generation of NATSKubeCon + CloudNative Con NA 2021 | A New Generation of NATS
KubeCon + CloudNative Con NA 2021 | A New Generation of NATSNATS
 
Infrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and AnsibleInfrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and AnsibleDevOps Meetup Bern
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
 
Time Series Data with InfluxDB
Time Series Data with InfluxDBTime Series Data with InfluxDB
Time Series Data with InfluxDBTuri, Inc.
 

Mais procurados (20)

機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)
機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)
機械学習、グラフ分析、SQLによるサイバー攻撃対策事例(金融業界)
 
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Advanced Terraform
Advanced TerraformAdvanced Terraform
Advanced Terraform
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
 
Terraform
TerraformTerraform
Terraform
 
VictoriaLogs: Open Source Log Management System - Preview
VictoriaLogs: Open Source Log Management System - PreviewVictoriaLogs: Open Source Log Management System - Preview
VictoriaLogs: Open Source Log Management System - Preview
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Ansible Introduction
Ansible Introduction Ansible Introduction
Ansible Introduction
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional World
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Configuration Management in Ansible
Configuration Management in Ansible Configuration Management in Ansible
Configuration Management in Ansible
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
KubeCon + CloudNative Con NA 2021 | A New Generation of NATS
KubeCon + CloudNative Con NA 2021 | A New Generation of NATSKubeCon + CloudNative Con NA 2021 | A New Generation of NATS
KubeCon + CloudNative Con NA 2021 | A New Generation of NATS
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Infrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and AnsibleInfrastructure as Code with Terraform and Ansible
Infrastructure as Code with Terraform and Ansible
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Introduce to Terraform
Introduce to TerraformIntroduce to Terraform
Introduce to Terraform
 
Time Series Data with InfluxDB
Time Series Data with InfluxDBTime Series Data with InfluxDB
Time Series Data with InfluxDB
 

Semelhante a Automating "Network Ready for Use" with pytest

Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...
Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...
Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...Synopsys Software Integrity Group
 
MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...
MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...
MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...MIPI Alliance
 
Powersoft19 Overview - 2013
Powersoft19 Overview - 2013Powersoft19 Overview - 2013
Powersoft19 Overview - 2013Huzaifa Saadat
 
The Path to a Programmable Network
The Path to a Programmable NetworkThe Path to a Programmable Network
The Path to a Programmable NetworkMyNOG
 
Network Simulation - Prague 2015
Network Simulation - Prague 2015Network Simulation - Prague 2015
Network Simulation - Prague 2015Wardner Maia
 
Test Tool for Industrial Ethernet Network Performance (June 2009)
Test Tool for Industrial Ethernet Network Performance (June 2009)Test Tool for Industrial Ethernet Network Performance (June 2009)
Test Tool for Industrial Ethernet Network Performance (June 2009)Jim Gilsinn
 
Performance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cPerformance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cAjith Narayanan
 
Viavi_TeraVM Core Emulator.pptx
Viavi_TeraVM Core Emulator.pptxViavi_TeraVM Core Emulator.pptx
Viavi_TeraVM Core Emulator.pptxmani723
 
Mule soft meetup_th_no1
Mule soft meetup_th_no1Mule soft meetup_th_no1
Mule soft meetup_th_no1WendyTey4
 
Testing strategies and best practices using MUnit
Testing strategies and best practices using MUnitTesting strategies and best practices using MUnit
Testing strategies and best practices using MUnitJimmy Attia
 
Automated Performance Testing for Desktop Applications by Ciprian Balea
Automated Performance Testing for Desktop Applications by Ciprian BaleaAutomated Performance Testing for Desktop Applications by Ciprian Balea
Automated Performance Testing for Desktop Applications by Ciprian Balea3Pillar Global
 
Continuous Performance Testing in DevOps - Lee Barnes
Continuous Performance Testing in DevOps - Lee BarnesContinuous Performance Testing in DevOps - Lee Barnes
Continuous Performance Testing in DevOps - Lee BarnesQA or the Highway
 
DSL, Gfast and Wireless Test Software: Test Sentinel
DSL, Gfast and Wireless Test Software: Test SentinelDSL, Gfast and Wireless Test Software: Test Sentinel
DSL, Gfast and Wireless Test Software: Test SentinelUNH InterOperability Lab
 
Mule soft meetup_tw_no1_june17
Mule soft meetup_tw_no1_june17Mule soft meetup_tw_no1_june17
Mule soft meetup_tw_no1_june17WendyTey4
 
Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?Ghodhbane Mohamed Amine
 
JavaOne2013: Implement a High Level Parallel API - Richard Ning
JavaOne2013: Implement a High Level Parallel API - Richard NingJavaOne2013: Implement a High Level Parallel API - Richard Ning
JavaOne2013: Implement a High Level Parallel API - Richard NingChris Bailey
 
MuleSoft Singapore Meetup May 2020
MuleSoft Singapore Meetup May 2020MuleSoft Singapore Meetup May 2020
MuleSoft Singapore Meetup May 2020Julian Douch
 

Semelhante a Automating "Network Ready for Use" with pytest (20)

Check Point sizing security
Check Point sizing securityCheck Point sizing security
Check Point sizing security
 
Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...
Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...
Webinar–Improving Fuzz Testing of Infotainment Systems and Telematics Units U...
 
Design Driven Network Assurance
Design Driven Network AssuranceDesign Driven Network Assurance
Design Driven Network Assurance
 
MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...
MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...
MIPI DevCon Taipei 2019: PHY Testing Challenges and Opportunities: The Need F...
 
Powersoft19 Overview - 2013
Powersoft19 Overview - 2013Powersoft19 Overview - 2013
Powersoft19 Overview - 2013
 
The Path to a Programmable Network
The Path to a Programmable NetworkThe Path to a Programmable Network
The Path to a Programmable Network
 
Network Simulation - Prague 2015
Network Simulation - Prague 2015Network Simulation - Prague 2015
Network Simulation - Prague 2015
 
Test Tool for Industrial Ethernet Network Performance (June 2009)
Test Tool for Industrial Ethernet Network Performance (June 2009)Test Tool for Industrial Ethernet Network Performance (June 2009)
Test Tool for Industrial Ethernet Network Performance (June 2009)
 
Performance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12cPerformance Tuning Oracle Weblogic Server 12c
Performance Tuning Oracle Weblogic Server 12c
 
Viavi_TeraVM Core Emulator.pptx
Viavi_TeraVM Core Emulator.pptxViavi_TeraVM Core Emulator.pptx
Viavi_TeraVM Core Emulator.pptx
 
Mule soft meetup_th_no1
Mule soft meetup_th_no1Mule soft meetup_th_no1
Mule soft meetup_th_no1
 
IFIP2023-Abhik.pptx
IFIP2023-Abhik.pptxIFIP2023-Abhik.pptx
IFIP2023-Abhik.pptx
 
Testing strategies and best practices using MUnit
Testing strategies and best practices using MUnitTesting strategies and best practices using MUnit
Testing strategies and best practices using MUnit
 
Automated Performance Testing for Desktop Applications by Ciprian Balea
Automated Performance Testing for Desktop Applications by Ciprian BaleaAutomated Performance Testing for Desktop Applications by Ciprian Balea
Automated Performance Testing for Desktop Applications by Ciprian Balea
 
Continuous Performance Testing in DevOps - Lee Barnes
Continuous Performance Testing in DevOps - Lee BarnesContinuous Performance Testing in DevOps - Lee Barnes
Continuous Performance Testing in DevOps - Lee Barnes
 
DSL, Gfast and Wireless Test Software: Test Sentinel
DSL, Gfast and Wireless Test Software: Test SentinelDSL, Gfast and Wireless Test Software: Test Sentinel
DSL, Gfast and Wireless Test Software: Test Sentinel
 
Mule soft meetup_tw_no1_june17
Mule soft meetup_tw_no1_june17Mule soft meetup_tw_no1_june17
Mule soft meetup_tw_no1_june17
 
Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?Need To Automate Test And Integration Beyond Current Limits?
Need To Automate Test And Integration Beyond Current Limits?
 
JavaOne2013: Implement a High Level Parallel API - Richard Ning
JavaOne2013: Implement a High Level Parallel API - Richard NingJavaOne2013: Implement a High Level Parallel API - Richard Ning
JavaOne2013: Implement a High Level Parallel API - Richard Ning
 
MuleSoft Singapore Meetup May 2020
MuleSoft Singapore Meetup May 2020MuleSoft Singapore Meetup May 2020
MuleSoft Singapore Meetup May 2020
 

Mais de Jeremy Schulman

Network Config Backups - Netbox, Github, Ansible
Network Config Backups - Netbox, Github, AnsibleNetwork Config Backups - Netbox, Github, Ansible
Network Config Backups - Netbox, Github, AnsibleJeremy Schulman
 
The Datacenter Network You Wish You Had
The Datacenter Network You Wish You HadThe Datacenter Network You Wish You Had
The Datacenter Network You Wish You HadJeremy Schulman
 
Interop 2015: Hardly Enough Theory, Barley Enough Code
Interop 2015: Hardly Enough Theory, Barley Enough CodeInterop 2015: Hardly Enough Theory, Barley Enough Code
Interop 2015: Hardly Enough Theory, Barley Enough CodeJeremy Schulman
 
The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014Jeremy Schulman
 
A Networking View for the DevOps Crew: SDN
A Networking View for the DevOps Crew: SDNA Networking View for the DevOps Crew: SDN
A Networking View for the DevOps Crew: SDNJeremy Schulman
 
A Network Engineer's Approach to Automation
A Network Engineer's Approach to AutomationA Network Engineer's Approach to Automation
A Network Engineer's Approach to AutomationJeremy Schulman
 

Mais de Jeremy Schulman (7)

Network Config Backups - Netbox, Github, Ansible
Network Config Backups - Netbox, Github, AnsibleNetwork Config Backups - Netbox, Github, Ansible
Network Config Backups - Netbox, Github, Ansible
 
The Datacenter Network You Wish You Had
The Datacenter Network You Wish You HadThe Datacenter Network You Wish You Had
The Datacenter Network You Wish You Had
 
Interop 2015: Hardly Enough Theory, Barley Enough Code
Interop 2015: Hardly Enough Theory, Barley Enough CodeInterop 2015: Hardly Enough Theory, Barley Enough Code
Interop 2015: Hardly Enough Theory, Barley Enough Code
 
The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014The Rules of Network Automation - Interop/NYC 2014
The Rules of Network Automation - Interop/NYC 2014
 
A Networking View for the DevOps Crew: SDN
A Networking View for the DevOps Crew: SDNA Networking View for the DevOps Crew: SDN
A Networking View for the DevOps Crew: SDN
 
About Jeremy Schulman
About Jeremy SchulmanAbout Jeremy Schulman
About Jeremy Schulman
 
A Network Engineer's Approach to Automation
A Network Engineer's Approach to AutomationA Network Engineer's Approach to Automation
A Network Engineer's Approach to Automation
 

Último

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Último (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Automating "Network Ready for Use" with pytest

  • 1. Is the Network Ready for Use? An automated testing approach using pytest Jeremy Schulman Heading up Network Automation at MLB 2019 - October - NANOG 77 @nwkautomaniac
  • 2. Copyright © 2019 - Jeremy Schulman - All Rights Reserved About Me ● Jeremy Schulman ○ Software engineer, sales & systems engineer, ... ○ 20 yrs @ Vendors ○ Now @ Major League Baseball ● @nwkautomaniac - Est. 2012 ● 100% focused on network automation ● Open-source & community contributor 2
  • 3. Copyright © 2019 - Jeremy Schulman - All Rights Reserved About this Tutorial ● Motivation for “Network Ready for Use” ● General testing concepts ● pytest to automate network tests ● Live coding tutorials ● Q & A 3 https://github.com/jeremyschulman/nanog77-nrfu-tutorial
  • 4. Copyright © 2019 - Jeremy Schulman - All Rights Reserved About You ● You have a working knowledge of Python ● You are a Network Engineer working on automation projects ● You are a Developer / DevOps working with Network Engineers 4
  • 5. Copyright © 2019 - Jeremy Schulman - All Rights Reserved About pytest pytest is an open-source software testing framework used by software developers to test their code 5 http://pytest.org ● We are going to treat the network as our “code” ● We are going to use pytest to validate operational states of the network
  • 6. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Network Ready For Use Does the actual operating states of the network match the expected outcomes based on the design? Motivation DESIGN BUILD DEPLOY VALIDATE Workflow Lifecycle NRFU ! 6
  • 7. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Motivating Use-Case New building network ● Consist of hundreds of network devices ● Multiple floors, multiple rooms per floor ● 3rd-party installing equipment ● 3rd-party (different) installing structured cabling ● Staggered installation schedule over multiple weeks 7 Use automated testing to run audits
  • 8. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Network Ready For Use - Phase 1 NRFU testing to validate physical installation ● Devices on-boarded into management system ● Optics installed properly ● Cabling installed properly 8 DONE = network is ready for use for NETENG to deploy network services
  • 9. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Network Ready for Use - Phase 2 NRFU audit to validate network services are operating correctly ● LACP, MLAG, BGP, VXLAN, … 9 DONE = network is ready for use for other teams to deploy their equipment ● VoIP, IPTV, InfoSec, Building Management, etc.
  • 10. Copyright © 2019 - Jeremy Schulman - All Rights Reserved The Installation & Cabling Plan We provide spreadsheets to the installation teams: 10 Phase-1
  • 11. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Audit Criteria Transceivers ○ For each interface is the correct transceiver installed? ○ Are transceivers only present where expected? Interface Status ○ For each interface is the operational state as expected? ○ Are unused interfaces placed in a shutdown state? Cabling ○ Is LLDP reporting the remote system/interface as expected? ○ Are any unexpected connections present? 11 Phase-1
  • 12. Copyright © 2019 - Jeremy Schulman - All Rights Reserved NRFU Audit Reporting We produce an audit report so we can pinpoint corrective actions for the installation team, for example: 12 Phase-1
  • 13. Copyright © 2019 - Jeremy Schulman - All Rights Reserved NRFU Dashboard Report 13 Not Done! ● 11 devices not tested ● 275 test failures ● Failures prioritized Phase-1
  • 14. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Automated Approach Required ● Total devices > 300 ● Building with multiple floors / rooms ● Mixture of different hardware devices ● Mixture of transceiver types; SMF, MMF, and CAT6 cabling 14 Test Case Number of Tests Transceiver check 4,248 Interface status check 16,688 Cabling check 2,046 Total 22,982 Audit Scope and Scale Based on the campus design, almost 23K test- cases covered by NRFU: Phase-1
  • 15. Screenshots using pytest Showcasing both command-line and WebUI reports 15 http://pytest.org
  • 16. Copyright © 2019 - Jeremy Schulman - All Rights Reserved pytest run for a given device 16 PASS
  • 17. Copyright © 2019 - Jeremy Schulman - All Rights Reserved pytest run for a given device 17 FAIL
  • 18. Copyright © 2019 - Jeremy Schulman - All Rights Reserved pytest run for a given device 18 FAILFAIL
  • 20. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Recap 20 ● pytest can be used to execute specific test cases against specific devices ● Test cases are parameterized ● Test cases uniquely named can be filtered based on these names ● Use CLI to show brief PASS / FAIL output ● Use HTML to show more actionable failure information
  • 22. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Testing 22 Testing is a means to provide a metric of quality and completeness. We are using testing to answer the question: Is the network ready for use?
  • 23. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Test Coverage Test coverage is the metric that measures the amount of testing performed by a set of tests over a collection of Devices Under Test (DUTs) 23 Total number of DUTs that are online and can be measured vs. The total number of DUTs For each DUT, the total number of test cases PASSING vs. The total number of DUT test cases Done ?
  • 24. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Test Coverage For each Device Under Test (DUT) we need to identify the specific test cases for each of the test functions. 24 Test Function Number of Test-cases test_optic_inventory 30 test_interface_status 36 test_cabling 34 Total 100 For example, “switch-2105” in our network requires the following number of test cases per test function.
  • 25. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Crafting Test-cases A test case is generally represented as a record of structured data. Each device, e.g. “switch-2105” will have a JSON file per test function, e.g. “cabling”, containing a list of test cases. Each unique test case is a specific dictionary in this list. 25
  • 26. Copyright © 2019 - Jeremy Schulman - All Rights Reserved DUT Actual Data The test function will need to examine the DUT actual data and apply the logic to compare it with the test-case data. The test function for this tutorial will be tightly coupled to the DUT actual data, i.e. specific to this device/NOS. An example JSON body is shown. The test function will extract the specific fields and perform the validation logic. 26 Example Arista EOS via eAPI show lldp neighbors
  • 27. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Putting it Together 27 Test function DUT Actual Data Test case PASS FAIL All expected outcomes are met without exception Expected outcomes not met due to one or more exceptions Data obtained originating from the device under test Data used to parameterize the test and identify expected outcomes Logic to determine if the actual data meets the expected outcomes of the test-case
  • 28. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Testing Considerations Separate the “What” from the “How” Actual data How does the test obtain the DUT data? Test-cases How are these test-cases created? How are these test-cases stored? How does test get these test-cases? 28
  • 29. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Obtaining DUT Actual Data ● Open a session directly to the device, e.g. using Netmiko, pyEAPI, etc. ● Use a controller-server that aggregates many devices ● Use a database that is populated by yet another software system ● Normalizing data from multiple vendors 29 … always based on your specific constraints
  • 30. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Obtaining Test-Cases 30 ● Write a program to generate test-case data based on some other Source-of-Truth system(s), which could be ○ One or more spreadsheets ○ From an internal database system ○ From other SoT systems like NetBox … always based on your specific constraints
  • 31. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Test Functions Writing tightly-coupled test functions … is OK The test functions uses the DUT actual data If the test function is written to use a specific DUT output format, then it is tightly-coupled to that DUT Same is true for the structure and/or content of the test-case 31 Decisions around abstractions, normalizing data, etc., are specific to your specific constraints
  • 32. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Recap ● Test coverage is a collection of test functions ● Test functions are run with multiple test-cases ● Test functions OK to be tightly coupled to DUT ○ Test-case structure not tightly coupled ○ Test-case data tightly coupled to DUT 32 There are no “right answers” only “right now answers”
  • 34. Copyright © 2019 - Jeremy Schulman - All Rights Reserved pytest Tutorial 34 ● Basic project setup ● Writing test functions ● Writing test function fixtures ● Writing parameterized test-cases ● Running pytest to filter test cases ● Creating HTML reports
  • 35. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Installing pytest 35 (venv)$ pip install pytest (venv)$ pip install pytest-html Recommend installing into virtualenv http://plugincompat.herokuapp.com/ Almost 700 pytest plugins listed:
  • 38. Copyright © 2019 - Jeremy Schulman - All Rights Reserved NRFU Tutorials 38 1. Create custom pytest options 2. Initially verify the device is online 3. Running test-functions a. Provide device instance to test-functions b. Load device specific test-cases c. Using “bulk-data” type device commands
  • 39. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Testing Strategy 39 Device NRFU Library of Functions nrfupytesteos Load DUT test-cases JSON file Get Actual Data pyEAPI The NetworkTest Function Each pytest Test File (python module) pytest ● Test one device per pytest run ● Write one test file per test function ● Each device has directory of JSON files, each per test function testcases/switch-21.bld1 ├── testcases-cabling.json ├── testcases-interface-status.json └── testcases-optic-inventory.json
  • 40. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Create Custom pytest Options 40 I want to tell pytest the device I want to run tests against. I need to provide the device hostname and also the directory that has the test-case files. $ pytest --nrfu-device switch-21.bld1 --nrfu-testcases /opt/nrfu/testcases/switch-21.bld1 <other pytest options> what
  • 41. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Create Custom pytest Options 41 Write a pytest_addoption hook function to add your custom options: how conftest.py
  • 42. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Initially Verify Device Online 42 Once I give pytest the device information, I want pytest to first ensure the device is online before I start running any tests. $ pytest --nrfu-device switch-111.bld2 <...> Exit: Unable to connect to device switch-111.bld2 !!!!!!!!! _pytest.outcomes.Exit: Unable to connect to device switch-111.bld2 !!!!!!!!!! what
  • 43. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Initially Verify Device Online 43 Write a pytest_sessionstart hook function to run code before any tests are executed: how conftest.py
  • 44. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Provide the device to test functions I will need to provide the device object to my test function so that I can retrieve the actual data from the device. 44 what test_cabling.py
  • 45. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Provide the device to test-cases Create a function called device() in conftest.py and as a session level fixture. This function will be run only once. 45 how conftest.py
  • 46. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Load device specific test-cases I need to use test-cases that are specific to the device under test. Using the CLI option I provided, load the test-case file to parameterize the test cases to the test functions 46 $ pytest --nrfu-testcases /opt/nrfu/testcases/switch-21.bld1 <...> what
  • 47. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Load device specific test-cases I want to see each test case instance reported. For example, cabling test shows the expected remote device and interface: 47 what
  • 48. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Load device specific test-cases Write the test function to uses a fixture, in this example called testcase. This fixture needs to be parameterized using a JSON file. 48 how test_cabling.py
  • 49. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Load device specific test-cases write the pytest_generate_tests hook function, in the same python file containing the test case function: 49 how test_cabling.py
  • 50. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Load device specific test-cases Use parametrize to dynamically load the testcase fixture values from any source, a JSON file in this example: 50 how test_cabling.py
  • 51. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Load device specific test-cases parametrize takes the fixture name as a string. This value must match the same argument name used by the test function. 51 how test_cabling.py
  • 52. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Generating test-cases names 52 how test_cabling.py
  • 53. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Recap: device specific test-cases The coding shown in the previous slides will result in pytest running the test function multiple times, each with the specific test name 53 what
  • 54. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Use “bulk-data” device results In some cases I need to run a device command that will contain the results for many test-cases. For example I must use the “show inventory” command to obtain the transceiver data. That command does not allow me to get data for one interface at a time. 54 what
  • 55. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Use “bulk-data” device results Define a module level fixture to return the bulk- data. A module fixture will be called only once per python test-function module. 55 how
  • 56. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Use “bulk-data” device results 56 how test_optics.py
  • 58. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Summary 58 ● pytest can be used to automate network testing ● pytest has a large community & catalog of plugins ● Useful for both “greenfield” and “brownfield” scenarios ● You still need to write your own test functions ● You still need to determine your testing strategy Opportunity for Networking community
  • 59. Copyright © 2019 - Jeremy Schulman - All Rights Reserved Reference Links https://twitter.com/pytestdotorg ● https://github.com/jeremyschulman/nanog77-nrfu-tutorial ● http://www.pytest.org ● http://www.pytest.org/en/latest/#documentation ● https://docs.pytest.org/en/latest/talks.html ● https://docs.pytest.org/en/latest/parametrize.html ● https://docs.pytest.org/en/latest/fixture.html#fixture-parametrize 59 https://pythontesting.net/ Podcasts, Blogs, and much more at:

Notas do Editor

  1. Poll the audience.
  2. The name of the fixture, “testcase”, could be named anything, for example “interface_status_testcase”.
  3. NOTE: The string value on line 61 MUST MATCH the test_interface_status fixture parameter testcase. You can change these names to whatever you’d like, but they MUST match.
  4. NOTE: The string value on line 61 MUST MATCH the test_interface_status fixture parameter testcase. You can change these names to whatever you’d like, but they MUST match.
  5. NOTE: The string value on line 61 MUST MATCH the test_interface_status fixture parameter testcase. You can change these names to whatever you’d like, but they MUST match.
  6. NOTE: The string value on line 61 MUST MATCH the test_interface_status fixture parameter testcase. You can change these names to whatever you’d like, but they MUST match.