Skip to content
Merged
Show file tree
Hide file tree
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
51 changes: 40 additions & 11 deletions py-json/interop_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ def __init__(self,
# adb get url
self.adb_url = 'http://{}:{}/adb'.format(self.lanforge_ip, self.port)

self.adb_data = self.get_adb_data()

def get_adb_data(self):
"""Fetch ADB device data from the LANforge API endpoint."""
try:
response = requests.get(self.adb_url, timeout=10)
response.raise_for_status()
adb_data = response.json()["devices"]
except Exception as e:
print(f"Failed to get adb data: {e}")
adb_data = []
return adb_data

# request function to send json post request to the adb api
def post_data(self, url, data):
logger.info("ANDROID API {} {} {}".format(url, data, datetime.now()))
Expand All @@ -151,9 +164,10 @@ async def stop_app(self, port_list=[]):
# Added key for adb request
for port_data in port_list:
shelf, resource, serial, band = port_data
resource = self.get_adb_resource_lf(serial)
data = {
'shelf': 1,
'resource': 1,
'resource': resource,
'adb_id': serial,
# key=8 modification for adb API to add faster callback option
'key': 8,
Expand Down Expand Up @@ -183,10 +197,10 @@ def set_wifi_state(self, port_list=[], state='enable'):
data_list = []
for port_data in port_list:
shelf, resource, serial, *extra = port_data

resource = self.get_adb_resource_lf(serial)
data = {
'shelf': 1,
'resource': 1,
'resource': resource,
'adb_id': serial,
# key=8 modification for adb API to add faster callback option
'key': 8,
Expand All @@ -197,6 +211,20 @@ def set_wifi_state(self, port_list=[], state='enable'):
loop = asyncio.get_event_loop()
tasks = [loop.run_in_executor(None, self.post_data, self.post_url, data) for data in data_list]

def get_adb_resource_lf(self, serial):
"""
Determine which LANforge (Manager LANforge / Resource LANforge)
the given Android device is connected to and return its resource.
"""
if self.adb_data is None:
self.adb_data = self.get_adb_data()
for dev in self.adb_data:
key = next(iter(dev))
eid = key.split('.')
if eid[2] == serial:
return eid[1]
return None

async def reboot_android(self, port_list=[], state='enable'):
if (port_list == []):
logger.info('Port list is empty')
Expand All @@ -212,10 +240,10 @@ async def reboot_android(self, port_list=[], state='enable'):
data_list = []
for port_data in port_list:
shelf, resource, serial, *extra = port_data

resource = self.get_adb_resource_lf(serial)
data = {
'shelf': 1,
'resource': 1,
'resource': resource,
'adb_id': serial,
# key=8 modification for adb API to add faster callback option
'key': 8,
Expand All @@ -238,10 +266,10 @@ async def forget_all_networks(self, port_list=[]):
data_list = []
for port_data in port_list:
shelf, resource, serial, *extra = port_data

resource = self.get_adb_resource_lf(serial)
data = {
'shelf': 1,
'resource': 1,
'resource': resource,
'id': serial,
'type': 'adb'
}
Expand Down Expand Up @@ -306,9 +334,10 @@ async def configure_wifi(self, port_list=[]):
username = self.get_username(shelf, resource)
# adding enable wifi option for android clients as a prerequisite step by-default
command = 'shell svc wifi enable'
resource_lf = self.get_adb_resource_lf(serial)
data = {
'shelf': 1,
'resource': 1,
'resource': resource_lf,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see support for resources greater then 1

'adb_id': serial,
# key=8 modification for adb API to add faster callback option
'key': 8,
Expand All @@ -319,7 +348,7 @@ async def configure_wifi(self, port_list=[]):
if (username is None):
# logger.warning('The device with serial {} not found'.format(serial))
username = \
requests.get('http://{}:{}/adb/1/1/{}'.format(self.lanforge_ip, self.port, serial)).json()['devices'][
requests.get('http://{}:{}/adb/1/{}/{}'.format(self.lanforge_ip, self.port, resource_lf, serial)).json()['devices'][
'user-name']

# check if the encryption is personal
Expand Down Expand Up @@ -350,7 +379,7 @@ async def configure_wifi(self, port_list=[]):
curr_eap_identity, curr_passwd)
data = {
'shelf': 1,
'resource': 1,
'resource': resource_lf,
'adb_id': serial,
# key=8 modification for adb API to add faster callback option
'key': 8,
Expand All @@ -369,7 +398,7 @@ async def configure_wifi(self, port_list=[]):
username, self.server_ip, curr_ssid, curr_passwd, curr_encryption)
data = {
'shelf': 1,
'resource': 1,
'resource': resource_lf,
'adb_id': serial,
# key=8 modification for adb API to add faster callback option
'key': 8,
Expand Down
2 changes: 1 addition & 1 deletion py-scripts/lf_base_interop_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, manager_ip=None,
self.release = release
self.debug = _debug_on
self.screen_size_prcnt = screen_size_prcnt
self.supported_sdk = ["11", "12", "13", "14", "15"]
self.supported_sdk = ["11", "12", "13", "14", "15", "16"]
self.supported_devices_names = []
self.supported_devices_resource_id = None
self.log_dur = log_dur
Expand Down
Loading