Skip to content

Commit

Permalink
Added code to override objective type, value and sustain duration.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmajumdarKS committed Sep 12, 2024
1 parent 423752f commit 21b6479
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
61 changes: 56 additions & 5 deletions cyperf/utils/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cyperf
import re
import urllib3
import requests
from cyperf.rest import ApiException
Expand All @@ -7,12 +8,33 @@
import time

class TestConfig(object):
def __init__(self, configFile, agentMapping, objectiveType, objectiveValue, verifyRules):
def __init__(self,
configFile,
agentMapping={},
objectiveType=cyperf.ObjectiveType.SIMULATED_USERS,
objectiveValue=100,
testDuration=0,
verifyRules=None):
objectiveUnit = None
if type(objectiveValue) == str:
val = re.compile('(\d+\.\d+|\d+)\s*(\w*)').match(objectiveValue).groups()
objectiveValue = float(val[0])
if val[1]:
objectiveUnit = val[1]

if not objectiveUnit:
if objectiveType == cyperf.ObjectiveType.THROUGHPUT:
objectiveUnit = 'bps'
else:
objectiveUnit = ''

self.file = configFile
self.agents = agentMapping
self.duration = testDuration
self.objective = {
'type' : objectiveType,
'value' : objectiveValue
'value' : objectiveValue,
'unit' : objectiveUnit
}
self.statRules = []

Expand Down Expand Up @@ -133,6 +155,34 @@ def CloseSessions(self, sessions):
except cyperf.exceptions.ApiException as e:
pprint (f'{e}')

def __updateObjective__(self, session, objective, duration):
for tProfile in session.config.config.traffic_profiles:
obj = tProfile.objectives_and_timeline.primary_objective
if not duration:
### [PARTHA] Segment durations get reset as soon as the objective type is changed.
### We need to find out a way to keep the existing segments even when the
### objective type is changed.
for segment in obj.timeline:
if segment.enabled:
### [PARTHA] How can I avoid accessing base_model
segmentType = segment.segment_type.base_model
if segmentType == cyperf.SegmentType.STEADYSEGMENT or segmentType == cyperf.SegmentType.NORMALSEGMENT:
duration = segment.duration
### [PARTHA]
### [PARTHA]
obj.type = objective['type']
obj.update()
for segment in obj.timeline:
if segment.enabled:
### [PARTHA] How can I avoid accessing base_model
segmentType = segment.segment_type.base_model
### [PARTHA]
if segmentType == cyperf.SegmentType.STEADYSEGMENT or segmentType == cyperf.SegmentType.NORMALSEGMENT:
segment.objective_value = objective['value']
segment.objective_unit = objective['unit']
segment.duration = duration
segment.update()

def __updateAgents__(self, session, agentMapping):
config = session.config.config
netProfiles = config.network_profiles
Expand All @@ -148,9 +198,10 @@ def __updateAgents__(self, session, agentMapping):
else:
pprint (f"Found no agents for the network segment {ipNet.name}")

def UpdateAgents(self, sessions, agentMapping):
def UpdateSessionConfig(self, sessions, config):
for session in sessions:
self.__updateAgents__(session, agentMapping)
self.__updateObjective__(session, config.objective, config.duration)
self.__updateAgents__(session, config.agents)


def StartSessions(self, sessions):
Expand Down Expand Up @@ -190,7 +241,7 @@ def Run(self, config):
pprint (f"Launching session for configuration {config.file} ...", width=width)
sessions = self.LaunchSessions (configs)
pprint (f"Updating agents as {config.agents} ...", width=width)
self.UpdateAgents (sessions, config.agents)
self.UpdateSessionConfig (sessions, config)
pprint (f"Statrting session for configuration {config.file} ...", width=width)
self.StartSessions(sessions)
pprint (f"Started test for configuration {config.file} ... session id: {sessions[0].index}", 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
@@ -1,7 +1,9 @@
from cyperf import ObjectiveType
from cyperf.utils.test import TestRunner, TestConfig

tests = [
TestConfig ('samples/configs/Msoft_tput_smartNIC_passthru.zip', {'IP Network Segment 1': ['10.36.74.185'], 'IP Network Segment 2': ['10.36.74.196']}, 'Throughput', 12500000000, None)
TestConfig ('samples/configs/Msoft_tput_smartNIC_passthru.zip', {'IP Network Segment 1': ['10.36.74.185'], 'IP Network Segment 2': ['10.36.74.196']}, ObjectiveType.THROUGHPUT, '15 Gbps'),
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')
Expand Down

0 comments on commit 21b6479

Please sign in to comment.