Skip to content
Snippets Groups Projects
Commit 7c2e38d3 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-573: added method TMSSsession.check_connection_and_exit_on_error with a...

TMSS-573: added method TMSSsession.check_connection_and_exit_on_error with a clear method name and intent. This also produces uch more user frienly log lines
parent a461863b
No related branches found
No related tags found
1 merge request!343Resolve TMSS-557 and TMSS-307
......@@ -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()
......
......@@ -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)
......
......@@ -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()
......
......@@ -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:
try:
client.get_path_as_string("")
logger.info("Http REST login to TMSS working on %s for user '%s'", client.host_url, client.username)
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment