From: peter_wang <peter.wang13@emc.com>
Date: Mon, 21 Dec 2015 10:37:12 +0000 (-0500)
Subject: Remove name_id when creating volume with cache enabled
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=864cd83c5a73cc274ba2193cc757b38a528b0332;p=openstack-build%2Fcinder-build.git

Remove name_id when creating volume with cache enabled

When image_volume_cache_enabled = True, Cinder will create
a cached image volume. But when creating this image volume,
the name_id is set to id of newly created volume, which causes
the image volume is unable to be created in the underlying storage
system.

This fix will remove the name_id so that volume.name can refer to
correct LUN on storage system

Also, a minor fix: passing volume.id to delete_volume since
it only accept volume id.

Change-Id: Ib47b189a525d8a9bd9026cc20f62542aede9c9d4
Closes-bug: 1528087
---

diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py
index 180d20743..21d48c0b1 100644
--- a/cinder/volume/manager.py
+++ b/cinder/volume/manager.py
@@ -1073,11 +1073,11 @@ class VolumeManager(manager.SchedulerDependentManager):
         reserve_opts = {'volumes': 1, 'gigabytes': volume.size}
         QUOTAS.add_volume_type_opts(ctx, reserve_opts, volume_type_id)
         reservations = QUOTAS.reserve(ctx, **reserve_opts)
-
         try:
             new_vol_values = dict(volume.items())
             new_vol_values.pop('id', None)
             new_vol_values.pop('_name_id', None)
+            new_vol_values.pop('name_id', None)
             new_vol_values.pop('volume_type', None)
             new_vol_values.pop('name', None)
 
@@ -1122,7 +1122,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                           {'volume_id': volume.id,
                            'image_id': image_meta['id']})
             try:
-                self.delete_volume(ctx, image_volume)
+                self.delete_volume(ctx, image_volume.id)
             except exception.CinderException:
                 LOG.exception(_LE('Could not delete the image volume %(id)s.'),
                               {'id': volume.id})