CORD-415 and Raising an 503 error when ceilometer container is not ready
diff --git a/xos/core/xoslib/methods/ceilometerview.py b/xos/core/xoslib/methods/ceilometerview.py
index f26d84a..c2ecb15 100644
--- a/xos/core/xoslib/methods/ceilometerview.py
+++ b/xos/core/xoslib/methods/ceilometerview.py
@@ -3,6 +3,7 @@
import urllib2
import pytz
import datetime
+import time
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
@@ -29,17 +30,23 @@
if not monitoring_channel:
raise XOSMissingField("Monitoring channel is missing for this tenant...Create one and invoke this REST API")
#TODO: Wait until URL is completely UP
+ MAX_ATTEMPTS = 5
+ attempts = 0
while True:
try:
- response = urllib2.urlopen(monitoring_channel.ceilometer_url,timeout=1)
+ response = urllib2.urlopen(monitoring_channel.ceilometer_url)
break
except urllib2.HTTPError, e:
- logger.info('SRIKANTH: HTTP error %(reason)s' % {'reason':e.reason})
+ logger.info('HTTP error %(reason)s' % {'reason':e.reason})
break
except urllib2.URLError, e:
- logger.info('SRIKANTH: URL error %(reason)s' % {'reason':e.reason})
+ attempts += 1
+ if attempts >= MAX_ATTEMPTS:
+ raise XOSServiceUnavailable("Ceilometer channel is not ready yet...Try again later")
+ logger.info('URL error %(reason)s' % {'reason':e.reason})
+ time.sleep(1)
pass
- logger.info("SRIKANTH: Ceilometer proxy URL for user %(user)s is %(url)s" % {'user':user.username,'url':monitoring_channel.ceilometer_url})
+ logger.info("Ceilometer proxy URL for user %(user)s is %(url)s" % {'user':user.username,'url':monitoring_channel.ceilometer_url})
return monitoring_channel.ceilometer_url
def getTenantControllerTenantMap(user, slice=None):
diff --git a/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml b/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml
index 6cda511..89f1aaf 100644
--- a/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml
+++ b/xos/synchronizers/monitoring_channel/steps/sync_monitoringchannel.yaml
@@ -42,19 +42,19 @@
- name: install Docker
apt: name=lxc-docker state=present update_cache=yes
- - name: install python-setuptools
- apt: name=python-setuptools state=present
+# - name: install python-setuptools
+# apt: name=python-setuptools state=present
- - name: install pip
- easy_install: name=pip
+# - name: install pip
+# easy_install: name=pip
- - name: install docker-py
- pip: name=docker-py version=0.5.3
+# - name: install docker-py
+# pip: name=docker-py version=0.5.3
- - name: install Pipework
- get_url: url=https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework
- dest=/usr/local/bin/pipework
- mode=0755
+# - name: install Pipework
+# get_url: url=https://raw.githubusercontent.com/jpetazzo/pipework/master/pipework
+# dest=/usr/local/bin/pipework
+# mode=0755
- name: Disable resolvconf service
shell: service resolvconf stop
diff --git a/xos/xos/exceptions.py b/xos/xos/exceptions.py
index 52badf8..9ab2605 100644
--- a/xos/xos/exceptions.py
+++ b/xos/xos/exceptions.py
@@ -62,3 +62,9 @@
"specific_error": why,
"fields": fields})
+class XOSServiceUnavailable(APIException):
+ status_code=503
+ def __init__(self, why="Service temporarily unavailable, try again later", fields={}):
+ APIException.__init__(self, {"error": "XOSServiceUnavailable",
+ "specific_error": why,
+ "fields": fields})