From 9abeca399e3e006e1ac6e8df2ba89b007cd93eac Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 10 Aug 2016 13:14:45 -0400 Subject: [PATCH] Fix volume creation with no volume type Allow creation of volumes with no volume type. This has always been supported but was accidentally broken with recent changes. If a type is not specified, the capabilities filter can skip processing type-related checks. This reverts most of 8a594c8 "Fix NoneType Attribute Error" Closes-Bug: #1610073 Co-Author: Tom Barron Change-Id: I7cb8435af379099c60f0f84d7bad4a6660d2d636 --- cinder/scheduler/filter_scheduler.py | 6 +----- cinder/scheduler/filters/capabilities_filter.py | 4 ++++ cinder/tests/unit/scheduler/test_filter_scheduler.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cinder/scheduler/filter_scheduler.py b/cinder/scheduler/filter_scheduler.py index e87c2f67d5b..459da3696a5 100644 --- a/cinder/scheduler/filter_scheduler.py +++ b/cinder/scheduler/filter_scheduler.py @@ -270,10 +270,6 @@ class FilterScheduler(driver.Scheduler): self._populate_retry(filter_properties, request_spec['volume_properties']) - if resource_type is None: - msg = _("volume_type cannot be None") - raise exception.InvalidVolumeType(reason=msg) - request_spec_dict = jsonutils.to_primitive(request_spec) filter_properties.update({'context': context, @@ -427,7 +423,7 @@ class FilterScheduler(driver.Scheduler): if not weighed_hosts: LOG.warning(_LW('No weighed hosts found for volume ' 'with properties: %s'), - filter_properties['request_spec']['volume_type']) + filter_properties['request_spec'].get('volume_type')) return None return self._choose_top_host(weighed_hosts, request_spec) diff --git a/cinder/scheduler/filters/capabilities_filter.py b/cinder/scheduler/filters/capabilities_filter.py index e6e3c2d5190..5d64b150c8a 100644 --- a/cinder/scheduler/filters/capabilities_filter.py +++ b/cinder/scheduler/filters/capabilities_filter.py @@ -30,6 +30,10 @@ class CapabilitiesFilter(filters.BaseHostFilter): Check that the capabilities provided by the services satisfy the extra specs associated with the resource type. """ + + if not resource_type: + return True + extra_specs = resource_type.get('extra_specs', []) if not extra_specs: return True diff --git a/cinder/tests/unit/scheduler/test_filter_scheduler.py b/cinder/tests/unit/scheduler/test_filter_scheduler.py index d92193065fb..1814e523465 100644 --- a/cinder/tests/unit/scheduler/test_filter_scheduler.py +++ b/cinder/tests/unit/scheduler/test_filter_scheduler.py @@ -147,7 +147,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): 'size': 1}, 'volume_id': fake.VOLUME_ID} request_spec = objects.RequestSpec.from_primitives(request_spec) - self.assertRaises(exception.InvalidVolumeType, + self.assertRaises(exception.NoValidHost, sched.schedule_create_volume, fake_context, request_spec,