204
206
logging.error('deployer: {}'.format(escape.utf8(error)))
205
207
data['Error'] = error
206
208
return gen.Return(data)
212
def increment_deployment_counter(bundle_id, charmworld_url):
213
"""Increment the deployment count in Charmworld.
215
If the call to Charmworld fails we log the error but don't report it.
216
This counter is a 'best effort' attempt but it will not impede our
217
deployment of the bundle.
220
- bundle_id: the ID for the bundle in Charmworld.
221
- charmworld_url: the URL for charmworld, including the protocol.
224
Returns True if the counter is successfully incremented else False.
226
if charmworld_url is None:
227
raise gen.Return(False)
229
if not all((isinstance(bundle_id, basestring),
230
isinstance(charmworld_url, basestring))):
231
raise gen.Return(False)
233
path = 'metric/deployments/increment'
234
url = u'{}api/3/bundle/{}/{}'.format(
236
urllib.quote(bundle_id), path)
237
logging.info('Incrementing bundle deployment count using\n{}.'.format(
238
url.encode('utf-8')))
239
client = AsyncHTTPClient()
240
# We use a GET instead of a POST since there is not request body.
242
resp = yield client.fetch(url, callback=None)
243
except Exception as exc:
244
logging.error('Attempt to increment deployment counter failed.')
245
logging.error('URL: {}'.format(url))
246
logging.exception(exc)
247
raise gen.Return(False)
248
success = bool(resp.code == 200)
249
raise gen.Return(success)