Skip to content

Commit

Permalink
Fixed many small logging mistakes and changed validation logging to l…
Browse files Browse the repository at this point in the history
…ocal
  • Loading branch information
XaverStiensmeier committed Aug 11, 2023
1 parent 23b7bff commit e7bde51
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 104 deletions.
12 changes: 5 additions & 7 deletions bibigrid/core/actions/check.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
"""
Module that acts as a wrapper and uses validate_configuration to validate given configuration
"""
import logging
from bibigrid.core.utility import validate_configuration

LOG = logging.getLogger("bibigrid")


def check(configurations, providers):
def check(configurations, providers, log):
"""
Uses validate_configuration to validate given configuration.
:param configurations: list of configurations (dicts)
:param providers: list of providers
:param log:
:return:
"""
success = validate_configuration.ValidateConfiguration(configurations, providers).validate()
success = validate_configuration.ValidateConfiguration(configurations, providers, log).validate()
check_result = "succeeded! Cluster is ready to start." if success else "failed!"
print(f"Total check {check_result}")
LOG.info("Total check returned %s.", success)
log.log(0, f"Total check {check_result}")
log.info("Total check returned %s.", success)
return 0
2 changes: 1 addition & 1 deletion bibigrid/core/actions/ide.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def ide(cluster_id, master_provider, master_configuration):
"""
LOG.info("Starting port forwarding for ide")
master_ip, ssh_user, used_private_key = cluster_ssh_handler.get_ssh_connection_info(cluster_id, master_provider,
master_configuration)
master_configuration, LOG)
used_local_bind_address = LOCAL_BIND_ADDRESS
if master_ip and ssh_user and used_private_key:
attempts = 0
Expand Down
4 changes: 1 addition & 3 deletions bibigrid/core/actions/list_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
This includes a method to create a dictionary containing all running clusters and their servers.
"""

import logging
import pprint
import re

from bibigrid.core.actions import create

SERVER_REGEX = re.compile(r"^bibigrid-((master)-([a-zA-Z0-9]+)|(worker|vpngtw)\d+-([a-zA-Z0-9]+)-\d+)$")
LOG = logging.getLogger("bibigrid")


def dict_clusters(providers, log):
Expand Down Expand Up @@ -91,7 +89,7 @@ def log_list(cluster_id, providers, log):
networks = get_networks(cluster_node_dict)
log.log(0, f"\tnetwork: {pprint.pformat(networks)}")
else:
LOG.warning("No master for cluster: %s.", cluster_key_id)
log.warning("No master for cluster: %s.", cluster_key_id)
master_count, worker_count, vpn_count = get_size_overview(cluster_node_dict, log)
log.log(0,
f"\tCluster has {master_count} master, {vpn_count} vpngtw and {worker_count} regular workers. "
Expand Down
2 changes: 1 addition & 1 deletion bibigrid/core/actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def update(cluster_id, master_provider, master_configuration):
LOG.info("Starting update...")
master_ip, ssh_user, used_private_key = cluster_ssh_handler.get_ssh_connection_info(cluster_id, master_provider,
master_configuration)
master_configuration, LOG)
if master_ip and ssh_user and used_private_key:
LOG.info("Trying to update %s@%s", master_ip, ssh_user)
ssh_handler.execute_ssh(floating_ip=master_ip, private_key=used_private_key, username=ssh_user,
Expand Down
12 changes: 7 additions & 5 deletions bibigrid/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ def set_logger_verbosity(verbosity):
capped_verbosity = min(verbosity, len(VERBOSITY_LIST) - 1)
# LOG.basicConfig(format=LOGGER_FORMAT, level=VERBOSITY_LIST[capped_verbosity],
# handlers=LOGGING_HANDLER_LIST)
LOG.setLevel(VERBOSITY_LIST[capped_verbosity])

log = logging.getLogger("bibigrid")
log.setLevel(VERBOSITY_LIST[capped_verbosity])

log.debug(f"Logging verbosity set to {capped_verbosity}")
LOG.debug(f"Logging verbosity set to {capped_verbosity}")


# pylint: disable=too-many-nested-blocks,too-many-branches, too-many-statements
Expand All @@ -79,13 +77,17 @@ def run_action(args, configurations, config_path):
exit_state = list_clusters.log_list(args.cluster_id, providers, LOG)
elif args.check:
LOG.info("Action check selected")
exit_state = check.check(configurations, providers)
exit_state = check.check(configurations, providers, LOG)
elif args.create:
LOG.info("Action create selected")
log = logging.getLogger("New")
for handler in log.handlers[:]: # remove all old handlers
log.removeHandler(handler)
log.addHandler(logging.FileHandler("test.log"))
log.setLevel(len(VERBOSITY_LIST))
LOG.addHandler(logging.FileHandler("bibigrid.log"))
log.info("Testing: log")
LOG.info("Testing LOG")
creator = create.Create(providers=providers,
configurations=configurations,
log=log,
Expand Down
2 changes: 1 addition & 1 deletion bibigrid/core/startup_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def validate_configuration(config_file: UploadFile = File(...)):
content = await config_file.read()
configurations = yaml.safe_load(content.decode())
providers = provider_handler.get_providers(configurations, log)
exit_state = check.check(configurations, providers)
exit_state = check.check(configurations, providers, log)
if exit_state:
return JSONResponse(content={"message": "Validation failed"}, status_code=420) # Fail
return JSONResponse(content={"message": "Validation successful"}, status_code=200) # Success
Expand Down
7 changes: 2 additions & 5 deletions bibigrid/core/utility/handler/cluster_ssh_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
This module gets information about ssh connection.
"""

import logging
import os

from bibigrid.core.actions import create, list_clusters

LOG = logging.getLogger("bibigrid")


def get_ssh_connection_info(cluster_id, master_provider, master_configuration):
def get_ssh_connection_info(cluster_id, master_provider, master_configuration, log):
"""
Gets master_ip, ssh_user and private key to enable other modules to create an ssh connection to a clusters master
@param cluster_id: id of cluster to connect to
Expand All @@ -20,7 +17,7 @@ def get_ssh_connection_info(cluster_id, master_provider, master_configuration):
"""
# If cluster_id is an ip, cluster_id will be used for master_ip
if "." in cluster_id:
LOG.info("Interpreting %s as ip since it doesn't match cluster_id", cluster_id)
log.info("Interpreting %s as ip since it doesn't match cluster_id", cluster_id)
master_ip = cluster_id
else:
master_ip = list_clusters.get_master_access_ip(cluster_id, master_provider)
Expand Down
Loading

0 comments on commit e7bde51

Please sign in to comment.