浏览代码

Support ports belonging to Neutron DHCP agents (ii)

This patch is fixing a bug from [0] when there were
network:dhcp owner ports belonging to Neutron DHCP agents.
In this case, metadata port was not being created and
instances were not able to reach the service.

[0] ecef7c27c1
Related-Bug: #1804390
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>

Change-Id: I26edf7ba8f66d39f0c1e6f4fa60ed81cb243c6a3
tags/6.0.0.0b1
Daniel Alvarez 5 个月前
父节点
当前提交
f7a234a6ff

+ 3
- 2
devstack/lib/networking-ovn 查看文件

@@ -258,9 +258,10 @@ function configure_ovn_plugin {
258 258
     fi
259 259
 
260 260
     if is_service_enabled q-dhcp ; then
261
-        die $LINENO "The q-dhcp service must be disabled with OVN."
261
+        iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification True
262
+    else
263
+        iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification False
262 264
     fi
263
-    iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification False
264 265
 
265 266
     if is_service_enabled q-l3 ; then
266 267
         die $LINENO "The q-l3 service must be disabled with OVN."

+ 2
- 13
networking_ovn/common/ovn_client.py 查看文件

@@ -1782,17 +1782,10 @@ class OVNClient(object):
1782 1782
                 if fixed_ip['subnet_id'] == subnet['id']:
1783 1783
                     return fixed_ip['ip_address']
1784 1784
 
1785
-    def _get_metadata_ports(self, context, network_id):
1786
-        if not config.is_ovn_metadata_enabled():
1787
-            return
1788
-
1789
-        return self._plugin.get_ports(context, filters=dict(
1790
-            network_id=[network_id], device_owner=[const.DEVICE_OWNER_DHCP]))
1791
-
1792 1785
     def create_metadata_port(self, context, network):
1793 1786
         if config.is_ovn_metadata_enabled():
1794
-            metadata_ports = self._get_metadata_ports(context, network['id'])
1795
-            if not metadata_ports:
1787
+            metadata_port = self._find_metadata_port(context, network['id'])
1788
+            if not metadata_port:
1796 1789
                 # Create a neutron port for DHCP/metadata services
1797 1790
                 port = {'port':
1798 1791
                         {'network_id': network['id'],
@@ -1801,10 +1794,6 @@ class OVNClient(object):
1801 1794
                          'device_id': 'ovnmeta-%s' % network['id']}}
1802 1795
                 # TODO(boden): rehome create_port into neutron-lib
1803 1796
                 p_utils.create_port(self._plugin, context, port)
1804
-            elif len(metadata_ports) > 1:
1805
-                LOG.error("More than one metadata ports found for network %s. "
1806
-                          "Please run the neutron-ovn-db-sync-util to fix it.",
1807
-                          network['id'])
1808 1797
 
1809 1798
     def update_metadata_port(self, context, network_id):
1810 1799
         """Update metadata port.

+ 7
- 7
networking_ovn/tests/functional/test_maintenance.py 查看文件

@@ -699,31 +699,31 @@ class TestMaintenance(_TestMaintenanceHelper):
699 699
         ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', True,
700 700
                                          group='ovn')
701 701
         neutron_net = self._create_network('network1')
702
-        metadata_ports = self._ovn_client._get_metadata_ports(
702
+        metadata_port = self._ovn_client._find_metadata_port(
703 703
             self.context, neutron_net['id'])
704 704
 
705 705
         # Assert the metadata port exists
706
-        self.assertEqual(1, len(metadata_ports))
706
+        self.assertIsNotNone(metadata_port)
707 707
 
708 708
         # Delete the metadata port
709
-        self._delete('ports', metadata_ports[0]['id'])
709
+        self._delete('ports', metadata_port['id'])
710 710
 
711
-        metadata_ports = self._ovn_client._get_metadata_ports(
711
+        metadata_port = self._ovn_client._find_metadata_port(
712 712
             self.context, neutron_net['id'])
713 713
 
714 714
         # Assert the metadata port is gone
715
-        self.assertEqual(0, len(metadata_ports))
715
+        self.assertIsNone(metadata_port)
716 716
 
717 717
         # Call the maintenance thread to fix the problem, it will raise
718 718
         # NeverAgain so that the job only runs once at startup
719 719
         self.assertRaises(periodics.NeverAgain,
720 720
                           self.maint.check_metadata_ports)
721 721
 
722
-        metadata_ports = self._ovn_client._get_metadata_ports(
722
+        metadata_port = self._ovn_client._find_metadata_port(
723 723
             self.context, neutron_net['id'])
724 724
 
725 725
         # Assert the metadata port was re-created
726
-        self.assertEqual(1, len(metadata_ports))
726
+        self.assertIsNotNone(metadata_port)
727 727
 
728 728
     def test_check_metadata_ports_not_enabled(self):
729 729
         ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', False,

+ 19
- 10
networking_ovn/tests/unit/ml2/test_mech_driver.py 查看文件

@@ -2496,8 +2496,8 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
2496 2496
         this port to be created again.
2497 2497
         """
2498 2498
         with mock.patch.object(
2499
-            self.mech_driver._ovn_client, '_get_metadata_ports',
2500
-                return_value=['metadata_port1']):
2499
+            self.mech_driver._ovn_client, '_find_metadata_port',
2500
+                return_value={'port': {'id': 'metadata_port1'}}):
2501 2501
             with self.network():
2502 2502
                 self.assertEqual(0, self.nb_ovn.create_lswitch_port.call_count)
2503 2503
 
@@ -2507,14 +2507,23 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
2507 2507
         Check that the metadata port is updated with a new IP address when a
2508 2508
         subnet is created.
2509 2509
         """
2510
-        with self.network() as net1:
2511
-            with self.subnet(network=net1, cidr='10.0.0.0/24'):
2512
-                self.assertEqual(1, self.nb_ovn.set_lswitch_port.call_count)
2513
-                args, kwargs = self.nb_ovn.set_lswitch_port.call_args
2514
-                self.assertEqual('localport', kwargs['type'])
2515
-                self.assertEqual('10.0.0.2/24',
2516
-                                 kwargs['external_ids'].get(
2517
-                                     ovn_const.OVN_CIDRS_EXT_ID_KEY, ''))
2510
+        with self.network(set_context=True, tenant_id='test') as net1:
2511
+            with self.subnet(network=net1, cidr='10.0.0.0/24') as subnet1:
2512
+                # Create a network:dhcp owner port just as how Neutron DHCP
2513
+                # agent would do.
2514
+                with self.port(subnet=subnet1,
2515
+                               device_owner=const.DEVICE_OWNER_DHCP,
2516
+                               device_id='dhcpxxxx',
2517
+                               set_context=True, tenant_id='test'):
2518
+                    with self.subnet(network=net1, cidr='20.0.0.0/24'):
2519
+                        self.assertEqual(
2520
+                            2, self.nb_ovn.set_lswitch_port.call_count)
2521
+                        args, kwargs = self.nb_ovn.set_lswitch_port.call_args
2522
+                        self.assertEqual('localport', kwargs['type'])
2523
+                        self.assertEqual('10.0.0.2/24 20.0.0.2/24',
2524
+                                         kwargs['external_ids'].get(
2525
+                                             ovn_const.OVN_CIDRS_EXT_ID_KEY,
2526
+                                             ''))
2518 2527
 
2519 2528
     def test_metadata_port_on_network_delete(self):
2520 2529
         """Check metadata port delete.

正在加载...
取消
保存