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 e5a8829c56)
This commit is contained in:
Terry Wilson 2024-07-03 09:27:09 -05:00 committed by Rodolfo Alonso Hernandez
parent 2efa78a86f
commit aec330bafe
2 changed files with 6 additions and 1 deletions

View File

@ -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)

View File

@ -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(