Perform unsafe f-string migrations

Run flynt -a to aggresively convert to f-strings. This includes some
operations that are considered lossy. These may not have 1-to-1
conversions or used incorrect formatting to begin with.

Change-Id: I92ebd8809a2530f3ff910f7d908a295fc0f6f831
Reviewed-on: https://fuchsia-review.googlesource.com/c/antlion/+/867287
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Fuchsia-Auto-Submit: Sam Balana <sbalana@google.com>
Reviewed-by: Patrick Lu <patricklu@google.com>
diff --git a/packages/antlion/base_test.py b/packages/antlion/base_test.py
index abc3306..d06921e 100755
--- a/packages/antlion/base_test.py
+++ b/packages/antlion/base_test.py
@@ -621,11 +621,11 @@
                     return func(*args, **kwargs)
                 except exceptions as e:
                     retry = True
-                    msg = "Failure on attempt %d: %s" % (i + 1, e.details)
+                    msg = f"Failure on attempt {i + 1}: {e.details}"
                     self.log.warning(msg)
                     error_msgs.append(msg)
                     if e.extras:
-                        extras["Attempt %d" % (i + 1)] = e.extras
+                        extras[f"Attempt {i + 1}"] = e.extras
             raise signals.TestFailure("\n".join(error_msgs), extras)
 
         return wrapper
diff --git a/packages/antlion/controllers/adb.py b/packages/antlion/controllers/adb.py
index 1420519..f369132 100644
--- a/packages/antlion/controllers/adb.py
+++ b/packages/antlion/controllers/adb.py
@@ -96,7 +96,7 @@
             self._server_local_port = local_port
 
         if self._server_local_port:
-            adb_cmd.append("-P %d" % local_port)
+            adb_cmd.append(f"-P {local_port}")
         self.adb_str = " ".join(adb_cmd)
         self._ssh_connection = ssh_connection
 
@@ -213,9 +213,7 @@
             host_port = self._ssh_connection.create_ssh_tunnel(
                 remote_port, local_port=host_port
             )
-        output = self.forward(
-            "tcp:%d tcp:%d" % (host_port, device_port), ignore_status=True
-        )
+        output = self.forward(f"tcp:{host_port} tcp:{device_port}", ignore_status=True)
         # If hinted_port is 0, the output will be the selected port.
         # Otherwise, there will be no output upon successfully
         # forwarding the hinted port.
@@ -242,7 +240,7 @@
                 return
             # The actual port we need to disable via adb is on the remote host.
             host_port = remote_port
-        self.forward("--remove tcp:%d" % host_port)
+        self.forward(f"--remove tcp:{host_port}")
 
     def getprop(self, prop_name):
         """Get a property of the device.
diff --git a/packages/antlion/controllers/android_device.py b/packages/antlion/controllers/android_device.py
index c9b2cce..59e24a9 100755
--- a/packages/antlion/controllers/android_device.py
+++ b/packages/antlion/controllers/android_device.py
@@ -706,7 +706,7 @@
 
         for attempt in range(ADB_ROOT_RETRY_COUNT):
             try:
-                self.log.debug("Enabling ADB root mode: attempt %d." % attempt)
+                self.log.debug(f"Enabling ADB root mode: attempt {attempt}.")
                 self.adb.root()
             except AdbError:
                 if attempt == ADB_ROOT_RETRY_COUNT:
diff --git a/packages/antlion/controllers/ap_lib/dhcp_config.py b/packages/antlion/controllers/ap_lib/dhcp_config.py
index a94e277..b02914f 100644
--- a/packages/antlion/controllers/ap_lib/dhcp_config.py
+++ b/packages/antlion/controllers/ap_lib/dhcp_config.py
@@ -157,7 +157,7 @@
         lines = []
 
         if self.default_lease_time:
-            lines.append("default-lease-time %d;" % self.default_lease_time)
+            lines.append(f"default-lease-time {self.default_lease_time};")
         if self.max_lease_time:
             lines.append(f"max-lease-time {self.max_lease_time};")
 
@@ -177,8 +177,8 @@
             lines.append(f"\t\toption routers {router};")
             lines.append(f"\t\trange {start} {end};")
             if lease_time:
-                lines.append("\t\tdefault-lease-time %d;" % lease_time)
-                lines.append("\t\tmax-lease-time %d;" % lease_time)
+                lines.append(f"\t\tdefault-lease-time {lease_time};")
+                lines.append(f"\t\tmax-lease-time {lease_time};")
             for param, value in additional_parameters.items():
                 lines.append(f"\t\t{param} {value};")
             for option, value in additional_options.items():
@@ -196,8 +196,8 @@
             lines.append(f"\thardware ethernet {identifier};")
             lines.append(f"\tfixed-address {fixed_address};")
             if lease_time:
-                lines.append("\tdefault-lease-time %d;" % lease_time)
-                lines.append("\tmax-lease-time %d;" % lease_time)
+                lines.append(f"\tdefault-lease-time {lease_time};")
+                lines.append(f"\tmax-lease-time {lease_time};")
             lines.append("}")
 
         config_str = "\n".join(lines)
diff --git a/packages/antlion/controllers/utils_lib/commands/shell.py b/packages/antlion/controllers/utils_lib/commands/shell.py
index 2e57e4f..b852813 100644
--- a/packages/antlion/controllers/utils_lib/commands/shell.py
+++ b/packages/antlion/controllers/utils_lib/commands/shell.py
@@ -241,4 +241,4 @@
             job.Error: Raised when the signal fail to reach
                        the specified program.
         """
