Pass DHCP tests on multiple discovers/offers

Allow DHCP tests to pass when the Fuchsia DHCP client enqueues discover
packets while EAPOL is in progress. Remove this logic if this is deemed
unacceptable behavior.

Bug: b/384790032
Change-Id: I362b587ab26b7dfad5b6c696b3de90e8fbdd9766
Reviewed-on: https://fuchsia-review.googlesource.com/c/antlion/+/1184761
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Peter Johnston <peterjohnston@google.com>
Fuchsia-Auto-Submit: Sam Balana <sbalana@google.com>
diff --git a/packages/antlion/test_utils/dhcp/base_test.py b/packages/antlion/test_utils/dhcp/base_test.py
index e3272c5..8c50ac7 100644
--- a/packages/antlion/test_utils/dhcp/base_test.py
+++ b/packages/antlion/test_utils/dhcp/base_test.py
@@ -224,10 +224,22 @@
             self.connect(ap_params=ap_params)
 
             # Typical log lines look like:
-            # dhcpd[26695]: DHCPDISCOVER from f8:0f:f9:3d:ce:d1 via wlan1
-            # dhcpd[26695]: DHCPOFFER on 192.168.9.2 to f8:0f:f9:3d:ce:d1 via wlan1
-            # dhcpd[26695]: DHCPREQUEST for 192.168.9.2 (192.168.9.1) from f8:0f:f9:3d:ce:d1 via wlan1
-            # dhcpd[26695]: DHCPACK on 192.168.9.2 to f8:0f:f9:3d:ce:d1 via wlan1
+            #
+            # dhcpd[26695]: DHCPDISCOVER from 01:23:45:67:89:ab via wlan1
+            # dhcpd[26695]: DHCPOFFER on 192.168.9.2 to 01:23:45:67:89:ab via wlan1
+            # dhcpd[26695]: DHCPREQUEST for 192.168.9.2 (192.168.9.1) from 01:23:45:67:89:ab via wlan1
+            # dhcpd[26695]: DHCPACK on 192.168.9.2 to 01:23:45:67:89:ab via wlan1
+
+            # Due to b/384790032, logs can also show duplicate DISCOVER and
+            # OFFER packets due to the Fuchsia DHCP client queuing packets while
+            # EAPOL is in progress:
+            #
+            # DHCPDISCOVER from 01:23:45:67:89:ab via wlan1
+            # DHCPOFFER on 192.168.9.2 to 01:23:45:67:89:ab via wlan1
+            # DHCPDISCOVER from 01:23:45:67:89:ab via wlan1
+            # DHCPOFFER on 192.168.9.2 to 01:23:45:67:89:ab via wlan1
+            # DHCPREQUEST for 192.168.9.2 (192.168.9.1) from 01:23:45:67:89:ab via wlan1
+            # DHCPACK on 192.168.9.2 to 01:23:45:67:89:ab via wlan1
 
             try:
                 ip = self.get_device_ipv4_addr()
@@ -240,22 +252,37 @@
             if dhcp_logs is None:
                 raise signals.TestFailure("No DHCP logs")
 
-            expected_string = f"DHCPDISCOVER from"
-            asserts.assert_equal(
-                dhcp_logs.count(expected_string),
-                1,
-                f'Incorrect count of DHCP Discovers ("{expected_string}") in logs:\n'
-                + dhcp_logs
-                + "\n",
-            )
+            # TODO(http://b/384790032): Replace with logic below with this
+            # comment once DHCP is started after EAPOL finishes. Or remove this
+            # comment if queueing is determined expected and acceptable
+            # behavior.
+            #
+            # expected_string = f"DHCPDISCOVER from"
+            # asserts.assert_equal(
+            #     dhcp_logs.count(expected_string),
+            #     1,
+            #     f'Incorrect count of DHCP Discovers ("{expected_string}") in logs',
+            #     dhcp_logs,
+            # )
+            #
+            # expected_string = f"DHCPOFFER on {ip}"
+            # asserts.assert_equal(
+            #     dhcp_logs.count(expected_string),
+            #     1,
+            #     f'Incorrect count of DHCP Offers ("{expected_string}") in logs',
+            #     dhcp_logs,
+            # )
 
-            expected_string = f"DHCPOFFER on {ip}"
+            discover_count = dhcp_logs.count("DHCPDISCOVER from")
+            offer_count = dhcp_logs.count(f"DHCPOFFER on {ip}")
+            asserts.assert_greater(
+                discover_count, 0, "Expected one or more DHCP Discovers", dhcp_logs
+            )
             asserts.assert_equal(
-                dhcp_logs.count(expected_string),
-                1,
-                f'Incorrect count of DHCP Offers ("{expected_string}") in logs:\n'
-                + dhcp_logs
-                + "\n",
+                discover_count,
+                offer_count,
+                "Expected an equal amount of DHCP Discovers and Offers",
+                dhcp_logs,
             )
 
             expected_string = f"DHCPREQUEST for {ip}"
diff --git a/tests/dhcp/Dhcpv4InteropBasicTest.py b/tests/dhcp/Dhcpv4InteropBasicTest.py
index 7f3da59..ab07b52 100644
--- a/tests/dhcp/Dhcpv4InteropBasicTest.py
+++ b/tests/dhcp/Dhcpv4InteropBasicTest.py
@@ -85,8 +85,8 @@
 
         # Fuchsia renews at LEASE_TIME / 2, so there should be at least 2 DHCPREQUESTs in logs.
         # The log lines look like:
-        # INFO dhcpd[17385]: DHCPREQUEST for 192.168.9.2 from f8:0f:f9:3d:ce:d1 via wlan1
-        # INFO dhcpd[17385]: DHCPACK on 192.168.9.2 to f8:0f:f9:3d:ce:d1 via wlan1
+        # INFO dhcpd[17385]: DHCPREQUEST for 192.168.9.2 from 01:23:45:67:89:ab via wlan1
+        # INFO dhcpd[17385]: DHCPACK on 192.168.9.2 to 01:23:45:67:89:ab via wlan1
         expected_string = f"DHCPREQUEST for {ip}"
         asserts.assert_true(
             dhcp_logs.count(expected_string) >= 2,