Merge "Fix AttributeError without share type provided"

This commit is contained in:
Jenkins 2015-09-01 12:58:34 +00:00 committed by Gerrit Code Review
commit 14c18049f7
2 changed files with 16 additions and 0 deletions

View File

@ -122,6 +122,12 @@ class FilterScheduler(driver.Scheduler):
# 'volume_XX' to 'resource_XX' will make both filters happy.
resource_properties = share_properties.copy()
share_type = request_spec.get("share_type", {})
if not share_type:
msg = _("You must create a share type in advance,"
" and specify in request body or"
" set default_share_type in manila.conf.")
LOG.error(msg)
raise exception.InvalidParameterValue(err=msg)
extra_specs = share_type.get('extra_specs', {})

View File

@ -132,6 +132,16 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
self.assertIsNone(weighed_host)
self.assertTrue(_mock_service_get_all_by_topic.called)
def test_schedule_share_type_is_none(self):
sched = fakes.FakeFilterScheduler()
request_spec = {
'share_type': None,
'share_properties': {'project_id': 1, 'size': 1},
}
self.assertRaises(exception.InvalidParameterValue,
sched._schedule_share,
self.context, request_spec)
def test_max_attempts(self):
self.flags(scheduler_max_attempts=4)
sched = fakes.FakeFilterScheduler()