Skip to content

Commit 5fd71ac

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add constant to identify OVN LB HM ports" into stable/2023.1
2 parents 4fcfd0b + de07552 commit 5fd71ac

File tree

9 files changed

+102
-15
lines changed

9 files changed

+102
-15
lines changed

neutron/common/ovn/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
OVN_PROVNET_PORT_NAME_PREFIX = 'provnet-'
7171
OVN_NAME_PREFIX = 'neutron-'
7272

73+
# TODO(froyo): Move this to neutron-lib as soon as possible, and when a new
74+
# release is created and pointed to in the requirements remove this code
75+
OVN_LB_HM_PORT_DISTRIBUTED = 'ovn-lb-hm:distributed'
76+
7377
# Agent extension constants
7478
OVN_AGENT_DESC_KEY = 'neutron:description'
7579
OVN_AGENT_METADATA_SB_CFG_KEY = 'neutron:ovn-metadata-sb-cfg'

neutron/common/ovn/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ def ovn_metadata_name(id_):
601601
return 'metadata-%s' % id_
602602

603603

604+
def is_ovn_lb_hm_port(port):
605+
return (port['device_owner'] == constants.OVN_LB_HM_PORT_DISTRIBUTED and
606+
port['device_id'].startswith('ovn-lb-hm'))
607+
608+
604609
def is_gateway_chassis_invalid(chassis_name, gw_chassis,
605610
physnet, chassis_physnets,
606611
az_hints, chassis_with_azs):

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import socket
1616
import uuid
1717

18+
from neutron_lib import constants
1819
from neutron_lib import exceptions as n_exc
1920
from neutron_lib.utils import helpers
2021
from oslo_log import log
@@ -917,7 +918,10 @@ def get_metadata_port_network(self, network):
917918
except idlutils.RowNotFound:
918919
return None
919920
cmd = self.db_find_rows('Port_Binding', ('datapath', '=', dp),
920-
('type', '=', ovn_const.LSP_TYPE_LOCALPORT))
921+
('type', '=', ovn_const.LSP_TYPE_LOCALPORT),
922+
('external_ids', '=', {
923+
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY:
924+
constants.DEVICE_OWNER_DISTRIBUTED}))
921925
return next(iter(cmd.execute(check_error=True)), None)
922926

923927
def set_chassis_neutron_description(self, chassis, description,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ def _get_port_options(self, port):
380380
cidrs += ' {}/{}'.format(ip['ip_address'],
381381
subnet['cidr'].split('/')[1])
382382

383-
# Metadata port.
384-
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:
383+
# Metadata or OVN LB HM port.
384+
if (port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED or
385+
utils.is_ovn_lb_hm_port(port)):
385386
port_type = ovn_const.LSP_TYPE_LOCALPORT
386387

387388
if utils.is_port_external(port):

neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
from unittest import mock
1818

19+
from neutron_lib import constants
1920
from oslo_config import fixture as fixture_config
2021
from oslo_utils import uuidutils
2122
from ovsdbapp.backend.ovs_idl import event
@@ -154,7 +155,9 @@ def _create_metadata_port(self, txn, lswitch_name, port_name=None):
154155
addresses='AA:AA:AA:AA:AA:AA 192.168.122.123',
155156
external_ids={
156157
ovn_const.OVN_CIDRS_EXT_ID_KEY: '192.168.122.123/24',
157-
ovn_const.OVN_DEVID_EXT_ID_KEY: 'ovnmeta-' + lswitch_name
158+
ovn_const.OVN_DEVID_EXT_ID_KEY: 'ovnmeta-' + lswitch_name,
159+
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY:
160+
constants.DEVICE_OWNER_DISTRIBUTED
158161
}))
159162

160163
def _update_metadata_port_ip(self, metadata_port_name):

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import copy
1616
import uuid
1717

18+
from neutron_lib import constants
1819
from ovsdbapp.backend.ovs_idl import connection
1920
from ovsdbapp import constants as const
2021
from ovsdbapp import event as ovsdb_event
@@ -103,34 +104,62 @@ def test_multiple_physnets_in_one_bridge(self):
103104
self.load_test_data()
104105
self.assertRaises(ValueError, self.api.get_chassis_and_physnets)
105106

106-
def _add_switch_port(self, chassis_name,
107-
type=ovn_const.LSP_TYPE_LOCALPORT):
108-
sname, pname = (utils.get_rand_device_name(prefix=p)
109-
for p in ('switch', 'port'))
107+
def _add_switch(self, chassis_name):
108+
sname = utils.get_rand_device_name(prefix='switch')
110109
chassis = self.api.lookup('Chassis', chassis_name)
110+
with self.nbapi.transaction(check_error=True) as txn:
111+
switch = txn.add(self.nbapi.ls_add(sname))
112+
return chassis, switch.result
113+
114+
def _add_port_to_switch(
115+
self, switch, type=ovn_const.LSP_TYPE_LOCALPORT,
116+
device_owner=constants.DEVICE_OWNER_DISTRIBUTED):
117+
pname = utils.get_rand_device_name(prefix='port')
111118
row_event = events.WaitForCreatePortBindingEvent(pname)
112119
self.handler.watch_event(row_event)
113120
with self.nbapi.transaction(check_error=True) as txn:
114-
switch = txn.add(self.nbapi.ls_add(sname))
115-
port = txn.add(self.nbapi.lsp_add(sname, pname, type=type))
121+
port = txn.add(self.nbapi.lsp_add(
122+
switch.uuid, pname, type=type,
123+
external_ids={
124+
ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY: device_owner}))
116125
row_event.wait()
117-
return chassis, switch.result, port.result, row_event.row
126+
return port.result, row_event.row
118127

