Fix CapacityFilter to accept None volume type

Change I8b43624b934fadf1036fafa1f5e2b94b5317f81c introduced reading
volume_type['extra specs'] from filter_properties in CapacityFilter
without taking into account that volume_type can be None (when
default_volume_type is not set in cinder.conf). This commit fixes that.

Closes-Bug: 1619246
Change-Id: Icfc6ba5f47c3a61b49cbec5110ef7df05eb47195
This commit is contained in:
Michał Dulko 2016-09-01 13:22:20 +02:00
parent 1244318fe2
commit 472ce4aae0
2 changed files with 8 additions and 12 deletions

View File

@ -86,7 +86,7 @@ class CapacityFilter(filters.BaseHostFilter):
# provisioned_capacity_gb to determine whether a volume can be
# provisioned. Instead free capacity will be used to evaluate.
thin = True
vol_type = filter_properties.get('volume_type', {})
vol_type = filter_properties.get('volume_type', {}) or {}
provision_type = vol_type.get('extra_specs', {}).get(
'provisioning:type')
if provision_type == 'thick':

View File

@ -512,23 +512,19 @@ class CapacityFilterTestCase(HostFiltersTestCase):
self.assertTrue(filt_cls.host_passes(host, filter_properties))
@ddt.data(
{'type_key': 'provisioning:type', 'type_val': 'thick',
'vol_type': 'volume_type', 'extra_specs': 'extra_specs'},
{'type_key': 'provisioning:type', 'type_val': 'thin',
'vol_type': 'volume_type', 'extra_specs': 'extra_specs'},
{'type_key': None, 'type_val': None,
'vol_type': 'volume_type', 'extra_specs': None},
{'type_key': None, 'type_val': None,
'vol_type': None, 'extra_specs': None},
{'volume_type': {'extra_specs': {'provisioning:type': 'thick'}}},
{'volume_type': {'extra_specs': {'provisioning:type': 'thin'}}},
{'volume_type': {'extra_specs': {}}},
{'volume_type': {}},
{'volume_type': None},
)
@ddt.unpack
@mock.patch('cinder.utils.service_is_up')
def test_filter_provisioning_type(self, _mock_serv_is_up, type_key,
type_val, vol_type, extra_specs):
def test_filter_provisioning_type(self, _mock_serv_is_up, volume_type):
_mock_serv_is_up.return_value = True
filt_cls = self.class_map['CapacityFilter']()
filter_properties = {'size': 100,
vol_type: {extra_specs: {type_key: type_val}}}
'volume_type': volume_type}
service = {'disabled': False}
host = fakes.FakeHostState('host1',
{'total_capacity_gb': 500,