Fix NoneType has no attribute get error

If volume_type is None and then create volumes with allow-multiattach,
Cinder-schduler will raise error:
AttributeError: 'NoneType' object has no attribute 'get'

Ied42d13b642617dd239ea92c019354b90657821a didn't fix it completely.
The error still exists. Here is the reproduce command:
"cinder create 1 ----allow-multiattach"

Because that the volume_type is always in the "request_spec", if
users doesn't pass it, its value is None.

Change-Id: I1140234dd69a644dcbf6fc3a01f382ee101624b2
Related-bug: #1683431
This commit is contained in:
wangxiyuan 2017-06-07 17:07:56 +08:00
parent cbddc11560
commit f3d66c3254
3 changed files with 9 additions and 5 deletions

View File

@ -278,7 +278,7 @@ class FilterScheduler(driver.Scheduler):
# takes 'resource_XX' and 'volume_XX' as input respectively, copying
# 'volume_XX' to 'resource_XX' will make both filters happy.
volume_type = request_spec.get("volume_type")
resource_type = request_spec.get("volume_type", {})
resource_type = volume_type if volume_type is not None else {}
config_options = self._get_configuration_options()

View File

@ -46,7 +46,8 @@ class FakeHostManager(host_manager.HostManager):
'thick_provisioning_support': True,
'reserved_percentage': 10,
'volume_backend_name': 'lvm1',
'timestamp': UTC_NOW},
'timestamp': UTC_NOW,
'multiattach': True},
'host2': {'total_capacity_gb': 2048,
'free_capacity_gb': 300,
'allocated_capacity_gb': 1748,

View File

@ -334,15 +334,18 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase):
return (sched, fake_context)
@ddt.data(None, {'name': 'LVM_iSCSI'})
@mock.patch('cinder.db.service_get_all')
def test_backend_passes_filters_happy_day(self, _mock_service_get_topic):
def test_backend_passes_filters_happy_day(self, volume_type,
_mock_service_get_topic):
"""Do a successful pass through of with backend_passes_filters()."""
sched, ctx = self._backend_passes_filters_setup(
_mock_service_get_topic)
request_spec = {'volume_id': fake.VOLUME_ID,
'volume_type': {'name': 'LVM_iSCSI'},
'volume_type': volume_type,
'volume_properties': {'project_id': 1,
'size': 1}}
'size': 1,
'multiattach': True}}
request_spec = objects.RequestSpec.from_primitives(request_spec)
ret_host = sched.backend_passes_filters(ctx, 'host1#lvm1',
request_spec, {})