Nothing Special   »   [go: up one dir, main page]

All-In-One Devnet Associate Exam: Devasc Exam 200-901 V1.0 Cert Guide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

All-in-One DevNet Associate Exam

DEVASC Exam 200-901 V1.0 Cert Guide

1st Edition

Copyright © 2020 FullStackNetworker


All rights reserved.
ISBN: 9781658709484
6

Contents at a Glance

Chapter 1 Software Development and Design


Chapter 2 Understanding and Using APIs
Chapter 3 Cisco Platforms and Development
Chapter 4 Application Deployment and Security
Chapter 5 Infrastructure and Automation
Chapter 6 Network Fundamentals
7

Table of Contents

About the Author .......................................................................................................................................... 11


Preface .............................................................................................................................................................. 13
Introduction to Cisco DevNet Certification Track ............................................................................. 14
What this Study Guide contains ............................................................................................................... 16
How to use this Study Guide ...................................................................................................................... 16
What’s available on the FullStackNetworker website ..................................................................... 17
CHAPTER 1 SOFTWARE DEVELOPMENT AND DESIGN ..................................................................... 19
Compare data formats (XML, JSON, and YAML) ................................................................................................................. 21
XML Example .............................................................................................................................................................................. 21
XML Prologue .............................................................................................................................................................................. 22
XML Comments .......................................................................................................................................................................... 22
XML Body ..................................................................................................................................................................................... 22
XML Attributes ............................................................................................................................................................................ 23
XML Namespaces ....................................................................................................................................................................... 23
JSON Example ............................................................................................................................................................................. 23
JSON Data Types ........................................................................................................................................................................ 24
JSON Objects ................................................................................................................................................................................ 24
JSON Maps and Lists ................................................................................................................................................................. 24
YAML Example ........................................................................................................................................................................... 24
YAML File Structure ................................................................................................................................................................. 25
YAML Data Types ...................................................................................................................................................................... 25
YAML Indentation and File Structure .................................................................................................................................. 25
YAML Maps and Lists .............................................................................................................................................................. 25
YAML Comments ....................................................................................................................................................................... 26
Describe parsing of common data formats (XML, JSON, and YAML) to Python data structures ................... 26
XML Parsing in Python ............................................................................................................................................................. 26
Using the ElementTree APIs to parse XML ....................................................................................................................... 27
Using Minidom Module to parse XML ................................................................................................................................ 29
JSON Parsing in Python ............................................................................................................................................................ 30
YAML Parsing in Python ......................................................................................................................................................... 31
Further Reading ............................................................................................................................................................................ 32
Describe the concepts of test-driven development .......................................................................................................... 33
Compare software development methods (Waterfall, Agile, and Lean) .................................................................. 38
Waterfall Method ......................................................................................................................................................................... 41
Agile Method ................................................................................................................................................................................ 42
Lean Method ................................................................................................................................................................................. 46
Explain the benefits of organizing code into methods, functions, classes, and modules ................................. 49
Identify the advantages of common design patterns (MVC and Observer, MVP, MVVM) ................................ 54
Model View Controller (MVC) .............................................................................................................................................. 54
The Observer Pattern .................................................................................................................................................................. 55
Explain the advantages of version control ........................................................................................................................... 57
Utilize common version control operations with Git ....................................................................................................... 58
Clone Operation ........................................................................................................................................................................... 61
Add/remove Operations ............................................................................................................................................................. 62
Commit Operation ....................................................................................................................................................................... 62
Push / Pull Operations ................................................................................................................................................................ 63
Branch .............................................................................................................................................................................................. 66
8

Merge and handling conflicts .................................................................................................................................................. 69


