Merge ~mthaddon/charm-mongodb/+git/mongodb-charm:lint-fixes into ~mongodb-charmers/charm-mongodb:master

Proposed by Tom Haddon
Status: Merged
Approved by: Tom Haddon
Approved revision: 7f30a2db9070487d5f76a47017b8bcddd65f87c4
Merged at revision: f478e62856504dc484dfdc005fb368bb29fbb727
Proposed branch: ~mthaddon/charm-mongodb/+git/mongodb-charm:lint-fixes
Merge into: ~mongodb-charmers/charm-mongodb:master
Diff against target: 195 lines (+25/-25)
1 file modified
hooks/hooks.py (+25/-25)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+359932@code.launchpad.net

Commit message

Fix lint with exception of complexity failures

Description of the change

Fix lint with exception of complexity failures

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
Stuart Bishop (stub) wrote :

Yup

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

Change successfully merged at revision f478e62856504dc484dfdc005fb368bb29fbb727

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/hooks/hooks.py b/hooks/hooks.py
index 08a7d62..c23198b 100755
--- a/hooks/hooks.py
+++ b/hooks/hooks.py
@@ -279,7 +279,6 @@ def mongodb_conf(config_data=None):
279 config.append("bind_ip = 0.0.0.0")279 config.append("bind_ip = 0.0.0.0")
280 config.append("")280 config.append("")
281281
282
283 # port282 # port
284 config.append("port = %d" % config_data['port'])283 config.append("port = %d" % config_data['port'])
285 config.append("")284 config.append("")
@@ -594,6 +593,7 @@ def enable_replset(replicaset_name=None):
594 finally:593 finally:
595 return retVal594 return retVal
596595
596
597def remove_replset_from_upstart():597def remove_replset_from_upstart():
598 """Removes replicaset configuration from upstart.598 """Removes replicaset configuration from upstart.
599 """599 """
@@ -602,7 +602,7 @@ def remove_replset_from_upstart():
602602
603 if re.search(' --replSet', mongodb_init_config,603 if re.search(' --replSet', mongodb_init_config,
604 re.MULTILINE) is not None:604 re.MULTILINE) is not None:
605 mongodb_init_config = re.sub(' --replSet .\w+', '',605 mongodb_init_config = re.sub(r' --replSet .\w+', '',
606 mongodb_init_config)606 mongodb_init_config)
607 retVal = update_file(default_mongodb_init_config, mongodb_init_config)607 retVal = update_file(default_mongodb_init_config, mongodb_init_config)
608 except Exception, e:608 except Exception, e:
@@ -634,7 +634,7 @@ def remove_rest_from_upstart():
634 try:634 try:
635 mongodb_init_config = open(default_mongodb_init_config).read()635 mongodb_init_config = open(default_mongodb_init_config).read()
636 if re.search(' --rest ', mongodb_init_config,636 if re.search(' --rest ', mongodb_init_config,
637 re.MULTILINE) is not None:637 re.MULTILINE) is not None:
638 mongodb_init_config = regex_sub([(' --rest ', ' ')],638 mongodb_init_config = regex_sub([(' --rest ', ' ')],
639 mongodb_init_config)639 mongodb_init_config)
640 retVal = update_file(default_mongodb_init_config, mongodb_init_config)640 retVal = update_file(default_mongodb_init_config, mongodb_init_config)
@@ -684,10 +684,10 @@ def configsvr_status(wait_for=default_wait_for, max_tries=default_max_tries):
684 config_data = config()684 config_data = config()
685 current_try = 0685 current_try = 0
686686
687 while (process_check_pidfile('/var/run/mongodb/configsvr.pid') !=687 while (process_check_pidfile('/var/run/mongodb/configsvr.pid') != (
688 (None, None)) and not port_check(688 None, None)) and not port_check(
689 unit_get('private-address'),689 unit_get('private-address'),
690 config_data['config_server_port']) and current_try < max_tries:690 config_data['config_server_port']) and current_try < max_tries:
691691
692 juju_log("configsvr_status: Waiting for Config Server to be ready ...")692 juju_log("configsvr_status: Waiting for Config Server to be ready ...")
693 time.sleep(wait_for)693 time.sleep(wait_for)
@@ -775,8 +775,8 @@ def enable_configsvr(config_data, wait_for=default_wait_for,
775def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries):775def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries):
776 config_data = config()776 config_data = config()
777 current_try = 0777 current_try = 0
778 while (process_check_pidfile('/var/run/mongodb/mongos.pid') !=778 while (process_check_pidfile('/var/run/mongodb/mongos.pid') != (
779 (None, None)) and not port_check(779 None, None)) and not port_check(
780 unit_get('private-address'),780 unit_get('private-address'),
781 config_data['mongos_port']) and current_try < max_tries:781 config_data['mongos_port']) and current_try < max_tries:
782782
@@ -784,8 +784,8 @@ def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries):
784 time.sleep(wait_for)784 time.sleep(wait_for)
785 current_try += 1785 current_try += 1
786 retVal = \786 retVal = \
787 (process_check_pidfile('/var/run/mongodb/mongos.pid') !=787 (process_check_pidfile('/var/run/mongodb/mongos.pid') != (
788 (None, None)) == port_check(788 None, None)) == port_check(
789 unit_get('private-address'),789 unit_get('private-address'),
790 config_data['mongos_port']) is True790 config_data['mongos_port']) is True
791791
@@ -876,9 +876,8 @@ def restart_mongod(wait_for=default_wait_for, max_tries=default_max_tries):
876 if not service('start', 'mongodb'):876 if not service('start', 'mongodb'):
877 return False877 return False
878878
879 while (service('status', 'mongodb') and879 while (service('status', 'mongodb') and not port_check(
880 not port_check(my_hostname, my_port) and880 my_hostname, my_port) and current_try < max_tries):
881 current_try < max_tries):
882 juju_log(881 juju_log(
883 "restart_mongod: Waiting for MongoDB to be ready ({}/{})".format(882 "restart_mongod: Waiting for MongoDB to be ready ({}/{})".format(
884 current_try, max_tries))883 current_try, max_tries))
@@ -1008,7 +1007,7 @@ def config_changed():
1008 sys.exit(1)1007 sys.exit(1)
10091008
1010 # current ports1009 # current ports
1011 current_mongodb_port = re.search('^#*port\s+=\s+(\w+)',1010 current_mongodb_port = re.search(r'^#*port\s+=\s+(\w+)',
1012 mongodb_config,1011 mongodb_config,
1013 re.MULTILINE).group(1)1012 re.MULTILINE).group(1)
10141013
@@ -1087,7 +1086,7 @@ def config_changed():
1087 juju_log("config_changed: Exception: %s" % str(e))1086 juju_log("config_changed: Exception: %s" % str(e))
10881087
1089 if configsvr_pid is not None:1088 if configsvr_pid is not None:
1090 configsvr_port = re.search('--port (\w+)', configsvr_cmd_line).group(2)1089 configsvr_port = re.search(r'--port (\w+)', configsvr_cmd_line).group(2)
1091 disable_configsvr(configsvr_port)1090 disable_configsvr(configsvr_port)
1092 enable_configsvr(config_data['config_server_port'])1091 enable_configsvr(config_data['config_server_port'])
1093 else:1092 else:
@@ -1103,7 +1102,7 @@ def config_changed():
1103 juju_log("config_changed: Exceptions: %s" % str(e))1102 juju_log("config_changed: Exceptions: %s" % str(e))
11041103
1105 if mongos_pid is not None:1104 if mongos_pid is not None:
1106 mongos_port = re.search('--port (\w+)', mongos_cmd_line).group(1)1105 mongos_port = re.search(r'--port (\w+)', mongos_cmd_line).group(1)
1107 disable_mongos(mongos_port)1106 disable_mongos(mongos_port)
1108 enable_mongos(config_data['mongos_port'])1107 enable_mongos(config_data['mongos_port'])
1109 else:1108 else:
@@ -1139,6 +1138,7 @@ def stop_hook():
1139 juju_log("stop_hook returns: %s" % retVal)1138 juju_log("stop_hook returns: %s" % retVal)
1140 return(retVal)1139 return(retVal)
11411140
1141
1142@hooks.hook('benchmark-relation-joined')1142@hooks.hook('benchmark-relation-joined')
1143@hooks.hook('benchmark-relation-changed')1143@hooks.hook('benchmark-relation-changed')
1144def benchmark_relation_joined():1144def benchmark_relation_joined():
@@ -1155,6 +1155,7 @@ def benchmark_relation_joined():
1155 benchmarks = ['perf']1155 benchmarks = ['perf']
1156 Benchmark(benchmarks)1156 Benchmark(benchmarks)
11571157
1158
1158@hooks.hook('database-relation-joined')1159@hooks.hook('database-relation-joined')
1159def database_relation_joined():1160def database_relation_joined():
1160 juju_log("database_relation_joined")1161 juju_log("database_relation_joined")
@@ -1221,7 +1222,7 @@ def rs_add(host):
12211222
1222 for i in xrange(MONGO_CLIENT_RETRIES):1223 for i in xrange(MONGO_CLIENT_RETRIES):
1223 c = MongoClient('localhost')1224 c = MongoClient('localhost')
1224 cmd_output = subprocess.check_output(cmd_line)1225 subprocess.check_output(cmd_line)
1225 r = run_admin_command(c, 'replSetGetStatus')1226 r = run_admin_command(c, 'replSetGetStatus')
1226 members = r["members"]1227 members = r["members"]
1227 ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY]1228 ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY]
@@ -1285,8 +1286,8 @@ def get_replicaset_status():
1285 # if 'self' was not found in the output, then log a warning and print1286 # if 'self' was not found in the output, then log a warning and print
1286 # the output given by replSetGetStatus1287 # the output given by replSetGetStatus
1287 r_pretty = pprint.pformat(r)1288 r_pretty = pprint.pformat(r)
1288 juju_log('get_replicaset_status() failed to get replicaset state:' +1289 juju_log('get_replicaset_status() failed to get replicaset state: '
1289 r_pretty, level=WARNING)1290 '%s' % r_pretty, level=WARNING)
1290 return 'Unknown replica set state'1291 return 'Unknown replica set state'
12911292
1292 except OperationFailure as e:1293 except OperationFailure as e:
@@ -1296,6 +1297,7 @@ def get_replicaset_status():
1296 else:1297 else:
1297 return str(e)1298 return str(e)
12981299
1300
1299def get_mongod_version():1301def get_mongod_version():
1300 """ Connects to mongod and get the db.version() output1302 """ Connects to mongod and get the db.version() output
1301 Mainly used for application_set_version in config-changed hook1303 Mainly used for application_set_version in config-changed hook
@@ -1347,7 +1349,6 @@ def replica_set_relation_changed():
1347 juju_log('replica_set_relation_changed-finish')1349 juju_log('replica_set_relation_changed-finish')
13481350
13491351
1350
1351@hooks.hook('replica-set-relation-departed')1352@hooks.hook('replica-set-relation-departed')
1352def replica_set_relation_departed():1353def replica_set_relation_departed():
1353 juju_log('replica_set_relation_departed-start')1354 juju_log('replica_set_relation_departed-start')
@@ -1546,9 +1547,9 @@ def update_nrpe_config():
1546 current_unit = local_unit()1547 current_unit = local_unit()
15471548
1548 if lsb_release()['DISTRIB_RELEASE'] > '15.04':1549 if lsb_release()['DISTRIB_RELEASE'] > '15.04':
1549 check_mongo_script='check_systemd.py mongodb'1550 check_mongo_script = 'check_systemd.py mongodb'
1550 else:1551 else:
1551 check_mongo_script='check_upstart_job mongodb'1552 check_mongo_script = 'check_upstart_job mongodb'
15521553
1553 nrpe.add_check(1554 nrpe.add_check(
1554 shortname='mongodb',1555 shortname='mongodb',
@@ -1598,7 +1599,6 @@ def update_status():
1598 return workload1599 return workload
15991600
16001601
1601
1602def run(command, exit_on_error=True):1602def run(command, exit_on_error=True):
1603 '''Run a command and return the output.'''1603 '''Run a command and return the output.'''
1604 try:1604 try:
@@ -1709,7 +1709,7 @@ def volume_get_volume_id():
1709# shell helper1709# shell helper
1710def volume_init_and_mount(volid):1710def volume_init_and_mount(volid):
1711 juju_log("Initialize and mount volume")1711 juju_log("Initialize and mount volume")
1712 command = ("scripts/volume-common.sh call " +1712 command = ("scripts/volume-common.sh call "
1713 "volume_init_and_mount %s" % volid)1713 "volume_init_and_mount %s" % volid)
1714 run(command)1714 run(command)
1715 return True1715 return True

Subscribers

People subscribed via source and target branches

to status/vote changes: