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:
parent
1244318fe2
commit
472ce4aae0
@ -86,7 +86,7 @@ class CapacityFilter(filters.BaseHostFilter):
|
|||||||
# provisioned_capacity_gb to determine whether a volume can be
|
# provisioned_capacity_gb to determine whether a volume can be
|
||||||
# provisioned. Instead free capacity will be used to evaluate.
|
# provisioned. Instead free capacity will be used to evaluate.
|
||||||
thin = True
|
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(
|
provision_type = vol_type.get('extra_specs', {}).get(
|
||||||
'provisioning:type')
|
'provisioning:type')
|
||||||
if provision_type == 'thick':
|
if provision_type == 'thick':
|
||||||
|
@ -512,23 +512,19 @@ class CapacityFilterTestCase(HostFiltersTestCase):
|
|||||||
self.assertTrue(filt_cls.host_passes(host, filter_properties))
|
self.assertTrue(filt_cls.host_passes(host, filter_properties))
|
||||||
|
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
{'type_key': 'provisioning:type', 'type_val': 'thick',
|
{'volume_type': {'extra_specs': {'provisioning:type': 'thick'}}},
|
||||||
'vol_type': 'volume_type', 'extra_specs': 'extra_specs'},
|
{'volume_type': {'extra_specs': {'provisioning:type': 'thin'}}},
|
||||||
{'type_key': 'provisioning:type', 'type_val': 'thin',
|
{'volume_type': {'extra_specs': {}}},
|
||||||
'vol_type': 'volume_type', 'extra_specs': 'extra_specs'},
|
{'volume_type': {}},
|
||||||
{'type_key': None, 'type_val': None,
|
{'volume_type': None},
|
||||||
'vol_type': 'volume_type', 'extra_specs': None},
|
|
||||||
{'type_key': None, 'type_val': None,
|
|
||||||
'vol_type': None, 'extra_specs': None},
|
|
||||||
)
|
)
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
@mock.patch('cinder.utils.service_is_up')
|
@mock.patch('cinder.utils.service_is_up')
|
||||||
def test_filter_provisioning_type(self, _mock_serv_is_up, type_key,
|
def test_filter_provisioning_type(self, _mock_serv_is_up, volume_type):
|
||||||
type_val, vol_type, extra_specs):
|
|
||||||
_mock_serv_is_up.return_value = True
|
_mock_serv_is_up.return_value = True
|
||||||
filt_cls = self.class_map['CapacityFilter']()
|
filt_cls = self.class_map['CapacityFilter']()
|
||||||
filter_properties = {'size': 100,
|
filter_properties = {'size': 100,
|
||||||
vol_type: {extra_specs: {type_key: type_val}}}
|
'volume_type': volume_type}
|
||||||
service = {'disabled': False}
|
service = {'disabled': False}
|
||||||
host = fakes.FakeHostState('host1',
|
host = fakes.FakeHostState('host1',
|
||||||
{'total_capacity_gb': 500,
|
{'total_capacity_gb': 500,
|
||||||
|
Loading…
Reference in New Issue
Block a user