connectTest: tabs to spaces

This commit is contained in:
Jed Reynolds
2020-05-26 11:49:55 -07:00
parent 0fa500576c
commit 363e7fddc9

View File

@@ -4,7 +4,7 @@ import time
import sys import sys
if 'py-json' not in sys.path: if 'py-json' not in sys.path:
sys.path.append('py-json') sys.path.append('py-json')
import subprocess import subprocess
import json import json
@@ -22,61 +22,61 @@ if sys.version_info[0] != 3:
mgrURL = "http://localhost:8080/" mgrURL = "http://localhost:8080/"
def execWrap(cmd): def execWrap(cmd):
if os.system(cmd) != 0: if os.system(cmd) != 0:
print("\nError with " + cmd + ",bye\n") print("\nError with " + cmd + ",bye\n")
exit(1) exit(1)
def jsonReq(mgrURL, reqURL, data, debug=False): def jsonReq(mgrURL, reqURL, data, debug=False):
lf_r = LFRequest.LFRequest(mgrURL + reqURL) lf_r = LFRequest.LFRequest(mgrURL + reqURL)
lf_r.addPostData(data) lf_r.addPostData(data)
if debug: if debug:
json_response = lf_r.jsonPost(debug) json_response = lf_r.jsonPost(debug)
LFUtils.debug_printer.pprint(json_response) LFUtils.debug_printer.pprint(json_response)
sys.exit(1) sys.exit(1)
else: else:
lf_r.jsonPost(debug) lf_r.jsonPost(debug)
def getJsonInfo(mgrURL, reqURL): def getJsonInfo(mgrURL, reqURL):
lf_r = LFRequest.LFRequest(mgrURL + reqURL) lf_r = LFRequest.LFRequest(mgrURL + reqURL)
json_response = lf_r.getAsJson(debugOn) json_response = lf_r.getAsJson(debugOn)
return json_response return json_response
#print(name) #print(name)
#j_printer = pprint.PrettyPrinter(indent=2) #j_printer = pprint.PrettyPrinter(indent=2)
#j_printer.pprint(json_response) #j_printer.pprint(json_response)
#for record in json_response[key]: #for record in json_response[key]:
# j_printer.pprint(record) # j_printer.pprint(record)
def removeEndps(mgrURL, endpNames): def removeEndps(mgrURL, endpNames):
for name in endpNames: for name in endpNames:
#print(f"Removing endp {name}") #print(f"Removing endp {name}")
data = { data = {
"endp_name":name "endp_name":name
} }
jsonReq(mgrURL, "cli-json/rm_endp", data) jsonReq(mgrURL, "cli-json/rm_endp", data)
def removeCX(mgrURL, cxNames): def removeCX(mgrURL, cxNames):
for name in cxNames: for name in cxNames:
#print(f"Removing CX {name}") #print(f"Removing CX {name}")
data = { data = {
"test_mgr":"all", "test_mgr":"all",
"cx_name":name "cx_name":name
} }
jsonReq(mgrURL,"cli-json/rm_cx", data) jsonReq(mgrURL,"cli-json/rm_cx", data)
print("Checking for LANforge Client") print("Checking for LANforge Client")
response = getJsonInfo(mgrURL, 'port/1/1/wlan0') response = getJsonInfo(mgrURL, 'port/1/1/wlan0')
timeout = 0 timeout = 0
while response == None and timeout != 300: while response == None and timeout != 300:
print("LANforge Client not found sleeping 5 seconds") print("LANforge Client not found sleeping 5 seconds")
timeout += 5 timeout += 5
time.sleep(5) time.sleep(5)
response = getJsonInfo(mgrURL, 'port/1/1/wlan0') response = getJsonInfo(mgrURL, 'port/1/1/wlan0')
#print(response) #print(response)
if timeout == 300: if timeout == 300:
print("Could not connect to LANforge Client") print("Could not connect to LANforge Client")
sys.exit(1) sys.exit(1)
@@ -115,35 +115,35 @@ time.sleep(10)
eth1IP = getJsonInfo(mgrURL, "port/1/1/eth1") eth1IP = getJsonInfo(mgrURL, "port/1/1/eth1")
if eth1IP['interface']['ip'] == "0.0.0.0": if eth1IP['interface']['ip'] == "0.0.0.0":
print("Warning: Eth1 lacks ip address") print("Warning: Eth1 lacks ip address")
reqURL = "cli-json/nc_show_ports" reqURL = "cli-json/nc_show_ports"
data = { "shelf":1, data = { "shelf":1,
"resource":1, "resource":1,
"port":"sta0000", "port":"sta0000",
"probe_flags":1 } "probe_flags":1 }
jsonReq(mgrURL,reqURL,data) jsonReq(mgrURL,reqURL,data)
staIP = getJsonInfo(mgrURL, "port/1/1/sta00000") staIP = getJsonInfo(mgrURL, "port/1/1/sta00000")
timeout = 0 timeout = 0
maxTime = 300 maxTime = 300
while staIP['interface']['ip'] == "0.0.0.0" and timeout != maxTime: while staIP['interface']['ip'] == "0.0.0.0" and timeout != maxTime:
print("Station failed to get IP. Waiting 10 seconds...") print("Station failed to get IP. Waiting 10 seconds...")
staIP = getJsonInfo(mgrURL, "port/1/1/sta00000") staIP = getJsonInfo(mgrURL, "port/1/1/sta00000")
timeout += 10 timeout += 10
time.sleep(10) time.sleep(10)
if timeout == maxTime: if timeout == maxTime:
print("sta00000 failed to get an ip. Ending test") print("sta00000 failed to get an ip. Ending test")
print("Cleaning up...") print("Cleaning up...")
reqURL = "cli-json/rm_vlan" reqURL = "cli-json/rm_vlan"
data = { data = {
"shelf":1, "shelf":1,
"resource":1, "resource":1,
"port":"sta00000" "port":"sta00000"
} }
jsonReq(mgrURL, reqURL, data) jsonReq(mgrURL, reqURL, data)
sys.exit(1) sys.exit(1)
#create endpoints and cxs #create endpoints and cxs
@@ -317,61 +317,61 @@ cxNames = ["testTCP","testUDP", "CX_l4Test", "CX_fioTest", "CX_genTest1", "CX_wl
#get data before running traffic #get data before running traffic
try: try:
testTCPA = getJsonInfo(mgrURL, "endp/testTCP-A?fields=tx+bytes,rx+bytes") testTCPA = getJsonInfo(mgrURL, "endp/testTCP-A?fields=tx+bytes,rx+bytes")
testTCPATX = testTCPA['endpoint']['tx bytes'] testTCPATX = testTCPA['endpoint']['tx bytes']
testTCPARX = testTCPA['endpoint']['rx bytes'] testTCPARX = testTCPA['endpoint']['rx bytes']
testTCPB = getJsonInfo(mgrURL, "endp/testTCP-B?fields=tx+bytes,rx+bytes") testTCPB = getJsonInfo(mgrURL, "endp/testTCP-B?fields=tx+bytes,rx+bytes")
testTCPBTX = testTCPB['endpoint']['tx bytes'] testTCPBTX = testTCPB['endpoint']['tx bytes']
testTCPBRX = testTCPB['endpoint']['rx bytes'] testTCPBRX = testTCPB['endpoint']['rx bytes']
testUDPA = getJsonInfo(mgrURL, "endp/testUDP-A?fields=tx+bytes,rx+bytes") testUDPA = getJsonInfo(mgrURL, "endp/testUDP-A?fields=tx+bytes,rx+bytes")
testUDPATX = testUDPA['endpoint']['tx bytes'] testUDPATX = testUDPA['endpoint']['tx bytes']
testUDPARX = testUDPA['endpoint']['rx bytes'] testUDPARX = testUDPA['endpoint']['rx bytes']
testUDPB = getJsonInfo(mgrURL, "endp/testUDP-B?fields=tx+bytes,rx+bytes") testUDPB = getJsonInfo(mgrURL, "endp/testUDP-B?fields=tx+bytes,rx+bytes")
testUDPBTX = testUDPB['endpoint']['tx bytes'] testUDPBTX = testUDPB['endpoint']['tx bytes']
testUDPBRX = testUDPB['endpoint']['rx bytes'] testUDPBRX = testUDPB['endpoint']['rx bytes']
l4Test = getJsonInfo(mgrURL, "layer4/l4Test?fields=bytes-rd") l4Test = getJsonInfo(mgrURL, "layer4/l4Test?fields=bytes-rd")
l4TestBR = l4Test['endpoint']['bytes-rd'] l4TestBR = l4Test['endpoint']['bytes-rd']
genTest1 = getJsonInfo(mgrURL, "generic/genTest1?fields=last+results") genTest1 = getJsonInfo(mgrURL, "generic/genTest1?fields=last+results")
genTest1LR = genTest1['endpoint']['last results'] genTest1LR = genTest1['endpoint']['last results']
wlTest1 = getJsonInfo(mgrURL,"wl_ep/wlTest1") wlTest1 = getJsonInfo(mgrURL,"wl_ep/wlTest1")
wlTest1TXB = wlTest1['endpoint']['tx bytes'] wlTest1TXB = wlTest1['endpoint']['tx bytes']
wlTest1RXP = wlTest1['endpoint']['rx pkts'] wlTest1RXP = wlTest1['endpoint']['rx pkts']
wlTest2 = getJsonInfo(mgrURL,"wl_ep/wlTest2") wlTest2 = getJsonInfo(mgrURL,"wl_ep/wlTest2")
wlTest2TXB = wlTest2['endpoint']['tx bytes'] wlTest2TXB = wlTest2['endpoint']['tx bytes']
wlTest2RXP = wlTest2['endpoint']['rx pkts'] wlTest2RXP = wlTest2['endpoint']['rx pkts']
except Exception as e: except Exception as e:
print("Something went wrong") print("Something went wrong")
print(e) print(e)
print("Cleaning up...") print("Cleaning up...")
reqURL = "cli-json/rm_vlan" reqURL = "cli-json/rm_vlan"
data = { data = {
"shelf":1, "shelf":1,
"resource":1, "resource":1,
"port":"sta00000" "port":"sta00000"
} }
jsonReq(mgrURL, reqURL, data) jsonReq(mgrURL, reqURL, data)
endpNames = ["testTCP-A", "testTCP-B", endpNames = ["testTCP-A", "testTCP-B",
"testUDP-A", "testUDP-B", "testUDP-A", "testUDP-B",
"l4Test", "fioTest", "l4Test", "fioTest",
"genTest1", "genTest2", "genTest1", "genTest2",
"wlTest1","wlTest2"] "wlTest1","wlTest2"]
removeCX(mgrURL, cxNames) removeCX(mgrURL, cxNames)
removeEndps(mgrURL, endpNames) removeEndps(mgrURL, endpNames)
sys.exit(1) sys.exit(1)
#start cx traffic #start cx traffic
print("\nStarting CX Traffic") print("\nStarting CX Traffic")
for name in range(len(cxNames)): for name in range(len(cxNames)):
cmd = (f"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm {cxNames[name]} RUNNING\" >> /tmp/connectTest.log") cmd = (f"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm {cxNames[name]} RUNNING\" >> /tmp/connectTest.log")
execWrap(cmd) execWrap(cmd)
#print("Sleeping for 5 seconds") #print("Sleeping for 5 seconds")
time.sleep(5) time.sleep(5)
@@ -420,63 +420,63 @@ execWrap(cmd)
#stop cx traffic #stop cx traffic
print("Stopping CX Traffic") print("Stopping CX Traffic")
for name in range(len(cxNames)): for name in range(len(cxNames)):
cmd = (f"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm {cxNames[name]} STOPPED\" >> /tmp/connectTest.log") cmd = (f"./lf_firemod.pl --mgr localhost --quiet yes --action do_cmd --cmd \"set_cx_state default_tm {cxNames[name]} STOPPED\" >> /tmp/connectTest.log")
execWrap(cmd) execWrap(cmd)
#print("Sleeping for 15 seconds") #print("Sleeping for 15 seconds")
time.sleep(15) time.sleep(15)
#get data for endpoints JSON #get data for endpoints JSON
print("Collecting Data") print("Collecting Data")
try: try:
ptestTCPA = getJsonInfo(mgrURL, "endp/testTCP-A?fields=tx+bytes,rx+bytes") ptestTCPA = getJsonInfo(mgrURL, "endp/testTCP-A?fields=tx+bytes,rx+bytes")
ptestTCPATX = ptestTCPA['endpoint']['tx bytes'] ptestTCPATX = ptestTCPA['endpoint']['tx bytes']
ptestTCPARX = ptestTCPA['endpoint']['rx bytes'] ptestTCPARX = ptestTCPA['endpoint']['rx bytes']
ptestTCPB = getJsonInfo(mgrURL, "endp/testTCP-B?fields=tx+bytes,rx+bytes") ptestTCPB = getJsonInfo(mgrURL, "endp/testTCP-B?fields=tx+bytes,rx+bytes")
ptestTCPBTX = ptestTCPB['endpoint']['tx bytes'] ptestTCPBTX = ptestTCPB['endpoint']['tx bytes']
ptestTCPBRX = ptestTCPB['endpoint']['rx bytes'] ptestTCPBRX = ptestTCPB['endpoint']['rx bytes']
ptestUDPA = getJsonInfo(mgrURL, "endp/testUDP-A?fields=tx+bytes,rx+bytes") ptestUDPA = getJsonInfo(mgrURL, "endp/testUDP-A?fields=tx+bytes,rx+bytes")
ptestUDPATX = ptestUDPA['endpoint']['tx bytes'] ptestUDPATX = ptestUDPA['endpoint']['tx bytes']
ptestUDPARX = ptestUDPA['endpoint']['rx bytes'] ptestUDPARX = ptestUDPA['endpoint']['rx bytes']
ptestUDPB = getJsonInfo(mgrURL, "endp/testUDP-B?fields=tx+bytes,rx+bytes") ptestUDPB = getJsonInfo(mgrURL, "endp/testUDP-B?fields=tx+bytes,rx+bytes")
ptestUDPBTX = ptestUDPB['endpoint']['tx bytes'] ptestUDPBTX = ptestUDPB['endpoint']['tx bytes']
ptestUDPBRX = ptestUDPB['endpoint']['rx bytes'] ptestUDPBRX = ptestUDPB['endpoint']['rx bytes']
pl4Test = getJsonInfo(mgrURL, "layer4/l4Test?fields=bytes-rd") pl4Test = getJsonInfo(mgrURL, "layer4/l4Test?fields=bytes-rd")
pl4TestBR = pl4Test['endpoint']['bytes-rd'] pl4TestBR = pl4Test['endpoint']['bytes-rd']
pgenTest1 = getJsonInfo(mgrURL, "generic/genTest1?fields=last+results") pgenTest1 = getJsonInfo(mgrURL, "generic/genTest1?fields=last+results")
pgenTest1LR = pgenTest1['endpoint']['last results'] pgenTest1LR = pgenTest1['endpoint']['last results']
pwlTest1 = getJsonInfo(mgrURL,"wl_ep/wlTest1") pwlTest1 = getJsonInfo(mgrURL,"wl_ep/wlTest1")
pwlTest1TXB = pwlTest1['endpoint']['tx bytes'] pwlTest1TXB = pwlTest1['endpoint']['tx bytes']
pwlTest1RXP = pwlTest1['endpoint']['rx pkts'] pwlTest1RXP = pwlTest1['endpoint']['rx pkts']
pwlTest2 = getJsonInfo(mgrURL,"wl_ep/wlTest2") pwlTest2 = getJsonInfo(mgrURL,"wl_ep/wlTest2")
pwlTest2TXB = pwlTest2['endpoint']['tx bytes'] pwlTest2TXB = pwlTest2['endpoint']['tx bytes']
pwlTest2RXP = pwlTest2['endpoint']['rx pkts'] pwlTest2RXP = pwlTest2['endpoint']['rx pkts']
except Exception as e: except Exception as e:
print("Something went wrong") print("Something went wrong")
print(e) print(e)
print("Cleaning up...") print("Cleaning up...")
reqURL = "cli-json/rm_vlan" reqURL = "cli-json/rm_vlan"
data = { data = {
"shelf":1, "shelf":1,
"resource":1, "resource":1,
"port":"sta00000" "port":"sta00000"
} }
jsonReq(mgrURL, reqURL, data) jsonReq(mgrURL, reqURL, data)
endpNames = ["testTCP-A", "testTCP-B", endpNames = ["testTCP-A", "testTCP-B",
"testUDP-A", "testUDP-B", "testUDP-A", "testUDP-B",
"l4Test", "fioTest", "l4Test", "fioTest",
"genTest1", "genTest2", "genTest1", "genTest2",
"wlTest1","wlTest2"] "wlTest1","wlTest2"]
removeCX(mgrURL, cxNames) removeCX(mgrURL, cxNames)
removeEndps(mgrURL, endpNames) removeEndps(mgrURL, endpNames)
sys.exit(1) sys.exit(1)
#print("Sleeping for 5 seconds") #print("Sleeping for 5 seconds")
time.sleep(5) time.sleep(5)
@@ -486,11 +486,11 @@ time.sleep(5)
#compare pre-test values to post-test values #compare pre-test values to post-test values
def compareVals(name, preVal, postVal): def compareVals(name, preVal, postVal):
print(f"Comparing {name}") print(f"Comparing {name}")
if postVal > preVal: if postVal > preVal:
print(" Test Passed") print(" Test Passed")
else: else:
print(f" Test Failed: {name} did not increase after 5 seconds") print(f" Test Failed: {name} did not increase after 5 seconds")
print("\n") print("\n")
compareVals("testTCP-A TX", testTCPATX, ptestTCPATX) compareVals("testTCP-A TX", testTCPATX, ptestTCPATX)
@@ -532,9 +532,9 @@ data = {
jsonReq(mgrURL, reqURL, data) jsonReq(mgrURL, reqURL, data)
endpNames = ["testTCP-A", "testTCP-B", endpNames = ["testTCP-A", "testTCP-B",
"testUDP-A", "testUDP-B", "testUDP-A", "testUDP-B",
"l4Test", "fioTest", "l4Test", "fioTest",
"genTest1", "genTest2", "genTest1", "genTest2",
"wlTest1","wlTest2"] "wlTest1","wlTest2"]
removeCX(mgrURL, cxNames) removeCX(mgrURL, cxNames)
removeEndps(mgrURL, endpNames) removeEndps(mgrURL, endpNames)