|
| 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