Merge "Scheduler: Remove unnecessary DB read"
This commit is contained in:
commit
95630360b2
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user