summaryrefslogtreecommitdiff
path: root/cloudinit/tests
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2018-11-13 03:14:58 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-11-13 03:14:58 +0000
commit6062595b83e08e0f12e1fe6d8e367d8db9d91ef8 (patch)
treea9d9d5096aebcb3b01c04efe2344990f0f9e24b2 /cloudinit/tests
parent6f9512049bbb594c3f01ffcd2ab25ae4e016f01e (diff)
downloadvyos-cloud-init-6062595b83e08e0f12e1fe6d8e367d8db9d91ef8.tar.gz
vyos-cloud-init-6062595b83e08e0f12e1fe6d8e367d8db9d91ef8.zip
azure: retry imds polling on requests.Timeout
There is an infrequent race when the booting instance can hit the IMDS service before it is fully available. This results in a requests.ConnectTimeout being raised. Azure's retry_callback logic now retries on either 404s or Timeouts. LP:1800223
Diffstat (limited to 'cloudinit/tests')
-rw-r--r--cloudinit/tests/test_url_helper.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/cloudinit/tests/test_url_helper.py b/cloudinit/tests/test_url_helper.py
index 113249d9..aa9f3ec1 100644
--- a/cloudinit/tests/test_url_helper.py
+++ b/cloudinit/tests/test_url_helper.py
@@ -1,10 +1,12 @@
# This file is part of cloud-init. See LICENSE file for license information.
-from cloudinit.url_helper import oauth_headers, read_file_or_url
+from cloudinit.url_helper import (
+ NOT_FOUND, UrlError, oauth_headers, read_file_or_url, retry_on_url_exc)
from cloudinit.tests.helpers import CiTestCase, mock, skipIf
from cloudinit import util
import httpretty
+import requests
try:
@@ -64,3 +66,24 @@ class TestReadFileOrUrl(CiTestCase):
result = read_file_or_url(url)
self.assertEqual(result.contents, data)
self.assertEqual(str(result), data.decode('utf-8'))
+
+
+class TestRetryOnUrlExc(CiTestCase):
+
+ def test_do_not_retry_non_urlerror(self):
+ """When exception is not UrlError return False."""
+ myerror = IOError('something unexcpected')
+ self.assertFalse(retry_on_url_exc(msg='', exc=myerror))
+
+ def test_perform_retries_on_not_found(self):
+ """When exception is UrlError with a 404 status code return True."""
+ myerror = UrlError(cause=RuntimeError(
+ 'something was not found'), code=NOT_FOUND)
+ self.assertTrue(retry_on_url_exc(msg='', exc=myerror))
+
+ def test_perform_retries_on_timeout(self):
+ """When exception is a requests.Timout return True."""
+ myerror = UrlError(cause=requests.Timeout('something timed out'))
+ self.assertTrue(retry_on_url_exc(msg='', exc=myerror))
+
+# vi: ts=4 expandtab