Merge ~larsks/cloud-init:rhbz/1408589 into cloud-init:master

Proposed by Lars Kellogg-Stedman
Status: Merged
Merged at revision: 4cf53f1544f8f5629330eab3efef1a18255c277a
Proposed branch: ~larsks/cloud-init:rhbz/1408589
Merge into: cloud-init:master
Diff against target: 92 lines (+16/-7)
2 files modified
cloudinit/sources/DataSourceOpenStack.py (+12/-3)
tests/unittests/test_datasource/test_openstack.py (+4/-4)
Reviewer Review Type Date Requested Status
Scott Moser Needs Fixing
Review via email: mp+314912@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Lars,
This looks conceptually fine, but you've broken some unit tests that pass a timeout to get_data.
So those need fixing.

Also, Could you please take a quick review of https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/314926 that I've added and references the 'retries' variable that you added here.

Revision history for this message
Scott Moser (smoser) :
review: Needs Fixing
Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

I've updated the tests so call get_data() without keywords.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/DataSourceOpenStack.py b/cloudinit/sources/DataSourceOpenStack.py
2index 2a58f1c..e1ea21f 100644
3--- a/cloudinit/sources/DataSourceOpenStack.py
4+++ b/cloudinit/sources/DataSourceOpenStack.py
5@@ -45,6 +45,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
6 # max_wait < 0 indicates do not wait
7 max_wait = -1
8 timeout = 10
9+ retries = 5
10
11 try:
12 max_wait = int(self.ds_cfg.get("max_wait", max_wait))
13@@ -55,7 +56,13 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
14 timeout = max(0, int(self.ds_cfg.get("timeout", timeout)))
15 except Exception:
16 util.logexc(LOG, "Failed to get timeout, using %s", timeout)
17- return (max_wait, timeout)
18+
19+ try:
20+ retries = int(self.ds_cfg.get("retries", retries))
21+ except Exception:
22+ util.logexc(LOG, "Failed to get max wait. using %s", retries)
23+
24+ return (max_wait, timeout, retries)
25
26 def wait_for_metadata_service(self):
27 urls = self.ds_cfg.get("metadata_urls", [DEF_MD_URL])
28@@ -76,7 +83,7 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
29 md_urls.append(md_url)
30 url2base[md_url] = url
31
32- (max_wait, timeout) = self._get_url_settings()
33+ (max_wait, timeout, retries) = self._get_url_settings()
34 start_time = time.time()
35 avail_url = url_helper.wait_for_url(urls=md_urls, max_wait=max_wait,
36 timeout=timeout)
37@@ -89,13 +96,15 @@ class DataSourceOpenStack(openstack.SourceMixin, sources.DataSource):
38 self.metadata_address = url2base.get(avail_url)
39 return bool(avail_url)
40
41- def get_data(self, retries=5, timeout=5):
42+ def get_data(self):
43 try:
44 if not self.wait_for_metadata_service():
45 return False
46 except IOError:
47 return False
48
49+ (max_wait, timeout, retries) = self._get_url_settings()
50+
51 try:
52 results = util.log_time(LOG.debug,
53 'Crawl of openstack metadata service',
54diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py
55index e5b6fcc..28e1833 100644
56--- a/tests/unittests/test_datasource/test_openstack.py
57+++ b/tests/unittests/test_datasource/test_openstack.py
58@@ -232,7 +232,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
59 None,
60 helpers.Paths({}))
61 self.assertIsNone(ds_os.version)
62- found = ds_os.get_data(timeout=0.1, retries=0)
63+ found = ds_os.get_data()
64 self.assertTrue(found)
65 self.assertEqual(2, ds_os.version)
66 md = dict(ds_os.metadata)
67@@ -256,7 +256,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
68 None,
69 helpers.Paths({}))
70 self.assertIsNone(ds_os.version)
71- found = ds_os.get_data(timeout=0.1, retries=0)
72+ found = ds_os.get_data()
73 self.assertFalse(found)
74 self.assertIsNone(ds_os.version)
75
76@@ -275,7 +275,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
77 'timeout': 0,
78 }
79 self.assertIsNone(ds_os.version)
80- found = ds_os.get_data(timeout=0.1, retries=0)
81+ found = ds_os.get_data()
82 self.assertFalse(found)
83 self.assertIsNone(ds_os.version)
84
85@@ -298,7 +298,7 @@ class TestOpenStackDataSource(test_helpers.HttprettyTestCase):
86 'timeout': 0,
87 }
88 self.assertIsNone(ds_os.version)
89- found = ds_os.get_data(timeout=0.1, retries=0)
90+ found = ds_os.get_data()
91 self.assertFalse(found)
92 self.assertIsNone(ds_os.version)
93

Subscribers

People subscribed via source and target branches