From aec330bafef0454450bb8d70dd5d289d65cb7c1a Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Wed, 3 Jul 2024 09:27:09 -0500 Subject: [PATCH] Return empty BpInfo if missing binding:profile https://review.opendev.org/c/openstack/neutron/+/867359 inadvertently dropped a return when binding:profile was missing, making it possible to hit a KeyError when trying to access port["binding:profile"]. This was seen in the Maintenance thread after adding a port. Fixes: b6750fb2b8 Closes-Bug: #2071822 Change-Id: I232daa2905904d464ddf84e66e857f8b1f08e941 (cherry picked from commit e5a8829c565755e4c7d4e8b2d52536234c90d8b4) --- neutron/common/ovn/utils.py | 2 +- neutron/tests/unit/common/ovn/test_utils.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/neutron/common/ovn/utils.py b/neutron/common/ovn/utils.py index 5958414eaf9..8aac6e8403d 100644 --- a/neutron/common/ovn/utils.py +++ b/neutron/common/ovn/utils.py @@ -368,7 +368,7 @@ def validate_and_get_data_from_binding_profile(port): if (constants.OVN_PORT_BINDING_PROFILE not in port or not validators.is_attr_set( port[constants.OVN_PORT_BINDING_PROFILE])): - BPInfo({}, None, []) + return BPInfo({}, None, []) param_set = {} param_dict = {} vnic_type = port.get(portbindings.VNIC_TYPE, portbindings.VNIC_NORMAL) diff --git a/neutron/tests/unit/common/ovn/test_utils.py b/neutron/tests/unit/common/ovn/test_utils.py index 7e9e1d1ff11..6bdfe8eb8bb 100644 --- a/neutron/tests/unit/common/ovn/test_utils.py +++ b/neutron/tests/unit/common/ovn/test_utils.py @@ -725,6 +725,11 @@ class TestValidateAndGetDataFromBindingProfile(base.BaseTestCase): {portbindings.VNIC_TYPE: portbindings.VNIC_DIRECT, constants.OVN_PORT_BINDING_PROFILE: binding_profile})) + def test_valid_input_no_binding_profile(self): + # Confirm that we treat a port without binding:profile as valid + self.assertEqual(utils.BPInfo({}, None, []), + utils.validate_and_get_data_from_binding_profile({})) + def test_unknown_profile_items_pruned(self): # Confirm that unknown profile items are pruned self.assertEqual(