Don't raise error when filtering on custom metadata
Hosts can have custom metadata. There is no restriction on the key names
used in this metadata, so we should not be raising an exception when
checking for the existence of any metadata key.
Originally worked on: https://review.openstack.org/#/c/271401
Co-Authored-By: Xiaowei Qian <xiaowei.qian@easystack.cn>
Closes-Bug: #1537062
Change-Id: Ie5ff3c1847e9c4533822a77d443e4ce1fcf047fe
(cherry picked from commit 85a307d338
)
This commit is contained in:
parent
b77a77d4cc
commit
53314c4904
|
@ -17,6 +17,7 @@ from oslo_log import log as logging
|
|||
import six
|
||||
|
||||
import nova.conf
|
||||
from nova.i18n import _LW
|
||||
from nova.scheduler import filters
|
||||
from nova.scheduler.filters import utils
|
||||
|
||||
|
@ -45,7 +46,15 @@ class AggregateImagePropertiesIsolation(filters.BaseHostFilter):
|
|||
if (cfg_namespace and
|
||||
not key.startswith(cfg_namespace + cfg_separator)):
|
||||
continue
|
||||
prop = image_props.get(key)
|
||||
prop = None
|
||||
try:
|
||||
prop = image_props.get(key)
|
||||
except AttributeError:
|
||||
LOG.warning(_LW("Host '%(host)s' has a metadata key '%(key)s' "
|
||||
"that is not present in the image metadata.") %
|
||||
{"host": host_state.host, "key": key})
|
||||
continue
|
||||
|
||||
# NOTE(sbauza): Aggregate metadata is only strings, we need to
|
||||
# stringify the property to match with the option
|
||||
# TODO(sbauza): Fix that very ugly pattern matching
|
||||
|
|
|
@ -103,3 +103,33 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
|
|||
hw_vm_mode='hvm', img_owner_id='wrong')))
|
||||
host = fakes.FakeHostState('host1', 'compute', {})
|
||||
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_aggregate_image_properties_iso_props_with_custom_meta(self,
|
||||
agg_mock):
|
||||
agg_mock.return_value = {'os': 'linux'}
|
||||
spec_obj = objects.RequestSpec(
|
||||
context=mock.sentinel.ctx,
|
||||
image=objects.ImageMeta(properties=objects.ImageMetaProps(
|
||||
os_type='linux')))
|
||||
host = fakes.FakeHostState('host1', 'compute', {})
|
||||
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_aggregate_image_properties_iso_props_with_matching_meta_pass(self,
|
||||
agg_mock):
|
||||
agg_mock.return_value = {'os_type': 'linux'}
|
||||
spec_obj = objects.RequestSpec(
|
||||
context=mock.sentinel.ctx,
|
||||
image=objects.ImageMeta(properties=objects.ImageMetaProps(
|
||||
os_type='linux')))
|
||||
host = fakes.FakeHostState('host1', 'compute', {})
|
||||
self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_aggregate_image_properties_iso_props_with_matching_meta_fail(
|
||||
self, agg_mock):
|
||||
agg_mock.return_value = {'os_type': 'windows'}
|
||||
spec_obj = objects.RequestSpec(
|
||||
context=mock.sentinel.ctx,
|
||||
image=objects.ImageMeta(properties=objects.ImageMetaProps(
|
||||
os_type='linux')))
|
||||
host = fakes.FakeHostState('host1', 'compute', {})
|
||||
self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
|
||||
|
|
Loading…
Reference in New Issue