Browse Source

Maintenance: Re-create the metadata port

This patch adds a new task to the maintenance thread which re-creates
the metadata port in case it's been wrongly deleted (by whatever
reasons). The task will run immediately at service restart and fix those
ports, just like ml2/ovs would do with the DHCP ports.

Closes-Bug: #1813939
Change-Id: I0819c2b956dd41c8fe59a2b1b4fec9d229afb067
Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
tags/6.0.0.0b1
Lucas Alvares Gomes 3 months ago
parent
commit
bb00dafd8b

+ 18
- 0
networking_ovn/common/maintenance.py View File

@@ -366,3 +366,21 @@ class DBInconsistenciesPeriodics(object):
366 366
                  '(took %.2f seconds)', self._sync_timer.elapsed())
367 367
 
368 368
         raise periodics.NeverAgain()
369
+
370
+    # A static spacing value is used here, but this method will only run
371
+    # once per lock due to the use of periodics.NeverAgain().
372
+    @periodics.periodic(spacing=1800, run_immediately=True)
373
+    def check_metadata_ports(self):
374
+        # If OVN metadata is disabled do not run this task again
375
+        if not ovn_conf.is_ovn_metadata_enabled():
376
+            raise periodics.NeverAgain()
377
+
378
+        # Make sure that only one worker is executing this
379
+        if not self.has_lock:
380
+            return
381
+
382
+        admin_context = n_context.get_admin_context()
383
+        for n in self._ovn_client._plugin.get_networks(admin_context):
384
+            self._ovn_client.create_metadata_port(admin_context, n)
385
+
386
+        raise periodics.NeverAgain()

+ 41
- 0
networking_ovn/tests/functional/test_maintenance.py View File

@@ -694,3 +694,44 @@ class TestMaintenance(_TestMaintenanceHelper):
694 694
 
695 695
         # Assert the revision number no longer exists
696 696
         self.assertIsNone(db_rev.get_revision_row(neutron_obj['port_id']))
697
+
698
+    def test_check_metadata_ports(self):
699
+        ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', True,
700
+                                         group='ovn')
701
+        neutron_net = self._create_network('network1')
702
+        metadata_ports = self._ovn_client._get_metadata_ports(
703
+            self.context, neutron_net['id'])
704
+
705
+        # Assert the metadata port exists
706
+        self.assertEqual(1, len(metadata_ports))
707
+
708
+        # Delete the metadata port
709
+        self._delete('ports', metadata_ports[0]['id'])
710
+
711
+        metadata_ports = self._ovn_client._get_metadata_ports(
712
+            self.context, neutron_net['id'])
713
+
714
+        # Assert the metadata port is gone
715
+        self.assertEqual(0, len(metadata_ports))
716
+
717
+        # Call the maintenance thread to fix the problem, it will raise
718
+        # NeverAgain so that the job only runs once at startup
719
+        self.assertRaises(periodics.NeverAgain,
720
+                          self.maint.check_metadata_ports)
721
+
722
+        metadata_ports = self._ovn_client._get_metadata_ports(
723
+            self.context, neutron_net['id'])
724
+
725
+        # Assert the metadata port was re-created
726
+        self.assertEqual(1, len(metadata_ports))
727
+
728
+    def test_check_metadata_ports_not_enabled(self):
729
+        ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', False,
730
+                                         group='ovn')
731
+        with mock.patch.object(self._ovn_client,
732
+                               'create_metadata_port') as mock_create_port:
733
+            self.assertRaises(periodics.NeverAgain,
734
+                              self.maint.check_metadata_ports)
735
+            # Assert create_metadata_port() wasn't called since metadata
736
+            # is not enabled
737
+            self.assertFalse(mock_create_port.called)

Loading…
Cancel
Save