Skip to content

Commit e11a326

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "[OVN] Fix remote-managed binding profile validation" into stable/2025.1
2 parents 77f48f7 + 6290746 commit e11a326

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

neutron/common/ovn/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ def validate_and_get_data_from_binding_profile(port):
463463
if pbp_param_set.vnic_type:
464464
if pbp_param_set.vnic_type != vnic_type:
465465
continue
466-
if capabilities and pbp_param_set.capability not in capabilities:
466+
if (capabilities and
467+
pbp_param_set.capability is not None and
468+
pbp_param_set.capability not in capabilities):
467469
continue
468470
param_set = pbp_param_set.param_set
469471
param_keys = param_set.keys()

neutron/tests/unit/common/ovn/test_utils.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,23 +606,24 @@ def setUp(self):
606606
'neutron_lib.plugins.directory.get_plugin').start()
607607
self.VNIC_FAKE_NORMAL = 'fake-vnic-normal'
608608
self.VNIC_FAKE_OTHER = 'fake-vnic-other'
609+
self.VNIC_FAKE_THIRD = 'fake-vnic-third'
609610

610611
# Replace constants.OVN_PORT_BINDING_PROFILE_PARAMS to allow synthesis
611612
_params = constants.OVN_PORT_BINDING_PROFILE_PARAMS.copy()
612613
_params.extend([
613614
constants.OVNPortBindingProfileParamSet(
614615
{'key': [str, type(None)]},
615616
self.VNIC_FAKE_NORMAL, None),
616-
constants.OVNPortBindingProfileParamSet(
617-
{'key': [str], 'other_key': [str]},
618-
self.VNIC_FAKE_OTHER, None),
619617
constants.OVNPortBindingProfileParamSet(
620618
{
621619
'key': [str],
622620
'other_key': [int],
623621
'third_key': [str]
624622
},
625623
self.VNIC_FAKE_OTHER, constants.PORT_CAP_SWITCHDEV),
624+
constants.OVNPortBindingProfileParamSet(
625+
{'key': [str], 'other_key': [str]},
626+
self.VNIC_FAKE_THIRD, None),
626627
])
627628
self.OVN_PORT_BINDING_PROFILE_PARAMS = mock.patch.object(
628629
constants,
@@ -737,6 +738,27 @@ def test_valid_input(self):
737738
{portbindings.VNIC_TYPE: portbindings.VNIC_REMOTE_MANAGED,
738739
constants.OVN_PORT_BINDING_PROFILE: expect}))
739740

741+
def test_valid_input_surplus_capabilities(self):
742+
capabilities = ['rx', 'tx', 'sg', 'tso', 'gso', 'gro', 'rxvlan',
743+
'txvlan', 'rxhash', 'rdma', 'txudptnl']
744+
binding_profile = {
745+
'pci_vendor_info': 'dead:beef',
746+
'pci_slot': '0000:ca:fe.42',
747+
'physical_network': 'physnet1',
748+
'card_serial_number': 'AB2000X00042',
749+
'pf_mac_address': '00:53:00:00:00:42',
750+
'vf_num': 42,
751+
constants.PORT_CAP_PARAM: capabilities
752+
}
753+
expect = binding_profile.copy()
754+
del(expect[constants.PORT_CAP_PARAM])
755+
self.assertEqual(
756+
utils.BPInfo(expect, portbindings.VNIC_REMOTE_MANAGED,
757+
capabilities),
758+
utils.validate_and_get_data_from_binding_profile(
759+
{portbindings.VNIC_TYPE: portbindings.VNIC_REMOTE_MANAGED,
760+
constants.OVN_PORT_BINDING_PROFILE: binding_profile}))
761+
740762
def test_valid_input_surplus_keys(self):
741763
# Confirm that extra keys are allowed
742764
binding_profile = {
@@ -810,12 +832,12 @@ def test_overlapping_param_set_different_vnic_type(self):
810832
utils.validate_and_get_data_from_binding_profile(
811833
{portbindings.VNIC_TYPE: self.VNIC_FAKE_NORMAL,
812834
constants.OVN_PORT_BINDING_PROFILE: binding_profile}))
813-
# It is valid for VNIC_FAKE_OTHER
835+
# It is valid for VNIC_FAKE_THIRD
814836
expected_bp = binding_profile.copy()
815837
self.assertEqual(
816-
utils.BPInfo(expected_bp, self.VNIC_FAKE_OTHER, []),
838+
utils.BPInfo(expected_bp, self.VNIC_FAKE_THIRD, []),
817839
utils.validate_and_get_data_from_binding_profile(
818-
{portbindings.VNIC_TYPE: self.VNIC_FAKE_OTHER,
840+
{portbindings.VNIC_TYPE: self.VNIC_FAKE_THIRD,
819841
constants.OVN_PORT_BINDING_PROFILE: binding_profile}))
820842

821843
def test_overlapping_param_set_different_vnic_type_and_capability(self):
@@ -825,13 +847,13 @@ def test_overlapping_param_set_different_vnic_type_and_capability(self):
825847
'other_key': 42,
826848
'third_key': 'value',
827849
}
828-
# This param set is not valid for VNIC_FAKE_OTHER without capability
850+
# This param set is not valid for VNIC_FAKE_THIRD without capability
829851
expect = binding_profile.copy()
830852
del(expect['third_key'])
831853
self.assertRaises(
832854
neutron_lib.exceptions.InvalidInput,
833855
utils.validate_and_get_data_from_binding_profile,
834-
{portbindings.VNIC_TYPE: self.VNIC_FAKE_OTHER,
856+
{portbindings.VNIC_TYPE: self.VNIC_FAKE_THIRD,
835857
constants.OVN_PORT_BINDING_PROFILE: binding_profile})
836858
# This param set is also not valid as the capabilities do not match
837859
binding_profile = {

0 commit comments

Comments
 (0)