def test_get_inconsistent_resources(self): # Set the intial revision to -1 to force it to be incosistent db_rev.create_initial_revision( self.net['id'], constants.TYPE_NETWORKS, self.session, revision_number=-1) res = db_maint.get_inconsistent_resources() self.assertEqual(1, len(res)) self.assertEqual(self.net['id'], res[0].resource_uuid)
def test_get_inconsistent_resources_consistent(self): # Set the initial revision to 0 which is the initial revision_number # for recently created resources db_rev.create_initial_revision( self.net['id'], constants.TYPE_NETWORKS, self.session, revision_number=0) res = db_maint.get_inconsistent_resources() # Assert nothing is inconsistent self.assertEqual([], res)
def test_get_inconsistent_resources_older_than(self): # Stop the mock so the INCONSISTENCIES_OLDER_THAN will have # it's default value self.older_than_mock.stop() db_rev.create_initial_revision( self.net['id'], constants.TYPE_NETWORKS, self.session, revision_number=-1) res = db_maint.get_inconsistent_resources() # Assert that nothing is returned because the entry is not old # enough to be picked as an inconsistency self.assertEqual(0, len(res)) # Start the mock again and make sure it nows shows up as an # inconsistency self.older_than_mock.start() res = db_maint.get_inconsistent_resources() self.assertEqual(1, len(res)) self.assertEqual(self.net['id'], res[0].resource_uuid)
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_inconsistent_resources_order(self): self._prepare_resources_for_ordering_test() res = db_maint.get_inconsistent_resources() actual_order = tuple(r.resource_type for r in res) self.assertEqual(constants._TYPES_PRIORITY_ORDER, actual_order)