Diff Operation ............................................................................................................................................................................... 70
GitOps .............................................................................................................................................................................................. 73
Further Reading ............................................................................................................................................................................ 73
Chapter Summary ............................................................................................................................................................................ 74
CHAPTER 2 UNDERSTANDING AND USING APIs ................................................................................. 76
Construct a REST API request to accomplish a task given API documentation ................................................... 77
Describe common usage patterns related to webhooks ................................................................................................. 78
Identify the constraints when consuming APIs .................................................................................................................. 81
Further Reading ............................................................................................................................................................................ 84
Explain common HTTP response codes associated with REST APIs ........................................................................ 84
Troubleshoot a problem given the HTTP response code, request and API documentation ........................... 85
Identify the parts of an HTTP response (response code, headers, body) ............................................................... 86
Utilize common API authentication mechanisms: basic, custom token, and API keys ...................................... 88
Compare common API styles (REST, RPC, synchronous, and asynchronous) ...................................................... 98
Further Reading .......................................................................................................................................................................... 101
Construct a Python script that calls a REST API using the requests library ........................................................ 101
Further Reading .......................................................................................................................................................................... 107
Chapter Summary .......................................................................................................................................................................... 108
CHAPTER 3 CISCO PLATFORMS AND DEVELOPMENT ................................................................... 109
Construct a Python script that uses a Cisco SDK given SDK documentation ....................................................... 110
Describe the capabilities of Cisco network management platforms and APIs (Meraki, Cisco DNA Center,
ACI, Cisco SD-WAN, and NSO) .................................................................................................................................................. 115
Further Reading .......................................................................................................................................................................... 132
Describe the capabilities of Cisco compute management platforms and APIs (UCS Manager, UCS
Director, and Intersight) ............................................................................................................................................................. 166
Further Reading .......................................................................................................................................................................... 190
Describe the capabilities of Cisco collaboration platforms and APIs (WebEx Teams, WebEx devices,
Cisco Unified Communication Manager including AXL and UDS interfaces, and Finesse) ............................ 190
Further Reading .......................................................................................................................................................................... 198
Cisco Finesse ............................................................................................................................................................................... 198
Further Reading .......................................................................................................................................................................... 200
Describe the capabilities of Cisco security platforms and APIs (Firepower, Umbrella, AMP, ISE, and
Threat Grid) ..................................................................................................................................................................................... 201
Describe the device level APIs and dynamic interfaces for IOS XE and NX-OS ................................................... 215
Identify the appropriate DevNet resource for a given scenario (Sandbox, Code Exchange, support,
forums, Learning Labs, and API documentation) ............................................................................................................ 218
Further Reading .......................................................................................................................................................................... 223
Apply concepts of model driven programmability (YANG, RESTCONF, and NETCONF) in a Cisco
environment .................................................................................................................................................................................... 224
NETCONF ................................................................................................................................................................................... 225
RESTCONF ................................................................................................................................................................................. 227
Construct code to perform a specific operation based on a set of requirements and given API reference
documentation ................................................................................................................................................................................ 242
Obtain a list of network devices by using Meraki, Cisco DNA Center, ACI, Cisco SD-WAN, or NSO .... 242
Manage spaces, participants, and messages in WebEx Teams ................................................................................... 243
Obtain a list of clients / hosts seen on a network using Cisco DNA Center .......................................................... 246
Further Reading .......................................................................................................................................................................... 256
Chapter Summary .......................................................................................................................................................................... 258
CHAPTER 4 APPLICATION DEPLOYMENT AND SECURITY ........................................................... 261
Describe benefits of edge computing .................................................................................................................................... 262
Identify attributes of different application deployment models (private cloud, public cloud, hybrid cloud,
and edge) ........................................................................................................................................................................................... 262
9

Identify the attributes of these application deployment types .................................................................................. 270


Hypervisor Type 1 and Type 2 .............................................................................................................................................. 272
Virtual Machine .......................................................................................................................................................................... 273
Containers .................................................................................................................................................................................... 274
Docker Containers ..................................................................................................................................................................... 275
Kubernetes ....................................................................................................................................................................................... 277
Describe components for a CI/CD pipeline in application deployments .............................................................. 281
Construct a Python unit test ..................................................................................................................................................... 284
Interpret contents of a Dockerfile .......................................................................................................................................... 284
Docker Architecture .................................................................................................................................................................. 285
Installing Docker ........................................................................................................................................................................ 286
Utilize Docker images in local developer environment ................................................................................................ 288
Identify application security issues related to secret protection, encryption (storage and transport), and
data handling ................................................................................................................................................................................... 288
Best Practices for Application Data Protection ............................................................................................................... 290
Data Handling ............................................................................................................................................................................. 290
Software Vulnerabilities .......................................................................................................................................................... 291
Explain how firewall, DNS, load balancers, and reverse proxy work in application deployment .............. 291
Describe top OWASP threats (such as XSS, SQL injections, and CSRF) .................................................................. 293
Utilize Bash commands (file management, directory navigation, and environmental variables) ............. 296
Identify the principles of DevOps practices ....................................................................................................................... 303
Chapter Summary .......................................................................................................................................................................... 306
CHAPTER 5 INFRASTRUCTURE AND AUTOMATION ....................................................................... 309
Describe the value of model driven programmability for infrastructure automation .................................... 310
Compare controller-level to device-level management ................................................................................................ 312
Describe the use and roles of network simulation and test tools (such as VIRL and pyATS) ...................... 312
Describe the components and benefits of CI/CD pipeline in infrastructure automation .............................. 315
Describe principles of infrastructure as code (IaC) ........................................................................................................ 317
Describe the capabilities of automation tools such as Ansible, Puppet, Chef, and Cisco NSO ...................... 318
Identify the workflow being automated by a Python script that uses Cisco APIs including ACI, Meraki,
Cisco DNA Center, or RESTCONF ............................................................................................................................................ 322
Identify the workflow being automated by an Ansible playbook (management packages, user
management related to services, basic service configuration, and start/stop) ................................................. 332
Identify the workflow being automated by a bash script (such as file management, app install, user
management, directory navigation) ...................................................................................................................................... 335
Interpret the results of a RESTCONF or NETCONF query ............................................................................................ 339
Interpret basic YANG models ................................................................................................................................................... 339
Interpret a unified diff ................................................................................................................................................................. 339
Describe the principles and benefits of a code review process ................................................................................. 342
Interpret sequence diagram that includes API calls ....................................................................................................... 344
Further Reading .......................................................................................................................................................................... 345
Chapter Summary .......................................................................................................................................................................... 346
CHAPTER 6 NETWORK FUNDAMENTALS ........................................................................................... 348
Describe the purpose and usage of MAC addresses and VLANs ............................................................................... 349
Describe the purpose and usage of IP addresses, routes, subnet mask / prefix, and gateways ................. 352
Describe the function of common networking components (such as switches, routers, firewalls, and load
balancers) ......................................................................................................................................................................................... 353
EIGRP ............................................................................................................................................................................................ 354
Further Reading .......................................................................................................................................................................... 355
OSPF .............................................................................................................................................................................................. 355
Further Reading .......................................................................................................................................................................... 357
BGP ................................................................................................................................................................................................ 357
Further Reading .......................................................................................................................................................................... 359
10

Interpret a basic network topology diagram with elements such as switches, routers, firewalls, load
balancers, and port values ......................................................................................................................................................... 359
Describe the function of management, data, and control planes in a network device .................................... 360
Describe the functionality of these IP Services: DHCP, DNS, NAT, SNMP, NTP .................................................. 361
Recognize common protocol port values (such as, SSH, Telnet, HTTP, HTTPS, and NETCONF) ................ 366
Identify cause of application connectivity issues (NAT problem, Transport Port blocked, proxy, and
VPN) ..................................................................................................................................................................................................... 366
Explain the impacts of network constraints on applications ..................................................................................... 369
Troubleshooting common network connectivity issues ................................................................................................ 369
Further Reading .......................................................................................................................................................................... 370
Networking basics and software-defined networks ........................................................................................................ 370
Networking topologies and models ..................................................................................................................................... 370
IPv4 Addresses and subnets ................................................................................................................................................... 370
Network Programmability Basics Video Course ............................................................................................................ 370
Chapter Summary .......................................................................................................................................................................... 371
11

About the Author

