From eeddd301162f6a71890ff343d30a45c4930e80f8 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Fri, 12 Jun 2015 17:46:15 +0300 Subject: [PATCH] Change the API of wait_any_url to return a tuple of url and response Previously wait_any_url returned the first url which responded correctly, but there was no way to actually retrieve its response. Change-Id: I41aec4fa1f0a5007af70e787a5503ffeb539c783 --- cloudinit/tests/test_url_helper.py | 4 +++- cloudinit/url_helper.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) 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