mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-02 19:58:03 +00:00
Improved cleanup function
This commit is contained in:
@@ -10,16 +10,15 @@ if 'py-json' not in sys.path:
|
|||||||
sys.path.append('../py-json')
|
sys.path.append('../py-json')
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from LANforge import LFUtils
|
|
||||||
# from LANforge import LFCliBase
|
|
||||||
from LANforge import lfcli_base
|
|
||||||
from LANforge.lfcli_base import LFCliBase
|
from LANforge.lfcli_base import LFCliBase
|
||||||
from LANforge.LFUtils import *
|
from LANforge.LFUtils import *
|
||||||
import realm
|
import realm
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
class IPv4Test(LFCliBase):
|
class IPv4Test(LFCliBase):
|
||||||
def __init__(self, host, port, ssid, security, password, num_stations, _debug_on=False, _exit_on_error=False,
|
def __init__(self, host, port, ssid, security, password, num_stations, prefix="00000", _debug_on=False,
|
||||||
|
_exit_on_error=False,
|
||||||
_exit_on_fail=False):
|
_exit_on_fail=False):
|
||||||
super().__init__(host, port, _debug=_debug_on, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
|
super().__init__(host, port, _debug=_debug_on, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
|
||||||
self.host = host
|
self.host = host
|
||||||
@@ -29,19 +28,31 @@ class IPv4Test(LFCliBase):
|
|||||||
self.password = password
|
self.password = password
|
||||||
self.num_stations = num_stations
|
self.num_stations = num_stations
|
||||||
self.timeout = 120
|
self.timeout = 120
|
||||||
|
self.prefix = prefix
|
||||||
|
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
|
||||||
|
self.profile = realm.StationProfile(self.lfclient_url, ssid=self.ssid, ssid_pass=self.password,
|
||||||
|
security=self.security, prefix=self.prefix, mode=0, up=True, dhcp=True,
|
||||||
|
debug_=False)
|
||||||
|
|
||||||
def run_test(self, sta_list, print_pass=False, print_fail=False):
|
def run_test(self, sta_list, print_pass=False, print_fail=False):
|
||||||
for sta_name in sta_list:
|
for sta_name in sta_list:
|
||||||
sta_status = super().json_get("port/1/1/" + sta_name)
|
sta_status = super().json_get("port/1/1/" + sta_name)
|
||||||
if len(sta_status['interface']['ap']) != 18 and sta_status['interface']['ap'][-3] != ':':
|
if sta_status['interface']['ap'] == '' or len(sta_status['interface']['ap']) != 18 and \
|
||||||
|
sta_status['interface']['ap'][-3] != ':':
|
||||||
self._fail("%s failed to associate" % sta_name, print_fail)
|
self._fail("%s failed to associate" % sta_name, print_fail)
|
||||||
elif sta_status['interface']['ip'] == "0.0.0.0":
|
elif sta_status['interface']['ip'] == "0.0.0.0":
|
||||||
self._fail("%s failed to get ip" % sta_name, print_fail)
|
self._fail("%s failed to get ip" % sta_name, print_fail)
|
||||||
else:
|
else:
|
||||||
self._pass("%s associated with ip" % sta_name, print_pass)
|
self._pass("%s associated with ip" % sta_name, print_pass)
|
||||||
|
|
||||||
def cleanup(self, sta_list):
|
def cleanup(self):
|
||||||
print("Cleaning up %s " % sta_list)
|
port_list = self.local_realm.station_list()
|
||||||
|
sta_list = []
|
||||||
|
for item in list(port_list):
|
||||||
|
# print(list(item))
|
||||||
|
if "sta" in list(item)[0]:
|
||||||
|
sta_list.append(self.local_realm.name_to_eid(list(item)[0])[2])
|
||||||
|
|
||||||
for sta_name in sta_list:
|
for sta_name in sta_list:
|
||||||
req_url = "cli-json/rm_vlan"
|
req_url = "cli-json/rm_vlan"
|
||||||
data = {
|
data = {
|
||||||
@@ -54,23 +65,21 @@ class IPv4Test(LFCliBase):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
super().clear_test_results()
|
super().clear_test_results()
|
||||||
local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
|
print("Cleaning up old stations")
|
||||||
profile = realm.StationProfile(self.lfclient_url, ssid=self.ssid, ssid_pass=self.password,
|
self.cleanup()
|
||||||
security=self.security, prefix="00000", mode=0, up=True, dhcp=True,
|
|
||||||
debug_=False)
|
|
||||||
profile.use_wpa2(True, self.ssid, self.password)
|
|
||||||
profile.set_prefix("000")
|
|
||||||
profile.create(resource = 1, radio = "wiphy0", num_stations = self.num_stations)
|
|
||||||
port_list = local_realm.station_list()
|
|
||||||
sta_list = []
|
sta_list = []
|
||||||
for item in list(port_list):
|
|
||||||
if "sta" in item:
|
|
||||||
sta_list.append(local_realm.name_to_eid(item)[2])
|
|
||||||
|
|
||||||
for sec in range(self.timeout):
|
self.profile.use_wpa2(True, self.ssid, self.password)
|
||||||
self.run_test(sta_list, True, True)
|
self.profile.set_prefix(self.prefix)
|
||||||
time.sleep(1)
|
self.profile.create(resource=1, radio="wiphy0", num_stations=self.num_stations)
|
||||||
self.cleanup(sta_list)
|
for sta_name in list(self.local_realm.find_ports_like("sta[%s..%s]" % (self.prefix[:-1], str(self.prefix[:-2]) + str(self.num_stations - 1)))):
|
||||||
|
sta_list.append(self.local_realm.name_to_eid(sta_name)[2])
|
||||||
|
print(sta_list)
|
||||||
|
time.sleep(self.timeout)
|
||||||
|
self.run_test(sta_list, True, True)
|
||||||
|
print("Cleaning up")
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
lfjson_host = "localhost"
|
lfjson_host = "localhost"
|
||||||
@@ -80,5 +89,6 @@ def main():
|
|||||||
ip_test.timeout = 120
|
ip_test.timeout = 120
|
||||||
ip_test.run()
|
ip_test.run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user