Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 56 additions & 36 deletions py-scripts/DeviceConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def __init__(self, lanforge_ip=None,
self.adb_url = '/adb/'

# stop app
async def stop_app(self, port_list=[]):
async def stop_app(self, port_list=None):
port_list = [] if port_list is None else port_list
if (port_list == []):
logger.info('Device list is empty')
return
Expand All @@ -138,7 +139,8 @@ async def stop_app(self, port_list=[]):
await asyncio.gather(*tasks)

# toggle wifi
def set_wifi_state(self, port_list=[], state='enable'):
def set_wifi_state(self, port_list=None, state='enable'):
port_list = [] if port_list is None else port_list
if (port_list == []):
logger.info('Port list is empty')
return
Expand Down Expand Up @@ -166,7 +168,11 @@ def set_wifi_state(self, port_list=[], state='enable'):
[loop.run_in_executor(None, self.json_post, self.adb_post_url, data) for data in data_list]

# Forget Networks
async def forget_all_networks(self, port_list=[]):
async def forget_all_networks(self, port_list=None):
port_list = [] if port_list is None else port_list
# Added stop app in prior to clearing wifi profiles because in build 5.5.2 we have issue with clearing profiles, so the app is still running with the existing ssid.
logger.info("STOPPING APP ANDROID")
await self.stop_app(port_list=port_list)
logger.info("FORGET ALL NETWORKS ANDROID")
if (port_list == []):
logger.info('Port list is empty')
Expand All @@ -191,7 +197,8 @@ async def forget_all_networks(self, port_list=[]):
await asyncio.gather(*tasks)

# Configure Wifi ADB
async def configure_wifi(self, port_list=[]):
async def configure_wifi(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("CONFIGURE ANDROIDS")
if (port_list == []):
logger.info('Port list is empty')
Expand Down Expand Up @@ -232,16 +239,17 @@ async def configure_wifi(self, port_list=[]):
if curr_encryption == "wpa3_enterprise":
curr_encryption = "wpa3-ent"
adb_cmd = (
"shell am start -n com.candela.wecan/com.candela.wecan.StartupActivity "
"--es auto_start 1 "
"--es username {} "
"--es serverip {} "
"--es ssid {} "
"--es password {} "
"--es encryption {} "
"--es eap_method {} "
"--es eap_user {} "
"--es eap_passwd {}".format(
'shell am start -n com.candela.wecan/com.candela.wecan.StartupActivity '
'--es auto_start 1 '
'--es username {} '
'--es serverip {} '
'--es ssid \\"{}\\" '
'--es password \\"{}\\" '
'--es encryption {} '
'--es eap_method {} '
'--es eap_user {} '
'--es eap_passwd {} '
'--es auto_wifi 1'.format(
username, server_ip, curr_ssid, curr_passwd, curr_encryption,
curr_eap_method, curr_eap_identity, curr_passwd
)
Expand All @@ -255,13 +263,14 @@ async def configure_wifi(self, port_list=[]):
}
else:
adb_cmd = (
"shell am start -n com.candela.wecan/com.candela.wecan.StartupActivity "
"--es auto_start 1 "
"--es username {} "
"--es serverip {} "
"--es ssid {} "
"--es password {} "
"--es encryption {}".format(
'shell am start -n com.candela.wecan/com.candela.wecan.StartupActivity '
'--es auto_start 1 '
'--es username {} '
'--es serverip {} '
'--es ssid \\"{}\\" '
'--es password \\"{}\\" '
'--es encryption {} '
'--es auto_wifi 1'.format(
username, server_ip, curr_ssid, curr_passwd, curr_encryption
)
)
Expand All @@ -284,7 +293,8 @@ async def configure_wifi(self, port_list=[]):
await asyncio.gather(*tasks)

# Reboot ADB Devices
async def reboot_android(self, port_list=[], state='enable'):
async def reboot_android(self, port_list=None, state='enable'):
port_list = [] if port_list is None else port_list
if (port_list == []):
logger.info('Port list is empty')
return
Expand Down Expand Up @@ -327,7 +337,7 @@ def get_devices(self):
# parameters for adb post request
try:
shelf, resource = interop_tab_data['resource-id'].split('.')
except BaseException:
except Exception:
# logger.warning('Resource id is missing for the device {} therefore skipping the device from usage'.format(name))
shelf, resource = '', ''
device["serial"] = serial
Expand All @@ -353,7 +363,7 @@ def get_devices(self):

try:
shelf, resource = data['resource-id'].split('.')
except BaseException:
except Exception:
# logger.warning('Resource id is missing for the device {} therefore skipping the device from usage'.format(name))
_, resource = '', ''
device["serial"] = serial
Expand All @@ -367,7 +377,7 @@ def get_devices(self):
devices_data.append(device)
return (devices_data)

def get_serial_from_port(self, port_list=[]):
def get_serial_from_port(self, port_list=None):

if (port_list == []):
logger.info('Androids list is empty')
Expand Down Expand Up @@ -463,7 +473,8 @@ def get_encoding(self, obj):

# remove station
# NOTE this is only for Linux Laptops
async def rm_station(self, port_list=[]):
async def rm_station(self, port_list=None):
port_list = [] if port_list is None else port_list
if (port_list == []):
logger.info('Port list is empty')
return
Expand All @@ -490,7 +501,8 @@ async def rm_station(self, port_list=[]):
time.sleep(2)

# add station
async def add_station(self, port_list=[]):
async def add_station(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("ADD STATION LAPTOP")
if (port_list == []):
logger.info('Port list is empty')
Expand Down Expand Up @@ -574,7 +586,8 @@ async def add_station(self, port_list=[]):
time.sleep(2)
# Set Wifi Extra

async def set_wifi_extra(self, port_list=[]):
async def set_wifi_extra(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("SET WIFI EXTRA LAPTOP")
if (port_list == []):
logger.info('Port list is empty')
Expand Down Expand Up @@ -635,7 +648,8 @@ async def set_wifi_extra(self, port_list=[]):
# Use asyncio.gather to await the completion of all tasks
await asyncio.gather(*tasks)

async def set_port_1(self, port_list=[]):
async def set_port_1(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("SET PORT LAPTOP")
if (port_list == []):
logger.info('Port list is empty')
Expand Down Expand Up @@ -676,7 +690,8 @@ async def set_port_1(self, port_list=[]):
await asyncio.gather(*tasks)

# set port (enable DHCP)
async def set_port(self, port_list=[]):
async def set_port(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("SET PORT LAPTOP")
if (port_list == []):
logger.info('Port list is empty')
Expand Down Expand Up @@ -718,7 +733,8 @@ async def set_port(self, port_list=[]):
await asyncio.gather(*tasks)

# Reboot Laptops
async def reboot_laptop(self, port_list=[]):
async def reboot_laptop(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("REBOOT LAPTOP")
if (port_list == []):
logger.info('Port list is empty')
Expand All @@ -744,7 +760,8 @@ async def reboot_laptop(self, port_list=[]):
await asyncio.gather(*tasks)

# Disconnect Wifi Laptops
async def disconnect_wifi(self, port_list=[]):
async def disconnect_wifi(self, port_list=None):
port_list = [] if port_list is None else port_list
logger.info("SET PORT LAPTOP")
if (port_list == []):
logger.info('Port list is empty')
Expand Down Expand Up @@ -1065,7 +1082,8 @@ def device_csv_file(self, csv_name='device.csv'):
writer.writerows(existing_data)
# input()

def update_device_csv(self, csv_name='device.csv', test='', device_dict={}):
def update_device_csv(self, csv_name='device.csv', test='', device_dict=None):
device_dict = {} if device_dict is None else device_dict
adbresponse = self.adb_obj.get_devices()
resource_manager = self.laptop_obj.get_devices()
device_csv = {}
Expand Down Expand Up @@ -1358,7 +1376,8 @@ def display_profiles(self):
logger.info("\n%s", result_df.to_string(index=False))
return result_df

def get_profiles(self, data=[]):
def get_profiles(self, data=None):
data = [] if data is None else data
py_scripts_dir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
# Read CSV file into DataFrame
file_path = os.path.join(py_scripts_dir, 'profile.csv')
Expand Down Expand Up @@ -1513,8 +1532,9 @@ async def connectivity(self, config=None, disconnect=False, reboot=False, device
time.sleep(10)
if not reboot and not disconnect:
if (selected_adb_devices != []):
await self.adb_obj.stop_app(port_list=selected_adb_devices)
# await self.adb_obj.forget_all_networks(port_list=selected_adb_devices)
# stop app is now included in forget_all_networks
# await self.adb_obj.stop_app(port_list=selected_adb_devices)
await self.adb_obj.forget_all_networks(port_list=selected_adb_devices)
await self.adb_obj.configure_wifi(port_list=selected_adb_devices)

if (selected_laptop_devices == []):
Expand Down