]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix NoneType Attribute error
authorNate Potter <nathaniel.potter@intel.com>
Wed, 21 Oct 2015 15:51:39 +0000 (15:51 +0000)
committerNate Potter <nathaniel.potter@intel.com>
Wed, 21 Oct 2015 15:51:39 +0000 (15:51 +0000)
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

cinder/scheduler/filter_scheduler.py
cinder/tests/unit/scheduler/test_filter_scheduler.py

index 66604f3c467c67af2cfcdfac22d80993a36638aa..5f19f0a459bab57a333f78457c678b33303b8738 100644 (file)
@@ -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,
index 26bf6508428463fd9157f8beba518ece481b438c..455bef4b57c42952537a870da1a6b13baa7a2009 100644 (file)
@@ -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):