json: Work on pre-cleanup logic.

Still doesn't work, but checking in what I have for now.
This commit is contained in:
Ben Greear
2020-08-06 08:27:58 -07:00
parent dc5d84b790
commit c17837dc64
3 changed files with 123 additions and 80 deletions

View File

@@ -187,7 +187,7 @@ def generateMac(parent_mac, random_octet, debug=False):
return ":".join(octets)
def portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000):
def portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000, radio=None):
"""
This produces a named series similar to "sta000, sta001, sta002...sta0(end_id)"
the padding_number is added to the start and end numbers and the resulting sum
@@ -199,10 +199,10 @@ def portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000)
:param padding_number_:
:return:
"""
return port_name_series(prefix=prefix_, start_id=start_id_, end_id=end_id_, padding_number=padding_number_)
return port_name_series(prefix=prefix_, start_id=start_id_, end_id=end_id_, padding_number=padding_number_, radio=radio)
def port_name_series(prefix="sta", start_id=0, end_id=1, padding_number=10000):
def port_name_series(prefix="sta", start_id=0, end_id=1, padding_number=10000, radio=None):
"""
This produces a named series similar to "sta000, sta001, sta002...sta0(end_id)"
the padding_number is added to the start and end numbers and the resulting sum
@@ -214,10 +214,18 @@ def port_name_series(prefix="sta", start_id=0, end_id=1, padding_number=10000):
:param padding_number_: used for width of resulting station number
:return: list of stations
"""
eid = None
if radio != None:
eid = name_to_eid(radio)
name_list = []
for i in range((padding_number + start_id), (padding_number + end_id + 1)):
sta_name = prefix + str(i)[1:]
name_list.append(sta_name)
if eid != None:
name_list.append("%i.%i.%s"%(eid[0], eid[1], sta_name))
else:
name_list.append(sta_name)
return name_list
@@ -338,18 +346,24 @@ def wait_until_ports_admin_up(resource_id=1, base_url="http://localhost:8080", p
sleep(1)
return None
def waitUntilPortsDisappear(resource_id=1, base_url="http://localhost:8080", port_list=[], debug=False):
wait_until_ports_disappear(resource_id, base_url, port_list, debug)
def waitUntilPortsDisappear(base_url="http://localhost:8080", port_list=[], debug=False):
wait_until_ports_disappear(base_url, port_list, debug)
def wait_until_ports_disappear(resource_id=1, base_url="http://localhost:8080", port_list=[], debug=False):
def wait_until_ports_disappear(base_url="http://localhost:8080", port_list=[], debug=False):
print("Waiting until ports disappear...")
url = "/port/1"
found_stations = port_list.copy()
sleep(1)
while len(found_stations) > 0:
found_stations = []
sleep(1)
for port_name in port_list:
for port_eid in port_list:
eid = name_to_eid(port_eid)
shelf = eid[0]
resource_id = eid[1]
port_name = eid[2]
check_url = "%s/%s/%s" % (url, resource_id, port_name)
if debug:
print("checking:" + check_url)
@@ -363,7 +377,6 @@ def wait_until_ports_disappear(resource_id=1, base_url="http://localhost:8080",
def waitUntilPortsAppear(base_url="http://localhost:8080", port_list=(), debug=False):
"""
Deprecated
:param resource_id:
:param base_url:
:param port_list:
:param debug:

View File

@@ -118,15 +118,40 @@ class Realm(LFCliBase):
self.freq_to_chan[4970] = 194
self.freq_to_chan[4980] = 196
def wait_until_ports_appear(self, resource_=1, sta_list=None, debug_=False):
def wait_until_ports_appear(self, sta_list=None, debug_=False):
if (sta_list is None) or (len(sta_list) < 1):
print("realm.wait_until_ports_appear: no stations provided")
return
LFUtils.wait_until_ports_appear(resource_id=resource_,
base_url=self.lfclient_url,
LFUtils.wait_until_ports_appear(base_url=self.lfclient_url,
port_list=sta_list,
debug=debug_)
def rm_port(self, port_eid, check_exists=True):
req_url = "/cli-json/rm_vlan"
data = {}
eid = self.name_to_eid(port_eid)
do_rm = True;
if check_exists:
if not self.port_exists(port_eid):
do_rm = False
if do_rm:
data["shelf"] = eid[0]
data["resource"] = eid[1]
data["port"] = eid[2]
self.json_post(req_url, data, debug_=True) #self.debug)
def port_exists(self, port_eid):
data = {}
eid = self.name_to_eid(port_eid)
data["shelf"] = eid[0]
data["resource"] = eid[1]
data["port"] = eid[2]
current_stations = self.json_get("/port/%s/%s/%s?fields=alias" % (eid[0], eid[1], eid[2]))
if not current_stations is None:
return True
return False
def admin_up(self, port_eid):
eid = self.name_to_eid(port_eid)
shelf = eid[0]
@@ -1844,33 +1869,17 @@ class StationProfile:
return result
def admin_up(self, resource):
set_port_r = LFRequest.LFRequest(self.lfclient_url, "/cli-json/set_port", debug_=self.debug)
req_json = LFUtils.portUpRequest(resource, None, debug_on=False)
def admin_up(self):
for sta_name in self.station_names:
req_json["port"] = self.local_realm.name_to_eid(sta_name)[-1]
set_port_r.addPostData(req_json)
json_response = set_port_r.jsonPost(self.debug)
time.sleep(0.03)
self.local_realm.admin_up(sta_name)
def admin_down(self, resource):
set_port_r = LFRequest.LFRequest(self.lfclient_url, "/cli-json/set_port", debug_=self.debug)
req_json = LFUtils.portDownRequest(resource, None, debug_on=False)
def admin_down(self):
for sta_name in self.station_names:
req_json["port"] = self.local_realm.name_to_eid(sta_name)[-1]
set_port_r.addPostData(req_json)
json_response = set_port_r.jsonPost(self.debug)
time.sleep(0.03)
self.local_realm.admin_down(sta_name)
def cleanup(self, desired_stations=None, delay=0.03):
print("Cleaning up stations")
req_url = "/cli-json/rm_vlan"
data = {
"shelf": 1,
"resource": 1,
"port": None
}
if (desired_stations is None):
desired_stations = self.station_names;
@@ -1882,18 +1891,7 @@ class StationProfile:
# First, request remove on the list.
for port_eid in desired_stations:
eid = self.local_realm.name_to_eid(port_eid)
data["shelf"] = eid[0]
data["resource"] = eid[1]
data["port"] = eid[2]
current_stations = self.local_realm.json_get("/port/%s/%s/%s?fields=alias" % (eid[0], eid[1], eid[2]))
if not current_stations is None:
eid = self.local_realm.name_to_eid(port_eid)
data["shelf"] = eid[0]
data["resource"] = eid[1]
data["port"] = eid[2]
self.local_realm.json_post(req_url, data, debug_=True) #self.debug)
time.sleep(delay)
self.local_relm.rm_port(port_eid, check_exists=True)
# And now see if they are gone
count = 0
@@ -1907,12 +1905,7 @@ class StationProfile:
current_stations = self.local_realm.json_get("/port/%s/%s/%s?fields=alias" % (eid[0], eid[1], eid[2]))
if not current_stations is None:
found_one = True
# Try again to delete
data["shelf"] = eid[0]
data["resource"] = eid[1]
data["port"] = eid[2]
self.local_realm.json_post(req_url, data, debug_=True) #self.debug)
time.sleep(delay)
self.local_relm.rm_port(port_eid, check_exists=False)
if not found_one:
return
count = count + 1
@@ -1972,8 +1965,9 @@ class StationProfile:
num = 0
#pprint(self.station_names)
#exit(1)
for name in my_sta_names:
self.set_port_data["port"] = name
for eidn in my_sta_names:
eid = self.local_realm.name_to_eid(eidn)
name = eid[2]
num += 1
self.add_sta_data["shelf"] = radio_shelf
self.add_sta_data["resource"] = radio_resource

View File

@@ -19,7 +19,7 @@ import datetime
class IPV4VariableTime(LFCliBase):
def __init__(self, host, port, ssid, security, password, sta_list, name_prefix, resource=1, radio="wiphy0",
def __init__(self, host, port, ssid, security, password, sta_list, name_prefix, upstream="eth1", radio="wiphy0",
side_a_min_rate=56, side_a_max_rate=0,
side_b_min_rate=56, side_b_max_rate=0,
number_template="00000", test_duration="5m", use_ht160=False,
@@ -27,6 +27,7 @@ class IPV4VariableTime(LFCliBase):
_exit_on_error=False,
_exit_on_fail=False):
super().__init__(host, port, _debug=_debug_on, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
self.upstream = upstream
self.host = host
self.port = port
self.ssid = ssid
@@ -36,7 +37,6 @@ class IPV4VariableTime(LFCliBase):
self.radio = radio
self.number_template = number_template
self.debug = _debug_on
self.resource = resource
self.name_prefix = name_prefix
self.test_duration = test_duration
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
@@ -93,8 +93,8 @@ class IPV4VariableTime(LFCliBase):
return False
def start(self, print_pass=False, print_fail=False):
self.station_profile.admin_up(self.resource)
temp_stas = self.sta_list.copy()
self.station_profile.admin_up()
temp_stas = self.station_profile.station_names.copy()
temp_stas.append("eth1")
if self.local_realm.wait_for_ip(temp_stas):
self._pass("All stations got IPs", print_pass)
@@ -132,46 +132,82 @@ class IPV4VariableTime(LFCliBase):
def stop(self):
self.cx_profile.stop_cx()
for sta_name in self.sta_list:
data = LFUtils.portDownRequest(1, sta_name)
url = "cli-json/set_port"
self.json_post(url, data)
self.station_profile.admin_down()
def cleanup(self, sta_list):
def pre_cleanup(self):
for sta in self.sta_list:
self.local_realm.rm_port(sta, check_exists=True)
def cleanup(self):
self.cx_profile.cleanup()
self.station_profile.cleanup(sta_list)
LFUtils.wait_until_ports_disappear(resource_id=self.resource, base_url=self.lfclient_url, port_list=sta_list,
self.station_profile.cleanup()
LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=self.station_profile.station_names,
debug=self.debug)
def build(self):
self.station_profile.use_security(self.security, self.ssid, self.password)
self.station_profile.set_number_template(self.number_template)
print("Creating stations")
self.station_profile.set_command_flag("add_sta", "create_admin_down", 1)
self.station_profile.set_command_param("set_port", "report_timer", 1500)
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
temp_sta_list = []
for station in range(len(self.sta_list)):
temp_sta_list.append(str(self.resource) + "." + self.sta_list[station])
self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug)
self.cx_profile.create(endp_type="lf_udp", side_a=temp_sta_list, side_b="1.eth1", sleep_time=.5)
self.cx_profile.create(endp_type="lf_udp", side_a=self.station_profile.station_names, side_b=self.upstream, sleep_time=0)
self._pass("PASS: Station build finished")
def main():
lfjson_host = "localhost"
lfjson_port = 8080
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000)
ip_var_test = IPV4VariableTime(lfjson_host, lfjson_port, number_template="00", sta_list=station_list,
name_prefix="var_time",
ssid="jedway-wpa2-160",
password="jedway-wpa2-160",
resource=1,
radio="wiphy2",
security="wpa2", test_duration="5m", use_ht160=False,
side_a_min_rate=256000, side_b_min_rate=256000, _debug_on=True)
ip_var_test.cleanup(station_list)
parser = argparse.ArgumentParser(
prog='test_ipv4_variable_time.py',
#formatter_class=argparse.RawDescriptionHelpFormatter,
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
Useful Information:
1. TBD
''',
description='''\
test_ipv4_variable_time.py:
--------------------
TBD
Generic command layout:
python ./test_ipv4_variable_time.py --upstream_port <port> --radio <radio 0> <stations> <ssid> <ssid password> <security type: wpa2, open, wpa3> --debug
Note: multiple --radio switches may be entered up to the number of radios available:
--radio <radio 0> <stations> <ssid> <ssid password> --radio <radio 01> <number of last station> <ssid> <ssid password>
python3 ./test_ipv4_variable_time.py --upstream_port eth1 --radio wiphy0 32 candelaTech-wpa2-x2048-4-1 candelaTech-wpa2-x2048-4-1 wpa2 --radio wiphy1 64 candelaTech-wpa2-x2048-5-3 candelaTech-wpa2-x2048-5-3 wpa2
''')
parser.add_argument('--mgr', help='--mgr <hostname for where LANforge GUI is running>',default='localhost')
parser.add_argument('--upstream', help='--upstream <1.eth1, etc>',default='1.eth1')
parser.add_argument('--radio', help='--radio <radio EID>',default='wiphy2')
parser.add_argument('--ssid', help='--ssid <SSID>',default='jedway-wpa2-160')
parser.add_argument('--passwd', help='--passwd <Password>',default='jedway-wpa2-160')
parser.add_argument('--security', help='--security <wpa2 | open | wpa3>',default='wpa2')
parser.add_argument('--debug', help='--debug: Enable debugging',default=False)
parser.add_argument('-u', '--upstream_port', help='--upstream_port <cross connect upstream_port> example: --upstream_port eth1',default='eth1')
args = parser.parse_args()
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000, radio=args.radio)
ip_var_test = IPV4VariableTime(args.mgr, lfjson_port, number_template="00", sta_list=station_list,
name_prefix="VT",
upstream=args.upstream,
ssid=args.ssid,
password=args.passwd,
radio=args.radio,
security=args.security, test_duration="5m", use_ht160=False,
side_a_min_rate=256000, side_b_min_rate=256000, _debug_on=args.debug)
ip_var_test.pre_cleanup()
ip_var_test.build()
if not ip_var_test.passes():
print(ip_var_test.get_fail_message())
@@ -182,7 +218,7 @@ def main():
print(ip_var_test.get_fail_message())
exit(1)
time.sleep(30)
ip_var_test.cleanup(station_list)
ip_var_test.cleanup()
if ip_var_test.passes():
print("Full test passed, all connections increased rx bytes")