|
|
ef3f20 |
From c98408a2cf874435c7423a1574a9ffc81053707a Mon Sep 17 00:00:00 2001
|
|
|
ef3f20 |
From: Lars Kellogg-Stedman <lars@redhat.com>
|
|
|
ef3f20 |
Date: Tue, 17 Jan 2017 08:53:22 -0500
|
|
|
ef3f20 |
Subject: [PATCH] OpenStack: Use timeout and retries from config in get_data.
|
|
|
ef3f20 |
|
|
|
ef3f20 |
This modifies get_data in DataSourceOpenStack.py to get the timeout
|
|
|
ef3f20 |
and retries values from the data source configuration, rather than
|
|
|
ef3f20 |
from keyword arguments. This permits get_data to use the same timeout
|
|
|
ef3f20 |
as other methods, and allows an operator to increase the timeout in
|
|
|
ef3f20 |
environments where the metadata service takes longer than five seconds
|
|
|
ef3f20 |
to respond.
|
|
|
ef3f20 |
|
|
|
ef3f20 |
LP: #1657130
|
|
|
ef3f20 |
Resolves: rhbz#1408589
|
|
|
ef3f20 |
(cherry picked from commit 4cf53f1544f8f5629330eab3efef1a18255c277a)
|
|
|
ef3f20 |
---
|
|
|
ef3f20 |
cloudinit/sources/DataSourceOpenStack.py | 15 ++++++++++++---
|
|
|
ef3f20 |
tests/unittests/test_datasource/test_openstack.py | 8 ++++----
|
|
|
ef3f20 |
2 files changed, 16 insertions(+), 7 deletions(-)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py
|
|
|
ef3f20 |
index 2a58f1c..e1ea21f 100644
|
|
|
ef3f20 |
--- a/cloudinit/sources/DataSourceOpenStack.py
|
|
|
ef3f20 |
+++ b/cloudinit/sources/DataSourceOpenStack.py
|
|
|
ef3f20 |
@@ -45,6 +45,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
|
|
|
ef3f20 |
# max_wait < 0 indicates do not wait
|
|
|
ef3f20 |
max_wait = -1
|
|
|
ef3f20 |
timeout = 10
|
|
|
ef3f20 |
+ retries = 5
|
|
|
ef3f20 |
|
|
|
ef3f20 |
try:
|
|
|
ef3f20 |
max_wait = int(self.ds_cfg.get("max_wait", max_wait))
|
|
|
ef3f20 |
@@ -55,7 +56,13 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
|
|
|
ef3f20 |
timeout = max(0, int(self.ds_cfg.get("timeout", timeout)))
|
|
|
ef3f20 |
except Exception:
|
|
|
ef3f20 |
util.logexc(LOG, "Failed to get timeout, using %s", timeout)
|
|
|
ef3f20 |
- return (max_wait, timeout)
|
|
|
ef3f20 |
+
|
|
|
ef3f20 |
+ try:
|
|
|
ef3f20 |
+ retries = int(self.ds_cfg.get("retries", retries))
|
|
|
ef3f20 |
+ except Exception:
|
|
|
ef3f20 |
+ util.logexc(LOG, "Failed to get max wait. using %s", retries)
|
|
|
ef3f20 |
+
|
|
|
ef3f20 |
+ return (max_wait, timeout, retries)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
def wait_for_metadata_service(self):
|
|
|
ef3f20 |
urls = self.ds_cfg.get("metadata_urls", [DEF_MD_URL])
|
|
|
ef3f20 |
@@ -76,7 +83,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
|
|
|
ef3f20 |
md_urls.append(md_url)
|
|
|
ef3f20 |
url2base[md_url] = url
|
|
|
ef3f20 |
|
|
|
ef3f20 |
- (max_wait, timeout) = self._get_url_settings()
|
|
|
ef3f20 |
+ (max_wait, timeout, retries) = self._get_url_settings()
|
|
|
ef3f20 |
start_time = time.time()
|
|
|
ef3f20 |
avail_url = url_helper.wait_for_url(urls=md_urls, max_wait=max_wait,
|
|
|
ef3f20 |
timeout=timeout)
|
|
|
ef3f20 |
@@ -89,13 +96,15 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
|
|
|
ef3f20 |
self.metadata_address = url2base.get(avail_url)
|
|
|
ef3f20 |
return bool(avail_url)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
- def get_data(self, retries=5, timeout=5):
|
|
|
ef3f20 |
+ def get_data(self):
|
|
|
ef3f20 |
try:
|
|
|
ef3f20 |
if not self.wait_for_metadata_service():
|
|
|
ef3f20 |
return False
|
|
|
ef3f20 |
except IOError:
|
|
|
ef3f20 |
return False
|
|
|
ef3f20 |
|
|
|
ef3f20 |
+ (max_wait, timeout, retries) = self._get_url_settings()
|
|
|
ef3f20 |
+
|
|
|
ef3f20 |
try:
|
|
|
ef3f20 |
results = util.log_time(LOG.debug,
|
|
|
ef3f20 |
'Crawl of openstack metadata service',
|
|
|
ef3f20 |
diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py
|
|
|
ef3f20 |
index e5b6fcc..28e1833 100644
|
|
|
ef3f20 |
--- a/tests/unittests/test_datasource/test_openstack.py
|
|
|
ef3f20 |
+++ b/tests/unittests/test_datasource/test_openstack.py
|
|
|
ef3f20 |
@@ -232,7 +232,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
|
|
|
ef3f20 |
None,
|
|
|
ef3f20 |
helpers.Paths({}))
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
- found = ds_os.get_data(timeout=0.1, retries=0)
|
|
|
ef3f20 |
+ found = ds_os.get_data()
|
|
|
ef3f20 |
self.assertTrue(found)
|
|
|
ef3f20 |
self.assertEqual(2, ds_os.version)
|
|
|
ef3f20 |
md = dict(ds_os.metadata)
|
|
|
ef3f20 |
@@ -256,7 +256,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
|
|
|
ef3f20 |
None,
|
|
|
ef3f20 |
helpers.Paths({}))
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
- found = ds_os.get_data(timeout=0.1, retries=0)
|
|
|
ef3f20 |
+ found = ds_os.get_data()
|
|
|
ef3f20 |
self.assertFalse(found)
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
@@ -275,7 +275,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
|
|
|
ef3f20 |
'timeout': 0,
|
|
|
ef3f20 |
}
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
- found = ds_os.get_data(timeout=0.1, retries=0)
|
|
|
ef3f20 |
+ found = ds_os.get_data()
|
|
|
ef3f20 |
self.assertFalse(found)
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
@@ -298,7 +298,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
|
|
|
ef3f20 |
'timeout': 0,
|
|
|
ef3f20 |
}
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
- found = ds_os.get_data(timeout=0.1, retries=0)
|
|
|
ef3f20 |
+ found = ds_os.get_data()
|
|
|
ef3f20 |
self.assertFalse(found)
|
|
|
ef3f20 |
self.assertIsNone(ds_os.version)
|
|
|
ef3f20 |
|