119128
def test_get_metadata_port_network(self):
120-
chassis, switch, port, binding = self._add_switch_port(
121-
self.data['chassis'][0]['name'])
129+
chassis, switch = self._add_switch(self.data['chassis'][0]['name'])
130+
port, binding = self._add_port_to_switch(switch)
131+
result = self.api.get_metadata_port_network(str(binding.datapath.uuid))
132+
self.assertEqual(binding, result)
133+
self.assertEqual(binding.datapath.external_ids['logical-switch'],
134+
str(switch.uuid))
135+
self.assertEqual(
136+
port.external_ids[ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY],
137+
constants.DEVICE_OWNER_DISTRIBUTED)
138+
139+
def test_get_metadata_port_network_other_non_metadata_port(self):
140+
chassis, switch = self._add_switch(self.data['chassis'][0]['name'])
141+
port, binding = self._add_port_to_switch(switch)
142+
port_lbhm, binding_port_lbhm = self._add_port_to_switch(
143+
switch, device_owner=ovn_const.OVN_LB_HM_PORT_DISTRIBUTED)
122144
result = self.api.get_metadata_port_network(str(binding.datapath.uuid))
123145
self.assertEqual(binding, result)
124146
self.assertEqual(binding.datapath.external_ids['logical-switch'],
125147
str(switch.uuid))
148+
self.assertEqual(
149+
binding_port_lbhm.datapath.external_ids['logical-switch'],
150+
str(switch.uuid))
151+
self.assertEqual(
152+
port_lbhm.external_ids[ovn_const.OVN_DEVICE_OWNER_EXT_ID_KEY],
153+
ovn_const.OVN_LB_HM_PORT_DISTRIBUTED)
126154

127155
def test_get_metadata_port_network_missing(self):
128156
val = str(uuid.uuid4())
129157
self.assertIsNone(self.api.get_metadata_port_network(val))
130158

131159
def _create_bound_port_with_ip(self):
132-
chassis, switch, port, binding = self._add_switch_port(
160+
chassis, switch = self._add_switch(
133161
self.data['chassis'][0]['name'])
162+
port, binding = self._add_port_to_switch(switch)
134163
mac = 'de:ad:be:ef:4d:ad'
135164
ipaddr = '192.0.2.1'
136165
mac_ip = '%s %s' % (mac, ipaddr)
@@ -164,8 +193,9 @@ def test_get_network_port_bindings_by_ip_with_unbound_port(self):
164193
self.assertEqual(1, len(result))
165194

166195
def test_get_ports_on_chassis(self):
167-
chassis, switch, port, binding = self._add_switch_port(
196+
chassis, switch = self._add_switch(
168197
self.data['chassis'][0]['name'])
198+
port, binding = self._add_port_to_switch(switch)
169199
self.api.lsp_bind(port.name, chassis.name).execute(check_error=True)
170200
self.assertEqual([binding],
171201
self.api.get_ports_on_chassis(chassis.name))

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ def test_get_gateway_chassis_without_azs(self):
203203
{'ch1'},
204204
utils.get_gateway_chassis_without_azs(chassis_list))
205205

206+
def test_is_ovn_lb_hm_port(self):
207+
ovn_lb_hm_port = {
208+
'device_owner': constants.OVN_LB_HM_PORT_DISTRIBUTED,
209+
'device_id': 'ovn-lb-hm-12345'}
210+
non_ovn_lb_hm_port_0 = {
211+
'device_owner': n_const.DEVICE_OWNER_DISTRIBUTED,
212+
'device_id': 'ovnmeta-12345'}
213+
non_ovn_lb_hm_port_1 = {
214+
'device_owner': n_const.DEVICE_OWNER_DHCP,
215+
'device_id': 'dhcp-12345'}
216+
217+
self.assertTrue(utils.is_ovn_lb_hm_port(ovn_lb_hm_port))
218+
self.assertFalse(utils.is_ovn_lb_hm_port(non_ovn_lb_hm_port_0))
219+
self.assertFalse(utils.is_ovn_lb_hm_port(non_ovn_lb_hm_port_1))
220+
206221

207222
class TestGateWayChassisValidity(base.BaseTestCase):
208223

neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,22 @@ def test__get_port_options_with_addr_scope(self):
18811881
self.assertEqual("address_scope_v4", options.address4_scope_id)
18821882
self.assertEqual("address_scope_v6", options.address6_scope_id)
18831883

1884+
def test__get_port_options_with_ovn_lb_hm_port(self):
1885+
port = {
1886+
'id': 'ovn-lb-hm-port',
1887+
'mac_address': '00:00:00:00:00:00',
1888+
'device_owner': ovn_const.OVN_LB_HM_PORT_DISTRIBUTED,
1889+
'device_id': 'ovn-lb-hm-foo',
1890+
'network_id': 'foo',
1891+
'fixed_ips': [],
1892+
portbindings.HOST_ID: 'fake-src',
1893+
portbindings.PROFILE: {
1894+
ovn_const.MIGRATING_ATTR: 'fake-dest',
1895+
}
1896+
}
1897+
options = self.mech_driver._ovn_client._get_port_options(port)
1898+
self.assertEqual('fake-src', options.options['requested-chassis'])
1899+
18841900
def test__get_port_options_migrating_additional_chassis_missing(self):
18851901
port = {
18861902
'id': 'virt-port',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
other:
3+
- |
4+
The new value for 'device_owner' for OVN loadbalancer health monitor ports
5+
(ovn-lb-hm:distributed) is now supported by Neutron, providing a LOCALPORT
6+
behavior to these ports. The responsibility to define these ports with the
7+
new value instead of the old one (network:distributed) is under the
8+
OVN-Octavia Provider driver, which will take care of database conversion
9+
for these ports.

0 commit comments

Comments
 (0)