Merge "Don't raise if an object's attribute is None in _retrieve_attribute"

This commit is contained in:
Zuul authored and Gerrit Code Review committed 2026-09-28 15:57:38 +00:00
commit f397600ddf
3 files changed
+3 -17

No files matched your search

-5
View File
@@ -1151,11 +1151,6 @@ class TBNComparatorCollectionTypeMismatch(TraitBasedNetworkingException):
pass
class TBNAttributeRetrievalException(TraitBasedNetworkingException):
"""Specified attribute could not be found."""
_msg_fmt = _("Could not retrieve attribute %(attr_name)s from "
"passed object")
class TBNNoTraitsApplicableToNode(TraitBasedNetworkingException):
"""If no traits apply to a node, then nothing can be done."""
_msg_fmt = _("No Trait Based Networking traits were found which could "
+1 -9
View File
@@ -149,12 +149,7 @@ class Variables(enum.Enum):
def _retrieve_attribute(attribute_name, tbn_obj):
"""Helper method to get an attribute from a TBN related object"""
attribute = getattr(tbn_obj, attribute_name, None)
if attribute is None:
raise exc.TBNAttributeRetrievalException(attr_name=attribute_name)
return attribute
return getattr(tbn_obj, attribute_name, '')
# Allows special case FilterExpression evaluations where Port does not
@@ -496,9 +491,6 @@ class Network:
def from_vif_info(cls, vif_info):
"""Helper method to create Networks from vif_info dictionaries"""
# tags defaults to an empty frozenset (rather than None)
# so that filters referencing network.tags don't raise
# TBNAttributeRetrievalException just because the vif_attach caller
# didn't supply a 'tags' key.
return cls(vif_info['id'], # vif_info is guaranteed to have 'id'.
vif_info.get('name'),
frozenset(vif_info.get('tags') or []))
@@ -26,7 +26,7 @@ class TraitBasedNetworkingBaseTestCase(base.TestCase):
)
self.assertEqual("port.address == 'test'", str(exp))
def test_filter_object_missing_attribute_raises(self):
def test_filter_object_missing_attribute_doesnt_match(self):
exp = tbn.SingleExpression(
tbn.Variables.PORT_ADDRESS, tbn.Comparator.EQUALITY, "test"
)
@@ -34,8 +34,7 @@ class TraitBasedNetworkingBaseTestCase(base.TestCase):
obj = tbn.Port.from_ironic_port(
tbn_test_utils.FauxPortLikeObject(address=None))
net = tbn_test_utils.FauxNetwork()
self.assertRaises(exc.TraitBasedNetworkingException, exp.eval,
obj, net)
self.assertFalse(exp.eval(obj, net))
def test_filter_comparator_eval_equality(self):
exp = tbn.SingleExpression(