diff --git a/cinder/scheduler/driver.py b/cinder/scheduler/driver.py index 0e3b5bb3554..3a59acf6bff 100644 --- a/cinder/scheduler/driver.py +++ b/cinder/scheduler/driver.py @@ -42,12 +42,13 @@ CONF.register_opts(scheduler_driver_opts) def volume_update_db(context, volume_id, host, cluster_name, - availability_zone=None): + availability_zone=None, volume=None): """Set the host, cluster_name, and set the scheduled_at field of a volume. :returns: A Volume with the updated fields set properly. """ - volume = objects.Volume.get_by_id(context, volume_id) + if not volume: + volume = objects.Volume.get_by_id(context, volume_id) volume.host = host volume.cluster_name = cluster_name volume.scheduled_at = timeutils.utcnow() diff --git a/cinder/scheduler/filter_scheduler.py b/cinder/scheduler/filter_scheduler.py index 9c968777a78..59f513769ed 100644 --- a/cinder/scheduler/filter_scheduler.py +++ b/cinder/scheduler/filter_scheduler.py @@ -110,7 +110,8 @@ class FilterScheduler(driver.Scheduler): context, volume_id, backend.host, backend.cluster_name, - availability_zone=backend.service['availability_zone']) + availability_zone=backend.service['availability_zone'], + volume=request_spec.get('volume')) self._post_select_populate_filter_properties(filter_properties, backend) diff --git a/cinder/tests/unit/scheduler/test_scheduler.py b/cinder/tests/unit/scheduler/test_scheduler.py index 9133771bd10..8c04bda9482 100644 --- a/cinder/tests/unit/scheduler/test_scheduler.py +++ b/cinder/tests/unit/scheduler/test_scheduler.py @@ -725,6 +725,23 @@ class SchedulerDriverModuleTestCase(test.TestCase): driver.volume_update_db(self.context, volume.id, 'fake_host', 'fake_cluster') scheduled_at = volume.scheduled_at.replace(tzinfo=None) + _mock_volume_get.assert_called_once_with(self.context, volume.id) + _mock_vol_update.assert_called_once_with( + self.context, volume.id, {'host': 'fake_host', + 'cluster_name': 'fake_cluster', + 'scheduled_at': scheduled_at, + 'availability_zone': None}) + + @mock.patch('cinder.db.volume_update') + @mock.patch('cinder.objects.volume.Volume.get_by_id') + def test_volume_host_update_db_vol_present(self, _mock_volume_get, + _mock_vol_update): + volume = fake_volume.fake_volume_obj(self.context, use_quota=True) + + driver.volume_update_db(self.context, volume.id, 'fake_host', + 'fake_cluster', volume=volume) + scheduled_at = volume.scheduled_at.replace(tzinfo=None) + _mock_volume_get.assert_not_called() _mock_vol_update.assert_called_once_with( self.context, volume.id, {'host': 'fake_host', 'cluster_name': 'fake_cluster',