Skip to content

Commit ddc54f1

Browse files
authored
Merge pull request #17 from OpenIxia/9.37
9.37
2 parents 7e8b3a8 + d550289 commit ddc54f1

File tree

9 files changed

+3890
-3612
lines changed

9 files changed

+3890
-3612
lines changed

.DS_Store

0 Bytes
Binary file not shown.

RestApi/.DS_Store

0 Bytes
Binary file not shown.

RestApi/Python/.DS_Store

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

RestApi/Python/RestApi_v2/Modules/bps_restpy/restPyWrapper3.py

Lines changed: 3615 additions & 3612 deletions
Large diffs are not rendered by default.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Title: Python Script Sample To Run a Canned Test.
2+
# Actions:
3+
# 1. Login to BPS box
4+
# 2. Reserve ports
5+
# 3. Load a test from the box and start the run
6+
# 4. Wait for the test to finish
7+
# 5. Get test result
8+
# 6. Get and print the Synopsis page from report
9+
# 7. Unreserve ports
10+
# 8. Logout
11+
12+
13+
#================
14+
15+
########################################
16+
import time, sys, os
17+
# Add bps_restpy libpath *required if the library is not installed
18+
libpath = os.path.abspath(__file__+"/../../..")
19+
sys.path.insert(0,libpath)
20+
21+
from bps_restpy.bps import BPS,pp
22+
23+
########################################
24+
25+
########################################
26+
# Demo script global variables
27+
########################################
28+
# Demo script global variables
29+
canned_test_name = 'AppSim'
30+
#bps system info
31+
bps_system = '10.36.66.31'
32+
bpsuser = 'admin'
33+
bpspass = 'admin'
34+
35+
36+
slot_number = 9
37+
port_list = [0, 4]
38+
39+
########################################
40+
41+
42+
########################################
43+
# Login to BPS box
44+
bps = BPS(bps_system, bpsuser, bpspass)
45+
bps.login()
46+
47+
48+
########################################
49+
print("Load a canned test: ")
50+
bps.testmodel.load(canned_test_name)
51+
52+
########################################
53+
print("Fanout the ports")
54+
fanout_result = bps.topology.getFanoutModes(slot_number)
55+
56+
'''
57+
The fan type represented by an integer id. Get card specific fanout modes by calling 'topology.getFanoutModes(<card_id>)'.
58+
For CloudStorm: 0(100G), 1(40G), 2(25G), 3(10G), 4(50G). For PerfectStorm 40G: 0(40G), 1(10G).
59+
For PerfectStorm 100G: 0(100G), 1(40G), 2(10G)
60+
'''
61+
62+
print("The list of Fanout options:")
63+
for li in fanout_result["fanouts"]:
64+
print("The ID {0} is referring to the fanout mode {1}".format(li["id"], li["name"]))
65+
#Specify the fanout mode here
66+
fanid = 2
67+
print("Fanning out the ports...")
68+
#Grabing the status URL and polling the latest fan out status progress
69+
pollUrl = bps.topology.setCardFanout(slot_number,fanid)["url"]
70+
response = bps.session.get(url=pollUrl, headers={'content-type': 'application/json'}, verify=False)
71+
if(response.status_code in [200, 204]):
72+
print("Fan out state {0}: {1}".format(response.json()["state"],response.json()["message"]), end="\r")
73+
else:
74+
bps.logout()
75+
raise Exception("Error: ", response.json())
76+
while response.json()["state"] == "IN_PROGRESS":
77+
response = bps.session.get(url=pollUrl, headers={'content-type': 'application/json'}, verify=False)
78+
if(response.status_code in [200, 204]):
79+
print("Fan out state {0}: {1}".format(response.json()["state"],response.json()["message"]), end="\r")
80+
else:
81+
bps.logout()
82+
raise Exception("Error: ", response.json())
83+
time.sleep(2)
84+
85+
if response.json()["state"] == "SUCCESS":
86+
print("Fanout completed!")
87+
time.sleep(3)
88+
print("\nInitializing ports..")
89+
time.sleep(3)
90+
else:
91+
bps.logout()
92+
raise Exception("Something wrong while fanning out ports!")
93+
94+
95+
#######################################
96+
print("Reserve Ports")
97+
for p in port_list:
98+
bps.topology.reserve([{'slot': slot_number, 'port': p, 'group': 2}])
99+
100+
101+
########################################
102+
print("Run test and Get Stats:")
103+
test_id_json = bps.testmodel.run(modelname=canned_test_name, group=2)
104+
testid = str( test_id_json["runid"] )
105+
run_id = 'TEST-' + testid
106+
print("Test Run Id: %s"%run_id)
107+
108+
#get the ids for all tests running on the chassis
109+
runningTests_Ids = [test['id'] for test in bps.topology.runningTest.get()]
110+
#wait while the test is still running
111+
while run_id in runningTests_Ids:
112+
run_state = bps.topology.runningTest[run_id].get()
113+
#print progress if test started
114+
try: print ('progress: %s%% , runtime %ss' % (run_state['progress'], run_state['runtime'] ), end="\r")
115+
except: print ("\nStarting...")
116+
time.sleep(2)
117+
#update the current running tests
118+
runningTests_Ids = [test['id'] for test in bps.topology.runningTest.get()]
119+
120+
print("~The test finished the execution.")
121+
results = bps.reports.search(searchString=canned_test_name, limit=10, sort="endTime", sortorder="descending")
122+
result = results[0]
123+
print ("%s execution duration %s ended with status: %s " % (result['name'], result['duration'], result['result']) )
124+
125+
#getting 3.4 Section: Synopsys Summary of Results from the Report
126+
tabledata = bps.reports.getReportTable(runid=testid, sectionId="3.4")
127+
pp(tabledata)
128+
129+
print ("Unreserving the ports")
130+
for p in port_list:
131+
bps.topology.unreserve([{'slot': slot_number, 'port': p, 'group': 2}])
132+
133+
bps.logout()
134+
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Title: Python Script Sample To Run a Canned Test.
2+
# Actions:
3+
# 1. Login to BPS box
4+
# 2. Reserve ports
5+
# 3. Load a test from the box and start the run
6+
# 4. Wait for the test to finish
7+
# 5. Get test result
8+
# 6. Get and print the Synopsis page from report
9+
# 7. Unreserve ports
10+
# 8. Logout
11+
12+
13+
#================
14+
15+
########################################
16+
import time, sys, os
17+
# Add bps_restpy libpath *required if the library is not installed
18+
libpath = os.path.abspath(__file__+"/../../..")
19+
sys.path.insert(0,libpath)
20+
21+
from bps_restpy.bps import BPS,pp
22+
23+
########################################
24+
25+
########################################
26+
# Demo script global variables
27+
########################################
28+
# Demo script global variables
29+
canned_test_name = 'AppSim'
30+
#bps system info
31+
bps_system = '10.36.83.31'
32+
bpsuser = 'admin'
33+
bpspass = 'admin'
34+
35+
36+
slot_number = 1
37+
port_list = [3, 4]
38+
port_list_postFanout = [3,4]
39+
l47_resource = [2,3]
40+
41+
########################################
42+
43+
44+
########################################
45+
# Login to BPS box
46+
bps = BPS(bps_system, bpsuser, bpspass)
47+
bps.login()
48+
49+
50+
########################################
51+
print("Load a canned test: ")
52+
bps.testmodel.load(canned_test_name)
53+
print("Disable L23 resource auto-reservation.")
54+
bps.administration.userSettings.changeUserSetting("autoreserve.l23","0")
55+
print("Disable L47 resource auto-reservation.")
56+
bps.administration.userSettings.changeUserSetting("autoreserve.l47","0")
57+
########################################
58+
print("Fanout the ports")
59+
fanout_result = bps.topology.getPortAvailableModes(slot_number, 40)
60+
print("The list of Fanout options:")
61+
for li in fanout_result["modes"]:
62+
print("The available fanout mode {0}".format(li["name"]))
63+
#Specify the fanout mode
64+
fanMode = "8x50G-PAM4"
65+
print("Fanning out the ports to {0} mode...".format(fanMode))
66+
67+
for p in port_list:
68+
#Grabing the status URL and polling the latest fan out status progress
69+
pollUrl = bps.topology.setPortFanoutMode(slot_number,p,fanMode)["url"]
70+
response = bps.session.get(url=pollUrl, headers={'content-type': 'application/json'}, verify=False)
71+
if(response.status_code in [200, 204]):
72+
print("Fan out state {0}: {1}".format(response.json()["state"],response.json()["message"]), end="\r")
73+
else:
74+
bps.logout()
75+
raise Exception("Error: ", response.json())
76+
while response.json()["state"] == "IN_PROGRESS":
77+
response = bps.session.get(url=pollUrl, headers={'content-type': 'application/json'}, verify=False)
78+
if(response.status_code in [200, 204]):
79+
print("Fan out state {0}: {1}".format(response.json()["state"],response.json()["message"]), end="\r")
80+
else:
81+
bps.logout()
82+
raise Exception("Error: ", response.json())
83+
time.sleep(2)
84+
if response.json()["state"] == "SUCCESS":
85+
print("\nFanout on port {0} completed!".format(p))
86+
time.sleep(3)
87+
print("Initializing ports..")
88+
time.sleep(3)
89+
else:
90+
bps.logout()
91+
raise Exception("\nSomething wrong while fanning out ports!")
92+
93+
print("All ports fanout completed!")
94+
time.sleep(3)
95+
#######################################
96+
print("Reserve L47 resources...")
97+
for r in l47_resource:
98+
bps.topology.reserveResource(group = 2, resourceId = r, resourceType = "l47")
99+
100+
print("Reserve Ports")
101+
for p in port_list:
102+
bps.topology.reserve([{'slot': slot_number, 'port': p, 'group': 2}])
103+
104+
########################################
105+
print("Run test and Get Stats:")
106+
test_id_json = bps.testmodel.run(modelname=canned_test_name, group=2)
107+
testid = str( test_id_json["runid"] )
108+
run_id = 'TEST-' + testid
109+
print("Test Run Id: %s"%run_id)
110+
111+
#get the ids for all tests running on the chassis
112+
runningTests_Ids = [test['id'] for test in bps.topology.runningTest.get()]
113+
#wait while the test is still running
114+
while run_id in runningTests_Ids:
115+
run_state = bps.topology.runningTest[run_id].get()
116+
#print progress if test started
117+
try: print ('progress: %s%% , runtime %ss' % (run_state['progress'], run_state['runtime'] ), end="\r")
118+
except: print ("\nStarting...")
119+
time.sleep(2)
120+
#update the current running tests
121+
runningTests_Ids = [test['id'] for test in bps.topology.runningTest.get()]
122+
123+
print("~The test finished the execution.")
124+
results = bps.reports.search(searchString=canned_test_name, limit=10, sort="endTime", sortorder="descending")
125+
result = results[0]
126+
print ("%s execution duration %s ended with status: %s " % (result['name'], result['duration'], result['result']) )
127+
128+
#getting 3.4 Section: Synopsys Summary of Results from the Report
129+
tabledata = bps.reports.getReportTable(runid=testid, sectionId="3.4")
130+
pp(tabledata)
131+
132+
print("Releasing resources...")
133+
for r in l47_resource:
134+
bps.topology.releaseResource(group = 2, resourceId = r, resourceType = "l47")
135+
136+
print ("Unreserving the ports")
137+
for p in port_list:
138+
bps.topology.unreserve([{'slot': slot_number, 'port': p, 'group': 2}])
139+
140+
bps.logout()
141+

0 commit comments

Comments
 (0)