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
diff --git a/cloudinit/util.py b/cloudinit/util.py
index b486e18..f570b9d 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2529,7 +2529,7 @@ def load_shell_content(content, add_empty=False, empty_val=None):
2529 if PY26 and isinstance(blob, six.text_type):2529 if PY26 and isinstance(blob, six.text_type):
2530 # Older versions don't support unicode input2530 # Older versions don't support unicode input
2531 blob = blob.encode("utf8")2531 blob = blob.encode("utf8")
2532 return shlex.split(blob)2532 return shlex.split(blob, comments=True)
25332533
2534 data = {}2534 data = {}
2535 for line in _shlex_split(content):2535 for line in _shlex_split(content):
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 65035be..f38a664 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -807,4 +807,20 @@ class TestSystemIsSnappy(helpers.FilesystemMockingTestCase):
807 self.reRoot(root_d)807 self.reRoot(root_d)
808 self.assertTrue(util.system_is_snappy())808 self.assertTrue(util.system_is_snappy())
809809
810
811class TestLoadShellContent(helpers.TestCase):
812 def test_comments_handled_correctly(self):
813 """Shell comments should be allowed in the content."""
814 self.assertEqual(
815 {'key1': 'val1', 'key2': 'val2', 'key3': 'val3 #tricky'},
816 util.load_shell_content('\n'.join([
817 "#top of file comment",
818 "key1=val1 #this is a comment",
819 "# second comment",
820 'key2="val2" # inlin comment'
821 '#badkey=wark',
822 'key3="val3 #tricky"',
823 ''])))
824
825
810# vi: ts=4 expandtab826# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches