diff --git a/cloudinit/tests/test_url_helper.py b/cloudinit/tests/test_url_helper.py index 338f0a13..be27d902 100644 --- a/cloudinit/tests/test_url_helper.py +++ b/cloudinit/tests/test_url_helper.py @@ -29,8 +29,10 @@ class UrlHelperWaitForUrlsTest(test.TestCase): url, body=b'no worky', status=400) - url = url_helper.wait_any_url(urls) + url, response = url_helper.wait_any_url(urls) self.assertEqual("http://www.yahoo.com", url) + self.assertIsInstance(response, url_helper.RequestsResponse) + self.assertEqual(response.contents, b'it worked!') @httpretty.activate def test_url_wait_for_no_work(self): diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index eb2d66c3..ec0a7a79 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -226,6 +226,9 @@ def wait_any_url(urls, max_wait=None, timeout=None, service but is not going to find one. It is possible that the instance data host (169.254.169.254) may be firewalled off Entirely for a sytem, meaning that the connection will block forever unless a timeout is set. + + This will return a tuple of the first url which succeeded and the + response object. """ start_time = now() @@ -268,7 +271,7 @@ def wait_any_url(urls, max_wait=None, timeout=None, url_exc = UrlError(ValueError(reason), code=response.code, headers=response.headers) else: - return url + return url, response except UrlError as e: reason = "request error [%s]" % e url_exc = e