From 902aa44e6f4d267b5a7a59abb463f7b22c8d14d8 Mon Sep 17 00:00:00 2001 From: Chris Patterson Date: Mon, 31 Jan 2022 16:35:10 -0500 Subject: sources/azure: refactor _report_ready_if_needed and _poll_imds (#1222) Refactor _report_ready_if_needed() to work for both Savable PPS and Runnable PPS: * rename _report_ready_if_needed() to _report_ready_for_pps() * return interface name from lease to support _poll_imds() behavior without changing it. * fixes an issue where reporting ready return value was silently ignored for Savable PPS. * add explicit handling for failure to obtain DHCP lease to result in sources.InvalidMetaDataException. Refactor _poll_imds(): * use _report_ready_for_pps() for reporting ready, removing this logic to simplify loop logic. * move netlink and vnetswitch out of while loop to simplify loop logic, leaving only reprovision polling in loop. * add explicit handling for failure to obtain DHCP lease and retry in the next iteration. Signed-off-by: Chris Patterson cpatterson@microsoft.com --- tests/unittests/sources/test_azure.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/unittests') diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py index 5581492e..c3d599bc 100644 --- a/tests/unittests/sources/test_azure.py +++ b/tests/unittests/sources/test_azure.py @@ -3213,10 +3213,8 @@ class TestPreprovisioningPollIMDS(CiTestCase): dsaz.BUILTIN_DS_CONFIG["data_dir"] = self.waagent_d @mock.patch("time.sleep", mock.MagicMock()) - @mock.patch(MOCKPATH + "EphemeralDHCPv4WithReporting", autospec=True) def test_poll_imds_re_dhcp_on_timeout( self, - m_dhcpv4, m_report_ready, m_request, m_media_switch, @@ -3236,7 +3234,6 @@ class TestPreprovisioningPollIMDS(CiTestCase): m_media_switch.return_value = None dhcp_ctx = mock.MagicMock(lease=lease) dhcp_ctx.obtain_lease.return_value = lease - m_dhcpv4.return_value = dhcp_ctx self.tries = 0 @@ -3260,7 +3257,7 @@ class TestPreprovisioningPollIMDS(CiTestCase): dsa._poll_imds() self.assertEqual(m_report_ready.call_count, 1) m_report_ready.assert_called_with(lease=lease) - self.assertEqual(3, m_dhcpv4.call_count, "Expected 3 DHCP calls") + self.assertEqual(3, m_dhcp.call_count, "Expected 3 DHCP calls") self.assertEqual(4, self.tries, "Expected 4 total reads from IMDS") @mock.patch("os.path.isfile") -- cgit v1.2.3