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.

Change-Id: I0a7267db894e7be4216a346752d299132df9a29a
Closes-Bug: #1689694
This commit is contained in:
jimmygc
2017-05-10 11:20:46 +08:00
committed by guochao
parent 19414ccb48
commit 4214fc2d75

View File

@@ -461,7 +461,16 @@ def image_create(request, **kwargs):
{'data': data})
else:
def upload():
return glanceclient(request).images.upload(image.id, data)
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)