OpenIxia / bps_restpy

This repository contains the python library and samples for controlling the REST API of BreakingPoint and BreakingPoint Virtual Edition tools
https://www.ixiacom.com/products/breakingpoint
MIT License
4 stars 2 forks source link

stopRun method doesn’t work in separate sessions #1

Open patrickdaj opened 4 years ago

patrickdaj commented 4 years ago

testmodel.stopRun method hangs when run in a different bps_restpy session than the testmodel.run. The test does stop but the python API just hangs infinitely. This is pretty useful when you are automating long running tests to split the start and stop between multiple scripts.

from bps_restpy.bps import BPS

bps = BPS(host, user, password)

bps.login()

Successfully connected to x.x.x.x.

Login successful.

Welcome user.

Your session id is 5d180626-49ac-4cf3-b694-1b5b4b229fe2

bps.testmodel.run(modelname='test', group=10)

Out[6]: {'host': '127.0.0.1', 'name': 'test', 'iteration': 30, 'runid': 96}

bps.testmodel.stopRun(96)

Out[7]: b'canceled'

bps.testmodel.run(modelname='test', group=10)

Out[8]: {'host': '127.0.0.1', 'name': 'test', 'iteration': 31, 'runid': 97}

bps.logout()

Logout successful.

Bye user.

Successfully disconnected from x.x.x.x.

bps.login()

Successfully connected to x.x.x.x.

Login successful.

Welcome user.

Your session id is aee3511f-dbed-4de5-a4f1-c9f7179f920d

bps.testmodel.stopRun(97)

The last stopRun call just hangs infinitely. Above when the stopRun was done in the same session it completed with a response of b’canceled’.

patrickdaj commented 4 years ago

Was this ever fixed?

nutu commented 4 years ago

Was this ever fixed? Hi Patrick, We are working on fixing this in the next 9.10 Patch build that is targeted to be released in the next couple of weeks. Thanks for bringing it to our attention.

Until then you can use this function as a workarround:

import json

def stopTest(testid, bps):
        testid = "TEST-%s" % testid
        service = 'https://' + bps.host + '/api/v1/bps/tests/operations/stop'
        jheaders = {'content-type': 'application/json'}
        jdata = json.dumps({'testid':testid})
        r = bps.session.post(service, data=jdata, headers=jheaders, verify=False)
        if(r.status_code == 200):
            print('Test: [' + testid + '] has been successfully stopped.')
        else:
            print('Some error occurred while cancelling the running test: [' + testid + ']')

# example ussage 
from bps_restpy.bps import BPS,pp

bps = BPS(bps_system, bpsuser, bpspass)
bps.login()

testid = 97

stopTest(testid, bps)

bps.logout()

Regards, Constantin