Clean /tmp after upload when using glance v2 client
When using glance v2 client, it will leave an upload
tmp file in /tmp folder, which will cause upload error
if its filesystem (in memory) is full.
Closes-Bug:
@@ -461,7 +461,16 @@ def image_create(request, **kwargs):
{'data': data})
else:
def upload():
+ try:
return glanceclient(request).images.upload(image.id, data)
+ finally:
+ filename = str(data.file.name)
+ try:
+ os.remove(filename)
+ except OSError as e:
+ LOG.warning('Failed to remove temporary image file '
+ '%(file)s (%(e)s)',
+ {'file': filename, 'e': e})
thread.start_new_thread(upload, ())
return Image(image)
