def test_get_deleted_resources(self): db_rev.create_initial_revision( self.net['id'], constants.TYPE_NETWORKS, self.session, revision_number=0) self._delete('networks', self.net['id']) res = db_maint.get_deleted_resources() self.assertEqual(1, len(res)) self.assertEqual(self.net['id'], res[0].resource_uuid) self.assertIsNone(res[0].standard_attr_id)
def check_for_inconsistencies(self): # Only the worker holding a valid lock within OVSDB will run # this periodic if not self.has_lock: return create_update_inconsistencies = db_maint.get_inconsistent_resources() delete_inconsistencies = db_maint.get_deleted_resources() if not any([create_update_inconsistencies, delete_inconsistencies]): return LOG.debug('Maintenance task: Synchronizing Neutron ' 'and OVN databases') self._sync_timer.restart() # Fix the create/update resources inconsistencies for row in create_update_inconsistencies: try: # NOTE(lucasagomes): The way to fix subnets is bit # different than other resources. A subnet in OVN language # is just a DHCP rule but, this rule only exist if the # subnet in Neutron has the "enable_dhcp" attribute set # to True. So, it's possible to have a consistent subnet # resource even when it does not exist in the OVN database. if row.resource_type == ovn_const.TYPE_SUBNETS: self._fix_create_update_subnet(row) else: self._fix_create_update(row) except Exception: LOG.exception( 'Failed to fix resource %(res_uuid)s ' '(type: %(res_type)s)', { 'res_uuid': row.resource_uuid, 'res_type': row.resource_type }) # Fix the deleted resources inconsistencies for row in delete_inconsistencies: try: if row.resource_type == ovn_const.TYPE_SUBNETS: self._ovn_client.delete_subnet(row.resource_uuid) else: self._fix_delete(row) except Exception: LOG.exception( 'Failed to fix deleted resource %(res_uuid)s ' '(type: %(res_type)s)', { 'res_uuid': row.resource_uuid, 'res_type': row.resource_type }) self._sync_timer.stop() LOG.info( 'Maintenance task synchronization finished ' '(took %.2f seconds)', self._sync_timer.elapsed())
def check_for_inconsistencies(self): # Only the worker holding a valid lock within OVSDB will run # this periodic if not self.has_lock: return create_update_inconsistencies = db_maint.get_inconsistent_resources() delete_inconsistencies = db_maint.get_deleted_resources() if not any([create_update_inconsistencies, delete_inconsistencies]): return LOG.warning('Inconsistencies found in the database!') # Fix the create/update resources inconsistencies for row in create_update_inconsistencies: try: if row.resource_type == ovn_const.TYPE_NETWORKS: self._fix_create_update_network(row) except Exception: LOG.exception( 'Failed to fix resource %(res_uuid)s ' '(type: %(res_type)s)', { 'res_uuid': row.resource_uuid, 'res_type': row.resource_type }) # Fix the deleted resources inconsistencies for row in delete_inconsistencies: try: if row.resource_type == ovn_const.TYPE_NETWORKS: self._fix_delete_network(row) except Exception: LOG.exception( 'Failed to fix deleted resource %(res_uuid)s ' '(type: %(res_type)s)', { 'res_uuid': row.resource_uuid, 'res_type': row.resource_type })
def test_get_deleted_resources_order(self): self._prepare_resources_for_ordering_test(delete=True) res = db_maint.get_deleted_resources() actual_order = tuple(r.resource_type for r in res) self.assertEqual(tuple(reversed(constants._TYPES_PRIORITY_ORDER)), actual_order)