From: Navneet Singh Date: Sat, 3 Aug 2013 12:46:44 +0000 (+0530) Subject: Fix chown fail for nfs file without necessary permission X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1498958299ccb807f406e9d257848cb4259e49e4;p=openstack-build%2Fcinder-build.git Fix chown fail for nfs file without necessary permission chown failed in case of volumes on nfs export when the permission is not granted on the storage system. Upload volume only requires read access on the nfs file and hence chown is not neccessary when current user has read permission. Chown only executed when read is not granted to the user. Change-Id: Ifa8eff7e79c6e4f15a1feb7cabec8cae8a0b0a83 Closes-Bug:#1221205 --- diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index c562a91da..a364a6961 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -316,11 +316,8 @@ def fetch_to_volume_format(context, image_service, if backing_file is not None: raise exception.ImageUnacceptable( image_id=image_id, - reason=_("fmt=%(fmt)s backed by:" - "%(backing_file)s") % { - 'fmt': fmt, - 'backing_file': backing_file, - }) + reason=_("fmt=%(fmt)s backed by:%(backing_file)s") + % {'fmt': fmt, 'backing_file': backing_file, }) # NOTE(jdg): I'm using qemu-img convert to write # to the volume regardless if it *needs* conversion or not @@ -349,12 +346,13 @@ def upload_volume(context, image_service, image_meta, volume_path, if (image_meta['disk_format'] == volume_format): LOG.debug("%s was %s, no need to convert to %s" % (image_id, volume_format, image_meta['disk_format'])) - if os.name == 'nt': - with fileutils.file_open(volume_path) as image_file: - image_service.update(context, image_id, {}, image_file) - with utils.temporary_chown(volume_path): + if os.name == 'nt' or os.access(volume_path, os.R_OK): with fileutils.file_open(volume_path) as image_file: image_service.update(context, image_id, {}, image_file) + else: + with utils.temporary_chown(volume_path): + with fileutils.file_open(volume_path) as image_file: + image_service.update(context, image_id, {}, image_file) return if (CONF.image_conversion_dir and not