From 76bba03abd7a2c75d0d419d99b5ebdf7ade1818b Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Tue, 17 Jul 2018 09:34:06 +0200 Subject: aktualizr: retry garage-sign version check and handle errors better. --- recipes-sota/aktualizr/garage-sign-version.inc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'recipes-sota/aktualizr/garage-sign-version.inc') diff --git a/recipes-sota/aktualizr/garage-sign-version.inc b/recipes-sota/aktualizr/garage-sign-version.inc index f2d04e8..1b89a3d 100644 --- a/recipes-sota/aktualizr/garage-sign-version.inc +++ b/recipes-sota/aktualizr/garage-sign-version.inc @@ -11,8 +11,21 @@ python () { url = url_file.read().decode().strip(' \t\n') + '/health/version' except (KeyError, ValueError, RuntimeError): return - r = urllib.request.urlopen(url) - if r.code != 200: + connected = False + tries = 3 + for i in range(tries): + try: + r = urllib.request.urlopen(url) + if r.code == 200: + connected = True + break + else: + print('Bad return code from server ' + url + ': ' + str(r.code) + + ' (attempt ' + str(i + 1) + ' of ' + str(tries) + ')') + except urllib.error.URLError as e: + print('Error connecting to server ' + url + ': ' + str(e) + + ' (attempt ' + str(i + 1) + ' of ' + str(tries) + ')') + if not connected: return resp = r.read().decode('utf-8') j = json.loads(resp) -- cgit v1.2.3-54-g00ecf