Merge ~smoser/cloud-init:fix/1792157-openstack-md-version-fix into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Chad Smith
Approved revision: 353c595077c4fb26abead76d7194c8da5d2300c2
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~smoser/cloud-init:fix/1792157-openstack-md-version-fix
Merge into: cloud-init:master
Diff against target: 52 lines (+31/-1)
2 files modified
cloudinit/sources/helpers/openstack.py (+1/-1)
tests/unittests/test_datasource/test_openstack.py (+30/-0)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+354796@code.launchpad.net

Commit message

OpenStack: fix bug causing 'latest' version to be used from network.

Cloud-init was reading a list of versions from the OpenStack metadata
service (http://169.254.169.254/openstack/) and attempt to select the
newest known supported version. The problem was that the list
of versions was not being decoded, so we were comparing a list of
bytes (found versions) to a list of strings (known versions).

LP: #1792157

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

tests coming. but this does fix.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:86f9ffdfc95696025dd5c012cfc578b16a753ba7
https://jenkins.ubuntu.com/server/job/cloud-init-ci/309/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/309/rebuild

review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:353c595077c4fb26abead76d7194c8da5d2300c2
https://jenkins.ubuntu.com/server/job/cloud-init-ci/310/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/310/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Approve, pending your decision about adding Ocata.

review: Approve
Revision history for this message
Scott Moser (smoser) wrote :

https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/354796
ocata is added ^

i went down that path too, but figured it was a feature part of this bug fix.

Revision history for this message
Scott Moser (smoser) :
review: Approve
Revision history for this message
Scott Moser (smoser) wrote :

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
2index 8f9c144..e3d372b 100644
3--- a/cloudinit/sources/helpers/openstack.py
4+++ b/cloudinit/sources/helpers/openstack.py
5@@ -439,7 +439,7 @@ class MetadataReader(BaseReader):
6 return self._versions
7 found = []
8 version_path = self._path_join(self.base_path, "openstack")
9- content = self._path_read(version_path)
10+ content = self._path_read(version_path, decode=True)
11 for line in content.splitlines():
12 line = line.strip()
13 if not line:
14diff --git a/tests/unittests/test_datasource/test_openstack.py b/tests/unittests/test_datasource/test_openstack.py
15index 6e1e971..ab5d3ad 100644
16--- a/tests/unittests/test_datasource/test_openstack.py
17+++ b/tests/unittests/test_datasource/test_openstack.py
18@@ -555,4 +555,34 @@ class TestDetectOpenStack(test_helpers.CiTestCase):
19 m_proc_env.assert_called_with(1)
20
21
22+class TestMetadataReader(test_helpers.HttprettyTestCase):
23+ """Test the MetadataReader."""
24+ burl = 'http://169.254.169.254/'
25+
26+ def register(self, path, body=None, status=200):
27+ hp.register_uri(
28+ hp.GET, self.burl + "openstack" + path, status=status, body=body)
29+
30+ def register_versions(self, versions):
31+ self.register("", '\n'.join(versions).encode('utf-8'))
32+
33+ def test__find_working_version(self):
34+ """Test a working version ignores unsupported."""
35+ unsup = "2016-11-09"
36+ self.register_versions(
37+ [openstack.OS_FOLSOM, openstack.OS_LIBERTY, unsup,
38+ openstack.OS_LATEST])
39+ self.assertEqual(
40+ openstack.OS_LIBERTY,
41+ openstack.MetadataReader(self.burl)._find_working_version())
42+
43+ def test__find_working_version_uses_latest(self):
44+ """'latest' should be used if no supported versions."""
45+ unsup1, unsup2 = ("2016-11-09", '2017-06-06')
46+ self.register_versions([unsup1, unsup2, openstack.OS_LATEST])
47+ self.assertEqual(
48+ openstack.OS_LATEST,
49+ openstack.MetadataReader(self.burl)._find_working_version())
50+
51+
52 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches