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())
# 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)
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)