From 56f1939061392c848268ae063908bf2188f07373 Mon Sep 17 00:00:00 2001 From: Moustafa Moustafa Date: Wed, 3 Jun 2020 13:39:48 -0700 Subject: Enhance poll imds logging (#365) Improving the debugability of this code path by logging the thrown exception details for the non 404 exceptions. Retry IMDS on HTTP Error 404 and 410, re-run DHCP on other exceptions. --- tests/unittests/test_datasource/test_azure.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tests/unittests/test_datasource') diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py index d8d812e3..b9f4d8fd 100644 --- a/tests/unittests/test_datasource/test_azure.py +++ b/tests/unittests/test_datasource/test_azure.py @@ -1951,11 +1951,12 @@ class TestPreprovisioningPollIMDS(CiTestCase): self.tries += 1 if self.tries == 1: raise requests.Timeout('Fake connection timeout') - elif self.tries == 2: + elif self.tries in (2, 3): response = requests.Response() - response.status_code = 404 + response.status_code = 404 if self.tries == 2 else 410 raise requests.exceptions.HTTPError( - "fake 404", response=response) + "fake {}".format(response.status_code), + response=response) # Third try should succeed and stop retries or redhcp return mock.MagicMock(status_code=200, text="good", content="good") @@ -1967,7 +1968,7 @@ class TestPreprovisioningPollIMDS(CiTestCase): self.assertEqual(report_ready_func.call_count, 1) report_ready_func.assert_called_with(lease=lease) self.assertEqual(3, m_dhcpv4.call_count, 'Expected 3 DHCP calls') - self.assertEqual(3, self.tries, 'Expected 3 total reads from IMDS') + self.assertEqual(4, self.tries, 'Expected 4 total reads from IMDS') def test_poll_imds_report_ready_false(self, report_ready_func, fake_resp, -- cgit v1.2.3