-        self.run("kill -%d %d" % (sig, pid))
+        self.run(f"kill -{sig} {pid}")
diff --git a/packages/antlion/controllers/utils_lib/ssh/connection.py b/packages/antlion/controllers/utils_lib/ssh/connection.py
index 35550a8..e5e2bb5 100644
--- a/packages/antlion/controllers/utils_lib/ssh/connection.py
+++ b/packages/antlion/controllers/utils_lib/ssh/connection.py
@@ -368,7 +368,7 @@
             "-n": None,  # Read from /dev/null for stdin
             "-N": None,  # Do not execute a remote command
             "-q": None,  # Suppress warnings and diagnostic commands
-            "-L": "%d:localhost:%d" % (local_port, port),
+            "-L": f"{local_port}:localhost:{port}",
         }
         extra_options = dict()
         if self._master_ssh_proc:
diff --git a/packages/antlion/test_utils/wifi/wifi_test_utils.py b/packages/antlion/test_utils/wifi/wifi_test_utils.py
index 21e5abf..5186327 100755
--- a/packages/antlion/test_utils/wifi/wifi_test_utils.py
+++ b/packages/antlion/test_utils/wifi/wifi_test_utils.py
@@ -1714,14 +1714,14 @@
             )
     except Empty:
         asserts.fail(
-            "Failed to connect to network with id %d on %s" % (network_id, ad.serial)
+            f"Failed to connect to network with id {network_id} on {ad.serial}"
         )
     except Exception as error:
         ad.log.error(
             "Failed to connect to network with id %d with error %s", network_id, error
         )
         raise signals.TestFailure(
-            "Failed to connect to network with network" " id %d" % network_id
+            f"Failed to connect to network with network id {network_id}"
         )
     finally:
         ad.droid.wifiStopTrackingStateChange()
@@ -2805,11 +2805,11 @@
     hostapd_2g = test.access_points[AP - 1]._aps["wlan0"].hostapd
     if hostapd_2g.is_alive():
         hostapd_2g.stop()
-        logging.debug("Turned WLAN0 AP%d off" % AP)
+        logging.debug(f"Turned WLAN0 AP{AP} off")
     hostapd_5g = test.access_points[AP - 1]._aps["wlan1"].hostapd
     if hostapd_5g.is_alive():
         hostapd_5g.stop()
-        logging.debug("Turned WLAN1 AP%d off" % AP)
+        logging.debug(f"Turned WLAN1 AP{AP} off")
 
 
 def turn_ap_on(test, AP):
@@ -2821,11 +2821,11 @@
     hostapd_2g = test.access_points[AP - 1]._aps["wlan0"].hostapd
     if not hostapd_2g.is_alive():
         hostapd_2g.start(hostapd_2g.config)
-        logging.debug("Turned WLAN0 AP%d on" % AP)
+        logging.debug(f"Turned WLAN0 AP{AP} on")
     hostapd_5g = test.access_points[AP - 1]._aps["wlan1"].hostapd
     if not hostapd_5g.is_alive():
         hostapd_5g.start(hostapd_5g.config)
-        logging.debug("Turned WLAN1 AP%d on" % AP)
+        logging.debug(f"Turned WLAN1 AP{AP} on")
 
 
 def turn_location_off_and_scan_toggle_off(ad):
diff --git a/packages/antlion/utils.py b/packages/antlion/utils.py
index 98e08f2..59ecfcb 100755
--- a/packages/antlion/utils.py
+++ b/packages/antlion/utils.py
@@ -1042,7 +1042,7 @@
     """
     ping_cmd = "ping -W 1"
     if count:
-        ping_cmd += " -c %d" % count
+        ping_cmd += f" -c {count}"
     if dest_ip:
         ping_cmd += f" {dest_ip}"
     try:
diff --git a/tests/wlan/functional/ConnectionStressTest.py b/tests/wlan/functional/ConnectionStressTest.py
index cff112a..e2d1036 100644
--- a/tests/wlan/functional/ConnectionStressTest.py
+++ b/tests/wlan/functional/ConnectionStressTest.py
@@ -51,7 +51,7 @@
                 "connection_stress_test_iterations", self.num_of_iterations
             )
         )
-        self.log.info("iterations: %d" % self.num_of_iterations)
+        self.log.info(f"iterations: {self.num_of_iterations}")
 
     def teardown_test(self):
         self.dut.reset_wifi()
@@ -69,7 +69,7 @@
             profile: Profile name such as 'whirlwind'
             channel: Channel to operate on
         """
