From: Erlon R. Cruz Date: Tue, 7 Jul 2015 14:30:15 +0000 (-0300) Subject: Move update_migrated_volume() to BaseVD X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=162f4125e13493d8e51e41363986c5167999f481;p=openstack-build%2Fcinder-build.git Move update_migrated_volume() to BaseVD The update_migrated_volume() function on volume/manager.py calls the update_migrated_volume() from the driver. If the driver does not implement the function, the manager falls back (by catching the NotImplementedError exception) and implements a default behavior, not renaming the volume. If the driver does not have the function implemented, the migration will fail as in this case, an AttributeError exception can be raised. We fix this by implementing the method update_migrate_volume() in the BaseVD driver so all drivers now throw the proper exception. Change-Id: I9f3cbdc5ae1cdcbf8fe61168abf35b985d4182c6 Closes-Bug: #1471807 --- diff --git a/cinder/tests/unit/test_nfs.py b/cinder/tests/unit/test_nfs.py index 8a2ee1bfc..d82a36b1a 100644 --- a/cinder/tests/unit/test_nfs.py +++ b/cinder/tests/unit/test_nfs.py @@ -32,6 +32,7 @@ from cinder.volume.drivers import remotefs class DumbVolume(object): + # TODO(eharney): replace this with an autospecced mock class fields = {} def __setitem__(self, key, value): @@ -1292,3 +1293,18 @@ class NfsDriverDoSetupTestCase(test.TestCase): [mock.call('mount.nfs', check_exit_code=False, run_as_root=False)]) + + def test_update_migrated_volume_is_there(self): + """Ensure that driver.update_migrated_volume() is there.""" + + drv = nfs.NfsDriver(configuration=self.configuration) + + v1 = DumbVolume() + v2 = DumbVolume() + + self.assertRaises(NotImplementedError, + drv.update_migrated_volume, + self.context, + v1, + v2, + mock.sentinel) diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 8873a84d2..dd1ff9de5 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -820,6 +820,25 @@ class BaseVD(object): """Fail if connector doesn't contain all the data needed by driver.""" pass + def update_migrated_volume(self, ctxt, volume, new_volume, + original_volume_status): + """Return model update for migrated volume. + + Each driver implementing this method needs to be responsible for the + values of _name_id and provider_location. If None is returned or either + key is not set, it means the volume table does not need to change the + value(s) for the key(s). + The return format is {"_name_id": value, "provider_location": value}. + + :param volume: The original volume that was migrated to this backend + :param new_volume: The migration volume object that was created on + this backend as part of the migration process + :param original_volume_status: The status of the original volume + :return model_update to update DB with any needed changes + """ + msg = _("The method update_migrated_volume is not implemented.") + raise NotImplementedError(msg) + @staticmethod def validate_connector_has_setting(connector, setting): pass @@ -1360,25 +1379,6 @@ class VolumeDriver(ConsistencyGroupVD, TransferVD, ManageableVD, ExtendVD, """ return None - def update_migrated_volume(self, ctxt, volume, new_volume, - original_volume_status): - """Return model update for migrated volume. - - Each driver implementing this method needs to be responsible for the - values of _name_id and provider_location. If None is returned or either - key is not set, it means the volume table does not need to change the - value(s) for the key(s). - The return format is {"_name_id": value, "provider_location": value}. - - :param volume: The original volume that was migrated to this backend - :param new_volume: The migration volume object that was created on - this backend as part of the migration process - :param original_volume_status: The status of the original volume - :return model_update to update DB with any needed changes - """ - msg = _("The method update_migrated_volume is not implemented.") - raise NotImplementedError(msg) - def migrate_volume(self, context, volume, host): return (False, None)