mirror of
https://github.com/Telecominfraproject/wlan-testing.git
synced 2025-11-01 11:28:09 +00:00
ssid, bssic, band collection mapping logic improved
Signed-off-by: shivamcandela <shivam.thakur@candelatech.com>
This commit is contained in:
@@ -433,7 +433,8 @@ class APNOS:
|
||||
|
||||
def get_iwinfo(self):
|
||||
try:
|
||||
|
||||
# [['ssid_wpa2_2g', 'wpa', 'something', '2G'], ['ssid_wpa2_2g', 'wpa', 'something', '5G']]
|
||||
# {'wlan0': ['"ssid_wpa3_p_5g"', '12:34:56:78:90:12', '5G'], 'wlan1': ['"ssid_wpa3_p_2g"','00:03:7F:12:34:56', '5G']}
|
||||
client = self.ssh_cli_connect()
|
||||
cmd = "iwinfo"
|
||||
if self.mode:
|
||||
@@ -449,7 +450,7 @@ class APNOS:
|
||||
band = "2G"
|
||||
else:
|
||||
band = "5G"
|
||||
iwinfo_bssid_data[o[i - 1]] = [o[i + 4], band]
|
||||
iwinfo_bssid_data[o[i - 1]] = [o[i+1].replace('"', ''), o[i + 4], band]
|
||||
client.close()
|
||||
except Exception as e:
|
||||
iwinfo_bssid_data = False
|
||||
@@ -536,5 +537,5 @@ if __name__ == '__main__':
|
||||
'version': "https://tip.jfrog.io/artifactory/tip-wlan-ap-firmware/uCentral/edgecore_eap102/20210625-edgecore_eap102-uCentral-trunk-4225122-upgrade.bin"
|
||||
}
|
||||
var = APNOS(credentials=obj, sdk="2.x")
|
||||
x = var.get_ap_version_ucentral()
|
||||
print(x.split("\n")[1])
|
||||
x = var.get_iwinfo()
|
||||
print(x)
|
||||
|
||||
@@ -96,7 +96,6 @@ class ConfigureController:
|
||||
gw_host = urlparse(services["endpoints"][0]["uri"])
|
||||
return gw_host
|
||||
|
||||
|
||||
def logout(self):
|
||||
uri = self.build_uri_sec('oauth2/%s' % self.access_token)
|
||||
resp = requests.delete(uri, headers=self.make_headers(), verify=False, timeout=100)
|
||||
@@ -160,7 +159,7 @@ class UProfileUtility:
|
||||
|
||||
def __init__(self, sdk_client=None, controller_data=None):
|
||||
if sdk_client is None:
|
||||
self.sdk_client = UController(controller_data=controller_data)
|
||||
self.sdk_client = Controller(controller_data=controller_data)
|
||||
self.sdk_client = sdk_client
|
||||
self.base_profile_config = {
|
||||
"uuid": 1,
|
||||
@@ -168,7 +167,7 @@ class UProfileUtility:
|
||||
"interfaces": [{
|
||||
"name": "WAN",
|
||||
"role": "upstream",
|
||||
"services": ["lldp", "dhcp-snooping"],
|
||||
"services": ["ssh", "lldp", "dhcp-snooping"],
|
||||
"ethernet": [
|
||||
{
|
||||
"select-ports": [
|
||||
@@ -254,6 +253,42 @@ class UProfileUtility:
|
||||
}
|
||||
self.mode = None
|
||||
|
||||
def encryption_lookup(self, encryption="psk"):
|
||||
encryption_mapping = {
|
||||
"none": "open",
|
||||
"psk": "wpa",
|
||||
"psk2": "wpa2",
|
||||
"sae": "wpa3",
|
||||
"psk-mixed": "wpa|wpa2",
|
||||
"sae-mixed": "wpa3",
|
||||
"wpa": 'wap',
|
||||
"wpa2": "eap",
|
||||
"wpa3": "eap",
|
||||
"wpa-mixed": "eap",
|
||||
"wpa3-mixed": "sae"
|
||||
}
|
||||
if encryption in encryption_mapping.keys():
|
||||
return encryption_mapping[encryption]
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_ssid_info(self):
|
||||
ssid_info = []
|
||||
for interfaces in self.base_profile_config["interfaces"]:
|
||||
if "ssids" in interfaces.keys():
|
||||
for ssid_data in interfaces["ssids"]:
|
||||
for band in ssid_data["wifi-bands"]:
|
||||
temp = [ssid_data["name"]]
|
||||
if ssid_data["encryption"]["proto"] == "none" or "radius" in ssid_data.keys():
|
||||
temp.append(self.encryption_lookup(encryption=ssid_data["encryption"]["proto"]))
|
||||
temp.append('[BLANK]')
|
||||
else:
|
||||
temp.append(self.encryption_lookup(encryption=ssid_data["encryption"]["proto"]))
|
||||
temp.append(ssid_data["encryption"]["key"])
|
||||
temp.append(band)
|
||||
ssid_info.append(temp)
|
||||
return ssid_info
|
||||
|
||||
def set_radio_config(self, radio_config=None):
|
||||
self.base_profile_config["radios"].append({
|
||||
"band": "2G",
|
||||
@@ -277,9 +312,7 @@ class UProfileUtility:
|
||||
self.mode = mode
|
||||
if mode == "NAT":
|
||||
self.base_profile_config['interfaces'][1]['ssids'] = []
|
||||
|
||||
elif mode == "BRIDGE":
|
||||
del self.base_profile_config['interfaces'][1]
|
||||
self.base_profile_config['interfaces'][0]['ssids'] = []
|
||||
elif mode == "VLAN":
|
||||
del self.base_profile_config['interfaces'][1]
|
||||
@@ -288,7 +321,7 @@ class UProfileUtility:
|
||||
wan_section_vlan = {
|
||||
"name": "WAN",
|
||||
"role": "upstream",
|
||||
"services": ["lldp"],
|
||||
"services": ["lldp", "ssh", "dhcp-snooping"],
|
||||
"ethernet": [
|
||||
{
|
||||
"select-ports": [
|
||||
@@ -381,6 +414,7 @@ class UProfileUtility:
|
||||
|
||||
uri = self.sdk_client.build_uri("device/" + serial_number + "/configure")
|
||||
basic_cfg_str = json.dumps(payload)
|
||||
print(self.base_profile_config)
|
||||
allure.attach(name="ucentral_config: ", body=str(self.base_profile_config))
|
||||
print(self.base_profile_config)
|
||||
resp = requests.post(uri, data=basic_cfg_str, headers=self.sdk_client.make_headers(),
|
||||
@@ -398,12 +432,13 @@ if __name__ == '__main__':
|
||||
'password': 'openwifi',
|
||||
}
|
||||
obj = Controller(controller_data=controller)
|
||||
# profile = UProfileUtility(sdk_client=obj)
|
||||
# profile.set_mode(mode="BRIDGE")
|
||||
# profile.set_radio_config()
|
||||
# ssid = {"ssid_name": "ssid_wpa2_2g", "appliedRadios": ["2G"], "security": "psk", "security_key": "something",
|
||||
# "vlan": 100, "rate-limit": {"ingress-rate": 50, "egress-rate": 50}}
|
||||
# profile.add_ssid(ssid_data=ssid)
|
||||
# profile.push_config(serial_number="903cb39d6918")
|
||||
profile = UProfileUtility(sdk_client=obj)
|
||||
profile.set_mode(mode="BRIDGE")
|
||||
profile.set_radio_config()
|
||||
ssid = {"ssid_name": "ssid_wpa2_2g", "appliedRadios": ["2G", "5G"], "security": "psk", "security_key": "something",
|
||||
"vlan": 100}
|
||||
profile.add_ssid(ssid_data=ssid, radius=False)
|
||||
profile.push_config(serial_number="903cb39d6918")
|
||||
print(profile.get_ssid_info())
|
||||
# print(obj.get_devices())
|
||||
obj.logout()
|
||||
|
||||
@@ -285,116 +285,36 @@ class Fixtures_2x:
|
||||
else:
|
||||
print("AP is Not Broadcasting Applied Config")
|
||||
allure.attach(name="Failed to Apply Config : Active Config in AP : ", body=str(ap_config_active))
|
||||
|
||||
time.sleep(10)
|
||||
ap_logs = ap_ssh.logread()
|
||||
allure.attach(body=ap_logs, name="AP LOgs: ")
|
||||
ap_wifi_data = ap_ssh.get_interface_details()
|
||||
idx_mapping = {}
|
||||
ssid_data = []
|
||||
ap_interfaces = list(ap_wifi_data.keys())
|
||||
for interface in range(len(ap_interfaces)):
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "none":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=OPEN" +
|
||||
" bssid=" + ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
# pass
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "psk":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=WPA" +
|
||||
" password=" + ap_wifi_data[ap_interfaces[interface]][2] +
|
||||
" bssid=" + ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
# pass
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "psk-mixed":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=WPA|WPA2" +
|
||||
" password=" + ap_wifi_data[ap_interfaces[interface]][2] +
|
||||
" bssid=" + ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
# pass
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "psk2":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=WPA2" +
|
||||
" password=" + ap_wifi_data[ap_interfaces[interface]][2] +
|
||||
" bssid=" + str(ap_wifi_data[ap_interfaces[interface]][3][0]).lower()
|
||||
]
|
||||
print(ssid)
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
# pass
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "sae":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=WPA3" +
|
||||
" password=" + ap_wifi_data[ap_interfaces[interface]][2] +
|
||||
" bssid=" + ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
# pass
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "sae-mixed":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=WPA3" +
|
||||
" password=" + ap_wifi_data[ap_interfaces[interface]][2] +
|
||||
" bssid=" + ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
]
|
||||
# pass
|
||||
if ap_wifi_data[ap_interfaces[interface]][1] == "wpa2":
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ap_wifi_data[ap_interfaces[interface]][0] +
|
||||
" security=EAP-TTLS" +
|
||||
" bssid=" + str(ap_wifi_data[ap_interfaces[interface]][3][0]).lower()
|
||||
]
|
||||
allure.attach(body=ap_logs, name="AP Logs: ")
|
||||
ssid_info_sdk = instantiate_profile_obj.get_ssid_info()
|
||||
ap_wifi_data = ap_ssh.get_iwinfo()
|
||||
|
||||
idx_mapping[str(interface)] = [ap_wifi_data[ap_interfaces[interface]][0],
|
||||
ap_wifi_data[ap_interfaces[interface]][2],
|
||||
ap_wifi_data[ap_interfaces[interface]][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][1],
|
||||
ap_wifi_data[ap_interfaces[interface]][3][0]
|
||||
for p in ap_wifi_data:
|
||||
for q in ssid_info_sdk:
|
||||
if ap_wifi_data[p][0] == q[0] and ap_wifi_data[p][2] == q[3]:
|
||||
q.append(ap_wifi_data[p][1])
|
||||
|
||||
ssid_data = []
|
||||
idx_mapping = {}
|
||||
for interface in range(len(ssid_info_sdk)):
|
||||
|
||||
ssid = ["ssid_idx=" + str(interface) +
|
||||
" ssid=" + ssid_info_sdk[interface][0] +
|
||||
" security=" + ssid_info_sdk[interface][1].upper() +
|
||||
" password=" + ssid_info_sdk[interface][2] +
|
||||
" bssid=" + ssid_info_sdk[interface][4].lower()
|
||||
]
|
||||
idx_mapping[str(interface)] = [ssid_info_sdk[interface][0],
|
||||
ssid_info_sdk[interface][2],
|
||||
ssid_info_sdk[interface][1],
|
||||
ssid_info_sdk[interface][3],
|
||||
ssid_info_sdk[interface][4].lower()
|
||||
]
|
||||
# pass
|
||||
ssid_data.append(ssid)
|
||||
lf_tools.ssid_list.append(ap_wifi_data[ap_interfaces[interface]][0])
|
||||
lf_tools.ssid_list.append(ssid_info_sdk[interface][0])
|
||||
lf_tools.dut_idx_mapping = idx_mapping
|
||||
print(ssid_data)
|
||||
lf_tools.update_ssid(ssid_data=ssid_data)
|
||||
|
||||
def teardown_session():
|
||||
|
||||
Reference in New Issue
Block a user