Skip to content

Commit ce7a692

Browse files
ralonsohCloud User
authored andcommitted
Filter the ports by VNIC type
In ``check_baremetal_ports_dhcp_options``, the ports need to be retrieved based on the VNIC type. The VNIC type is stored in "ml2_port_bindings" table, not "ports" table. Because the ML2Plugin ``get_ports`` method can filter only by "ports" database register fields, it is needed to retrieve those ports using a custom database query and then use the plugin method to retrieve the ports, converted to dictionaries and the extensions processed. Closes-Bug: #1979643 Change-Id: Iab227d9de75e4b1b927043ce27bdc346066478e8 (cherry picked from commit b497ad1)
1 parent 0615e11 commit ce7a692

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

neutron/objects/ports.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,12 @@ def get_ports_by_binding_type_and_host(cls, context,
684684
return [cls._load_object(context, db_obj) for db_obj in query.all()]
685685

686686
@classmethod
687-
def get_ports_by_vnic_type_and_host(
688-
cls, context, vnic_type, host):
687+
def get_ports_by_vnic_type_and_host(cls, context, vnic_type, host=None):
689688
query = context.session.query(models_v2.Port).join(
690689
ml2_models.PortBinding)
691-
query = query.filter(
692-
ml2_models.PortBinding.vnic_type == vnic_type,
693-
ml2_models.PortBinding.host == host)
690+
query = query.filter(ml2_models.PortBinding.vnic_type == vnic_type)
691+
if host:
692+
query = query.filter(ml2_models.PortBinding.host == host)
694693
return [cls._load_object(context, db_obj) for db_obj in query.all()]
695694

696695
@classmethod

neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/maintenance.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from neutron.db import ovn_revision_numbers_db as revision_numbers_db
4242
from neutron.db import segments_db
4343
from neutron.objects import router as router_obj
44+
from neutron.objects import ports as ports_obj
4445
from neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb import ovn_db_sync
4546

4647

@@ -907,9 +908,10 @@ def check_baremetal_ports_dhcp_options(self):
907908
return
908909

909910
context = n_context.get_admin_context()
911+
ports = ports_obj.Port.get_ports_by_vnic_type_and_host(
912+
context, portbindings.VNIC_BAREMETAL)
910913
ports = self._ovn_client._plugin.get_ports(
911-
context,
912-
filters={portbindings.VNIC_TYPE: portbindings.VNIC_BAREMETAL})
914+
context, filters={'id': [p.id for p in ports]})
913915
if not ports:
914916
raise periodics.NeverAgain()
915917

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,19 +416,19 @@ def test_get_lsp_dhcp_opts_dhcp_disabled_for_baremetal(self):
416416
# Assert no options were passed
417417
self.assertEqual({}, options)
418418

419-
def test_get_lsp_dhcp_opts_for_domain_search(self):
420-
opt = {'opt_name': 'domain-search',
421-
'opt_value': 'openstack.org,ovn.org',
422-
'ip_version': 4}
423-
port = {portbindings.VNIC_TYPE: portbindings.VNIC_NORMAL,
424-
edo_ext.EXTRADHCPOPTS: [opt]}
425-
426-
dhcp_disabled, options = utils.get_lsp_dhcp_opts(port, 4)
427-
self.assertFalse(dhcp_disabled)
428-
# Assert option got translated to "domain_search_list" and
429-
# the value is a string (double-quoted)
430-
expected_options = {'domain_search_list': '"openstack.org,ovn.org"'}
431-
self.assertEqual(expected_options, options)
419+
def test_get_lsp_dhcp_opts_for_domain_search(self):
420+
opt = {'opt_name': 'domain-search',
421+
'opt_value': 'openstack.org,ovn.org',
422+
'ip_version': 4}
423+
port = {portbindings.VNIC_TYPE: portbindings.VNIC_NORMAL,
424+
edo_ext.EXTRADHCPOPTS: [opt]}
425+
426+
dhcp_disabled, options = utils.get_lsp_dhcp_opts(port, 4)
427+
self.assertFalse(dhcp_disabled)
428+
# Assert option got translated to "domain_search_list" and
429+
# the value is a string (double-quoted)
430+
expected_options = {'domain_search_list': '"openstack.org,ovn.org"'}
431+
self.assertEqual(expected_options, options)
432432

433433
class TestGetDhcpDnsServers(base.BaseTestCase):
434434

0 commit comments

Comments
 (0)