Merge "Fix volume manage"

This commit is contained in:
Jenkins
2017-01-23 23:36:29 +00:00
committed by Gerrit Code Review
3 changed files with 30 additions and 7 deletions
+7 -3
View File
@@ -133,10 +133,14 @@ class FilterScheduler(driver.Scheduler):
"""Check if the specified backend passes the filters."""
weighed_backends = self._get_weighted_candidates(context, request_spec,
filter_properties)
# If backend has no pool defined we will ignore it in the comparison
ignore_pool = not bool(utils.extract_host(backend, 'pool'))
for weighed_backend in weighed_backends:
backend_state = weighed_backend.obj
if backend_state.backend_id == backend:
return backend_state
backend_id = weighed_backend.obj.backend_id
if ignore_pool:
backend_id = utils.extract_host(backend_id)
if backend_id == backend:
return weighed_backend.obj
volume_id = request_spec.get('volume_id', '??volume_id missing??')
raise exception.NoValidBackend(reason=_('Cannot place volume %(id)s '
+10 -4
View File
@@ -315,10 +315,16 @@ class SchedulerManager(manager.CleanableManager, manager.Manager):
context, ex, request_spec)
try:
self.driver.backend_passes_filters(context,
volume.service_topic_queue,
request_spec,
filter_properties)
backend = self.driver.backend_passes_filters(
context, volume.service_topic_queue, request_spec,
filter_properties)
# At the API we didn't have the pool info, so the volume DB entry
# was created without it, now we add it.
volume.host = backend.host
volume.cluster_name = backend.cluster_name
volume.save()
except exception.NoValidBackend as ex:
_manage_existing_set_error(self, context, ex, request_spec)
except Exception as ex:
@@ -467,6 +467,19 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
self.assertEqual('host5', utils.extract_host(ret_host.host))
self.assertTrue(_mock_service_get_topic.called)
@mock.patch('cinder.db.service_get_all')
def test_backend_passes_filters_without_pool(self, mock_service_get_all):
"""Do a successful pass through of with backend_passes_filters()."""
sched, ctx = self._backend_passes_filters_setup(mock_service_get_all)
request_spec = {'volume_id': fake.VOLUME_ID,
'volume_type': {'name': 'LVM_iSCSI'},
'volume_properties': {'project_id': 1,
'size': 1}}
request_spec = objects.RequestSpec.from_primitives(request_spec)
ret_host = sched.backend_passes_filters(ctx, 'host1', request_spec, {})
self.assertEqual('host1', utils.extract_host(ret_host.host))
self.assertTrue(mock_service_get_all.called)
@mock.patch('cinder.db.service_get_all')
def test_backend_passes_filters_no_capacity(self, _mock_service_get_topic):
"""Fail the host due to insufficient capacity."""