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
diff --git a/config.yaml b/config.yaml
index cbaf414..f06d870 100644
--- a/config.yaml
+++ b/config.yaml
@@ -58,7 +58,7 @@ options:
58 diaglog:58 diaglog:
59 default: 059 default: 0
60 type: int60 type: int
61 description: Set oplogging level where n is 0=off (default), 1=W, 2=R, 3=both, 7=W+some reads61 description: DEPRECATED Set oplogging level where n is 0=off (default), 1=W, 2=R, 3=both, 7=W+some reads
62 nocursors:62 nocursors:
63 default: False63 default: False
64 type: boolean64 type: boolean
@@ -114,7 +114,7 @@ options:
114 web_admin_ui:114 web_admin_ui:
115 default: True115 default: True
116 type: boolean116 type: boolean
117 description: Replica Set Admin UI (accessible via default_port + 1000)117 description: DEPRECATED Replica Set Admin UI (accessible via default_port + 1000)
118 replicaset_master:118 replicaset_master:
119 default: auto119 default: auto
120 type: string120 type: string
diff --git a/hooks/hooks.py b/hooks/hooks.py
index 9de334d..a458e99 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -6,8 +6,10 @@ Created on Aug 1, 2012
6'''6'''
77
8import commands8import commands
9import distutils
9import json10import json
10import os11import os
12import platform
11import pprint13import pprint
12import re14import re
13import signal15import signal
@@ -88,6 +90,7 @@ hooks = Hooks()
88###############################################################################90###############################################################################
89default_mongodb_config = "/etc/mongodb.conf"91default_mongodb_config = "/etc/mongodb.conf"
90default_mongodb_init_config = "/etc/init/mongodb.conf"92default_mongodb_init_config = "/etc/init/mongodb.conf"
93mongodb_env_config = "/etc/default/mongodb"
91default_mongos_list = "/etc/mongos.list"94default_mongos_list = "/etc/mongos.list"
92default_wait_for = 395default_wait_for = 3
93default_max_tries = 796default_max_tries = 7
@@ -122,6 +125,12 @@ was_i_primary = False
122###############################################################################125###############################################################################
123126
124127
128def is_bionic_or_greater():
129 current_version = platform.linux_distribution()[1]
130 if distutils.version.LooseVersion(current_version) >= distutils.version.LooseVersion('18.04'):
131 return True
132
133
125def port_check(host=None, port=None, protocol='TCP'):134def port_check(host=None, port=None, protocol='TCP'):
126 if host is None or port is None:135 if host is None or port is None:
127 juju_log("port_check: host and port must be defined.")136 juju_log("port_check: host and port must be defined.")
@@ -302,9 +311,14 @@ def mongodb_conf(config_data=None):
302 config.append("quota = true")311 config.append("quota = true")
303 config.append("")312 config.append("")
304313
305 # diaglog314 if not is_bionic_or_greater():
306 config.append("diaglog = %d" % config_data['diaglog'])315 # diaglog
307 config.append("")316 config.append("diaglog = %d" % config_data['diaglog'])
317 config.append("")
318 # nohttpinterface
319 if config_data['web_admin_ui']:
320 config.append("rest = true")
321 config.append("")
308322
309 # nocursors323 # nocursors
310 if config_data['nocursors']:324 if config_data['nocursors']:
@@ -316,11 +330,6 @@ def mongodb_conf(config_data=None):
316 config.append("nohints = true")330 config.append("nohints = true")
317 config.append("")331 config.append("")
318332
319 # nohttpinterface
320 if config_data['web_admin_ui']:
321 config.append("rest = true")
322 config.append("")
323
324 # noscripting333 # noscripting
325 if config_data['noscripting']:334 if config_data['noscripting']:
326 config.append("noscripting = true")335 config.append("noscripting = true")
@@ -537,7 +546,7 @@ def join_replset(master_node=None, host=None):
537 if master_node is None or host is None:546 if master_node is None or host is None:
538 retVal = False547 retVal = False
539 else:548 else:
540 retVal = mongo_client_smart('localhost', 'rs.add("%s")' % host)549 retVal = rs_add(host)
541 juju_log("join_replset returns: %s" % retVal, level=DEBUG)550 juju_log("join_replset returns: %s" % retVal, level=DEBUG)
542 return(retVal)551 return(retVal)
543552
@@ -618,18 +627,27 @@ def remove_rest_from_upstart():
618627
619628
620def update_daemon_options(daemon_options=None):629def update_daemon_options(daemon_options=None):
621 mongodb_init_config = open(default_mongodb_init_config).read()630 if is_bionic_or_greater():
622 pat_replace = []631 if daemon_options and daemon_options != "none":
623 if daemon_options is None or daemon_options == "none":632 daemon_opts = 'DAEMON_OPTS="{0}"\n'.format(daemon_options)
624 pat_replace.append(633 return(update_file(mongodb_env_config, daemon_opts))
625 (' --config /etc/mongodb.conf.*',634 else:
626 ' --config /etc/mongodb.conf; fi'))635 if os.path.exists(mongodb_env_config):
636 os.remove(mongodb_env_config)
637 return True
627 else:638 else:
628 pat_replace.append(639 mongodb_init_config = open(default_mongodb_init_config).read()
629 (' --config /etc/mongodb.conf.*',640 pat_replace = []
630 ' --config /etc/mongodb.conf %s; fi' % daemon_options))641 if daemon_options is None or daemon_options == "none":
631 regex_sub(pat_replace, mongodb_init_config)642 pat_replace.append(
632 return(update_file(default_mongodb_init_config, mongodb_init_config))643 (' --config /etc/mongodb.conf.*',
644 ' --config /etc/mongodb.conf; fi'))
645 else:
646 pat_replace.append(
647 (' --config /etc/mongodb.conf.*',
648 ' --config /etc/mongodb.conf %s; fi' % daemon_options))
649 regex_sub(pat_replace, mongodb_init_config)
650 return(update_file(default_mongodb_init_config, mongodb_init_config))
633651
634652
635def enable_arbiter(master_node=None, host=None):653def enable_arbiter(master_node=None, host=None):
@@ -1169,6 +1187,33 @@ def replica_set_relation_joined():
1169 juju_log("replica_set_relation_joined-finish")1187 juju_log("replica_set_relation_joined-finish")
11701188
11711189
1190def rs_add(host):
1191 if not is_bionic_or_greater():
1192 return mongo_client_smart('localhost', 'rs.add("%s")' % host)
1193
1194 command = 'rs.add("%s")' % host
1195 if host is None:
1196 raise ValueError("missing host")
1197 else:
1198 cmd_line = ['mongo', '--quiet', '--host', "localhost",
1199 '--eval', 'printjson(%s)' % command]
1200 juju_log("Executing: %s" % cmd_line, level=DEBUG)
1201 run(cmd_line)
1202
1203 for i in xrange(MONGO_CLIENT_RETRIES):
1204 c = MongoClient('localhost')
1205 cmd_output = subprocess.check_output(cmd_line)
1206 r = run_admin_command(c, 'replSetGetStatus')
1207 members = r["members"]
1208 ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY]
1209 if ok:
1210 return ok
1211
1212 time.sleep(1.5)
1213
1214 return False
1215
1216
1172def am_i_primary():1217def am_i_primary():
1173 c = MongoClient('localhost')1218 c = MongoClient('localhost')
1174 for i in xrange(10):1219 for i in xrange(10):

Subscribers

People subscribed via source and target branches

to status/vote changes: