Rest and Automated Testing

Representational State Transfer, or more commonly called REST, is an architectural style that leverages HTTP and its simple verbs like GET, PUT, POST, and DELETE for interaction between two entities.

REST's simplicity and overwhelming adoption by all types of applications makes it an obvious choice for automation and testing. Its simplified structure, use of HTTP, and cloud readiness enable it to seamlessly integrate into test automation harnesses. REST can be used standalone to create new automation tests, but since it’s just HTTP requests and response, literally any programming language like Python or Perl can wrap around REST API calls.

Getting Started

Users can download the Python Library that will wrap around the REST commands from the web interface of BreakingPoint.

BreakingPoint Web UI

To try the Keysight Python sample you need Python 2.7 and the “requests” and “json” additional packages used in the Ixia example library above.

The Python sample script and a Python library that implements over REST the most used operations are examples that can be replicated with other languages.

To test your environment, run the “” included in the above download. Just customize the script with your chassis settings (chassis ip, username, password, slot, and ports):

#Details of the Chassis, username and password

bps = BPS('IP-Of-Chassis', 'user', 'pass')

# The below procedure will login to the BPS chassis.


# Showing current port reservation state


# Reserving first two ports of the first card in the chassis

bps.reservePorts(slot = 1, portList = [0,1], group = 1, force = True)

BreakingPoint REST API—Under the X-Ray Similar to the other Keysight products, the RESTAPI is accessed at: https://<REST Server>/api/v1/<product name> (for Breaking Point: https://<IP-Of-Chassis>/api/v1/bps)

Let’s see one simple example with the BreakingPoint Python REST library abstracting the REST calls. The below script will login, get port status, and log out of a chassis.

#!/usr/bin/env python

#This command will import the BPS REST library

from bpsRest import *

#Creating an instance of the BPS object defined in bpsRest lib

bps = BPS('IP-Of-Chassis’, 'admin', 'admin')

# login


# showing current port reservation state

bps.portsState() # logging out bps.logout()

Now let’s seen an example of the same actions (login, get port status, log out) with the REST interface calls, without using the sample bpsRest wrapper library:

#!/usr/bin/env python

import requests

import json

#Connectivity details like IP and credentials to the bps chassis

ipstr = 'IP-Of-Chassis'

username = '<username>'

password = '<password>'

#Creating an instance for http session in python

session = requests.Session()

#Login to the url using post request with the credentials in as json body "jdata"

url = 'https://' + ipstr + '/api/v1/auth/session'

jheaders = {'content-type': 'application/json'}

jdata = json.dumps({'username':username, 'password':password})

r =, data=jdata, headers=jheaders, verify=False)

if(r.status_code == 200):

print 'Login successful Welcome ' + username


print r.content

#Using a GET request to obtain the status of the ports.

url = 'https://' + ipstr +'/api/v1/bps/ports/'

r = session.get(url)

#If successful. From the return json print 'portReservationState' value <

if(r.status_code == 200):

print 'Port Status: ', r.json()['portReservationState']


print r.content

#Log out using a DELETE request

url = 'https://' + ipstr + '/api/v1/auth/session'

r = session.delete(url)

if(r.status_code == 204):

print 'Log Out successful. Good Bye ' + username


print r.content

As you may observe from the two examples above, the library significantly simplifies the actions. However, users are also advised to create their own REST calls without the wrapper to enjoy the flexibility it provides.

A more advanced script that will import a template, modify, run, and get real-time stats can be downloaded from here. Below are explanations of the main blocks of code included in the script and their purposes:

1. Customizing methods by extending the BreakingPoint class:

In the first few blocks we create a class MY_BPS_REST that inherits the BPS class with 3 custom methods: saveAsNormalTest, viewNormalTest, and stopTest.


def saveAsNormalTest(self, name_, force, enableRequestPrints = False):


def viewNormalTest(self, enableRequestPrints = False):


def stopTest(self, runid, enableRequestPrints = False):


2. Changing Test Strategy – Using Rest API to change security component:

We are loading a test that already exists in the system (in this case: 'Clientside Strikes') and modifying the security component ‘attackPlanIterations’ value to 2. To identify the component and the name of the parameter that we want to change, we printed the test configuration as a json string with the custom method (defined at paragraph 2.a. above): bps.viewNormalTest( enableRequestPrints = True). Similarly, you can modify other test elements, parameters (for Network Neighborhood use modifyNetwork method from the library), or labs using the appropriate methods.

print "Mofifying %s existent template and saving as: %s" % (template, testModel)

#bps.viewNormalTest( enableRequestPrints = True)

bps.modifyNormalTest(componentId = 'Security1', elementId = 'attackPlanIterations', Value=2)

3. Start the test using a customized Network Neighborhood:

Want help or have questions?