diff options
author | Tom Haddon <tom.haddon@canonical.com> | 2018-12-04 08:48:33 +0000 |
---|---|---|
committer | Canonial IS Mergebot <canonical-is-mergebot@canonical.com> | 2018-12-04 08:48:33 +0000 |
commit | f478e62856504dc484dfdc005fb368bb29fbb727 (patch) | |
tree | 4762f8869344d6978f5b221b4c8b1723056c1cd9 | |
parent | 7c4f968f20391665064f55f6bea0899a4f278202 (diff) | |
parent | 7f30a2db9070487d5f76a47017b8bcddd65f87c4 (diff) |
Fix lint with exception of complexity failures
Reviewed-on: https://code.launchpad.net/~mthaddon/mongodb-charm/+git/mongodb-charm/+merge/359932 Reviewed-by: Stuart Bishop <stuart.bishop@canonical.com>
-rwxr-xr-x | hooks/hooks.py | 50 |
1 files changed, 25 insertions, 25 deletions
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): config.append("bind_ip = 0.0.0.0") config.append("") - # port config.append("port = %d" % config_data['port']) config.append("") @@ -594,6 +593,7 @@ def enable_replset(replicaset_name=None): finally: return retVal + def remove_replset_from_upstart(): """Removes replicaset configuration from upstart. """ @@ -602,7 +602,7 @@ def remove_replset_from_upstart(): if re.search(' --replSet', mongodb_init_config, re.MULTILINE) is not None: - mongodb_init_config = re.sub(' --replSet .\w+', '', + mongodb_init_config = re.sub(r' --replSet .\w+', '', mongodb_init_config) retVal = update_file(default_mongodb_init_config, mongodb_init_config) except Exception, e: @@ -634,7 +634,7 @@ def remove_rest_from_upstart(): try: mongodb_init_config = open(default_mongodb_init_config).read() if re.search(' --rest ', mongodb_init_config, - re.MULTILINE) is not None: + re.MULTILINE) is not None: mongodb_init_config = regex_sub([(' --rest ', ' ')], mongodb_init_config) 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): config_data = config() current_try = 0 - while (process_check_pidfile('/var/run/mongodb/configsvr.pid') != - (None, None)) and not port_check( - unit_get('private-address'), - config_data['config_server_port']) and current_try < max_tries: + while (process_check_pidfile('/var/run/mongodb/configsvr.pid') != ( + None, None)) and not port_check( + unit_get('private-address'), + config_data['config_server_port']) and current_try < max_tries: juju_log("configsvr_status: Waiting for Config Server to be ready ...") time.sleep(wait_for) @@ -775,8 +775,8 @@ def enable_configsvr(config_data, wait_for=default_wait_for, def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries): config_data = config() current_try = 0 - while (process_check_pidfile('/var/run/mongodb/mongos.pid') != - (None, None)) and not port_check( + while (process_check_pidfile('/var/run/mongodb/mongos.pid') != ( + None, None)) and not port_check( unit_get('private-address'), config_data['mongos_port']) and current_try < max_tries: @@ -784,8 +784,8 @@ def mongos_status(wait_for=default_wait_for, max_tries=default_max_tries): time.sleep(wait_for) current_try += 1 retVal = \ - (process_check_pidfile('/var/run/mongodb/mongos.pid') != - (None, None)) == port_check( + (process_check_pidfile('/var/run/mongodb/mongos.pid') != ( + None, None)) == port_check( unit_get('private-address'), config_data['mongos_port']) is True @@ -876,9 +876,8 @@ def restart_mongod(wait_for=default_wait_for, max_tries=default_max_tries): if not service('start', 'mongodb'): return False - while (service('status', 'mongodb') and - not port_check(my_hostname, my_port) and - current_try < max_tries): + while (service('status', 'mongodb') and not port_check( + my_hostname, my_port) and current_try < max_tries): juju_log( "restart_mongod: Waiting for MongoDB to be ready ({}/{})".format( current_try, max_tries)) @@ -1008,7 +1007,7 @@ def config_changed(): sys.exit(1) # current ports - current_mongodb_port = re.search('^#*port\s+=\s+(\w+)', + current_mongodb_port = re.search(r'^#*port\s+=\s+(\w+)', mongodb_config, re.MULTILINE).group(1) @@ -1087,7 +1086,7 @@ def config_changed(): juju_log("config_changed: Exception: %s" % str(e)) if configsvr_pid is not None: - configsvr_port = re.search('--port (\w+)', configsvr_cmd_line).group(2) + configsvr_port = re.search(r'--port (\w+)', configsvr_cmd_line).group(2) disable_configsvr(configsvr_port) enable_configsvr(config_data['config_server_port']) else: @@ -1103,7 +1102,7 @@ def config_changed(): juju_log("config_changed: Exceptions: %s" % str(e)) if mongos_pid is not None: - mongos_port = re.search('--port (\w+)', mongos_cmd_line).group(1) + mongos_port = re.search(r'--port (\w+)', mongos_cmd_line).group(1) disable_mongos(mongos_port) enable_mongos(config_data['mongos_port']) else: @@ -1139,6 +1138,7 @@ def stop_hook(): juju_log("stop_hook returns: %s" % retVal) return(retVal) + @hooks.hook('benchmark-relation-joined') @hooks.hook('benchmark-relation-changed') def benchmark_relation_joined(): @@ -1155,6 +1155,7 @@ def benchmark_relation_joined(): benchmarks = ['perf'] Benchmark(benchmarks) + @hooks.hook('database-relation-joined') def database_relation_joined(): juju_log("database_relation_joined") @@ -1221,7 +1222,7 @@ def rs_add(host): for i in xrange(MONGO_CLIENT_RETRIES): c = MongoClient('localhost') - cmd_output = subprocess.check_output(cmd_line) + subprocess.check_output(cmd_line) r = run_admin_command(c, 'replSetGetStatus') members = r["members"] ok = [m for m in members if m['name'] == host and m['state'] == MONGO_SECONDARY] @@ -1285,8 +1286,8 @@ def get_replicaset_status(): # if 'self' was not found in the output, then log a warning and print # the output given by replSetGetStatus r_pretty = pprint.pformat(r) - juju_log('get_replicaset_status() failed to get replicaset state:' + - r_pretty, level=WARNING) + juju_log('get_replicaset_status() failed to get replicaset state: ' + '%s' % r_pretty, level=WARNING) return 'Unknown replica set state' except OperationFailure as e: @@ -1296,6 +1297,7 @@ def get_replicaset_status(): else: return str(e) + def get_mongod_version(): """ Connects to mongod and get the db.version() output Mainly used for application_set_version in config-changed hook @@ -1347,7 +1349,6 @@ def replica_set_relation_changed(): juju_log('replica_set_relation_changed-finish') - @hooks.hook('replica-set-relation-departed') def replica_set_relation_departed(): juju_log('replica_set_relation_departed-start') @@ -1546,9 +1547,9 @@ def update_nrpe_config(): current_unit = local_unit() if lsb_release()['DISTRIB_RELEASE'] > '15.04': - check_mongo_script='check_systemd.py mongodb' + check_mongo_script = 'check_systemd.py mongodb' else: - check_mongo_script='check_upstart_job mongodb' + check_mongo_script = 'check_upstart_job mongodb' nrpe.add_check( shortname='mongodb', @@ -1598,7 +1599,6 @@ def update_status(): return workload - def run(command, exit_on_error=True): '''Run a command and return the output.''' try: @@ -1709,7 +1709,7 @@ def volume_get_volume_id(): # shell helper def volume_init_and_mount(volid): juju_log("Initialize and mount volume") - command = ("scripts/volume-common.sh call " + + command = ("scripts/volume-common.sh call " "volume_init_and_mount %s" % volid) run(command) return True |