mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-11-03 20:27:54 +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:
		
							
								
								
									
										119
									
								
								connectTest.py
									
									
									
									
									
								
							
							
						
						
									
										119
									
								
								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,44 +45,35 @@ 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,
 | 
				
			||||||
@@ -97,9 +85,10 @@ data = {
 | 
				
			|||||||
   "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 = {
 | 
				
			||||||
@@ -109,9 +98,10 @@ data = {
 | 
				
			|||||||
   "current_flags": 2147483648, #0x80000000 | 2147483648
 | 
					   "current_flags": 2147483648, #0x80000000 | 2147483648
 | 
				
			||||||
   "interest":16386 # 0x4002 | 16386
 | 
					   "interest":16386 # 0x4002 | 16386
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					print("configuring port")
 | 
				
			||||||
jsonReq(mgrURL, reqURL, data)
 | 
					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":
 | 
				
			||||||
@@ -124,25 +114,24 @@ data = { "shelf":1,
 | 
				
			|||||||
    "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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -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