Merge ~smoser/cloud-init:feature/load_shell_content-comments into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merge reported by: Scott Moser
Merged at revision: be8e84b3639d41202a4e1ce7626b2053498fecdb
Proposed branch: ~smoser/cloud-init:feature/load_shell_content-comments
Merge into: cloud-init:master
Diff against target: 38 lines (+17/-1)
2 files modified
cloudinit/util.py (+1/-1)
tests/unittests/test_util.py (+16/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Ryan Harper Approve
Review via email: mp+327525@code.launchpad.net

Commit message

Support comments in content read by load_shell_content.

load_shell_content previously would not allow shell comment characters
in the content being parsed. If comments=True is not passed then an
exception would previously be raised as the line would not be guaranteed to
have an '=' in it.

To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) :
review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:be8e84b3639d41202a4e1ce7626b2053498fecdb
https://jenkins.ubuntu.com/server/job/cloud-init-ci/41/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: CentOS 6 & 7: Build & Test
    IN_PROGRESS: Declarative: Post Actions

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

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/util.py b/cloudinit/util.py
2index b486e18..f570b9d 100644
3--- a/cloudinit/util.py
4+++ b/cloudinit/util.py
5@@ -2529,7 +2529,7 @@ def load_shell_content(content, add_empty=False, empty_val=None):
6 if PY26 and isinstance(blob, six.text_type):
7 # Older versions don't support unicode input
8 blob = blob.encode("utf8")
9- return shlex.split(blob)
10+ return shlex.split(blob, comments=True)
11
12 data = {}
13 for line in _shlex_split(content):
14diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
15index 65035be..f38a664 100644
16--- a/tests/unittests/test_util.py
17+++ b/tests/unittests/test_util.py
18@@ -807,4 +807,20 @@ class TestSystemIsSnappy(helpers.FilesystemMockingTestCase):
19 self.reRoot(root_d)
20 self.assertTrue(util.system_is_snappy())
21
22+
23+class TestLoadShellContent(helpers.TestCase):
24+ def test_comments_handled_correctly(self):
25+ """Shell comments should be allowed in the content."""
26+ self.assertEqual(
27+ {'key1': 'val1', 'key2': 'val2', 'key3': 'val3 #tricky'},
28+ util.load_shell_content('\n'.join([
29+ "#top of file comment",
30+ "key1=val1 #this is a comment",
31+ "# second comment",
32+ 'key2="val2" # inlin comment'
33+ '#badkey=wark',
34+ 'key3="val3 #tricky"',
35+ ''])))
36+
37+
38 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches