Browse Source

Merge "Maintenance: Re-create the metadata port"

changes/11/636011/4
Zuul 3 years ago
committed by Gerrit Code Review
parent
commit
132004a30e
  1. 18
      networking_ovn/common/maintenance.py
  2. 41
      networking_ovn/tests/functional/test_maintenance.py

18
networking_ovn/common/maintenance.py

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

41
networking_ovn/tests/functional/test_maintenance.py

@ -694,3 +694,44 @@ class TestMaintenance(_TestMaintenanceHelper):
# Assert the revision number no longer exists
self.assertIsNone(db_rev.get_revision_row(neutron_obj['port_id']))
def test_check_metadata_ports(self):
ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', True,
group='ovn')
neutron_net = self._create_network('network1')
metadata_ports = self._ovn_client._get_metadata_ports(
self.context, neutron_net['id'])
# Assert the metadata port exists
self.assertEqual(1, len(metadata_ports))
# Delete the metadata port
self._delete('ports', metadata_ports[0]['id'])
metadata_ports = self._ovn_client._get_metadata_ports(
self.context, neutron_net['id'])
# Assert the metadata port is gone
self.assertEqual(0, len(metadata_ports))
# Call the maintenance thread to fix the problem, it will raise
# NeverAgain so that the job only runs once at startup
self.assertRaises(periodics.NeverAgain,
self.maint.check_metadata_ports)
metadata_ports = self._ovn_client._get_metadata_ports(
self.context, neutron_net['id'])
# Assert the metadata port was re-created
self.assertEqual(1, len(metadata_ports))
def test_check_metadata_ports_not_enabled(self):
ovn_config.cfg.CONF.set_override('ovn_metadata_enabled', False,
group='ovn')
with mock.patch.object(self._ovn_client,
'create_metadata_port') as mock_create_port:
self.assertRaises(periodics.NeverAgain,
self.maint.check_metadata_ports)
# Assert create_metadata_port() wasn't called since metadata
# is not enabled
self.assertFalse(mock_create_port.called)
Loading…
Cancel
Save