From: Javeme Date: Wed, 18 Nov 2015 08:26:08 +0000 (+0800) Subject: Remove those unnecessary statements "return True" X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=066313c0d0b8a90d88b85d12ce302db24bb3b73a;p=openstack-build%2Fcinder-build.git Remove those unnecessary statements "return True" The reasons to remove them: * These asynchronous API is not necessary to return a value. * We do not see the purpose of the statements, because it always returns true regardless of success or failure. These statements are unnecessary and misleading, this commit we will remove these "return True" (Or just remove "True" if it's not at the end of a function, in order not to change the execution path). Affected methods: * delete_volume * delete_snapshot * delete_consistencygroup * update_consistencygroup * delete_cgsnapshot Closes-Bug: #1533997 Change-Id: I38bac64b9eb1be6a4756cfcd3894615d2b849551 --- diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index a330fb7e9..91fb4a14a 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -1101,8 +1101,7 @@ class VolumeTestCase(BaseVolumeTestCase): mox.IgnoreArg()).AndRaise(exception.VolumeIsBusy( volume_name='fake')) self.mox.ReplayAll() - res = self.volume.delete_volume(self.context, volume_id) - self.assertTrue(res) + self.volume.delete_volume(self.context, volume_id) volume_ref = db.volume_get(context.get_admin_context(), volume_id) self.assertEqual(volume_id, volume_ref.id) self.assertEqual("available", volume_ref.status) @@ -1191,7 +1190,7 @@ class VolumeTestCase(BaseVolumeTestCase): def test_delete_volume_not_found(self, mock_get_volume): """Test delete volume moves on if the volume does not exist.""" volume_id = '12345678-1234-5678-1234-567812345678' - self.assertTrue(self.volume.delete_volume(self.context, volume_id)) + self.volume.delete_volume(self.context, volume_id) self.assertTrue(mock_get_volume.called) @mock.patch('cinder.volume.drivers.lvm.LVMVolumeDriver.' diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index f34d4bb32..d833ff4eb 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -682,7 +682,7 @@ class VolumeManager(manager.SchedulerDependentManager): # be deleted when resuming deletes from init_host(). LOG.debug("Attempted delete of non-existent volume: %s", volume_id) - return True + return if context.project_id != volume.project_id: project_id = volume.project_id @@ -749,7 +749,7 @@ class VolumeManager(manager.SchedulerDependentManager): # record to avoid user confusion. self._clear_db(context, is_migrating_dest, volume, 'available') - return True + return except Exception: with excutils.save_and_reraise_exception(): # If this is a destination volume, we have to clear the @@ -806,7 +806,6 @@ class VolumeManager(manager.SchedulerDependentManager): self.publish_service_capabilities(context) LOG.info(_LI("Deleted volume successfully."), resource=volume) - return True def _clear_db(self, context, is_migrating_dest, volume_ref, status): # This method is called when driver.unmanage() or @@ -906,7 +905,7 @@ class VolumeManager(manager.SchedulerDependentManager): resource=snapshot) snapshot.status = 'available' snapshot.save() - return True + return except Exception: with excutils.save_and_reraise_exception(): snapshot.status = 'error_deleting' @@ -941,7 +940,6 @@ class VolumeManager(manager.SchedulerDependentManager): QUOTAS.commit(context, reservations, project_id=project_id) LOG.info(_LI("Delete snapshot completed successfully"), resource=snapshot) - return True def attach_volume(self, context, volume_id, instance_uuid, host_name, mountpoint, mode): @@ -2860,8 +2858,6 @@ class VolumeManager(manager.SchedulerDependentManager): resource={'type': 'consistency_group', 'id': group.id}) - return True - def update_consistencygroup(self, context, group, add_volumes=None, remove_volumes=None): """Updates consistency group. @@ -3006,8 +3002,6 @@ class VolumeManager(manager.SchedulerDependentManager): resource={'type': 'consistency_group', 'id': group.id}) - return True - def create_cgsnapshot(self, context, cgsnapshot): """Creates the cgsnapshot.""" caller_context = context @@ -3215,8 +3209,6 @@ class VolumeManager(manager.SchedulerDependentManager): self._notify_about_cgsnapshot_usage(context, cgsnapshot, "delete.end", snapshots) - return True - def update_migrated_volume(self, ctxt, volume, new_volume, volume_status): """Finalize migration process on backend device."""