]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Volume manager should set filter_function and goodness_function
authorDaniel Wilson <daniel.wilson@purestorage.com>
Wed, 10 Jun 2015 21:32:49 +0000 (14:32 -0700)
committerDaniel Wilson <daniel.wilson@purestorage.com>
Thu, 11 Jun 2015 23:18:50 +0000 (16:18 -0700)
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

cinder/tests/unit/test_volume.py
cinder/volume/manager.py

index 82b482fb0cce90807efd67dce47a3e4660d7bcf9..d6bad2a4160707db4b045781384b49f0f1b943de 100644 (file)
@@ -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())
index 6dba70668a0ce593a669463e7f56a32a1a4c61f7..15781d840eab0ed613d79fef0406703642ba481b 100644 (file)
@@ -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)