From 2e35a7e46f0929438c1c206e3116caa829f07dc6 Mon Sep 17 00:00:00 2001 From: Thomas Duval Date: Fri, 5 Oct 2018 16:54:37 +0200 Subject: Update code to 4.6 official version Change-Id: Ibd0da0e476e24b2685f54693efc11f7a58d40a62 --- moon_interface/moon_interface/authz_requests.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'moon_interface/moon_interface/authz_requests.py') diff --git a/moon_interface/moon_interface/authz_requests.py b/moon_interface/moon_interface/authz_requests.py index c809053b..cf50dfe5 100644 --- a/moon_interface/moon_interface/authz_requests.py +++ b/moon_interface/moon_interface/authz_requests.py @@ -53,7 +53,9 @@ class AuthzRequest: raise exceptions.AuthzException( "error in address no hostname or hostip" ) + tried_hostnames = [] while tries < 2: + tried_hostnames.append(hostname) try: req = requests.post("http://{}:{}/authz".format( hostname, @@ -62,18 +64,20 @@ class AuthzRequest: if req.status_code != 200: raise exceptions.AuthzException( "Receive bad response from Authz function " - "(with address - {})".format(req.status_code) + "(with {} -> {})".format(hostname, req.status_code) ) success = True - break except requests.exceptions.ConnectionError: - logger.error("Cannot connect to {}".format( - "http://{}:{}/authz".format( - hostname, - self.container_chaining[0]["port"] - ))) - except: - logger.error("Unexpected error:", sys.exc_info()[0]) + if tries > 1: + logger.error("Cannot connect to {}".format( + "http://[{}]:{}/authz".format( + ", ".join(tried_hostnames), + self.container_chaining[0]["port"] + ))) + except Exception as e: + logger.exception(e) + else: + break hostname = self.container_chaining[0]["hostname"], tries += 1 -- cgit 1.2.3-korg