From d0ffa18f59be426d82c5768e942a40375ec45abb Mon Sep 17 00:00:00 2001 From: Jerome Pansanel Date: Wed, 19 Jul 2017 13:29:41 +0200 Subject: [PATCH] Fix the issue where the retrieved image is not deleted by cloudkeeper-os --- cloudkeeper_os/imagemanager.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cloudkeeper_os/imagemanager.py b/cloudkeeper_os/imagemanager.py index 5cfc21d..5202c47 100644 --- a/cloudkeeper_os/imagemanager.py +++ b/cloudkeeper_os/imagemanager.py @@ -18,6 +18,7 @@ """ import json +import os from oslo_config import cfg from oslo_log import log @@ -60,9 +61,11 @@ def add_appliance(self, appliance): LOG.debug("Image access mode: " "%s" % appliance.image.Mode.Name(appliance.image.mode)) if appliance.image.Mode.Name(appliance.image.mode) == 'REMOTE': + remote_image = True filename = utils.retrieve_image(appliance) else: filename = appliance.image.location + remote_image = False if not filename: LOG.error("Image filename is not set.") return None @@ -89,6 +92,13 @@ def add_appliance(self, appliance): ) glance.images.upload(glance_image.id, image_data) glance.images.update(glance_image.id, **properties) + + image_data.close() + + if remote_image: + LOG.debug("Delete retrieved image: %s" % (filename)) + os.unlink(filename) + return glance_image.id def update_appliance(self, appliance): @@ -113,8 +123,10 @@ def update_appliance(self, appliance): LOG.debug("Image access mode: " "%s" % appliance.image.Mode.Name(appliance.image.mode)) if appliance.image.Mode.Name(appliance.image.mode) == 'REMOTE': + remote_image = True filename = utils.retrieve_image(appliance) else: + remote_image = False filename = appliance.image.location if not filename: LOG.error("Image filename is not set.") @@ -136,6 +148,13 @@ def update_appliance(self, appliance): "values: %s" % (properties)) glance.images.upload(glance_image.id, image_data) glance.images.update(glance_image.id, **properties) + + image_data.close() + + if remote_image: + LOG.debug("Delete retrieved image: %s" % (filename)) + os.unlink(filename) + return glance_image.id