Merge ~tcuthbert/charm-mongodb:master into ~mongodb-charmers/charm-mongodb:master

Proposed by Thomas Cuthbert
Status: Merged
Approved by: Thomas Cuthbert
Approved revision: 76df3b0c81cb9c8e3de0ce09898c70c89f2c2d93
Merged at revision: 7e6f2361252055c19e8f70752d071eecc17e468e
Proposed branch: ~tcuthbert/charm-mongodb:master
Merge into: ~mongodb-charmers/charm-mongodb:master
Diff against target: 170 lines (+67/-22)
2 files modified
config.yaml (+2/-2)
hooks/hooks.py (+65/-20)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+349115@code.launchpad.net

Commit message

Initial implementation of bionic support

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks fine.

Comments inline. The biggest change is I think that the version check would be better done on the mongo version rather than the OS version, but that doesn't need to block this landing and can be done easily enough in a followup branch.

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

One suspected bug in the update, per inline comment. LooseVersion(..) should be compared with another LooseVersion(...), not to a string.

review: Approve
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
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 7e6f2361252055c19e8f70752d071eecc17e468e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index cbaf414..f06d870 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -58,7 +58,7 @@ options:
6 diaglog:
7 default: 0
8 type: int
9- description: Set oplogging level where n is 0=off (default), 1=W, 2=R, 3=both, 7=W+some reads
10+ description: DEPRECATED Set oplogging level where n is 0=off (default), 1=W, 2=R, 3=both, 7=W+some reads
11 nocursors:
12 default: False
13 type: boolean
14@@ -114,7 +114,7 @@ options:
15 web_admin_ui:
16 default: True
17 type: boolean
18- description: Replica Set Admin UI (accessible via default_port + 1000)
19+ description: DEPRECATED Replica Set Admin UI (accessible via default_port + 1000)
20 replicaset_master:
21 default: auto
22 type: string
23diff --git a/hooks/hooks.py b/hooks/hooks.py
24index 9de334d..a458e99 100755
25--- a/hooks/hooks.py
26+++ b/hooks/hooks.py
27@@ -6,8 +6,10 @@ Created on Aug 1, 2012
28 '''
29
30 import commands
31+import distutils
32 import json
33 import os
34+import platform
35 import pprint
36 import re
37 import signal
38@@ -88,6 +90,7 @@ hooks = Hooks()
39 ###############################################################################
40 default_mongodb_config = "/etc/mongodb.conf"
41 default_mongodb_init_config = "/etc/init/mongodb.conf"
42+mongodb_env_config = "/etc/default/mongodb"
43 default_mongos_list = "/etc/mongos.list"
44 default_wait_for = 3
45 default_max_tries = 7
46@@ -122,6 +125,12 @@ was_i_primary = False
47 ###############################################################################
48
49
50+def is_bionic_or_greater():
51+ current_version = platform.linux_distribution()[1]
52+ if distutils.version.LooseVersion(current_version) >= distutils.version.LooseVersion('18.04'):
53+ return True
54+
55+
56 def port_check(host=None, port=None, protocol='TCP'):
57 if host is None or port is None:
58 juju_log("port_check: host and port must be defined.")
59@@ -302,9 +311,14 @@ def mongodb_conf(config_data=None):
60 config.append("quota = true")
61 config.append("")
62
63- # diaglog
64- config.append("diaglog = %d" % config_data['diaglog'])
65- config.append("")
66+ if not is_bionic_or_greater():
67+ # diaglog
68+ config.append("diaglog = %d" % config_data['diaglog'])
69+ config.append("")
70+ # nohttpinterface
71+ if config_data['web_admin_ui']:
72+ config.append("rest = true")
73+ config.append("")
74
75 # nocursors
76 if config_data['nocursors']:
77@@ -316,11 +330,6 @@ def mongodb_conf(config_data=None):
78 config.append("nohints = true")
79 config.append("")
80
81- # nohttpinterface
82- if config_data['web_admin_ui']:
83- config.append("rest = true")
84- config.append("")
85-
86 # noscripting
87 if config_data['noscripting']:
88 config.append("noscripting = true")
89@@ -537,7 +546,7 @@ def join_replset(master_node=None, host=None):
90 if master_node is None or host is None:
91 retVal = False
92 else:
93- retVal = mongo_client_smart('localhost', 'rs.add("%s")' % host)
94+ retVal = rs_add(host)
95 juju_log("join_replset returns: %s" % retVal, level=DEBUG)
96 return(retVal)
97
98@@ -618,18 +627,27 @@ def remove_rest_from_upstart():
99
100
101 def update_daemon_options(daemon_options=None):
102- mongodb_init_config = open(default_mongodb_init_config).read()
103- pat_replace = []
104- if daemon_options is None or daemon_options == "none":
105- pat_replace.append(
106- (' --config /etc/mongodb.conf.*',
107- ' --config /etc/mongodb.conf; fi'))
108+ if is_bionic_or_greater():
109+ if daemon_options and daemon_options != "none":
110+ daemon_opts = 'DAEMON_OPTS="{0}"\n'.format(daemon_options)
111+ return(update_file(mongodb_env_config, daemon_opts))
112+ else:
113+ if os.path.exists(mongodb_env_config):
114+ os.remove(mongodb_env_config)
115+ return True
116 else:
117- pat_replace.append(
118- (' --config /etc/mongodb.conf.*',
119- ' --config /etc/mongodb.conf %s; fi' % daemon_options))
120- regex_sub(pat_replace, mongodb_init_config)
121- return(update_file(default_mongodb_init_config, mongodb_init_config))
122+ mongodb_init_config = open(default_mongodb_init_config).read()
123+ pat_replace = []
124+ if daemon_options is None or daemon_options == "none":
125+ pat_replace.append(
126+ (' --config /etc/mongodb.conf.*',
127+ ' --config /etc/mongodb.conf; fi'))
128+ else:
129+ pat_replace.append(
130+ (' --config /etc/mongodb.conf.*',
131+ ' --config /etc/mongodb.conf %s; fi' % daemon_options))
132+ regex_sub(pat_replace, mongodb_init_config)
133+ return(update_file(default_mongodb_init_config, mongodb_init_config))
134
135
136 def enable_arbiter(master_node=None, host=None):
137@@ -1169,6 +1187,33 @@ def replica_set_relation_joined():
138 juju_log("replica_set_relation_joined-finish")
139
140
141+def rs_add(host):
142+ if not is_bionic_or_greater():
143+ return mongo_client_smart('localhost', 'rs.add("%s")' % host)
144+
145+ command = 'rs.add("%s")' % host
146+ if host is None:
147+ raise ValueError("missing host")
148+ else:
149+ cmd_line = ['mongo', '--quiet', '--host', "localhost",
150+ '--eval', 'printjson(%s)' % command]
151+ juju_log("Executing: %s" % cmd_line, level=DEBUG)
152+ run(cmd_line)
153+
154+ for i in xrange(MONGO_CLIENT_RETRIES):
155+ c = MongoClient('localhost')
156+ cmd_output = subprocess.check_output(cmd_line)
157+ r = run_admin_command(c, 'replSetGetStatus')
158+ members = r["members"]
159+ ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY]
160+ if ok:
161+ return ok
162+
163+ time.sleep(1.5)
164+
165+ return False
166+
167+
168 def am_i_primary():
169 c = MongoClient('localhost')
170 for i in xrange(10):

Subscribers

People subscribed via source and target branches

to status/vote changes: