From: Nate Potter Date: Wed, 21 Oct 2015 15:51:39 +0000 (+0000) Subject: Fix NoneType Attribute error X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8a594c837c0ffeba2b6b93b79bf079d3a8129d46;p=openstack-build%2Fcinder-build.git Fix NoneType Attribute error Currently when creating a volume without a specified volume_type, the capabilities_filter fails saying that NoneType object has no attribute 'get'. This patch will make that issue instead throw an exception telling the user that they need to specify a volume type. Change-Id: I89635f9e4f4f44d16f391284ccc027e86c552cdf Closes-Bug: #1446031 --- diff --git a/cinder/scheduler/filter_scheduler.py b/cinder/scheduler/filter_scheduler.py index 66604f3c4..5f19f0a45 100644 --- a/cinder/scheduler/filter_scheduler.py +++ b/cinder/scheduler/filter_scheduler.py @@ -272,6 +272,10 @@ class FilterScheduler(driver.Scheduler): filter_properties = {} self._populate_retry(filter_properties, resource_properties) + if resource_type is None: + msg = _("volume_type cannot be None") + raise exception.InvalidVolumeType(reason=msg) + filter_properties.update({'context': context, 'request_spec': request_spec, 'config_options': config_options, diff --git a/cinder/tests/unit/scheduler/test_filter_scheduler.py b/cinder/tests/unit/scheduler/test_filter_scheduler.py index 26bf65084..455bef4b5 100644 --- a/cinder/tests/unit/scheduler/test_filter_scheduler.py +++ b/cinder/tests/unit/scheduler/test_filter_scheduler.py @@ -133,6 +133,21 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): request_spec, {}) + def test_create_volume_no_volume_type(self): + sched = fakes.FakeFilterScheduler() + + fake_context = context.RequestContext('user', 'project') + + # request_spec is missing 'volume_type' + request_spec = {'volume_properties': {'project_id': 1, + 'size': 1}, + 'volume_id': ['fake-id1']} + self.assertRaises(exception.InvalidVolumeType, + sched.schedule_create_volume, + fake_context, + request_spec, + {}) + @mock.patch('cinder.scheduler.host_manager.HostManager.' 'get_all_host_states') def test_create_volume_non_admin(self, _mock_get_all_host_states):