diff --git a/ironic/common/exception.py b/ironic/common/exception.py index 2ed47b4ae42..80b706dbdf5 100644 --- a/ironic/common/exception.py +++ b/ironic/common/exception.py @@ -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 " diff --git a/ironic/common/trait_based_networking/base.py b/ironic/common/trait_based_networking/base.py index 92009192cdd..1737ba59424 100644 --- a/ironic/common/trait_based_networking/base.py +++ b/ironic/common/trait_based_networking/base.py @@ -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 [])) diff --git a/ironic/tests/unit/common/trait_based_networking/test_base.py b/ironic/tests/unit/common/trait_based_networking/test_base.py index 00d3eb25fe2..cf912b80ca2 100644 --- a/ironic/tests/unit/common/trait_based_networking/test_base.py +++ b/ironic/tests/unit/common/trait_based_networking/test_base.py @@ -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(