Wait for MAAS warmup - also, for URLError
* Handle situation, when apache\etc not ready yet
Closes-Bug: PROD-21039 (PROD:21039)
Change-Id: I0bd37b76b479758847bfc34e8e08d168f18054aa
diff --git a/_modules/maasng.py b/_modules/maasng.py
index 0ea58ae..c93f8ab 100644
--- a/_modules/maasng.py
+++ b/_modules/maasng.py
@@ -1159,14 +1159,21 @@
def _getHTTPCode(url):
- code = 404
+ code = '003'
+ m = ''
try:
connection = urllib2.urlopen(url)
code = connection.getcode()
connection.close()
- except urllib2.HTTPError as e:
- code = e.getcode()
- LOG.warning("Catch http code:{} from url:{}".format(code, url))
+ except (urllib2.HTTPError, urllib2.URLError) as e:
+ try:
+ code = e.getcode()
+ except:
+ m = e.reason
+ pass
+ LOG.debug(
+ "Unexpected http code:{} from url:{}\n"
+ "with message:{}".format(code, url, m))
pass
return code
@@ -1190,7 +1197,7 @@
c_timeout = timeout - (time.time() - started_at)
if c_timeout <= 0:
ret['result'] = False
- ret["comment"] = "api:{} not answered up in time".format(url)
+ ret["comment"] = "api:{} not answered in time".format(url)
return ret
LOG.info(
"Waiting for api:{0}\n"