summaryrefslogtreecommitdiff
diff options
authorMartin Hilton <martin.hilton@canonical.com>2018-11-13 09:58:18 +0000
committerCanonial IS Mergebot <canonical-is-mergebot@canonical.com>2018-11-13 09:58:18 +0000
commit7c4f968f20391665064f55f6bea0899a4f278202 (patch)
tree0f369ec221771dd8c2a81cef3a1b2ec6896db2f6
parentf04914ab678d2808d0bd8d22386fe5f2f3657470 (diff)
parent6e5604c174ae3ddc9dfb5f6884d7df1012fc4041 (diff)
Fix bionic IP address binding
Reviewed-on: https://code.launchpad.net/~martin-hilton/mongodb-charm/+git/mongodb-charm/+merge/358450 Reviewed-by: Tom Haddon <tom.haddon@canonical.com>
-rwxr-xr-xhooks/hooks.py2
-rw-r--r--unit_tests/test_hooks.py71
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)