From e6b70b5c37070579c916cc5a1ea511ff9934851b Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Wed, 7 Mar 2012 15:53:30 -0500 Subject: [PATCH] Increase logging for xenapi plugin glance uploads Without this change, the glance plugin is pretty quiet about image uploads. But it can definitely be helpful to debugging to have information such as which glance server is handling the upload, how much data was sent, and more information about the glance server response if it was something other than 200 OK. Change-Id: I0269478ad1061fc2021ef4b5d9c3c1dea9b2f6cb --- plugins/xenserver/xenapi/etc/xapi.d/plugins/glance | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance index e7998bb8ebd9..95fe54524c6a 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/glance @@ -354,6 +354,8 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port, Create a tarball of the image and then stream that into Glance using chunked-transfer-encoded HTTP. """ + url = 'http://%s:%s/v1/images/%s' % (glance_host, glance_port, image_id) + logging.info("Writing image data to %s" % url) conn = httplib.HTTPConnection(glance_host, glance_port) # NOTE(sirp): httplib under python2.4 won't accept a file-like object @@ -395,17 +397,25 @@ def _upload_tarball(staging_path, image_id, glance_host, glance_port, tar_cmd = "tar -zc --directory=%(staging_path)s ." % locals() tar_proc = _make_subprocess(tar_cmd, stdout=True, stderr=True) + length = 0 chunk = tar_proc.stdout.read(CHUNK_SIZE) while chunk: + length += len(chunk) conn.send("%x\r\n%s\r\n" % (len(chunk), chunk)) chunk = tar_proc.stdout.read(CHUNK_SIZE) conn.send("0\r\n\r\n") + logging.info("Wrote %s bytes to %s" % (length, url)) _finish_subprocess(tar_proc, tar_cmd) resp = conn.getresponse() if resp.status != httplib.OK: - raise Exception("Unexpected response from Glance %i" % resp.status) + logging.error("Unexpected response while writing image data to %s: " + "Response Status: %i, Response body: %s" + % (url, resp.status, resp.read())) + raise Exception("Unexpected response [%i] while uploading image [%s] " + "to glance host [%s:%s]" + % (resp.status, image_id, glance_host, glance_port)) conn.close()