diff options
author | Thomas Duval <thomas.duval@orange.com> | 2018-10-05 16:54:37 +0200 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2018-10-05 16:58:48 +0200 |
commit | 2e35a7e46f0929438c1c206e3116caa829f07dc6 (patch) | |
tree | 759a83b3dfefe70faeada1c3af7377f4cd89b8eb /moon_interface/moon_interface/authz_requests.py | |
parent | 2dbe655587ca98b67c1a3e3798c63fd47229adc0 (diff) |
Update code to 4.6 official version
Change-Id: Ibd0da0e476e24b2685f54693efc11f7a58d40a62
Diffstat (limited to 'moon_interface/moon_interface/authz_requests.py')
-rw-r--r-- | moon_interface/moon_interface/authz_requests.py | 22 |
1 files changed, 13 insertions, 9 deletions
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 |