Skip to content

Commit 7f1a525

Browse files
committed
Initial commits
1 parent 71225a1 commit 7f1a525

File tree

2 files changed

+321
-0
lines changed

2 files changed

+321
-0
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Description
2+
# A sample Python REST API script to:
3+
# - Load a saved configuration file
4+
# - Enable port analyzer
5+
# - Set runtime stats
6+
# - Run traffic
7+
# - Get stats and evaluate for user defined expected stat values.
8+
# - Retrieve port capture files to local folder.
9+
# - Get test result
10+
#
11+
# Supports both Windows and Linux gateway Server. If connecting to a
12+
#
13+
# If the saved config file is located on a remote pc, this script could upload it to the gateway.
14+
# Otherwise, the saved config file must be already in the IxLoad API gateway server.
15+
#
16+
# Requirements
17+
# IxL_RestApi.py
18+
#
19+
# IxL_RestApi.py and sample scripts by: Hubert Gee
20+
21+
import os, sys, time, signal, traceback, platform
22+
from keystackEnv import keystackObj
23+
from IxL_RestApi import *
24+
25+
# Insert the Modules path to env in order to import IxL_RestApi.py
26+
currentDir = os.path.abspath(os.path.dirname(__file__))
27+
28+
# Choices of IxLoad Gateway server OS: linux or windows
29+
serverOs = keystackObj.testcaseConfigParams['configParams']['serverOs']
30+
31+
# Which IxLoad version are you using for your test?
32+
# To view all the installed versions, go on a web browser and enter:
33+
# http://<server ip>:8080/api/v0/applicationTypes
34+
ixLoadVersion = keystackObj.testcaseConfigParams['configParams']['ixLoadVersion']
35+
36+
# Do you want to delete the session at the end of the test or if the test failed?
37+
deleteSession = keystackObj.testcaseConfigParams['configParams']['deleteSession']
38+
forceTakePortOwnership = bool(keystackObj.testcaseConfigParams['configParams']['forceTakePortOwnership'])
39+
40+
# API-Key: Use your user API-Key if you want added security
41+
apiKey = keystackObj.testcaseConfigParams['configParams']['apiKey']
42+
if apiKey in ['None', 'none']: apiKey = None
43+
44+
# The saved config file to load located in the ConfigFiles folder
45+
rxfFile = keystackObj.exportedConfigFullPath
46+
47+
if serverOs == 'windows':
48+
apiServerIp = keystackObj.moduleProperties['envParams'].get('windowsApiServerIp', None)
49+
50+
# Where to store all of the csv result files in Windows
51+
resultsDir = keystackObj.moduleProperties['envParams'].get('windowsResultsDir', None)
52+
53+
# Where to upload the config file or where to tell IxLoad the location if you're not uploading it.
54+
rxfFileOnServer = f'C:\\Results\\{rxfFile}'
55+
56+
if serverOs == 'linux':
57+
apiServerIp = keystackObj.moduleProperties['envParams'].get('linuxApiServerIp', None)
58+
59+
# Leave the 2 lines as default. For your reference only.
60+
resultsDir = keystackObj.moduleProperties['envParams'].get('linuxResultsDir', None)
61+
rxfFileOnServer = f'/mnt/ixload-share/{rxfFile}'
62+
63+
# Where to put the downloaded csv results
64+
saveResultsInPath = keystackObj.moduleProperties['artifactsRepo']
65+
66+
# On the local host where you are running this script.
67+
# The path to the saved config file. In this example, get it from the current folder
68+
localConfigFileToUpload = rxfFile
69+
70+
# The path where you want to download the csv result files to. This is mostly used if using a Linux Gateway server.
71+
# If you're using IxLoad in Windows, SSH must be installed. Otherwise, this variable will be ignored.
72+
scpDestPath = keystackObj.moduleProperties['artifactsRepo']
73+
74+
# For IxLoad versions prior to 8.50 that doesn't have the rest api to download results.
75+
# Set to True if you want to save run time stat results to CSV files.
76+
saveStatsToCsvFile = bool(keystackObj.testcaseConfigParams['configParams']['saveStatsToCsvFile'])
77+
78+
# http=8080. https=8443 (https is supported starting 8.50)
79+
apiServerIpPort = keystackObj.moduleProperties['envParams']['apiServerIpPort']
80+
81+
licenseServerIp = keystackObj.moduleProperties['envParams']['licenseServerIp']
82+
83+
# licenseModel choices: 'Subscription Mode' or 'Perpetual Mode'
84+
licenseModel = keystackObj.moduleProperties['envParams']['licenseModel']
85+
86+
# To assign ports for testing. Format = (cardId,portId)
87+
# Traffic1@Network1 are activity names.
88+
# To get the Activity names, got to: /ixload/test/activeTest/communityList
89+
communityPortList1 = {
90+
'chassisIp': keystackObj.moduleProperties['envParams']['communityPortList1']['chassisIp'],
91+
'Traffic1@Network1': keystackObj.moduleProperties['envParams']['communityPortList1']['Traffic1@Network1']
92+
}
93+
94+
communityPortList2 = {
95+
'chassisIp': keystackObj.moduleProperties['envParams']['communityPortList2']['chassisIp'],
96+
'Traffic2@Network2': keystackObj.moduleProperties['envParams']['communityPortList2']['Traffic2@Network2']
97+
}
98+
99+
# Stat names to display at run time.
100+
# To see how to get the stat names, go to the link below for step-by-step guidance:
101+
# https://www.openixia.com/tutorials?subject=ixLoad/getStatName&page=fromApiBrowserForRestApi.html
102+
#
103+
# What this does:
104+
# Get run time stats and evaluate the stats with an operator and the expected value.
105+
# Due to stats going through ramp up and ramp down, stats will fluctuate.
106+
# Once the stat hits and maintains the expected threshold value, the stat is marked as passed.
107+
#
108+
# If evaluating stats at run time is not what you need, use PollStats() instead shown
109+
# in sample script LoadConfigFile.py
110+
#
111+
# operator options: None, >, <, <=, >=
112+
statsDict = {
113+
'HTTPClient': [{'caption': 'TCP Connections Established', 'operator': '>', 'expect': 60},
114+
{'caption': 'HTTP Simulated Users', 'operator': '>', 'expect': 100},
115+
{'caption': 'HTTP Connections', 'operator': '>', 'expect': 300},
116+
{'caption': 'HTTP Transactions', 'operator': '>', 'expect': 190},
117+
{'caption': 'HTTP Connection Attempts', 'operator': '>', 'expect': 300}
118+
],
119+
'HTTPServer': [{'caption': 'TCP Connections Established', 'operator': '>=', 'expect': 1000},
120+
{'caption': 'TCP Connection Requests Failed', 'operator': '<', 'expect': 1}
121+
]
122+
}
123+
124+
try:
125+
restObj = Main(apiServerIp=apiServerIp,
126+
apiServerIpPort=apiServerIpPort,
127+
osPlatform=serverOs,
128+
deleteSession=deleteSession,
129+
pollStatusInterval=1,
130+
apiKey=apiKey,
131+
generateRestLogFile=None, keystackObj=keystackObj)
132+
133+
# sessionId is an opened existing session that you like to connect to instead of starting a new session.
134+
restObj.connect(ixLoadVersion, sessionId=None, timeout=120)
135+
136+
restObj.configLicensePreferences(licenseServerIp=licenseServerIp, licenseModel=licenseModel)
137+
138+
# The folder to store the results on the IxLoad Gateway server.
139+
restObj.setResultDir(resultsDir, createTimestampFolder=True)
140+
141+
# uploadConfigFile: None or path to the config file on your local host
142+
restObj.loadConfigFile(rxfFileOnServer, uploadConfigFile=localConfigFileToUpload)
143+
144+
restObj.assignChassisAndPorts([communityPortList1, communityPortList2])
145+
if forceTakePortOwnership:
146+
restObj.enableForceOwnership(enable=True, enableResetPorts=True)
147+
148+
restObj.enableAnalyzerOnAssignedPorts()
149+
150+
# Optional: Modify the sustain time
151+
restObj.configTimeline(name='Timeline1', sustainTime=12)
152+
153+
# Example on how to use the configActivityAttribute function to modify
154+
# some of its attributes.
155+
restObj.configActivityAttributes(communityName='Traffic1@Network1',
156+
activityName='HTTPClient1',
157+
attributes={'userObjectiveValue': 100})
158+
159+
runTestOperationsId = restObj.runTraffic()
160+
161+
restObj.pollStatsAndCheckStatResults(statsDict,
162+
csvFile=saveStatsToCsvFile,
163+
csvFilePrependName=None,
164+
pollStatInterval=2,
165+
exitAfterPollingIteration=None)
166+
167+
168+
testResult = restObj.getTestResults()
169+
170+
restObj.waitForActiveTestToUnconfigure()
171+
restObj.downloadResults(targetPath=saveResultsInPath)
172+
restObj.retrievePortCaptureFileForAssignedPorts(saveResultsInPath)
173+
174+
if deleteSession:
175+
restObj.deleteSessionId()
176+
177+
except (IxLoadRestApiException, Exception) as errMsg:
178+
print('\n%s' % traceback.format_exc())
179+
keystackObj.logError(errMsg)
180+
keystackObj.playbookObj.overallSummaryData['exceptionErrors'].append(errMsg)
181+
if deleteSession:
182+
restObj.abortActiveTest()
183+
restObj.deleteSessionId()
184+
185+
sys.exit(errMsg)
186+
187+
except KeyboardInterrupt:
188+
print('\nCTRL-C detected.')
189+
keystackObj.logError('CTRL-C detected')
190+
if deleteSession:
191+
restObj.abortActiveTest()
192+
restObj.deleteSessionId()
193+
194+
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
version: 1.0.0
2+
3+
applet: Apps/IxLoad/LoadConfigFileEvalStats.py
4+
5+
description:
6+
7+
- Load an exported configuration file
8+
- Start test
9+
- Show stats expectation at runtime
10+
- Optional: Get capture files
11+
12+
keystack requirements:
13+
14+
- Env yml file
15+
- Testcase yml file
16+
- Create playbook or add testcases to playbook playlist
17+
18+
instructions:
19+
20+
- Manually run test on IxLoad
21+
- When test configuration is satisfied, export the config file
22+
- Put the exported config file to /your_path/KeystackTests/Modules/LoadCore/ExportedConfigs
23+
- Create testcase yml files:
24+
- Create an env file containing the IxLoad setup IP addresses and
25+
login credentials
26+
- Create a playbook to run testcases or add a testcase to existing playbook
27+
28+
env yml file sample:
29+
file location: /your_path/Keystack/Tests/Envs/ixLoad_qa
30+
31+
windowsApiServerIp: 192.168.28.10
32+
33+
# Where to store all of the csv result files in Windows
34+
windowsResultsDir: c:\\Results
35+
36+
linuxApiServerIp: 192.168.28.24
37+
38+
# Leave the 2 lines as default. For your reference only.
39+
linuxResultsDir: /mnt/ixload-share/Results
40+
41+
# http=8080. https=8443 (https is supported starting 8.50)
42+
apiServerIpPort: 8443
43+
44+
licenseServerIp: 192.168.28.10
45+
46+
# licenseModel choices: 'Subscription Mode' or 'Perpetual Mode'
47+
licenseModel: Subscription Mode
48+
49+
# To assign ports for testing. Format = (cardId,portId)
50+
# Traffic1@Network1 are activity names.
51+
# To get the Activity names, got to: /ixload/test/activeTest/communityList
52+
communityPortList1:
53+
chassisIp: 192.168.28.5
54+
Traffic1@Network1:
55+
- [1,1]
56+
57+
communityPortList2:
58+
chassisIp: 192.168.28.5
59+
Traffic2@Network2:
60+
- [1,2]
61+
62+
testcase yml file sample:
63+
64+
file location: /keystack_path/KeystackTests/Modules/IxLoad/Testcases/http.yml
65+
66+
title: HTTP
67+
68+
description: Validate HTTP
69+
70+
# The path must begins with /Modules or /Apps
71+
script: /Apps/IxLoad/Applets/LoadSavedConfigFile/LoadConfigFileEvalStats.py
72+
73+
# Store exported config files in /Modules/IxLoad/ExportedConfigs
74+
exportedConfigFile: IxL_Http_Ipv4Ftp_vm_8.20.rxf
75+
76+
# Store data-model files / param files in /Modules/IxLoad/ConfigParameters
77+
configParametersFile: demoConfigs.yml
78+
79+
# Provide a list with dashes of paths to append to sys.path
80+
# For scripts to import. Must begin with either /Apps or /Modules.
81+
importAppLibraryPaths:
82+
- /Apps/IxLoad
83+
84+
85+
Configuration Parameters file:
86+
87+
file location: /keystack_path/KeystackTests/Modules/IxLoad/ConfigParameters/demoConfigs.yml
88+
89+
# Choices of IxLoad Gateway server OS: linux or windows
90+
serverOs: windows
91+
92+
# Which IxLoad version are you using for your test?
93+
# To view all the installed versions, go on a web browser and enter:
94+
# http://<server ip>:8080/api/v0/applicationTypes
95+
ixLoadVersion: 9.30.0.331
96+
97+
# Do you want to delete the session at the end of the test or if the test failed?
98+
deleteSession: True
99+
forceTakePortOwnership: True
100+
101+
# API-Key: Use your user API-Key if you want added security
102+
apiKey: None
103+
104+
# For IxLoad versions prior to 8.50 that doesn't have the rest api to download results.
105+
# Set to True if you want to save run time stat results to CSV files.
106+
saveStatsToCsvFile: True
107+
108+
playbook yml file sample:
109+
110+
file location: /keystack_path/KeystackTests/Playbooks/ixLoadRegression.yml
111+
112+
---
113+
stages:
114+
Test:
115+
enable: True
116+
runModulesInParallel: False
117+
abortModuleFailure: False
118+
119+
modules:
120+
- /Modules/IxLoad:
121+
enable: True
122+
abortModuleFailure: False
123+
env: ixLoadDemo
124+
playlist:
125+
- /Modules/IxLoad/Testcases/http.yml
126+
127+

0 commit comments

Comments
 (0)