Skip to content

Commit

Permalink
improved connection test error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-weka committed Sep 27, 2024
1 parent 3201cb3 commit b20ab46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
33 changes: 21 additions & 12 deletions snaptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import flask_ui
from contextlib import contextmanager

VERSION = "1.6.1"
VERSION = "1.6.2"

# get the root logger, get snaptool logger
log = logging.getLogger()
Expand Down Expand Up @@ -179,12 +179,17 @@ def setup_logging_initial():
log.info("---------------------- Program initialize, log handlers added ------------")


def setup_logging_levels(snaptool_level, snapshots_level=logging.ERROR,
def setup_logging_levels(args, snaptool_level, snapshots_level=logging.ERROR,
background_level=logging.ERROR, wekalib_level=logging.ERROR):
log.setLevel(snaptool_level)
log.info(" ---------------------- Setting new log levels ----------------------------")

urllib3.add_stderr_logger(level=logging.ERROR)
if args.test_connection_only:
urllib3.add_stderr_logger(level=logging.WARNING)
wekalib_level=logging.INFO
else:
urllib3.add_stderr_logger(level=logging.ERROR)

logging.getLogger("wekalib.wekacluster").setLevel(wekalib_level)
logging.getLogger("wekalib.wekaapi").setLevel(wekalib_level)
logging.getLogger("wekalib.sthreads").setLevel(wekalib_level)
Expand Down Expand Up @@ -262,6 +267,7 @@ def __init__(self, clusterspec, authfile, force_https, cert_check, mgmt_port):
def connect(self):
connected = False
msg = ""
attrException, otherException = False, False
try:
log.info("Attempting cluster connection...")
self.weka_cluster = wekacluster.WekaCluster(self.clusterspec, self.authfile,
Expand All @@ -272,16 +278,17 @@ def connect(self):
self.weka_cluster_name = self.weka_cluster.name
self.connected_since = now()
connected = self.weka_cluster
except Exception as exc:
except BaseException as excinst:
otherException = True
msg2 = f" ERROR {excinst}"
if attrException or otherException:
msg1 = f"Connecting to cluster failed. "
msg1 += f" Connection options: hosts='{self.clusterspec}'"
msg1 += f", mgmt_port={self.mgmt_port}"
msg1 += f", authfile='{self.authfile}'"
msg1 += f", verify_cert={self.verify_cert}"
msg2 = f" ERROR {exc}"
log.error(msg1)
log.error(msg2)
msg = msg1 + msg2
log.error(msg1)
return connected, msg

def connection_info_different(self, new_connection):
Expand Down Expand Up @@ -390,11 +397,13 @@ def delete_old_snapshots(self, parsed_schedules_dict):

def _exit_with_connection_status(connected):
if connected:
print("Connection Succeeded")
sys.exit(0)
print(f"\nConnection Succeeded")
exit_code = 0
else:
print("Connection Failed")
sys.exit(1)
print(f"\nConnection Failed")
exit_code = 1
print(f"\n--test-connection-only - exiting with code {exit_code}.")
sys.exit(exit_code)

class ScheduleGroup(object):
def __str__(self):
Expand Down Expand Up @@ -755,7 +764,7 @@ def main():
setup_logging_initial()
# handle signals (ie: ^C and such)
signals.signal_handling()
setup_logging_levels(loglevel, snapshots_level=loglevel, background_level=loglevel)
setup_logging_levels(args, loglevel, snapshots_level=loglevel, background_level=loglevel)
log.info(f"Version info: {version_string()}")

check_other_snaptool_args(args)
Expand Down
5 changes: 3 additions & 2 deletions snaptool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@

cluster:
auth_token_file: auth-token.json
hosts: vweka01,vweka02,vweka03
hosts: wekapod001,wekapod002,wekapod003
force_https: True # only 3.10+ clusters support https
verify_cert: False # default cert cannot be verified
# mgmt_port: 14000 # port for api calls to weka cluster. default 14000

snaptool:
port: 8090 # use 0 to disable the status web ui. This overrides command line port argument
port: 8090 # snaptool web ui http port - use 0 to disable it. This overrides the command line 'port' argument

filesystems:
fs01: default
Expand Down

0 comments on commit b20ab46

Please sign in to comment.