Skip to content

Commit 5cc41f0

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "[OVN] Allow VIP ports with a defined "device_owner"" into stable/yoga
2 parents 70e59a9 + 7b53aae commit 5cc41f0

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,15 @@ def _get_port_options(self, port):
299299
subnet['cidr'].split('/')[1])
300300

301301
# Check if the port being created is a virtual port
302-
if not port['device_owner']:
303-
parents = self.get_virtual_port_parents(ip_addr, port)
304-
if parents:
305-
port_type = ovn_const.LSP_TYPE_VIRTUAL
306-
options[ovn_const.LSP_OPTIONS_VIRTUAL_IP_KEY] = ip_addr
307-
options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY] = (
308-
','.join(parents))
302+
parents = self.get_virtual_port_parents(ip_addr, port)
303+
if not parents:
304+
continue
305+
306+
port_type = ovn_const.LSP_TYPE_VIRTUAL
307+
options[ovn_const.LSP_OPTIONS_VIRTUAL_IP_KEY] = ip_addr
308+
options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY] = (
309+
','.join(parents))
310+
break
309311

310312
# Metadata port.
311313
if port['device_owner'] == const.DEVICE_OWNER_DISTRIBUTED:

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,9 @@ def _test_segments_helper(self):
27382738
segment_id=self.seg_2['id']) as subnet:
27392739
self.sub_2 = subnet
27402740

2741-
def test_create_segments_subnet_metadata_ip_allocation(self):
2741+
@mock.patch.object(ovn_client.OVNClient, 'get_virtual_port_parents',
2742+
return_value=[])
2743+
def test_create_segments_subnet_metadata_ip_allocation(self, *args):
27422744
self._test_segments_helper()
27432745
ovn_nb_api = self.mech_driver.nb_ovn
27442746

@@ -3810,7 +3812,9 @@ def test_metadata_port_not_created_if_exists(self):
38103812
with self.network():
38113813
self.assertEqual(0, self.nb_ovn.create_lswitch_port.call_count)
38123814

3813-
def test_metadata_ip_on_subnet_create(self):
3815+
@mock.patch.object(ovn_client.OVNClient, 'get_virtual_port_parents',
3816+
return_value=[])
3817+
def test_metadata_ip_on_subnet_create(self, *args):
38143818
"""Check metadata port update.
38153819
38163820
Check that the metadata port is updated with a new IP address when a
@@ -3980,26 +3984,24 @@ def test_create_port_with_virtual_type_and_options(
39803984
self, mock_get_parents, mock_determine_bind_host):
39813985
fake_parents = ['parent-0', 'parent-1']
39823986
mock_get_parents.return_value = fake_parents
3983-
port = {'id': 'virt-port',
3984-
'mac_address': '00:00:00:00:00:00',
3985-
'device_owner': '',
3986-
'network_id': self.net['id'],
3987-
'fixed_ips': [{'subnet_id': self.subnet['id'],
3988-
'ip_address': '10.0.0.55'}]}
3989-
port_info = self.mech_driver._ovn_client._get_port_options(
3990-
port)
3991-
self.assertEqual(ovn_const.LSP_TYPE_VIRTUAL, port_info.type)
3992-
self.assertEqual(
3993-
'10.0.0.55',
3994-
port_info.options[ovn_const.LSP_OPTIONS_VIRTUAL_IP_KEY])
3995-
self.assertIn(
3996-
'parent-0',
3997-
port_info.options[
3998-
ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY])
3999-
self.assertIn(
4000-
'parent-1',
4001-
port_info.options[
4002-
ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY])
3987+
for device_owner in ('', 'myVIPowner'):
3988+
port = {'id': 'virt-port',
3989+
'mac_address': '00:00:00:00:00:00',
3990+
'device_owner': device_owner,
3991+
'network_id': self.net['id'],
3992+
'fixed_ips': [{'subnet_id': self.subnet['id'],
3993+
'ip_address': '10.0.0.55'}]}
3994+
port_info = self.mech_driver._ovn_client._get_port_options(port)
3995+
self.assertEqual(ovn_const.LSP_TYPE_VIRTUAL, port_info.type)
3996+
self.assertEqual(
3997+
'10.0.0.55',
3998+
port_info.options[ovn_const.LSP_OPTIONS_VIRTUAL_IP_KEY])
3999+
self.assertIn(
4000+
'parent-0',
4001+
port_info.options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY])
4002+
self.assertIn(
4003+
'parent-1',
4004+
port_info.options[ovn_const.LSP_OPTIONS_VIRTUAL_PARENTS_KEY])
40034005

40044006
@mock.patch.object(db_base_plugin_v2.NeutronDbPluginV2, 'get_ports')
40054007
def _test_set_unset_virtual_port_type(self, mock_get_ports, unset=False):

0 commit comments

Comments
 (0)