]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Clone_image method added image_id as parameter.
authorNavneet Singh <singn@netapp.com>
Mon, 15 Jul 2013 05:12:00 +0000 (10:42 +0530)
committerNavneet Singh <singn@netapp.com>
Fri, 19 Jul 2013 11:00:08 +0000 (16:30 +0530)
Clone_image method contains volume and image_location
as parameters. It needs to add additional image_id
as a parameter for driver implementations to introspect
internal image stores or registry for efficient image cloning.

blueprint clone-image-imageid

Change-Id: I20ae519492d73abecb1d0efc3b8e7204d2b2a4cb

cinder/tests/test_rbd.py
cinder/volume/driver.py
cinder/volume/drivers/lvm.py
cinder/volume/drivers/rbd.py
cinder/volume/drivers/scality.py
cinder/volume/flows/create_volume.py

index f9a6986b27e0917160789c065a9c3ae6c3becd7d..6d68b8198c7b135515e28c1af6c13b72f0196002 100644 (file)
@@ -474,10 +474,10 @@ class ManagedRBDTestCase(DriverTestCase):
         """Try to clone a volume from an image, and check the status
         afterwards.
         """
-        def fake_clone_image(volume, image_location):
+        def fake_clone_image(volume, image_location, image_id):
             return {'provider_location': None}, True
 
-        def fake_clone_error(volume, image_location):
+        def fake_clone_error(volume, image_location, image_id):
             raise exception.CinderException()
 
         self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
@@ -528,12 +528,12 @@ class ManagedRBDTestCase(DriverTestCase):
         expected = ({}, False)
 
         self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: False)
-        self.assertEquals(expected,
-                          self.volume.driver.clone_image(object(), object()))
+        actual = self.volume.driver.clone_image(object(), object(), object())
+        self.assertEquals(expected, actual)
 
         self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
         self.assertEquals(expected,
-                          self.volume.driver.clone_image(object(), None))
+                          self.volume.driver.clone_image(object(), None, None))
 
         # Test Success Case(s)
         expected = ({'provider_location': None}, True)
@@ -543,12 +543,11 @@ class ManagedRBDTestCase(DriverTestCase):
 
         self.stubs.Set(self.volume.driver, '_clone', lambda *args: None)
         self.stubs.Set(self.volume.driver, '_resize', lambda *args: None)
-
-        self.assertEquals(expected,
-                          self.volume.driver.clone_image(object(), object()))
+        actual = self.volume.driver.clone_image(object(), object(), object())
+        self.assertEquals(expected, actual)
 
     def test_clone_success(self):
         self.stubs.Set(self.volume.driver, '_is_cloneable', lambda x: True)
-        self.stubs.Set(self.volume.driver, 'clone_image', lambda a, b: True)
+        self.stubs.Set(self.volume.driver, 'clone_image', lambda a, b, c: True)
         image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
-        self.assertTrue(self.volume.driver.clone_image({}, image_id))
+        self.assertTrue(self.volume.driver.clone_image({}, image_id, image_id))
index ec72808792133604ac58477355fb1476ca43e103..e509fe4054129b5e706bac3af6c8674e837c0c23 100644 (file)
@@ -326,9 +326,8 @@ class VolumeDriver(object):
         # Use Brick's code to do attach/detach
         use_multipath = self.configuration.use_multipath_for_image_xfer
         protocol = conn['driver_volume_type']
-        connector = initiator.InitiatorConnector.factory(protocol,
-                                                         use_multipath=
-                                                         use_multipath)
+        connector = initiator.InitiatorConnector.factory(
+            protocol, use_multipath=use_multipath)
         device = connector.connect_volume(conn['data'])
         host_device = device['path']
 
@@ -348,13 +347,17 @@ class VolumeDriver(object):
         connector.disconnect_volume(attach_info['conn']['data'],
                                     attach_info['device'])
 
-    def clone_image(self, volume, image_location):
+    def clone_image(self, volume, image_location, image_id):
         """Create a volume efficiently from an existing image.
 
         image_location is a string whose format depends on the
         image service backend in use. The driver should use it
         to determine whether cloning is possible.
 
+        image_id is a string which represents id of the image.
+        It can be used by the driver to introspect internal
+        stores or registry to do an efficient image clone.
+
         Returns a dict of volume properties eg. provider_location,
         boolean indicating whether cloning occurred
         """
index 6b54142978a6d6e23086d429de4fdec535d840ea..552289f0e342d7685b16012e5371e550df26e25a 100644 (file)
@@ -263,7 +263,7 @@ class LVMVolumeDriver(driver.VolumeDriver):
         finally:
             self.delete_snapshot(temp_snapshot)
 
-    def clone_image(self, volume, image_location):
+    def clone_image(self, volume, image_location, image_id):
         return None, False
 
     def backup_volume(self, context, backup, backup_service):
index 91c132f1fbfef32c02d3e473579c0941ebb1f7de..3cbde15aa6e80bab3c3d840a9cb26c6894da0138 100644 (file)
@@ -519,7 +519,7 @@ class RBDDriver(driver.VolumeDriver):
                       dict(loc=image_location, err=e))
             return False
 
-    def clone_image(self, volume, image_location):
+    def clone_image(self, volume, image_location, image_id):
         if image_location is None or not self._is_cloneable(image_location):
             return ({}, False)
         prefix, pool, image, snapshot = self._parse_location(image_location)
index abf2fcda54344ec1ac78feaaf685018384221a68..0b62b41ca6a00c034eeb31567fa8b7469c6da3a9 100644 (file)
@@ -246,13 +246,17 @@ class ScalityDriver(driver.VolumeDriver):
                                   image_meta,
                                   self.local_path(volume))
 
-    def clone_image(self, volume, image_location):
+    def clone_image(self, volume, image_location, image_id):
         """Create a volume efficiently from an existing image.
 
         image_location is a string whose format depends on the
         image service backend in use. The driver should use it
         to determine whether cloning is possible.
 
+        image_id is a string which represents id of the image.
+        It can be used by the driver to introspect internal
+        stores or registry to do an efficient image clone.
+
         Returns a dict of volume properties eg. provider_location,
         boolean indicating whether cloning occurred
         """
index 702254553c3424ee8473452016d9aa6c91d427f5..0d7f49703afeb4f67b9c3c482269ba0820442c9a 100644 (file)
@@ -1213,11 +1213,10 @@ class CreateVolumeFromSpecTask(CinderTask):
         if srcvol_ref.bootable:
             self._enable_bootable_flag(context, volume_ref['id'])
         try:
-            LOG.debug(_('Copying metadata from source volume %(source_volid)s'
-                        ' to cloned volume %(clone_vol_id)s') % {
-                            'source_volid': source_volid,
-                            'clone_vol_id': volume_ref['id'],
-                        })
+            msg = _('Copying metadata from source volume %(source_volid)s'
+                    ' to cloned volume %(clone_vol_id)s')
+            LOG.debug(msg % {'source_volid': source_volid,
+                             'clone_vol_id': volume_ref['id'], })
             self.db.volume_glance_metadata_copy_from_volume_to_volume(
                 context,
                 source_volid,
@@ -1317,8 +1316,8 @@ class CreateVolumeFromSpecTask(CinderTask):
         # NOTE (singn): two params need to be returned
         # dict containing provider_location for cloned volume
         # and clone status.
-        model_update, cloned = self.driver.clone_image(volume_ref,
-                                                       image_location)
+        model_update, cloned = self.driver.clone_image(
+            volume_ref, image_location, image_id)
         make_bootable = False
         if not cloned:
             # TODO(harlowja): what needs to be rolled back in the clone if this