-        self.log.info("Profile: %s, Channel: %d" % (profile, channel))
+        self.log.info(f"Profile: {profile}, Channel: {channel}")
         setup_ap(
             access_point=self.access_point,
             profile_name=profile,
@@ -116,7 +116,7 @@
                 if not self.dut.associate(
                     ssid, target_pwd=password, target_security=target_security
                 ):
-                    self.log.info("Attempt %d. Did not associate as expected." % x)
+                    self.log.info(f"Attempt {x}. Did not associate as expected.")
                 else:
                     self.log.error(
                         "Attempt %d. Negative test successfully "
@@ -126,9 +126,9 @@
             else:
                 # Connect
                 if self.dut.associate(ssid, target_pwd=password):
-                    self.log.info("Attempt %d. Successfully associated" % x)
+                    self.log.info(f"Attempt {x}. Successfully associated")
                 else:
-                    self.log.error("Attempt %d. Failed to associate." % x)
+                    self.log.error(f"Attempt {x}. Failed to associate.")
                     failed = True
                 # Disconnect
                 self.dut.disconnect()
diff --git a/tests/wlan/functional/DownloadStressTest.py b/tests/wlan/functional/DownloadStressTest.py
index b0d0af4..eecf373 100644
--- a/tests/wlan/functional/DownloadStressTest.py
+++ b/tests/wlan/functional/DownloadStressTest.py
@@ -96,7 +96,7 @@
         return utils.http_file_download_by_curl(
             self.dut.device,
             url,
-            additional_args="--max-time %d --silent" % self.download_timeout_s,
+            additional_args=f"--max-time {self.download_timeout_s} --silent",
         )
 
     def download_thread(self, url):
@@ -116,7 +116,7 @@
         try:
             # Start multiple downloads at the same time
             for index, url in enumerate(download_urls):
-                self.log.info("Create and start thread %d." % index)
+                self.log.info(f"Create and start thread {index}.")
                 t = threading.Thread(target=self.download_thread, args=(url,))
                 download_threads.append(t)
                 t.start()
@@ -134,12 +134,12 @@
                     is_alive = True
 
             if is_alive:
-                raise signals.TestFailure("Thread %d timedout" % index)
+                raise signals.TestFailure(f"Thread {index} timedout")
 
         for index in range(0, len(self.download_threads_result)):
             if not self.download_threads_result[index]:
-                self.log.info("Download failed for %d" % index)
-                raise signals.TestFailure("Thread %d failed to download" % index)
+                self.log.info(f"Download failed for {index}")
+                raise signals.TestFailure(f"Thread {index} failed to download")
                 return False
 
         return True
@@ -176,12 +176,12 @@
                         is_alive = True
 
                 if is_alive:
-                    raise signals.TestFailure("Thread %d timedout" % index)
+                    raise signals.TestFailure(f"Thread {index} timedout")
 
             for index in range(0, len(self.download_threads_result)):
                 if not self.download_threads_result[index]:
-                    self.log.info("Download failed for %d" % index)
-                    raise signals.TestFailure("Thread %d failed to download" % index)
+                    self.log.info(f"Download failed for {index}")
+                    raise signals.TestFailure(f"Thread {index} failed to download")
                     return False
 
             # Clear results before looping again
diff --git a/tests/wlan/functional/WlanScanTest.py b/tests/wlan/functional/WlanScanTest.py
index bb49431..85d629f 100644
--- a/tests/wlan/functional/WlanScanTest.py
+++ b/tests/wlan/functional/WlanScanTest.py
@@ -232,11 +232,11 @@
         self.log.info("scan contained %d results", len(scan_results))
 
         total_time_ms = (datetime.now() - start_time).total_seconds() * 1000
-        self.log.info("scan time: %d ms", total_time_ms)
+        self.log.info(f"scan time: {total_time_ms:.2f} ms")
 
         if len(scan_results) > 0:
             raise signals.TestPass(
-                details="", extras={"Scan time": "%d" % total_time_ms}
+                details="", extras={"Scan time": f"{total_time_ms:.2f}"}
             )
         else:
             raise signals.TestFailure("Scan failed or did not " "find any networks")
diff --git a/tests/wlan_policy/HiddenNetworksTest.py b/tests/wlan_policy/HiddenNetworksTest.py
index 8885d75..fb687bb 100644
--- a/tests/wlan_policy/HiddenNetworksTest.py
+++ b/tests/wlan_policy/HiddenNetworksTest.py
@@ -118,7 +118,7 @@
                 # Don't overload SL4F with scan requests
                 time.sleep(1)
 
-            self.log.error("Failed to see SSID after %d scans" % num_performed_scans)
+            self.log.error(f"Failed to see SSID after {num_performed_scans} scans")
             raise signals.TestFailure("Failed to see hidden network in scans")
 
     def test_auto_connect_hidden_on_startup(self):