Skip to content

Commit

Permalink
Added code to configure license server and collect stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmajumdarKS committed Sep 19, 2024
1 parent 7601f97 commit ee42dcb
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
85 changes: 78 additions & 7 deletions cyperf/utils/test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import cyperf
import sys
import time
import datetime
import re
import urllib3
import requests
from pprint import pprint

import time
import cyperf

class TestConfig(object):
def __init__(self,
Expand Down Expand Up @@ -48,15 +50,21 @@ def __init__(self, controller, username="", password="", refreshToken="", licens
self.licenseServer = licenseServer

self.configuration = cyperf.Configuration(host = self.host)
self.configuration.verify_ssl = False
self.configuration.verify_ssl = False
self.apiClient = cyperf.ApiClient(self.configuration)
self.addedLicenseServers = []
self.agents = {}

self.configuration.access_token = self.__authorize__()

self.UpdateLicenseServer()
self.RefreshAgents()

def __del__(self, time=time, datetime=datetime):
if not sys.modules ['time']:
sys.modules ['time'] = time
self.RemoveLicenseServer()

def __authorize__(self):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
apiInstance = cyperf.AuthorizationApi(self.apiClient)
Expand All @@ -80,19 +88,41 @@ def UpdateLicenseServer (self):
apiInstance = cyperf.LicenseServersApi (self.apiClient)
try:
response = apiInstance.get_license_servers()
servers = [lData.host_name for lData in response if lData.connection_status == 'ESTABLISHED']
servers = [lData.host_name for lData in response]
if self.licenseServer in servers:
pprint(f'License server {self.licenseServer} is already configured')
else:
lServer = cyperf.LicenseServerMetadata(host_name = self.licenseServer,
interactive_fingerprint_verification = False,
trust_new = True,
user = self.username,
password = self.password)
#api_response = apiInstance.create_license_servers(license_server_metadata=[lServer])
#pprint(api_instance)
newServers = apiInstance.create_license_servers(license_server_metadata=[lServer])
while newServers:
for server in newServers:
### [PARTHA] If get_license_servers_by_id expects a string as id then
### LicenseServerMetadata shoud have it as a string. User shouldn't
### need to change the type.
s = apiInstance.get_license_servers_by_id(str(server.id))
### [PARTHA]
if 'IN_PROGRESS' != s.connection_status:
newServers.remove(server)
self.addedLicenseServers.append(server)
if 'ESTABLISHED' == s.connection_status:
print (f'Successfully added license server {s.host_name}')
else:
print (f'Could not connect to license server {s.host_name}')
time.sleep(0.5)
except cyperf.ApiException as e:
raise (e)

def RemoveLicenseServer (self):
apiInstance = cyperf.LicenseServersApi (self.apiClient)
for server in self.addedLicenseServers:
try:
apiInstance.delete_license_servers(str(server.id))
except cyperf.ApiException as e:
pprint (f'{e}')

def RefreshAgents(self):
apiInstance = cyperf.AgentsApi(self.apiClient)
try:
Expand Down Expand Up @@ -220,6 +250,41 @@ def WaitUntilStopped(self, sessions):
tmpSessions.append(session)
sessions = tmpSessions

def __CollectStats__(self, session):
apiInstance = cyperf.StatisticsApi(self.apiClient)
try:
resp = apiInstance.get_stats(session.test.test_id)
stats = {}
for stats_group in resp:
stat = apiInstance.get_stats_by_id(session.test.test_id, stats_group.name)
stats [stat.name] = stat
return stats
except cyperf.exceptions.ApiException as e:
pprint (f'{e}')

def CollectStats(self, sessions):
return [self.__CollectStats__(session) for session in sessions]

def __Analyze__(self, stats):
statDict = {}
for statName in stats:
pprint(statName)
stat = stats[statName]
statDict[statName] = {}
if stat.snapshots:
for snapshot in stat.snapshots:
timeStamp = snapshot.timestamp
statDict[statName][timeStamp] = []
for val in snapshot.values:
d = dict(zip(stat.columns, [data.actual_instance for data in val]))
statDict[statName][timeStamp].append(d)

pprint (statDict)
return True

def Analyze(self, stats):
return [self.__Analyze__(s) for s in stats]

def Run(self, config):
width = 200
pprint (f"Loading configuration {config.file} ...", width=width)
Expand All @@ -232,6 +297,12 @@ def Run(self, config):
self.StartSessions(sessions)
pprint (f"Started test for configuration {config.file} ... session id: {sessions[0].index}", width=width)
self.WaitUntilStopped(sessions)
pprint (f"Collecting stats for configuration {config.file} ...", width=width)
stats = self.CollectStats(sessions)
if False in self.Analyze(stats):
pprint (f"Test Failed for {config.file}")
else:
pprint (f"Test Passed for {config.file}")
pprint (f"Closing session for configuration {config.file} ...", width=width)
self.CloseSessions (sessions)
pprint (f"Deleting configuration {config.file} ...", width=width)
Expand Down
4 changes: 3 additions & 1 deletion samples/cyperf_ipv4_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
TestConfig ('samples/configs/Msoft_tput_smartNIC_passthru.zip', {'IP Network Segment 1': ['10.36.74.185'], 'IP Network Segment 2': ['10.36.74.196']})
]

runner = TestRunner ('10.36.75.169', 'admin', 'CyPerf&Keysight#1', licenseServer = '10.38.167.200')
runner = TestRunner ('10.36.75.169', 'admin', 'CyPerf&Keysight#1', licenseServer = 'slum-3-0.buh.is.keysight.com')
#runner = TestRunner ('10.36.75.169', 'admin', 'CyPerf&Keysight#1', licenseServer = '10.38.167.200')
#runner = TestRunner ('10.36.75.169', 'admin', 'CyPerf&Keysight#1', licenseServer = '3.135.19.236')

for config in tests:
runner.Run (config)

0 comments on commit ee42dcb

Please sign in to comment.