From: Daniel Wilson Date: Wed, 10 Jun 2015 21:32:49 +0000 (-0700) Subject: Volume manager should set filter_function and goodness_function X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=cbc708b13982bc11eb4956c9f3f1f96f009dafff;p=openstack-build%2Fcinder-build.git Volume manager should set filter_function and goodness_function If a user defines a filter_function or goodness_function in their cinder.conf file the scheduler should use that function. This change appends those functions to volume_stats if the driver has not specified them. Change-Id: I76f90aa3c1bda7564185d8e130926af7d0827e0e Closes-Bug: #1458061 --- diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 82b482fb0..d6bad2a41 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -330,6 +330,30 @@ class VolumeTestCase(BaseVolumeTestCase): manager.init_host() self.assertEqual(0, mock_add_p_task.call_count) + @mock.patch.object(vol_manager.VolumeManager, + 'update_service_capabilities') + def test_report_filter_goodness_function(self, mock_update): + manager = vol_manager.VolumeManager() + manager.driver.set_initialized() + myfilterfunction = "myFilterFunction" + mygoodnessfunction = "myGoodnessFunction" + expected = {'name': 'cinder-volumes', + 'filter_function': myfilterfunction, + 'goodness_function': mygoodnessfunction, + } + with mock.patch.object(manager.driver, + 'get_volume_stats') as m_get_stats: + with mock.patch.object(manager.driver, + 'get_goodness_function') as m_get_goodness: + with mock.patch.object(manager.driver, + 'get_filter_function') as m_get_filter: + m_get_stats.return_value = {'name': 'cinder-volumes'} + m_get_filter.return_value = myfilterfunction + m_get_goodness.return_value = mygoodnessfunction + manager._report_driver_status(1) + self.assertTrue(m_get_stats.called) + mock_update.assert_called_once_with(expected) + def test_is_working(self): # By default we have driver mocked to be initialized... self.assertTrue(self.volume.is_working()) diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 6dba70668..15781d840 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -1478,6 +1478,10 @@ class VolumeManager(manager.SchedulerDependentManager): # Append volume stats with 'allocated_capacity_gb' self._append_volume_stats(volume_stats) + # Append filter and goodness function if needed + volume_stats = ( + self._append_filter_goodness_functions(volume_stats)) + # queue it to be sent to the Schedulers. self.update_service_capabilities(volume_stats) @@ -1494,6 +1498,21 @@ class VolumeManager(manager.SchedulerDependentManager): pool.update(pool_stats) + def _append_filter_goodness_functions(self, volume_stats): + """Returns volume_stats updated as needed.""" + + # Append filter_function if needed + if 'filter_function' not in volume_stats: + volume_stats['filter_function'] = ( + self.driver.get_filter_function()) + + # Append goodness_function if needed + if 'goodness_function' not in volume_stats: + volume_stats['goodness_function'] = ( + self.driver.get_goodness_function()) + + return volume_stats + def publish_service_capabilities(self, context): """Collect driver status and then publish.""" self._report_driver_status(context)