diff options
author | Felipe Reyes <felipe.reyes@canonical.com> | 2018-05-25 15:28:56 +0000 |
---|---|---|
committer | Felipe Reyes <felipe.reyes@canonical.com> | 2018-05-25 15:28:56 +0000 |
commit | 44d66f8b955b26606cf04f3f6fb7ddfc478d5e14 (patch) | |
tree | 3c23aa793da2eb5bdb79f2b8cea09c0fe11f2b58 | |
parent | 0c9089402490dfdf4cba6b7e5e4086cf38c19d9c (diff) |
Replace print() with juju_log()
-rwxr-xr-x | hooks/hooks.py | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/hooks/hooks.py b/hooks/hooks.py index 38353d3..9de334d 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -939,7 +939,7 @@ def config_changed(): juju_log("Entering config_changed") status_set('maintenance', 'Configuring unit') config_data = config() - print "config_data: ", config_data + juju_log("config_data: {}".format(config_data), level=DEBUG) mongodb_config = open(default_mongodb_config).read() # Trigger volume initialization logic for permanent storage @@ -978,11 +978,12 @@ def config_changed(): current_web_admin_ui_port = int(current_mongodb_port) + 1000 new_web_admin_ui_port = int(config_data['port']) + 1000 - print "current_mongodb_port: ", current_mongodb_port + juju_log("Configured mongodb port: {}".format(current_mongodb_port), + level=DEBUG) public_address = unit_get('public-address') - print "public_address: ", public_address + juju_log("unit's public_address: {}".format(public_address), level=DEBUG) private_address = unit_get('private-address') - print "private_address: ", private_address + juju_log("unit's private_address: {}".format(private_address), level=DEBUG) # Update mongodb configuration file mongodb_config = mongodb_conf(config_data) @@ -1075,7 +1076,7 @@ def config_changed(): application_version_set(get_mongod_version()) update_status() - print "About to leave config_changed" + juju_log("About to leave config_changed", level=DEBUG) return(True) @@ -1412,11 +1413,12 @@ def mongos_relation_changed(): port = relation_get('port') rel_type = relation_get('type') if hostname is None or port is None or rel_type is None: - print("mongos_relation_changed: relation data not ready.") + juju_log("mongos_relation_changed: relation data not ready.", + level=DEBUG) return if rel_type == 'configsvr': config_servers = load_config_servers(default_mongos_list) - print "Adding config server: %s:%s" % (hostname, port) + juju_log("Adding config server: %s:%s" % (hostname, port), level=DEBUG) if hostname is not None and \ port is not None and \ hostname != '' and \ @@ -1441,11 +1443,11 @@ def mongos_relation_changed(): mongo_client(mongos_host, shard_command2) else: - print("mongos_relation_change: undefined rel_type: %s" % - rel_type) + juju_log("mongos_relation_change: undefined rel_type: %s" % rel_type, + level=DEBUG) return - print("mongos_relation_changed returns: %s" % retVal) + juju_log("mongos_relation_changed returns: %s" % retVal, level=DEBUG) @hooks.hook('mongos-relation-broken') @@ -1508,8 +1510,6 @@ def update_status(): update_status if needed) """ - juju_log('$$$ update_status()', 'DEBUG') - workload = 'active' status = 'Unit is ready' @@ -1518,23 +1518,19 @@ def update_status(): # more than 1 units were deployed and peer related. mongo_status = get_replicaset_status() if mongo_status in ('PRIMARY', 'SECONDARY'): - print ' ## mongo_status in PRI/SEC' workload = 'active' status = 'Unit is ready as ' + mongo_status elif mongo_status in ('not in replicaset',): - print ' ## mongo_status in "not in replicaset"' workload = 'active' status = 'Unit is ready, ' + mongo_status else: workload = 'maintenance' status = mongo_status - print ' ## mongo_status something else: ', status - print ' #> forcing "return False" for update_status()' - - juju_log(' $ status:' + status, 'DEBUG') - juju_log(' $ workload: ' + workload, 'DEBUG') + juju_log('mongo_status is unknown: {}'.format(status), level=DEBUG) + juju_log('Setting workload: {} - {}'.format(workload, status), level=DEBUG) status_set(workload, status) + return workload |