Muhammad Afaq Khan started his professional career at Cisco TAC San Jose and passed his
first CCIE in 2002 (#9070). He held multiple technical and management positions at Cisco San
Jose HQ over his 11 years of tenure at the company before moving into cloud software and data
center infrastructure IT industries.

He has worked at startups as well as Fortune 100 companies in senior leadership positions over
his career. He is also a published author (Cisco Press, 2009) and holds multiple patents in the
areas of networking, security, and virtualization. Currently, he is a founder at Full Stack
Networker and a vocal advocate for network automation technologies and NetDevOps. He is a
Cisco Certified DevNet Associate1 and was among the first 500 people #DevNet500 worldwide
to pass the exam.

1
https://bit.ly/2Pt7R9J
12
13

Preface

Congratulations! You have taken your first step towards preparing and passing the Cisco DevNet
Associate (DEVASC) 200-901 V1.0 Exam.

Did you just purchase a copy? Interested in getting access to a complimentary DEVASC
Exam Quiz? Register here2 and send us an email at support@fullstacknetworker.com to get
started.

This study guide is dedicated to all those souls who will never settle for less than they can be, do,
share, and give!

2
https://bit.ly/2Sb6Xzw
14

Introduction to Cisco DevNet Certification Track

Just to recap, Cisco announced the DevNet program back in June this year at Cisco Live in San
Diego, after tinkering around with DevNet initiative for about 5 years. Like the Network side of
things with CCNA and CCNP tracks, DevNet program also contains Associate and Professional
tracks with several exams depending on the certification level.

Well, Cisco knows, like every other networking vendor, that networking hardware and even
software have now become commoditized, thanks to Cloud that made owning infrastructure a
stupid thing of the past and likewise SDN that helped us move away from black boxes with
proprietary operating systems to mostly branded white boxes with highly programmable
operating systems such as Arista EOS or Cumulus Linux. Now, keep in mind that Cisco didn’t
arrive at this conclusion overnight, obviously, their profit margins were tied up into
infrastructure and they still are, but they seem to now have embraced the subscription-based
pricing model.

Anyhow, with DevNet, Cisco is hoping to turn their products into platforms where they can
focus on providing the APIs and let the infrastructure and application software developers do the
integration work. Cisco now claims that they have well over 500K members enrolled in their
DevNet initiative, obviously, a lot of them come from channel partners. What I also noticed is
that Cisco is walking a fine line here, they are not going all out and saying network engineers
should all become developers or that developers should consider becoming CCIEs.

The most critical question is, what does it all mean for you as a Network Engineer. Regardless of
what Cisco’s party line is, the DevNet certification program represents a tremendous opportunity
for you to graduate out of being a networker to an Automation Engineer or a Network DevOps.

If you are clueless about programming, DevOps, encoding formats such as JSON, and APIs, then
you want to start with the Associate track. But, if you find yourself writing python code during
downtime, or perhaps you came from a coding background like I did, then you can venture
straight into the Professional track. Another way to figure this out is to simply read through the
Associate exam topics, if you find a lot of unfamiliar jargon in it, then congratulations you have
hit the jackpot. I personally think, most network engineers would want to start at the Associate
level.

Now, you can become Cisco Certified DevNet Associate or CCDA by just passing DEVASC
200-901 exam. This exam is about APIs, Infrastructure, deployment, software development
principles and obviously knowing your network fundamentals, i.e. knowing your protocols and
some of the bits and bytes.
15

Cisco Certified DevNet Professional track, or path to CCDP, requires passing not just one but
two exams. You need to pass one Core exam, i.e. DEVCOR 350-901 and one concentration
exam. The only key difference between the two exam topics, i.e. Associate exam versus DevNet
Core exam is the level of difficulty as knowledge domains remain the same with the exception of
Network fundamentals. For Professional track, you are expected to know your networking
protocols and devices.

As for the concentration exam, Cisco has offered 8 exam choices and all you need to do is to
pick one from either list. If you are familiar with the DevOps tooling ecosystem, then you can
pick DevOps. Likewise, if you find yourself deeply interested in pursuing network automation,
go for the Enterprise (ENAUTO) exam.

Below, I have broken down the actual domains of knowledge that you need to master to get
DevNet certified. The foundation of all is still networking, but then the meat of it is around
programming, which is mostly Python and corresponding libraries, DevOps toolchain, becoming
familiar with infra APIs and application deployment. If you prefer the DIY approach, you can
create your syllabus and google every topic until you are ready. On the other hand, if you like a
more structured approach, then feel free to check out our DevNet Associate Course.

Let me summarize.

• DevNet certification program offers two tracks, Associate track, the entry level, and the
next step up, the Professional track.
• While Cisco doesn’t explicitly say so, Network Engineers, please pay attention to DevNet
track and network automation, if you don’t want to witness your job getting automated.
• Associate requires passing one exam, whereas Pro track requires passing two.
16

What this Study Guide contains

This guide will help you comprehensively prepare for the DEVASC exam. As you may already
have noticed on the "Contents at a Glance" page that this guide has been formatted around the
Cisco's official DevNet Associate 200-901 official exam topics or curriculum3. The benefit?
Well, as you read through the various topics, you will know exactly where you're within your
learning journey.

All contents are carefully covered with core concepts, code snippets, and topic summaries to help
you master the skills so you can confidently face the pressures of the Cisco exam as well as its
real-world application. DevNet jargon is going to be uncharted territory for most network
engineers, perhaps to the point, that it may be taken for typos at first glance. For this reason, I’d
strongly suggest looking up all the terms that appear foreign to you.

How to use this Study Guide

This guide is for anyone who's studying for Cisco DevNet Associate 200-901 exam. I strongly
suggest taking a methodical approach for exam preparation, i.e. start with a target date or when
you would like to sit for the actual exam and then work backwards to see what kind of study plan
would work for you. To augment this study guide, I have put together a 200 hours learning plan4
consisting entirely of public resources, something that you can download today and follow along.

DevNet Associate DEVASC 200-901 V1.0 Exam Topics Exam


Bodies of Knowledge Weight
Software Development and Design 15%
Understanding and Using APIs 20%
Cisco Platforms and Development 15%
Application Deployment and Security 15%
Network Fundamentals 15%
Infrastructure Automation 20%

3
https://bit.ly/36Q8O1X

4
https://bit.ly/2Sevaoq
17

What’s available on the FullStackNetworker website

FullStackNetworker.com carries the supplemental resources (sold separately) that go hand in


hand with this study guide to further ensure your exam success.

• All-in-One Course5 that covers all concepts and hands-on labs for the DEVASC Exam
• 19+ Skill Tracks6 that cover the entire Network Automation bodies of knowledge beyond
DevNet curriculum
• 6x Practice Quizzes (one for each section as per the official curriculum)
• 1x Exam Simulation (to help you prepare to face the pressure of a real Cisco exam)
• Hands-on Labs with cloud-hosted IDE for immediate Python code execution
• Code snippets hosted as GitHub Gists that you can clone/fork for modification

5
https://bit.ly/2vMTkPz

6
https://bit.ly/2RR2hzP
18
19

CHAPTER 1 SOFTWARE DEVELOPMENT AND DESIGN

This chapter covers the following exam topics from Cisco’s official 200-901 V1.07 DevNet
Associate exam blueprint.

• Compare data formats (XML, JSON, and YAML)


• Describe parsing of common data format (XML, JSON, and YAML) to Python data
structures
• Describe the concepts of test-driven development
• Compare software development methods (agile, lean, and waterfall)
• Explain the benefits of organizing code into methods / functions, classes, and modules
• Identify the advantages of common design patterns (MVC and Observer)
• Explain the advantages of version control
• Utilize common version control operations with Git
o Clone
o Add/remove
o Commit
o Push / pull
o Branch
o Merge and handling conflicts
o diff

7
https://bit.ly/2uh1Zcv
20
21

Compare data formats (XML, JSON, and YAML)

When using Application Programming Interfaces (or APIs) through software, it is super critical
to receive and transmit data in forms that are standards-based and machine and human readable.

Let’s go over a few reasons why it is so.

• It allows use of off-the-shelf software tools to convert and accept them into native data
structures (e.g. JSON value/pairs to Python dictionaries)
• It makes it easier to write code that communicates with messages in format that another
remote endpoint can easily consume
• It is easier to read and manipulate received messages
• It makes it easier to detect malformed messages

Extensible Markup Language (XML) and JavaScript Object Notation (or JSON, pronounced as
Jay-sun) and YAML Ain't Markup Language (YAML) are the main data encoding formats used
in remote APIs today. JSON is both a human-friendly and machine-readable format and sends
data in name-value pairs.

JSON and YAML can be converted to each other without much effort. JSON is best known for
the curly brace syntax. It is popular because it is easier to read and natively maps to Python
dictionary data structure. However, XML is bit of an outlier, it is less simple to parse and convert
to JSON or YAML. It is an older format so there are plenty of mature APIs that still use it.

Parsing JSON, YAML and XML is a common requirement of interacting with REST APIs.

XML Example

XML is the parent of HTML. It is generic method to wrapping textual data in symmetrical tags
to indicate semantics. XML files typically carry an extension of .xml.

<?xml version="1.0" encoding="utf-8"?>


<root>
<persons>
<element>
<gender>male</gender>
<name>Jeff Bezos</name>
22

</element>
<element>
<gender>male</gender>
<name>Elon Musk</name>
</element>
<element>
<gender>female</gender>
<name>Jessica Alba</name>
</element>
</persons>
</root>

XML Prologue

The first line in XML file is known as the XML prologue. It has a special format and bracketed
by <? and ?>. It contains the tag name xml and attributes stating the version and a character
encoding. Normally, you’d find the version to be “1.0” and the character encoding to be “UTF-
8” or 8-bit Unicode Transformation Format.

XML Comments

XML files can include comments, much like their HTML counterpart, they are enclosed in <! --
and --> tags.

XML Body

Everything after the prologue is considered to be the XML body. The individual elements are
surrounded by symmetrical pairs of tags, the opening tag < and the closing tag > symbols. The
closing tag includes a “/” preceding the closing tag.

The main body of the document as a whole is always surrounded by an outermost tag pair, e.g.
<root> and </root> in the example.

The structure of an XML document is like a tree with branches (known as elements) containing
further branches (known as sub-elements), e.g. <element></element> are elements whereas
<gender></gender> are sub-elements.
23

XML Attributes

XML allows you to embed attributes inside the tags to convey additional information. Version
and the encoding types in the XML prologue are examples of attributes. Attribute values are
carried inside double quotes and an element can have multiple attributes each with a unique
name.

XML Namespaces

Some XML messages or documents incorporate a reference to a specific namespace to convey


how they should be consumed. Namespaces are defined by standard bodies such as the IETF,
e.g. xml:ns:netconf for NETCONF.

JSON Example

Now, let’s convert above XML into JSON.

{
"persons": [
{
"name": "Jeff Bezos",
"gender": "male"
24

},
{
"name": "Elon Musk",
"gender": "male"
},
{
"name": "Jessica Alba",
"gender": "female"
}
]
}

JSON Data Types

JSON data types include numbers, strings, and boolean (True or False). JSON filenames
typically end in “.json”.

JSON Objects

Much like JavaScript, individual objects comprise of key/value pairs surrounded by braces e.g.
{“key”:”value”}.

JSON Maps and Lists

Objects can also contain multiple key/value pairs, separated by commas, similar to Python
dictionaries. JSON values can also contain lists of data objects.

Unlike XML or YAML, JSON doesn’t support adding any kind of comments. JSON format also
doesn’t give any significance to whitespaces, so you can ident your JSON data using tabs or
spaces or nothing at all.

YAML Example

YAML format is like a superset of JSON but even easier to read. One of the most commonly
known use of YAML is configuration files and particularly for writing declarative automation
templates such as Ansible playbooks. YAML parsers can also parse JSON but not vice versa.
25

YAML File Structure

YAML files open with “---” and end with “…”. You can also have multiple YAML documents
within one file where each document is separated by “---“. YAML filenames typically end in
“.yaml”.

YAML Data Types

YAML data types include numbers, strings, and Booleans. Strings don’t need to be quoted,
quotes are only needed when strings contain characters that have meaning in YAML.

YAML Indentation and File Structure

YAML uses indentation to describe hierarchies. Items indented below a label are considered
members of that labeled element. There are no specific requirements for indentation amount, you
can use a space or a tab. However, the best practice is to use two spaces per indent level.

YAML Maps and Lists

YAML maps can contain multiple key/value pairs and ordered lists. Maps are expresses over
multiple lines, beginning with a label key and a colon, followed by members.

Lists are represented in a similar way, but members are preceded with a hyphen (dash) and a
space.

Maps and lists can also be written in flow syntax (much like Python).
26

YAML Comments

Comments in YAML can be inserted anywhere inside the document with the exception of in a
long string. All comments are preceded by the hash sign.

Now, let’s convert our JSON document into YAML.

Describe parsing of common data formats (XML, JSON, and YAML) to


Python data structures

As we discussed earlier, XML is a markup language much like HTML and consists of a set of rules for
encoding documents that are human and machine-readable. XML was formally defined in W3C
specifications. Using XML, you can define your tags or elements, their order, and how they are
supposed to be processed or displayed on screen. XML encoded file can live on a server or take
on a transient when being transmitted between two machines.

One of the most distinguishing characteristics of XML is that it allows you to define your tags or
elements, as opposed to HTML where tags are standardized. It is similar to HTML, but at the same time
more flexible, i.e. it is both a language as well as a meta-language where you can define other languages
using as it the basis, for example, RSS or XSLT.

XML Parsing in Python

Parsing means analyzing a message and breaking it into its components. When messages are
transmitted over the wire, they are communicated as a stream of characters. Upon arrival, they
need to be parsed into a semantically appropriate data structure where each component is
recognized as an integer, float, string, and so on.
27

Compiling source code is also a type of parsing. Serialization, on the other hand, is about
converting a data structure into a format that can be transmitted. When you use a REST API
which reads data from Python dictionaries and output them as equivalent JSON/YAML/XML in
string form to the remote resource – when you are serializing, you are actually encoding.
Deserialization is a particular type of parsing (or decoding); it takes serialized data and recreates
the original data structure from it.

Python allows you to parse, modify and build XML documents. Your XML document can be
stored in a file or the form of a string. There are two well-known methods to parse XML with
Python, i.e. you can use the ElementTree (ET) APIs or the Minidom module to load and parse
XML.

The XML data format is hierarchical and the most fitting way to represent that data is with a tree.
ET has two classes to help break that hierarchy down into two levels, i.e. ElementTree which
represents the whole XML document as a tree and Element which represents a single node in that
tree.

Interaction with the entire document, such as reading and writing files, is commonly done using
the ElementTree, whereas interactions with a single XML element (or child) or sub-elements (or
sub-child) are carried out using the Element level.

Using the ElementTree APIs to parse XML

XML Document

<persons>
<element>
<gender>male</gender>
<name>Jeff Bezos</name>
</element>
<element>
<gender>male</gender>
<name>Elon Musk</name>
</element>
<element>
<gender>female</gender>
28

<name>Jessica Alba</name>
</element>
</persons>

Python Code

Code Output
29

Using Minidom Module to parse XML

You can also use Minimal Document Object Model (or Mini DOM) module to parse XML
documents, however, for security reasons, it is preferred to use the ElementTree module instead.

Using Minidom, you can achieve parsing in three simple steps.

• Import xml.dom.minidom module


• Utilize the function parse (i.e. minidom.parse) to parse the document (minidom.parse
(“persons.xml”)
• Get the XML Elements using doc.getElementsByTagName("element")

Python Code

Code Output
30

JSON Parsing in Python

JavaScript Object Notation (or JSON) is language-agnostic is documented as its data encoding
standard. It supports primitive types such as strings and numbers along with nested lists and
objects.

Python includes a native JSON package that you can use to both encode and decode data. You
can use “import json” to import the entire package and parse JSON data into a python dictionary
or list. You can parse the JSON file using the json.load() into python dictionary data structure
which is organized in key-value pairs. You can also read and write JSON strings using
json.loads() and json.dumps methods respectively.

JSON Document

[
{
"gender": "male",
"name": "Jeff Bezos"
},
{
"gender": "male",
"name": "Elon Musk"
},
{
"gender": "female",
"name": "Jessica Alba"
}
]
31

Python Code

Code Output

YAML Parsing in Python

YAML Ain’t Markup Language (or YAML) is the most human-friendly data encoding or
serialization standard out there. Much like JSON, it is also a language-agnostic data encoding
method. You can use the PyYAML library to read and write YAML data.

You can import pyYAML library using “import yaml” and then load YAML file into python
dictionary object or data structure using yaml.safe_load() method. You can use yaml.dump()
method to write YAML.
32

YAML Document

Python Code

Code Output

Further Reading
Python syntax, I/O, conditionals, and functions8

8
https://bit.ly/339zydy
33

Python data structures and loops9


Parsing JSON using Python10
XML Basics11

Describe the concepts of test-driven development

The primary goal behind testing is to make sure that the software works the way it’s supposed to
work. Software testing can be divided into two categories.

• Functional testing
• Non-functional testing

Functional testing is about determining whether software works correctly, i.e. it behaves as
intended in the logical sense. It encompasses the lowest level of detail examined with unit testing
to the higher levels of complexity commonly explored in integration testing.

Non-functional testing examines aspects of usability, security, fault tolerance, compliance and
many more issues. It is critical to understand that non-functional testing doesn’t have to wait
until most of the software is ready or finalized.

There are two most common types of software development methodologies, i.e. Behavior-Driven
and Test-Driven Developments, commonly known as BDD and TDD respectively.

BDD is a set of software practices that target to reduce resource waste in activities such as
rework due to requirements not being clear, hesitance to refactor code or slower feedback cycles
primarily due to organization silos and multiple hand-offs. BDD is about testing the behavior or
outcome as opposed to the implementation.

Now, you may have heard about various testing techniques such as unit or integration or
acceptance testing. As the name suggests, unit testing is about testing a “unit” of code, where the
unit refers to a function in an object or a module. By narrowing down the scope of testing such as
a single function, unit testing is simple to write and perform. There may be multiple unit tests,
but they are isolated from each other.

9
https://bit.ly/2TGYN3H

10
https://bit.ly/3cTRMUU

11
https://bit.ly/2wTrJwg

You might also like