Merge "Aggregate Extra Specs Filter should return if extra_specs is empty"

This commit is contained in:
Jenkins 2015-11-18 01:12:28 +00:00 committed by Gerrit Code Review
commit a334ea49d4
2 changed files with 12 additions and 1 deletions

View File

@ -40,7 +40,9 @@ class AggregateInstanceExtraSpecsFilter(filters.BaseHostFilter):
the metadata provided by aggregates. If not present return False.
"""
instance_type = filter_properties.get('instance_type')
if 'extra_specs' not in instance_type:
# If 'extra_specs' is not present or extra_specs are empty then we
# need not proceed further
if not instance_type.get('extra_specs'):
return True
metadata = utils.aggregate_metadata_get_by_host(host_state)

View File

@ -33,6 +33,15 @@ class TestAggregateInstanceExtraSpecsFilter(test.NoDBTestCase):
self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
self.assertFalse(agg_mock.called)
def test_aggregate_filter_passes_empty_extra_specs(self, agg_mock):
capabilities = {'opt1': 1, 'opt2': 2}
filter_properties = {'context': mock.sentinel.ctx, 'instance_type':
{'memory_mb': 1024, 'extra_specs': {}}}
host = fakes.FakeHostState('host1', 'node1', capabilities)
self.assertTrue(self.filt_cls.host_passes(host, filter_properties))
self.assertFalse(agg_mock.called)
def _do_test_aggregate_filter_extra_specs(self, especs, passes):
filter_properties = {'context': mock.sentinel.ctx,
'instance_type': {'memory_mb': 1024, 'extra_specs': especs}}