Migrate SL4F BaseLib to Mobly logger
Fix an issue to pickle any SL4F lib due to the ACTS logger containing a
lambda function, which is not pickable.
See https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled
Fixed: b/292006446
Change-Id: I2e85a39d144cc4188e32eb57b5458f01883550a6
Reviewed-on: https://fuchsia-review.googlesource.com/c/antlion/+/887297
Reviewed-by: Patrick Lu <patricklu@google.com>
Fuchsia-Auto-Submit: Sam Balana <sbalana@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/packages/antlion/controllers/fuchsia_lib/base_lib.py b/packages/antlion/controllers/fuchsia_lib/base_lib.py
index cc0ba34..4966b79 100644
--- a/packages/antlion/controllers/fuchsia_lib/base_lib.py
+++ b/packages/antlion/controllers/fuchsia_lib/base_lib.py
@@ -15,11 +15,12 @@
# limitations under the License.
import json
+import logging
import socket
from typing import Any, Dict, Mapping
from urllib.request import Request, urlopen
-from antlion import logger
+from mobly.logger import PrefixLoggerAdapter
DEFAULT_SL4F_RESPONSE_TIMEOUT_SEC = 30
@@ -35,8 +36,11 @@
class BaseLib:
def __init__(self, addr: str, logger_tag: str) -> None:
self.address = addr
- self.log = logger.create_tagged_trace_logger(
- f"SL4F | {self.address} | {logger_tag}"
+ self.log = PrefixLoggerAdapter(
+ logging.getLogger(),
+ {
+ PrefixLoggerAdapter.EXTRA_KEY_LOG_PREFIX: f"SL4F | {self.address} | {logger_tag}"
+ },
)
def send_command(
diff --git a/packages/antlion/controllers/fuchsia_lib/lib_controllers/wlan_policy_controller.py b/packages/antlion/controllers/fuchsia_lib/lib_controllers/wlan_policy_controller.py
index 0b8bf9d..035bd82 100644
--- a/packages/antlion/controllers/fuchsia_lib/lib_controllers/wlan_policy_controller.py
+++ b/packages/antlion/controllers/fuchsia_lib/lib_controllers/wlan_policy_controller.py
@@ -50,17 +50,23 @@
client_connections_state: Optional[str]
-def get_country_code_from_phy(wlan_lib: FuchsiaWlanLib, id: str) -> Tuple[str, str]:
- get_country_response = wlan_lib.wlanGetCountry(id)
+@dataclass
+class GetCountryCodeFromPhyParams:
+ wlan_lib: FuchsiaWlanLib
+ id: str
+
+
+def get_country_code_from_phy(params: GetCountryCodeFromPhyParams) -> Tuple[str, str]:
+ get_country_response = params.wlan_lib.wlanGetCountry(params.id)
if get_country_response.get("error"):
raise ConnectionError(
- f"Failed to query PHY ID ({id}) for country. "
+ f"Failed to query PHY ID ({params.id}) for country. "
f'Error: {get_country_response["error"]}'
)
country_code = "".join(
[chr(ascii_char) for ascii_char in get_country_response["result"]]
)
- return (id, country_code)
+ return (params.id, country_code)
class WlanPolicyController:
@@ -685,7 +691,7 @@
def _get_phy_country_codes(self) -> Dict[str, str]:
"""Get mapping of WLAN interfaces to the country code they are set to."""
phy_ids = self._get_phy_ids()
- args = [(self.sl4f.wlan_lib, id) for id in phy_ids]
+ args = [GetCountryCodeFromPhyParams(self.sl4f.wlan_lib, id) for id in phy_ids]
with multiprocessing.Pool() as p:
items = p.map(get_country_code_from_phy, args)
return dict(items)