From 129b9b266a5fc588ad447e72528677cba005903d Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Wed, 6 Dec 2023 21:17:54 -0800 Subject: [PATCH 1/6] Remove platform specific url --- .../capture/ecosystem/play_services/prober.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py index 8dcda80ddf3133..ecf7f7d3bca4d3 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py @@ -21,8 +21,9 @@ from . import config -logger = log.get_logger(__file__) - +_LOGGER = log.get_logger(__file__) +_URLS_FILE = os.path.join(os.path.dirname(__file__), "urls.txt") +_URLS_FILE_EXISTS = os.path.exists(_URLS_FILE) class PlayServicesProber: @@ -30,10 +31,10 @@ def __init__(self, platform, artifact_dir): # TODO: Handle all resolved addresses self.platform = platform self.artifact_dir = artifact_dir - self.logger = logger + self.logger = _LOGGER self.probe_artifact = os.path.join(self.artifact_dir, "net_probes.txt") self.command_suffix = f" 2>&1 | tee -a {self.probe_artifact}" - self.target = "googlehomefoyer-pa.googleapis.com" + self.target = "" self.tracert_limit = config.foyer_prober_traceroute_limit def run_command(self, command): @@ -66,6 +67,12 @@ async def _probe_from_phone_ping_foyer(self) -> None: self.platform.run_adb_command(f"shell ping -c 4 {self.target} {self.command_suffix}") async def probe_services(self) -> None: - self.logger.info(f"Probing {self.target}") - for probe_func in [s for s in dir(self) if s.startswith('_probe')]: - await getattr(self, probe_func)() + if _URLS_FILE_EXISTS: + with open(_URLS_FILE) as urls_file: + for line in urls_file: + self.target = line + self.logger.info(f"Probing {self.target}") + for probe_func in [s for s in dir(self) if s.startswith('_probe')]: + await getattr(self, probe_func)() + else: + self.logger.info("No probe targets configured") From 74d4fd828b761eaaf891aa01e9d038691951de6b Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Wed, 6 Dec 2023 23:35:47 -0800 Subject: [PATCH 2/6] Fix crash where service info can be None, add trel, cleanup --- src/tools/interop/idt/discovery/dnssd.py | 183 ++++++++++++----------- 1 file changed, 99 insertions(+), 84 deletions(-) diff --git a/src/tools/interop/idt/discovery/dnssd.py b/src/tools/interop/idt/discovery/dnssd.py index 04dd8de3494eda..d2fdd6623f52d7 100644 --- a/src/tools/interop/idt/discovery/dnssd.py +++ b/src/tools/interop/idt/discovery/dnssd.py @@ -17,6 +17,7 @@ import asyncio import os +import re import traceback from dataclasses import dataclass from textwrap import dedent @@ -31,104 +32,114 @@ @dataclass() -class MdnsTypeInfo: +class ServiceTypeInfo: type: str description: str -commissioner = MdnsTypeInfo( +_COMMISSIONER_SERVICE_INFO = ServiceTypeInfo( "COMMISSIONER", - "This is a service for a Matter commissioner aka. controller" + "A service for a Matter commissioner aka. controller" ) -commissionable = MdnsTypeInfo( +_COMMISSIONABLE_SERVICE_INFO = ServiceTypeInfo( "COMMISSIONABLE / EXTENDED DISCOVERY", - "This is a service to be used in the commissioning process and provides more info about the device." + "A service to be used in the commissioning process and provides more info about the device." ) -operational = MdnsTypeInfo( +_OPERATIONAL_SERVICE_INFO = ServiceTypeInfo( "OPERATIONAL", - "This is a service for a commissioned Matter device. It exposes limited info about the device." + "A service for a commissioned Matter device. It exposes limited info about the device." ) -border_router = MdnsTypeInfo( +_TBR_SERVICE_INFO = ServiceTypeInfo( "THREAD BORDER ROUTER", - "This is a service for a thread border router; may be used for thread+Matter devices." + "A service for a thread border router; may be used for thread+Matter devices." ) -_MDNS_TYPES = { - "_matterd._udp.local.": commissioner, - "_matterc._udp.local.": commissionable, - "_matter._tcp.local.": operational, - "_meshcop._udp.local.": border_router, +_TREL_SERVICE_INFO = ServiceTypeInfo( + "THREAD RADIO ENCAPSULATION LINK", + "A service for Thread Radio Encapsulation Link which is a method for thread BRs to exchange data on IP links." +) + +_SERVICE_INFO = { + "_matterd._udp.local.": _COMMISSIONER_SERVICE_INFO, + "_matterc._udp.local.": _COMMISSIONABLE_SERVICE_INFO, + "_matter._tcp.local.": _OPERATIONAL_SERVICE_INFO, + "_meshcop._udp.local.": _TBR_SERVICE_INFO, + "_trel._udp.local.": _TREL_SERVICE_INFO, } @dataclass() -class RecordParser: +class TxtRecordParser: readable_name: str explanation: str parse: Callable[[str], str] -# TODO: Meshcop parser +def unwrap_str(to_unwrap: str) -> str: + to_unwrap = to_unwrap.replace("\n", " ") + to_unwrap = to_unwrap.replace("\t", " ") + return re.sub(' +', ' ', to_unwrap) + + +# TODO: Thread parser class MatterTxtRecordParser: def __init__(self): self.parsers = { - "D": RecordParser("Discriminator", - dedent("\ - Differentiates this instance of the device from others w/ same VID/PID that might be \n\ - in the environment."), - MatterTxtRecordParser.parse_d), # To hex - "VP": RecordParser("VID/PID", - "The Vendor ID and Product ID (each are two bytes of hex) that identify this product.", - MatterTxtRecordParser.parse_vp), # Split + to hex - "CM": RecordParser("Commissioning mode", - "Whether the device is in commissioning mode or not.", - MatterTxtRecordParser.parse_cm), # Decode - "DT": RecordParser("Device type", - "Application type for this end device.", - MatterTxtRecordParser.parse_dt), # Decode - "DN": RecordParser("Device name", - "Manufacturer provided device name. MAY match NodeLabel in Basic info cluster.", - MatterTxtRecordParser.parse_pass_through), # None - "RI": RecordParser("Rotating identifier", - "Vendor specific, non-trackable per-device ID.", - MatterTxtRecordParser.parse_pass_through), # None - "PH": RecordParser("Pairing hint", - dedent("\ - Given the current device state, follow these instructions to make the device \n\ - commissionable."), - MatterTxtRecordParser.parse_ph), # Decode - "PI": RecordParser("Pairing instructions", - dedent("\ - Used with the Pairing hint. If the Pairing hint mentions N, this is the \n\ - value of N."), - MatterTxtRecordParser.parse_pass_through), # None - # General records - "SII": RecordParser("Session idle interval", - "Message Reliability Protocol retry interval while the device is idle in milliseconds.", - MatterTxtRecordParser.parse_pass_through), # None - "SAI": RecordParser("Session active interval", - dedent("\ - Message Reliability Protocol retry interval while the device is active \n\ - in milliseconds."), - MatterTxtRecordParser.parse_pass_through), # None - "SAT": RecordParser("Session active threshold", - "Duration of time this device stays active after last activity in milliseconds.", - MatterTxtRecordParser.parse_pass_through), # None - "T": RecordParser("Supports TCP", - "Whether this device supports TCP client and or Server.", - MatterTxtRecordParser.parse_t), # Decode + # Commissioning + "D": TxtRecordParser("Discriminator", + unwrap_str("Differentiates advertisements from this instance of the device from \ + advertisement from others devices w/ the same VID/PID."), + MatterTxtRecordParser.parse_d), # To hex + "VP": TxtRecordParser("VID/PID", + "The Vendor ID and Product ID (each two bytes of hex) that identify this product.", + MatterTxtRecordParser.parse_vp), # Split + to hex + "CM": TxtRecordParser("Commissioning mode", + "Whether the device is in commissioning mode or not.", + MatterTxtRecordParser.parse_cm), # Decode + "DT": TxtRecordParser("Device type", + "Application type for this end device.", + MatterTxtRecordParser.parse_dt), # Decode map + "DN": TxtRecordParser("Device name", + "Manufacturer provided device name. MAY match NodeLabel in Basic info cluster.", + MatterTxtRecordParser.parse_pass_through), # None + "RI": TxtRecordParser("Rotating identifier", + "Vendor specific, non-trackable per-device ID.", + MatterTxtRecordParser.parse_pass_through), # None + "PH": TxtRecordParser("Pairing hint", + unwrap_str("Given the current device state, follow these instructions to make the \ + device commissionable."), + MatterTxtRecordParser.parse_ph), # Decode bitmap + "PI": TxtRecordParser("Pairing instructions", + unwrap_str("Used with the Pairing hint. If the Pairing hint mentions N, this \ + is the value of N."), + MatterTxtRecordParser.parse_pass_through), # None + # General + "SII": TxtRecordParser("Session idle interval", + unwrap_str("Message Reliability Protocol retry interval while the device is idle in \ + milliseconds."), + MatterTxtRecordParser.parse_pass_through), # None + "SAI": TxtRecordParser("Session active interval", + unwrap_str("Message Reliability Protocol retry interval while the device is \ + active in milliseconds."), + MatterTxtRecordParser.parse_pass_through), # None + "SAT": TxtRecordParser("Session active threshold", + "Duration of time this device stays active after last activity in milliseconds.", + MatterTxtRecordParser.parse_pass_through), # None + "T": TxtRecordParser("Supports TCP", + "Whether this device supports TCP.", + MatterTxtRecordParser.parse_t), # Decode } self.unparsed_records = "" self.parsed_records = "" - def parse_single_record(self, key: str, value: str): - parser: RecordParser = self.parsers[key] + def parse_single_txt_record(self, key: str, value: str): + parser: TxtRecordParser = self.parsers[key] self.parsed_records += add_border(parser.readable_name + "\n") self.parsed_records += parser.explanation + "\n\n" try: - self.parsed_records += "PARSED VALUE: " + parser.parse(value) + "\n" + self.parsed_records += "PARSED VALUE:\n" + parser.parse(value) + "\n" except Exception: logger.error("Exception parsing TXT record, appending raw value") logger.error(traceback.format_exc()) @@ -144,7 +155,7 @@ def get_output(self) -> str: ret += parsed_exp + self.parsed_records return ret - def parse_records(self, info: ServiceInfo) -> str: + def parse_txt_records(self, info: ServiceInfo) -> str: if info.properties is not None: for name, value in info.properties.items(): try: @@ -158,7 +169,7 @@ def parse_records(self, info: ServiceInfo) -> str: if name not in self.parsers: self.unparsed_records += f"KEY: {name} VALUE: {value}\n" else: - self.parse_single_record(name, value) + self.parse_single_txt_record(name, value) return self.get_output() @staticmethod @@ -301,20 +312,23 @@ def handle_service_info( type_: str, name: str, delta_type: str) -> None: + to_log = "SERVICE EVENT\n" + to_log += f"{name}\n" + to_log += f"SERVICE {delta_type}\n" + to_log += _SERVICE_INFO[type_].type + "\n" + to_log += _SERVICE_INFO[type_].description + "\n" info = zc.get_service_info(type_, name) - self.discovered_matter_devices[name] = info - to_log = f"{name}\n" - update_str = f"\nSERVICE {delta_type}\n" - to_log += ("*" * (len(update_str) - 2)) + update_str - to_log += _MDNS_TYPES[type_].type + "\n" - to_log += _MDNS_TYPES[type_].description + "\n" - to_log += f"A/SRV TTL: {str(info.host_ttl)}\n" - to_log += f"PTR/TXT TTL: {str(info.other_ttl)}\n" - txt_parser = MatterTxtRecordParser() - to_log += txt_parser.parse_records(info) - to_log += self.log_addr(info) - self.logger.info(to_log) - self.write_log(to_log, name) + if info is not None: + self.discovered_matter_devices[name] = info + to_log += f"A/SRV TTL: {str(info.host_ttl)}\n" + to_log += f"PTR/TXT TTL: {str(info.other_ttl)}\n" + txt_parser = MatterTxtRecordParser() + to_log += txt_parser.parse_txt_records(info) + to_log += self.log_addr(info) + self.logger.info(to_log) + self.write_log(to_log, name) + else: + self.logger.warning(f"No info found for {to_log}") def add_service(self, zc: Zeroconf, type_: str, name: str) -> None: self.handle_service_info(zc, type_, name, "ADDED") @@ -323,9 +337,10 @@ def update_service(self, zc: Zeroconf, type_: str, name: str) -> None: self.handle_service_info(zc, type_, name, "UPDATED") def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: - to_log = f"Service {name} removed\n" - to_log += _MDNS_TYPES[type_].type + "\n" - to_log += _MDNS_TYPES[type_].description + to_log = "SERVICE_EVENT\n" + to_log += f"Service {name} removed\n" + to_log += _SERVICE_INFO[type_].type + "\n" + to_log += _SERVICE_INFO[type_].description if name in self.discovered_matter_devices: del self.discovered_matter_devices[name] self.logger.warning(to_log) @@ -333,7 +348,7 @@ def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: def browse_interactive(self) -> None: zc = Zeroconf() - ServiceBrowser(zc, list(_MDNS_TYPES.keys()), self) + ServiceBrowser(zc, list(_SERVICE_INFO.keys()), self) try: self.logger.warning( dedent("\ @@ -348,7 +363,7 @@ def browse_interactive(self) -> None: async def browse_once(self, browse_time_seconds: int) -> Zeroconf: zc = Zeroconf() - ServiceBrowser(zc, list(_MDNS_TYPES.keys()), self) + ServiceBrowser(zc, list(_SERVICE_INFO.keys()), self) await asyncio.sleep(browse_time_seconds) zc.close() return zc From 04280945574ad6c022b6b653049e7b8c182b0bcf Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Wed, 6 Dec 2023 23:45:41 -0800 Subject: [PATCH 3/6] Nit --- src/tools/interop/idt/discovery/dnssd.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/interop/idt/discovery/dnssd.py b/src/tools/interop/idt/discovery/dnssd.py index d2fdd6623f52d7..ad92df0e872030 100644 --- a/src/tools/interop/idt/discovery/dnssd.py +++ b/src/tools/interop/idt/discovery/dnssd.py @@ -59,7 +59,7 @@ class ServiceTypeInfo: "A service for Thread Radio Encapsulation Link which is a method for thread BRs to exchange data on IP links." ) -_SERVICE_INFO = { +_SERVICE_TYPE_INFO = { "_matterd._udp.local.": _COMMISSIONER_SERVICE_INFO, "_matterc._udp.local.": _COMMISSIONABLE_SERVICE_INFO, "_matter._tcp.local.": _OPERATIONAL_SERVICE_INFO, @@ -315,8 +315,8 @@ def handle_service_info( to_log = "SERVICE EVENT\n" to_log += f"{name}\n" to_log += f"SERVICE {delta_type}\n" - to_log += _SERVICE_INFO[type_].type + "\n" - to_log += _SERVICE_INFO[type_].description + "\n" + to_log += _SERVICE_TYPE_INFO[type_].type + "\n" + to_log += _SERVICE_TYPE_INFO[type_].description + "\n" info = zc.get_service_info(type_, name) if info is not None: self.discovered_matter_devices[name] = info @@ -339,8 +339,8 @@ def update_service(self, zc: Zeroconf, type_: str, name: str) -> None: def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: to_log = "SERVICE_EVENT\n" to_log += f"Service {name} removed\n" - to_log += _SERVICE_INFO[type_].type + "\n" - to_log += _SERVICE_INFO[type_].description + to_log += _SERVICE_TYPE_INFO[type_].type + "\n" + to_log += _SERVICE_TYPE_INFO[type_].description if name in self.discovered_matter_devices: del self.discovered_matter_devices[name] self.logger.warning(to_log) @@ -348,7 +348,7 @@ def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: def browse_interactive(self) -> None: zc = Zeroconf() - ServiceBrowser(zc, list(_SERVICE_INFO.keys()), self) + ServiceBrowser(zc, list(_SERVICE_TYPE_INFO.keys()), self) try: self.logger.warning( dedent("\ @@ -363,7 +363,7 @@ def browse_interactive(self) -> None: async def browse_once(self, browse_time_seconds: int) -> Zeroconf: zc = Zeroconf() - ServiceBrowser(zc, list(_SERVICE_INFO.keys()), self) + ServiceBrowser(zc, list(_SERVICE_TYPE_INFO.keys()), self) await asyncio.sleep(browse_time_seconds) zc.close() return zc From 89964563279ecd7f73dae8dd97680d64e7d7de75 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 7 Dec 2023 07:46:26 +0000 Subject: [PATCH 4/6] Restyled by autopep8 --- src/tools/interop/idt/capture/ecosystem/play_services/prober.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py index ecf7f7d3bca4d3..bfeb7a9ac718e9 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py @@ -25,6 +25,7 @@ _URLS_FILE = os.path.join(os.path.dirname(__file__), "urls.txt") _URLS_FILE_EXISTS = os.path.exists(_URLS_FILE) + class PlayServicesProber: def __init__(self, platform, artifact_dir): From 224050793d528ca57af7dea199d526632830f926 Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Wed, 6 Dec 2023 23:55:40 -0800 Subject: [PATCH 5/6] Nits and ignore --- src/tools/interop/idt/.gitignore | 1 + .../idt/capture/ecosystem/play_services/config.py | 4 ++-- .../ecosystem/play_services/play_services.py | 4 ++-- .../idt/capture/ecosystem/play_services/prober.py | 14 +++++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/tools/interop/idt/.gitignore b/src/tools/interop/idt/.gitignore index 55da2a806dd412..e58b46cdac900c 100644 --- a/src/tools/interop/idt/.gitignore +++ b/src/tools/interop/idt/.gitignore @@ -8,3 +8,4 @@ pycache/ venv/ .zip BUILD +urls.txt diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/config.py b/src/tools/interop/idt/capture/ecosystem/play_services/config.py index 2daacb38dcf909..dd01aba6aa0bf4 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/config.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/config.py @@ -15,5 +15,5 @@ # limitations under the License. # -enable_foyer_probers = True -foyer_prober_traceroute_limit = 32 +enable_probers = True +prober_traceroute_limit = 32 diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py b/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py index e94a10f9260b94..670e01395a9c7c 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/play_services.py @@ -111,7 +111,7 @@ async def stop_capture(self) -> None: self.analysis.show_analysis() async def probe_capture(self) -> None: - if config.enable_foyer_probers: + if config.enable_probers: await PlayServicesProber(self.platform, self.artifact_dir).probe_services() else: - logger.critical("Foyer probers disabled in config!") + logger.critical("Probers disabled in config!") diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py index bfeb7a9ac718e9..68cb9017fb3349 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py @@ -36,34 +36,34 @@ def __init__(self, platform, artifact_dir): self.probe_artifact = os.path.join(self.artifact_dir, "net_probes.txt") self.command_suffix = f" 2>&1 | tee -a {self.probe_artifact}" self.target = "" - self.tracert_limit = config.foyer_prober_traceroute_limit + self.tracert_limit = config.prober_traceroute_limit def run_command(self, command): Bash(f"{command} {self.command_suffix}", sync=True).start_command() - async def _probe_tracert_icmp_foyer(self) -> None: + async def _probe_tracert_icmp(self) -> None: self.logger.info(f"icmp traceroute to {self.target}") self.run_command(f"traceroute -m {self.tracert_limit} {self.target}") - async def _probe_tracert_udp_foyer(self) -> None: + async def _probe_tracert_udp(self) -> None: # TODO: Per-host-platform impl self.logger.info(f"udp traceroute to {self.target}") self.run_command(f"traceroute -m {self.tracert_limit} -U -p 443 {self.target}") - async def _probe_tracert_tcp_foyer(self) -> None: + async def _probe_tracert_tcp(self) -> None: # TODO: Per-host-platform impl self.logger.info(f"tcp traceroute to {self.target}") self.run_command(f"traceroute -m {self.tracert_limit} -T -p 443 {self.target}") - async def _probe_ping_foyer(self) -> None: + async def _probe_ping(self) -> None: self.logger.info(f"ping {self.target}") self.run_command(f"ping -c 4 {self.target}") - async def _probe_dns_foyer(self) -> None: + async def _probe_dns(self) -> None: self.logger.info(f"dig {self.target}") self.run_command(f"dig {self.target}") - async def _probe_from_phone_ping_foyer(self) -> None: + async def _probe_from_phone_ping(self) -> None: self.logger.info(f"ping {self.target} from phone") self.platform.run_adb_command(f"shell ping -c 4 {self.target} {self.command_suffix}") From 67441cdcf8e32146cfb08b47beade35dee8cff98 Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Thu, 7 Dec 2023 12:31:07 -0800 Subject: [PATCH 6/6] Address initial comments --- src/tools/interop/idt/.gitignore | 2 +- .../capture/ecosystem/play_services/config.py | 3 +++ .../capture/ecosystem/play_services/prober.py | 18 ++++++++---------- src/tools/interop/idt/discovery/dnssd.py | 4 +--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/tools/interop/idt/.gitignore b/src/tools/interop/idt/.gitignore index e58b46cdac900c..fa78173492a507 100644 --- a/src/tools/interop/idt/.gitignore +++ b/src/tools/interop/idt/.gitignore @@ -8,4 +8,4 @@ pycache/ venv/ .zip BUILD -urls.txt +prober_urls.txt diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/config.py b/src/tools/interop/idt/capture/ecosystem/play_services/config.py index dd01aba6aa0bf4..a2246f8c8c7c66 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/config.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/config.py @@ -15,5 +15,8 @@ # limitations under the License. # +import os + enable_probers = True prober_traceroute_limit = 32 +prober_urls_file_name = os.path.join(os.path.dirname(__file__), "prober_urls.txt") diff --git a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py index 68cb9017fb3349..29af54075c2008 100644 --- a/src/tools/interop/idt/capture/ecosystem/play_services/prober.py +++ b/src/tools/interop/idt/capture/ecosystem/play_services/prober.py @@ -22,8 +22,6 @@ from . import config _LOGGER = log.get_logger(__file__) -_URLS_FILE = os.path.join(os.path.dirname(__file__), "urls.txt") -_URLS_FILE_EXISTS = os.path.exists(_URLS_FILE) class PlayServicesProber: @@ -68,12 +66,12 @@ async def _probe_from_phone_ping(self) -> None: self.platform.run_adb_command(f"shell ping -c 4 {self.target} {self.command_suffix}") async def probe_services(self) -> None: - if _URLS_FILE_EXISTS: - with open(_URLS_FILE) as urls_file: - for line in urls_file: - self.target = line - self.logger.info(f"Probing {self.target}") - for probe_func in [s for s in dir(self) if s.startswith('_probe')]: - await getattr(self, probe_func)() - else: + if not os.path.exists(config.prober_urls_file_name): self.logger.info("No probe targets configured") + return + with open(config.prober_urls_file_name) as urls_file: + for line in urls_file: + self.target = line + self.logger.info(f"Probing {self.target}") + for probe_func in [s for s in dir(self) if s.startswith('_probe')]: + await getattr(self, probe_func)() diff --git a/src/tools/interop/idt/discovery/dnssd.py b/src/tools/interop/idt/discovery/dnssd.py index ad92df0e872030..2d29420969b097 100644 --- a/src/tools/interop/idt/discovery/dnssd.py +++ b/src/tools/interop/idt/discovery/dnssd.py @@ -76,9 +76,7 @@ class TxtRecordParser: def unwrap_str(to_unwrap: str) -> str: - to_unwrap = to_unwrap.replace("\n", " ") - to_unwrap = to_unwrap.replace("\t", " ") - return re.sub(' +', ' ', to_unwrap) + return re.sub(r"\s+", ' ', to_unwrap) # TODO: Thread parser