summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorSergii Golovatiuk <sgolovatiuk@mirantis.com>2016-07-14 16:58:56 +0200
committerSergii Golovatiuk <sgolovatiuk@mirantis.com>2016-07-14 16:58:56 +0200
commit200e811268b7c17e814cfb6b7ef3f603c0590abc (patch)
treef767381cae14c9d66e7e224e4863f1910e1e3293 /tests/unittests
parentb3193a4b5204d12825d8317bf0f8c3577c1d8153 (diff)
downloadvyos-cloud-init-200e811268b7c17e814cfb6b7ef3f603c0590abc.tar.gz
vyos-cloud-init-200e811268b7c17e814cfb6b7ef3f603c0590abc.zip
Change StringIO to BytesIO in cc_mcollective.py
* StringIO from six doesn't act as 'binary stream' in Python 3. This patch changes StringIO to BytesIO to have code compatible with Python 3 and Python 2. * Add try/except for IOError in case when server.cfg doesn't exists. This is necessary for unit tests or cases when server.cfg is not included to package * Add UnitTest for cc_mcollective.py LP: #1597699
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_handler/test_handler_mcollective.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_handler_mcollective.py b/tests/unittests/test_handler/test_handler_mcollective.py
new file mode 100644
index 00000000..0e3fcc8c
--- /dev/null
+++ b/tests/unittests/test_handler/test_handler_mcollective.py
@@ -0,0 +1,60 @@
+from cloudinit.config import cc_mcollective
+from cloudinit import util
+
+from .. import helpers
+
+import configobj
+import logging
+import shutil
+from six import BytesIO
+import tempfile
+
+LOG = logging.getLogger(__name__)
+
+
+class TestConfig(helpers.FilesystemMockingTestCase):
+ def setUp(self):
+ super(TestConfig, self).setUp()
+ self.tmp = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, self.tmp)
+
+ def test_basic_config(self):
+ cfg = {
+ 'mcollective': {
+ 'conf': {
+ 'loglevel': 'debug',
+ 'connector': 'rabbitmq',
+ 'logfile': '/var/log/mcollective.log',
+ 'ttl': '4294957',
+ 'collectives': 'mcollective',
+ 'main_collective': 'mcollective',
+ 'securityprovider': 'psk',
+ 'daemonize': '1',
+ 'factsource': 'yaml',
+ 'direct_addressing': '1',
+ 'plugin.psk': 'unset',
+ 'libdir': '/usr/share/mcollective/plugins',
+ 'identity': '1',
+ },
+ },
+ }
+ self.patchUtils(self.tmp)
+ cc_mcollective.configure(cfg['mcollective']['conf'])
+ contents = util.load_file("/etc/mcollective/server.cfg", decode=False)
+ contents = configobj.ConfigObj(BytesIO(contents))
+ expected = {
+ 'loglevel': 'debug',
+ 'connector': 'rabbitmq',
+ 'logfile': '/var/log/mcollective.log',
+ 'ttl': '4294957',
+ 'collectives': 'mcollective',
+ 'main_collective': 'mcollective',
+ 'securityprovider': 'psk',
+ 'daemonize': '1',
+ 'factsource': 'yaml',
+ 'direct_addressing': '1',
+ 'plugin.psk': 'unset',
+ 'libdir': '/usr/share/mcollective/plugins',
+ 'identity': '1',
+ }
+ self.assertEqual(expected, dict(contents))