diff --git a/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py b/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py index 5a8145bb7ec5c55bc9b7f87a930954aae125b573..0740de6b3a9e51f73df91fe2eaaa986759e2e69b 100644 --- a/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py +++ b/SAS/TMSS/backend/services/feedback_handling/lib/feedback_handling.py @@ -203,7 +203,7 @@ def main(): (options, args) = parser.parse_args() - TMSSsession.check_connection(options.rest_credentials) + TMSSsession.check_connection_and_exit_on_error(options.rest_credentials) with create_service(exchange=options.exchange, broker=options.broker, rest_client_creds_id=options.rest_credentials, qpid_broker=options.qpid_broker, feedback_wait_timeout=options.timeout): waitForInterrupt() diff --git a/SAS/TMSS/backend/services/scheduling/bin/tmss_scheduling_service b/SAS/TMSS/backend/services/scheduling/bin/tmss_scheduling_service index 13210ce16091528e21105ec9b44a1fdecb4d0362..fcbc1d107f5ec773cbe7ca183f4e5fa8fce26e59 100755 --- a/SAS/TMSS/backend/services/scheduling/bin/tmss_scheduling_service +++ b/SAS/TMSS/backend/services/scheduling/bin/tmss_scheduling_service @@ -48,7 +48,7 @@ def main(): (options, args) = parser.parse_args() from lofar.sas.tmss.client.tmss_http_rest_client import TMSSsession - TMSSsession.check_connection(options.rest_credentials) + TMSSsession.check_connection_and_exit_on_error(options.rest_credentials) from lofar.sas.tmss.tmss import setup_and_check_tmss_django setup_and_check_tmss_django(options.dbcredentials) diff --git a/SAS/TMSS/backend/services/websocket/lib/websocket_service.py b/SAS/TMSS/backend/services/websocket/lib/websocket_service.py index 9f641d04aaf7e2fdacae6995b5d7424583bcea82..e87029d4d684fc20f4f9f7d1e6f19c0a94f8ce59 100644 --- a/SAS/TMSS/backend/services/websocket/lib/websocket_service.py +++ b/SAS/TMSS/backend/services/websocket/lib/websocket_service.py @@ -184,7 +184,7 @@ def main(): (options, args) = parser.parse_args() - TMSSsession.check_connection(options.rest_credentials) + TMSSsession.check_connection_and_exit_on_error(options.rest_credentials) with create_service(options.websocket_port, options.exchange, options.broker, rest_client_creds_id=options.rest_credentials): waitForInterrupt() diff --git a/SAS/TMSS/client/lib/tmss_http_rest_client.py b/SAS/TMSS/client/lib/tmss_http_rest_client.py index 760097c1623a773b1106ac0e9f6be7d5eb205572..ee8e5494123458201c4b558667b1d1be096362d2 100644 --- a/SAS/TMSS/client/lib/tmss_http_rest_client.py +++ b/SAS/TMSS/client/lib/tmss_http_rest_client.py @@ -64,8 +64,21 @@ class TMSSsession(object): '''Open a connection to TMSS using the credentials for the given dbcreds_name raises if no connection possible''' with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name) as client: - client.get_path_as_string("") - logger.info("Http REST login to TMSS working on %s for user '%s'", client.host_url, client.username) + try: + client.get_path_as_string("") + logger.info("Http REST login to TMSS working on %s for user '%s'", client.api_url, client.username) + except: + raise ConnectionError("Cannot connect to TMSS REST API %s for user '%s'" % (client.api_url, client.username)) + + @staticmethod + def check_connection_and_exit_on_error(dbcreds_name: str=None): + '''Open a connection to TMSS using the credentials for the given dbcreds_name + exit(1) upon ConnectionError''' + try: + TMSSsession.check_connection(dbcreds_name) + except Exception as e: + logger.error(e) + exit(1) def __enter__(self): self.open()