Skip to content

Commit

Permalink
bot: logs: Pull the autoptsserver log file from vm
Browse files Browse the repository at this point in the history
For completeness, pull the autoptsserver_65000.log file into tmp
folder.
  • Loading branch information
mkasenberg committed Sep 11, 2024
1 parent 7632448 commit c4de233
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions autopts/bot/common_features/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ def split_xml_filename(file_path):
return test_name, timestamp


def copy_server_log_file(tmp_dir, pts, ports):
try:
autopts_dir = pts.get_path()

tag = '_'.join(str(x) for x in ports)
file_name = f'autoptsserver_{tag}.log'
file_path = f'{autopts_dir}\\{file_name}'
file_bin = pts.copy_file(file_path)

file_path = os.path.join(tmp_dir, file_name)
Path(tmp_dir).mkdir(parents=True, exist_ok=True)

with open(file_path, 'wb') as handle:
handle.write(file_bin.data)
except BaseException as e:
logging.exception(e)


def pull_server_logs(args, tmp_dir, xml_folder):
"""Copy Bluetooth Protocol Viewer logs from auto-pts servers.
:param args: args
Expand Down Expand Up @@ -429,14 +447,18 @@ def _pull_logs(_pts):
# Use xmlrpc proxy to pull logs
server_addr = args.ip_addr
server_port = args.srv_port
for i in range(len(server_addr)):
if i != 0 and server_addr[i] in server_addr[0:i]:
# Skip pulling from other sever instances if those
# are at the same address as the first one,
# we have pulled their logs already.
continue
with ServerProxy(f"http://{server_addr[i]}:{server_port[i]}/",

servers = {}
for address, port in zip(server_addr, server_port):
if address in servers:
servers[address].append(port)
else:
servers[address] = [port]

for addr in servers:
with ServerProxy(f"http://{addr}:{servers[addr][0]}/",
allow_none=True) as proxy:
_pull_logs(proxy)
copy_server_log_file(tmp_dir, proxy, servers[addr])

return logs_folder, xml_folder

0 comments on commit c4de233

Please sign in to comment.