Skip to content

Commit 6709960

Browse files
committed
ENH: separate connection check step in CLI tool
1 parent 070aaa5 commit 6709960

File tree

1 file changed

+14
-0
lines changed
  • src/save_and_restore_api/tools

1 file changed

+14
-0
lines changed

src/save_and_restore_api/tools/cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,16 @@ def set_username_password(settings):
477477
print("")
478478

479479

480+
def check_connection(SR):
481+
logger.debug("Connecting to the Save-and-Restore service ...")
482+
try:
483+
info = SR.info_get()
484+
except SR.HTTPClientError as ex:
485+
logger.debug("Failed to connect to Save-and-Restore service.")
486+
raise RuntimeError(f"Failed to connect to the Save-and-Restore service: {ex}") from ex
487+
logger.debug(f"Save-and-Restore info:\n{pprint.pformat(info)}")
488+
489+
480490
def process_login_command(settings):
481491
"""
482492
Process the LOGIN command, which checks of user name and password are valid.
@@ -496,6 +506,8 @@ def process_login_command(settings):
496506

497507
with SaveRestoreAPI(base_url=settings.base_url, timeout=settings.timeout) as SR:
498508
try:
509+
check_connection(SR=SR)
510+
499511
logger.debug("Sending 'login' request ...")
500512
response = SR.login(username=settings.user_name, password=settings.user_password)
501513
logger.debug(f"Response received: {response}")
@@ -665,6 +677,8 @@ def process_config_command(settings):
665677
logger.debug("Configuring authentication parameters ...")
666678
SR.auth_set(username=settings.user_name, password=settings.user_password)
667679

680+
check_connection(SR=SR)
681+
668682
logger.debug(f"Checking if config node {settings.config_name!r} exists ...")
669683
node_uid = check_node_exists(SR, settings.config_name, node_type="CONFIGURATION")
670684
logger.debug(f"Config node UID: {node_uid}")

0 commit comments

Comments
 (0)