summaryrefslogtreecommitdiff
path: root/cloudinit/helpers.py
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2017-08-23 13:24:38 -0600
committerChad Smith <chad.smith@canonical.com>2017-08-23 13:24:38 -0600
commitf831a874021f3d6d24cbe5639a176f416b5436a6 (patch)
treebde30e1520ea195fdf3c2d2faeca47810f7f4034 /cloudinit/helpers.py
parentcc9762a2d737ead386ffb9f067adc5e543224560 (diff)
downloadvyos-cloud-init-f831a874021f3d6d24cbe5639a176f416b5436a6.tar.gz
vyos-cloud-init-f831a874021f3d6d24cbe5639a176f416b5436a6.zip
cc_landscape & cc_puppet: Fix six.StringIO use in writing configs
Both landscape and puppet modules had issues with the way they wrote /etc/landscape/client.conf or /etc/puppet/puppet.conf in either python3 or python2. This branch adds initial unit tests for both modules which will get better exercise under both python2 and python3. The unit tests shed light on a few issues: - In the cc_landscape module py3 can't provide six.StringIO content to ConfigParser.write, so we need to use six.BytesIO instead - In the cc_puppet module, python <= 2.7 doesn't support using six.StringIO as a context manager, so we drop the context manager fanciness and directly set outputstream = StringIO(). - The docstring in cc_puppet is fixed to document the 'conf' sub-key requiring valid puppet section names for each key-value list. LP: #1699282 LP: #1710932
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r--cloudinit/helpers.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index f01021aa..1979cd96 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -13,7 +13,7 @@ from time import time
import contextlib
import os
-import six
+from six import StringIO
from six.moves.configparser import (
NoSectionError, NoOptionError, RawConfigParser)
@@ -441,12 +441,12 @@ class DefaultingConfigParser(RawConfigParser):
def stringify(self, header=None):
contents = ''
- with six.StringIO() as outputstream:
- self.write(outputstream)
- outputstream.flush()
- contents = outputstream.getvalue()
- if header:
- contents = "\n".join([header, contents])
+ outputstream = StringIO()
+ self.write(outputstream)
+ outputstream.flush()
+ contents = outputstream.getvalue()
+ if header:
+ contents = '\n'.join([header, contents, ''])
return contents
# vi: ts=4 expandtab