Browse Source

Merge "Support ports belonging to Neutron DHCP agents (ii)"

tags/6.0.0.0b1
Zuul 2 months ago
parent
commit
ae5589155f

+ 3
- 2
devstack/lib/networking-ovn View File

@@ -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 View File

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

+ 7
- 7
networking_ovn/tests/functional/test_maintenance.py View File

@@ -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 View File

@@ -2516,8 +2516,8 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
2516 2516
         this port to be created again.
2517 2517
         """
2518 2518
         with mock.patch.object(
2519
-            self.mech_driver._ovn_client, '_get_metadata_ports',
2520
-                return_value=['metadata_port1']):
2519
+            self.mech_driver._ovn_client, '_find_metadata_port',
2520
+                return_value={'port': {'id': 'metadata_port1'}}):
2521 2521
             with self.network():
2522 2522
                 self.assertEqual(0, self.nb_ovn.create_lswitch_port.call_count)
2523 2523
 
@@ -2527,14 +2527,23 @@ class TestOVNMechanismDriverMetadataPort(test_plugin.Ml2PluginV2TestCase):
2527 2527
         Check that the metadata port is updated with a new IP address when a
2528 2528
         subnet is created.
2529 2529
         """
2530
-        with self.network() as net1:
2531
-            with self.subnet(network=net1, cidr='10.0.0.0/24'):
2532
-                self.assertEqual(1, self.nb_ovn.set_lswitch_port.call_count)
2533
-                args, kwargs = self.nb_ovn.set_lswitch_port.call_args
2534
-                self.assertEqual('localport', kwargs['type'])
2535
-                self.assertEqual('10.0.0.2/24',
2536
-                                 kwargs['external_ids'].get(
2537
-                                     ovn_const.OVN_CIDRS_EXT_ID_KEY, ''))
2530
+        with self.network(set_context=True, tenant_id='test') as net1:
2531
+            with self.subnet(network=net1, cidr='10.0.0.0/24') as subnet1:
2532
+                # Create a network:dhcp owner port just as how Neutron DHCP
2533
+                # agent would do.
2534
+                with self.port(subnet=subnet1,
2535
+                               device_owner=const.DEVICE_OWNER_DHCP,
2536
+                               device_id='dhcpxxxx',
2537
+                               set_context=True, tenant_id='test'):
2538
+                    with self.subnet(network=net1, cidr='20.0.0.0/24'):
2539
+                        self.assertEqual(
2540
+                            2, self.nb_ovn.set_lswitch_port.call_count)
2541
+                        args, kwargs = self.nb_ovn.set_lswitch_port.call_args
2542
+                        self.assertEqual('localport', kwargs['type'])
2543
+                        self.assertEqual('10.0.0.2/24 20.0.0.2/24',
2544
+                                         kwargs['external_ids'].get(
2545
+                                             ovn_const.OVN_CIDRS_EXT_ID_KEY,
2546
+                                             ''))
2538 2547
 
2539 2548
     def test_metadata_port_on_network_delete(self):
2540 2549
         """Check metadata port delete.

Loading…
Cancel
Save