From 6e5604c174ae3ddc9dfb5f6884d7df1012fc4041 Mon Sep 17 00:00:00 2001 From: Martin Hilton Date: Wed, 7 Nov 2018 16:46:23 +0000 Subject: fix bionic IP address binding --- hooks/hooks.py | 2 +- unit_tests/test_hooks.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/hooks/hooks.py b/hooks/hooks.py index 54902f5..08a7d62 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -276,7 +276,7 @@ def mongodb_conf(config_data=None): if config_data['bind_ip'] != "all": config.append("bind_ip = %s" % config_data['bind_ip']) elif is_bionic_or_greater(): - config_data['bind_ip'] = '0.0.0.0' + config.append("bind_ip = 0.0.0.0") config.append("") diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py index 3432cfb..ab78bbd 100644 --- a/unit_tests/test_hooks.py +++ b/unit_tests/test_hooks.py @@ -1,3 +1,7 @@ +import os +import shutil +import tempfile + from mock import patch, call from test_utils import CharmTestCase @@ -7,8 +11,6 @@ from subprocess import CalledProcessError import hooks -import tempfile -import os # Defines a set of functions to patch on the hooks object. Any of these # methods will be patched by default on the default invocations of the @@ -434,3 +436,68 @@ class MongoHooksTest(CharmTestCase): self.assertEqual(changed_contents, expected) finally: os.unlink(mocked_upstart.name) + + @patch.object(hooks, 'is_relation_made') + @patch.object(hooks, 'is_bionic_or_greater') + def test_mongodb_conf(self, mock_is_bionic_or_greater, mock_is_relation_made): + mock_is_bionic_or_greater.return_value = False + mock_is_relation_made.return_value = False + tmpdir = tempfile.mkdtemp() + self.test_config.set('dbpath', os.path.join(tmpdir, 'db')) + self.test_config.set('logpath', os.path.join(tmpdir, 'log')) + try: + mongodb_conf = hooks.mongodb_conf(self.test_config.get_all()) + finally: + shutil.rmtree(tmpdir) + expected = """# mongodb.conf + +dbpath={tmpdir}/db + +ipv6=true +logpath={tmpdir}/log + +logappend=true + + +port = 27017 + +journal=true + +diaglog = 0 + +rest = true + +master = true +""".format(tmpdir=tmpdir) + self.assertEqual(mongodb_conf, expected) + + @patch.object(hooks, 'is_relation_made') + @patch.object(hooks, 'is_bionic_or_greater') + def test_mongodb_conf_bionic(self, mock_is_bionic_or_greater, mock_is_relation_made): + mock_is_bionic_or_greater.return_value = True + mock_is_relation_made.return_value = False + tmpdir = tempfile.mkdtemp() + self.test_config.set('dbpath', os.path.join(tmpdir, 'db')) + self.test_config.set('logpath', os.path.join(tmpdir, 'log')) + try: + mongodb_conf = hooks.mongodb_conf(self.test_config.get_all()) + finally: + shutil.rmtree(tmpdir) + expected = """# mongodb.conf + +dbpath={tmpdir}/db + +ipv6=true +logpath={tmpdir}/log + +logappend=true + +bind_ip = 0.0.0.0 + +port = 27017 + +journal=true + +master = true +""".format(tmpdir=tmpdir) + self.assertEqual(mongodb_conf, expected) -- cgit v1.2.3