mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 19:28:00 +00:00
connectTest.py: several changes:
- whitespace, prefer indenting dicts - moved subroutines out to LFUtils - renamed a few variables - fixes inspecting possibly null return values
This commit is contained in:
263
connectTest.py
263
connectTest.py
@@ -11,36 +11,33 @@ import json
|
|||||||
import pprint
|
import pprint
|
||||||
from LANforge import LFRequest
|
from LANforge import LFRequest
|
||||||
from LANforge import LFUtils
|
from LANforge import LFUtils
|
||||||
|
from LANforge.LFUtils import *
|
||||||
|
|
||||||
import create_genlink as genl
|
import create_genlink as genl
|
||||||
|
|
||||||
debugOn = True
|
debugOn = True
|
||||||
|
|
||||||
if sys.version_info[0] != 3:
|
if sys.version_info[0] != 3:
|
||||||
print("This script requires Python 3")
|
print("This script requires Python 3")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
mgrURL = "http://localhost:8080/"
|
mgrURL = "http://localhost:8080/"
|
||||||
|
|
||||||
def execWrap(cmd):
|
def jsonReq(mgrURL, reqURL, data, exitWhenCalled=False):
|
||||||
if os.system(cmd) != 0:
|
|
||||||
print("\nError with " + cmd + ",bye\n")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
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 exitWhenCalled:
|
||||||
json_response = lf_r.jsonPost(debug)
|
json_response = lf_r.jsonPost(True)
|
||||||
LFUtils.debug_printer.pprint(json_response)
|
print("jsonReq: debugdie Response: ")
|
||||||
|
LFUtils.debug_printer.pprint(vars(json_response))
|
||||||
|
print("jsonReq: bye")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
lf_r.jsonPost(debug)
|
lf_r.jsonPost(exitWhenCalled)
|
||||||
|
|
||||||
def getJsonInfo(mgrURL, reqURL):
|
def getJsonInfo(mgrURL, reqURL, debug=False):
|
||||||
lf_r = LFRequest.LFRequest(mgrURL + reqURL)
|
lf_r = LFRequest.LFRequest(mgrURL + reqURL)
|
||||||
json_response = lf_r.getAsJson(debugOn)
|
json_response = lf_r.getAsJson(debug)
|
||||||
return json_response
|
return json_response
|
||||||
#print(name)
|
#print(name)
|
||||||
#j_printer = pprint.PrettyPrinter(indent=2)
|
#j_printer = pprint.PrettyPrinter(indent=2)
|
||||||
@@ -48,70 +45,63 @@ def getJsonInfo(mgrURL, reqURL):
|
|||||||
#for record in json_response[key]:
|
#for record in json_response[key]:
|
||||||
# j_printer.pprint(record)
|
# j_printer.pprint(record)
|
||||||
|
|
||||||
def removeEndps(mgrURL, endpNames):
|
|
||||||
for name in endpNames:
|
|
||||||
#print(f"Removing endp {name}")
|
|
||||||
data = {
|
|
||||||
"endp_name":name
|
|
||||||
}
|
|
||||||
jsonReq(mgrURL, "cli-json/rm_endp", data)
|
|
||||||
|
|
||||||
def removeCX(mgrURL, cxNames):
|
|
||||||
for name in cxNames:
|
|
||||||
#print(f"Removing CX {name}")
|
|
||||||
data = {
|
|
||||||
"test_mgr":"all",
|
|
||||||
"cx_name":name
|
|
||||||
}
|
|
||||||
jsonReq(mgrURL,"cli-json/rm_cx", data)
|
|
||||||
|
|
||||||
print("Checking for LANforge Client")
|
print("Checking for LANforge Client")
|
||||||
response = getJsonInfo(mgrURL, 'port/1/1/wiphy0')
|
response = getJsonInfo(mgrURL, 'port/1/1/wiphy0')
|
||||||
timeout = 0
|
duration = 0
|
||||||
while response == None and timeout != 300:
|
while ((response == None) and (duration < 300)):
|
||||||
print("LANforge Client not found sleeping 5 seconds")
|
print("LANforge Client not found sleeping 5 seconds")
|
||||||
timeout += 5
|
duration += 2
|
||||||
time.sleep(5)
|
time.sleep(2)
|
||||||
response = getJsonInfo(mgrURL, 'port/1/1/wiphy0')
|
response = getJsonInfo(mgrURL, 'port/1/1/wiphy0')
|
||||||
#print(response)
|
|
||||||
if timeout == 300:
|
if duration >= 300:
|
||||||
print("Could not connect to LANforge Client")
|
print("Could not connect to LANforge Client")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print("See home/lanforge/Documents/connectTestLogs/connectTestLatest for specific values on latest test")
|
print("See home/lanforge/Documents/connectTestLogs/connectTestLatest for specific values on latest test")
|
||||||
#Create stations and turn dhcp on
|
#Create stations and turn dhcp on
|
||||||
print("Creating station and turning on dhcp")
|
print("Creating station and turning on dhcp")
|
||||||
url = "cli-json/add_sta"
|
|
||||||
|
|
||||||
|
url = "port/1/1/sta00000"
|
||||||
|
debugOn = True
|
||||||
|
response = getJsonInfo(mgrURL, url)
|
||||||
|
if (response is not None):
|
||||||
|
if (response["interface"] is not None):
|
||||||
|
print("removing old station")
|
||||||
|
LFUtils.removePortByName("1.1.sta00000", mgrURL)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
url = "cli-json/add_sta"
|
||||||
data = {
|
data = {
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"radio":"wiphy0",
|
"radio":"wiphy0",
|
||||||
"sta_name":"sta00000",
|
"sta_name":"sta00000",
|
||||||
"ssid":"jedway-wpa2-x2048-5-1",
|
"ssid":"jedway-wpa2-x2048-5-1",
|
||||||
"key":"jedway-wpa2-x2048-5-1",
|
"key":"jedway-wpa2-x2048-5-1",
|
||||||
"mode":1,
|
"mode":1,
|
||||||
"mac":"xx:xx:xx:xx:*:xx",
|
"mac":"xx:xx:xx:xx:*:xx",
|
||||||
"flags":1024 #0x400 | 1024
|
"flags":1024 #0x400 | 1024
|
||||||
}
|
}
|
||||||
|
print("adding new station")
|
||||||
jsonReq(mgrURL, url, data)
|
jsonReq(mgrURL, url, data)
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
|
|
||||||
reqURL = "cli-json/set_port"
|
reqURL = "cli-json/set_port"
|
||||||
data = {
|
data = {
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"sta00000",
|
"port":"sta00000",
|
||||||
"current_flags": 2147483648, #0x80000000 | 2147483648
|
"current_flags": 2147483648, #0x80000000 | 2147483648
|
||||||
"interest":16386 # 0x4002 | 16386
|
"interest":16386 # 0x4002 | 16386
|
||||||
}
|
}
|
||||||
jsonReq(mgrURL,reqURL,data)
|
print("configuring port")
|
||||||
|
jsonReq(mgrURL, reqURL, data)
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
|
|
||||||
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":
|
||||||
@@ -122,27 +112,26 @@ 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")
|
station_info = getJsonInfo(mgrURL, "port/1/1/sta00000?fields=port,ip")
|
||||||
timeout = 0
|
duration = 0
|
||||||
maxTime = 300
|
maxTime = 300
|
||||||
while staIP['interface']['ip'] == "0.0.0.0" and timeout != maxTime:
|
ip = "0.0.0.0"
|
||||||
|
while ((ip == "0.0.0.0") and (duration < 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")
|
station_info = getJsonInfo(mgrURL, "port/1/1/sta00000?fields=port,ip")
|
||||||
timeout += 10
|
|
||||||
time.sleep(10)
|
LFUtils.debug_printer.pprint(station_info)
|
||||||
if timeout == maxTime:
|
if ((station_info is not None) and ("interface" in station_info) and ("ip" in station_info["interface"])):
|
||||||
|
ip = station_info["interface"]["ip"]
|
||||||
|
duration += 2
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
if duration >= 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"
|
removePortByName("1.sta00000", mgrURL)
|
||||||
data = {
|
|
||||||
"shelf":1,
|
|
||||||
"resource":1,
|
|
||||||
"port":"sta00000"
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonReq(mgrURL, reqURL, data)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -160,14 +149,14 @@ time.sleep(.5)
|
|||||||
#create l4 endpoint
|
#create l4 endpoint
|
||||||
url = "cli-json/add_l4_endp"
|
url = "cli-json/add_l4_endp"
|
||||||
data = {
|
data = {
|
||||||
"alias":"l4Test",
|
"alias":"l4Test",
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"sta00000",
|
"port":"sta00000",
|
||||||
"type":"l4_generic",
|
"type":"l4_generic",
|
||||||
"timeout":1000,
|
"timeout":1000,
|
||||||
"url_rate":600,
|
"url_rate":600,
|
||||||
"url":"dl http://10.40.0.1/ /dev/null"
|
"url":"dl http://10.40.0.1/ /dev/null"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL, url, data)
|
jsonReq(mgrURL, url, data)
|
||||||
@@ -176,10 +165,10 @@ time.sleep(.5)
|
|||||||
#create cx for l4_endp
|
#create cx for l4_endp
|
||||||
url = "cli-json/add_cx"
|
url = "cli-json/add_cx"
|
||||||
data = {
|
data = {
|
||||||
"alias":"CX_l4Test",
|
"alias":"CX_l4Test",
|
||||||
"test_mgr":"default_tm",
|
"test_mgr":"default_tm",
|
||||||
"tx_endp":"l4Test",
|
"tx_endp":"l4Test",
|
||||||
"rx_endp":"NA"
|
"rx_endp":"NA"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL, url, data)
|
jsonReq(mgrURL, url, data)
|
||||||
@@ -188,12 +177,12 @@ time.sleep(.5)
|
|||||||
#create fileio endpoint
|
#create fileio endpoint
|
||||||
url = "cli-json/add_file_endp"
|
url = "cli-json/add_file_endp"
|
||||||
data = {
|
data = {
|
||||||
"alias":"fioTest",
|
"alias":"fioTest",
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"sta00000",
|
"port":"sta00000",
|
||||||
"type":"fe_nfs",
|
"type":"fe_nfs",
|
||||||
"directory":"/mnt/fe-test"
|
"directory":"/mnt/fe-test"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -202,10 +191,10 @@ time.sleep(.5)
|
|||||||
#create fileio cx
|
#create fileio cx
|
||||||
url = "cli-json/add_cx"
|
url = "cli-json/add_cx"
|
||||||
data = {
|
data = {
|
||||||
"alias":"CX_fioTest",
|
"alias":"CX_fioTest",
|
||||||
"test_mgr":"default_tm",
|
"test_mgr":"default_tm",
|
||||||
"tx_endp":"fioTest",
|
"tx_endp":"fioTest",
|
||||||
"rx_endp":"NA"
|
"rx_endp":"NA"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -223,10 +212,10 @@ time.sleep(.5)
|
|||||||
#create generic cx
|
#create generic cx
|
||||||
url = "cli-json/add_cx"
|
url = "cli-json/add_cx"
|
||||||
data = {
|
data = {
|
||||||
"alias":"CX_genTest1",
|
"alias":"CX_genTest1",
|
||||||
"test_mgr":"default_tm",
|
"test_mgr":"default_tm",
|
||||||
"tx_endp":"genTest1",
|
"tx_endp":"genTest1",
|
||||||
"rx_endp":"genTest2"
|
"rx_endp":"genTest2"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -235,20 +224,20 @@ time.sleep(.5)
|
|||||||
#create redirects for wanlink
|
#create redirects for wanlink
|
||||||
url = "cli-json/add_rdd"
|
url = "cli-json/add_rdd"
|
||||||
data = {
|
data = {
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"rdd0",
|
"port":"rdd0",
|
||||||
"peer_ifname":"rdd1"
|
"peer_ifname":"rdd1"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
|
|
||||||
url = "cli-json/add_rdd"
|
url = "cli-json/add_rdd"
|
||||||
data = {
|
data = {
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"rdd1",
|
"port":"rdd1",
|
||||||
"peer_ifname":"rdd0"
|
"peer_ifname":"rdd0"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -257,18 +246,18 @@ time.sleep(.5)
|
|||||||
#reset redirect ports
|
#reset redirect ports
|
||||||
url = "cli-json/reset_port"
|
url = "cli-json/reset_port"
|
||||||
data = {
|
data = {
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"rdd0"
|
"port":"rdd0"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
|
|
||||||
url = "cli-json/reset_port"
|
url = "cli-json/reset_port"
|
||||||
data = {
|
data = {
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"rdd1"
|
"port":"rdd1"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -278,24 +267,24 @@ time.sleep(.5)
|
|||||||
#create wanlink endpoints
|
#create wanlink endpoints
|
||||||
url = "cli-json/add_wl_endp"
|
url = "cli-json/add_wl_endp"
|
||||||
data = {
|
data = {
|
||||||
"alias":"wlTest1",
|
"alias":"wlTest1",
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"rdd0",
|
"port":"rdd0",
|
||||||
"latency":20,
|
"latency":20,
|
||||||
"max_rate":1544000
|
"max_rate":1544000
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
|
|
||||||
url = "cli-json/add_wl_endp"
|
url = "cli-json/add_wl_endp"
|
||||||
data = {
|
data = {
|
||||||
"alias":"wlTest2",
|
"alias":"wlTest2",
|
||||||
"shelf":1,
|
"shelf":1,
|
||||||
"resource":1,
|
"resource":1,
|
||||||
"port":"rdd1",
|
"port":"rdd1",
|
||||||
"latency":30,
|
"latency":30,
|
||||||
"max_rate":1544000
|
"max_rate":1544000
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -304,10 +293,10 @@ time.sleep(.5)
|
|||||||
#create wanlink cx
|
#create wanlink cx
|
||||||
url = "cli-json/add_cx"
|
url = "cli-json/add_cx"
|
||||||
data = {
|
data = {
|
||||||
"alias":"CX_wlTest1",
|
"alias":"CX_wlTest1",
|
||||||
"test_mgr":"default_tm",
|
"test_mgr":"default_tm",
|
||||||
"tx_endp":"wlTest1",
|
"tx_endp":"wlTest1",
|
||||||
"rx_endp":"wlTest2"
|
"rx_endp":"wlTest2"
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonReq(mgrURL,url,data)
|
jsonReq(mgrURL,url,data)
|
||||||
@@ -349,14 +338,7 @@ 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"
|
LFUtils.removePortByName("1.sta00000", mgrURL)
|
||||||
data = {
|
|
||||||
"shelf":1,
|
|
||||||
"resource":1,
|
|
||||||
"port":"sta00000"
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonReq(mgrURL, reqURL, data)
|
|
||||||
|
|
||||||
endpNames = ["testTCP-A", "testTCP-B",
|
endpNames = ["testTCP-A", "testTCP-B",
|
||||||
"testUDP-A", "testUDP-B",
|
"testUDP-A", "testUDP-B",
|
||||||
@@ -522,14 +504,7 @@ print("\n")
|
|||||||
#remove all endpoints and cxs
|
#remove all endpoints and cxs
|
||||||
print("Cleaning up...")
|
print("Cleaning up...")
|
||||||
|
|
||||||
reqURL = "cli-json/rm_vlan"
|
LFUtils.removePortByName("1.sta00000", mgrURL)
|
||||||
data = {
|
|
||||||
"shelf":1,
|
|
||||||
"resource":1,
|
|
||||||
"port":"sta00000"
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonReq(mgrURL, reqURL, data)
|
|
||||||
|
|
||||||
endpNames = ["testTCP-A", "testTCP-B",
|
endpNames = ["testTCP-A", "testTCP-B",
|
||||||
"testUDP-A", "testUDP-B",
|
"testUDP-A", "testUDP-B",
|
||||||
|
|||||||
Reference in New Issue
Block a user