summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-07-14 11:30:14 -0400
committerScott Moser <smoser@ubuntu.com>2016-07-14 11:30:14 -0400
commit660e04e658381ee52c9dc5f877745614cee15c42 (patch)
tree2e1a411155c04ec2335c18bc6dc38fa08aecf3df /tests/unittests
parent333eea5105956c978043579a49d935af6d3ceff2 (diff)
parentcd1bd176d2f83c2718a0bf921af7ee9116b204c0 (diff)
downloadvyos-cloud-init-660e04e658381ee52c9dc5f877745614cee15c42.tar.gz
vyos-cloud-init-660e04e658381ee52c9dc5f877745614cee15c42.zip
Fix mcollective module with python3
fixes mcollective when used with python3 and also adds a unit test. 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..f9448d80
--- /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))