Merge ~martin-hilton/charm-mongodb:003-bionic-bind-ip into ~mongodb-charmers/charm-mongodb:master

Proposed by Martin Hilton
Status: Merged
Approved by: Tom Haddon
Approved revision: 6e5604c174ae3ddc9dfb5f6884d7df1012fc4041
Merged at revision: 7c4f968f20391665064f55f6bea0899a4f278202
Proposed branch: ~martin-hilton/charm-mongodb:003-bionic-bind-ip
Merge into: ~mongodb-charmers/charm-mongodb:master
Diff against target: 103 lines (+70/-3)
2 files modified
hooks/hooks.py (+1/-1)
unit_tests/test_hooks.py (+69/-2)
Reviewer Review Type Date Requested Status
Tom Haddon (community) Approve
Review via email: mp+358450@code.launchpad.net

Commit message

Fix bionic IP address binding

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Tom Haddon (mthaddon) wrote :

Could we add a test for this? Looks like unit_tests/test_hooks.py would be the appropriate place?

Revision history for this message
Tom Haddon (mthaddon) wrote :

I've confirmed that tests pass on xenial currently, just not on bionic or later (did this by spinning up a xenial LXC and running "sudo apt update && sudo apt install charm && charm pull cs:mongodb && cd mongodb && make test").

Revision history for this message
Tom Haddon (mthaddon) wrote :

Tests have now been fixed on bionic as well, so there shouldn't be anything blocking adding a test for this change.

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thanks

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 7c4f968f20391665064f55f6bea0899a4f278202

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index 54902f5..08a7d62 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -276,7 +276,7 @@ def mongodb_conf(config_data=None):
6 if config_data['bind_ip'] != "all":
7 config.append("bind_ip = %s" % config_data['bind_ip'])
8 elif is_bionic_or_greater():
9- config_data['bind_ip'] = '0.0.0.0'
10+ config.append("bind_ip = 0.0.0.0")
11 config.append("")
12
13
14diff --git a/unit_tests/test_hooks.py b/unit_tests/test_hooks.py
15index 3432cfb..ab78bbd 100644
16--- a/unit_tests/test_hooks.py
17+++ b/unit_tests/test_hooks.py
18@@ -1,3 +1,7 @@
19+import os
20+import shutil
21+import tempfile
22+
23 from mock import patch, call
24
25 from test_utils import CharmTestCase
26@@ -7,8 +11,6 @@ from subprocess import CalledProcessError
27
28 import hooks
29
30-import tempfile
31-import os
32
33 # Defines a set of functions to patch on the hooks object. Any of these
34 # methods will be patched by default on the default invocations of the
35@@ -434,3 +436,68 @@ class MongoHooksTest(CharmTestCase):
36 self.assertEqual(changed_contents, expected)
37 finally:
38 os.unlink(mocked_upstart.name)
39+
40+ @patch.object(hooks, 'is_relation_made')
41+ @patch.object(hooks, 'is_bionic_or_greater')
42+ def test_mongodb_conf(self, mock_is_bionic_or_greater, mock_is_relation_made):
43+ mock_is_bionic_or_greater.return_value = False
44+ mock_is_relation_made.return_value = False
45+ tmpdir = tempfile.mkdtemp()
46+ self.test_config.set('dbpath', os.path.join(tmpdir, 'db'))
47+ self.test_config.set('logpath', os.path.join(tmpdir, 'log'))
48+ try:
49+ mongodb_conf = hooks.mongodb_conf(self.test_config.get_all())
50+ finally:
51+ shutil.rmtree(tmpdir)
52+ expected = """# mongodb.conf
53+
54+dbpath={tmpdir}/db
55+
56+ipv6=true
57+logpath={tmpdir}/log
58+
59+logappend=true
60+
61+
62+port = 27017
63+
64+journal=true
65+
66+diaglog = 0
67+
68+rest = true
69+
70+master = true
71+""".format(tmpdir=tmpdir)
72+ self.assertEqual(mongodb_conf, expected)
73+
74+ @patch.object(hooks, 'is_relation_made')
75+ @patch.object(hooks, 'is_bionic_or_greater')
76+ def test_mongodb_conf_bionic(self, mock_is_bionic_or_greater, mock_is_relation_made):
77+ mock_is_bionic_or_greater.return_value = True
78+ mock_is_relation_made.return_value = False
79+ tmpdir = tempfile.mkdtemp()
80+ self.test_config.set('dbpath', os.path.join(tmpdir, 'db'))
81+ self.test_config.set('logpath', os.path.join(tmpdir, 'log'))
82+ try:
83+ mongodb_conf = hooks.mongodb_conf(self.test_config.get_all())
84+ finally:
85+ shutil.rmtree(tmpdir)
86+ expected = """# mongodb.conf
87+
88+dbpath={tmpdir}/db
89+
90+ipv6=true
91+logpath={tmpdir}/log
92+
93+logappend=true
94+
95+bind_ip = 0.0.0.0
96+
97+port = 27017
98+
99+journal=true
100+
101+master = true
102+""".format(tmpdir=tmpdir)
103+ self.assertEqual(mongodb_conf, expected)

Subscribers

People subscribed via source and target branches

to status/vote changes: