def _test_dependency_processing(self, test_operation, test_object, test_id, test_context, dep_operation, dep_object, dep_id, dep_context): # Mock sendjson to verify that it never gets called. mock_sendjson = mock.patch.object(client.OpenDaylightRestClient, 'sendjson').start() # Create dependency db row and mark as 'processing' so it won't # be processed by the journal thread. db.create_pending_row(self.db_session, dep_object, dep_id, dep_operation, dep_context) row = db.get_all_db_rows_by_state(self.db_session, 'pending') db.update_pending_db_row_processing(self.db_session, row[0]) # Create test row with dependent ID. db.create_pending_row(self.db_session, test_object, test_id, test_operation, test_context) # Call journal thread. with mock.patch.object(self.thread.event, 'wait', return_value=False): self.thread.sync_pending_row(exit_after_run=True) # Verify that dependency row is still set at 'processing'. rows = db.get_all_db_rows_by_state(self.db_session, 'processing') self.assertEqual(1, len(rows)) # Verify that the test row was processed and set back to 'pending' # to be processed again. rows = db.get_all_db_rows_by_state(self.db_session, 'pending') self.assertEqual(1, len(rows)) # Verify that _json_data was not called. self.assertFalse(mock_sendjson.call_count)
def _test_object_type_processing_network(self, object_type): # Create a network (creates db row in pending state). self._call_operation_object(odl_const.ODL_CREATE, odl_const.ODL_NETWORK) # Get pending network row and mark as processing so that # this row will not be processed by journal thread. row = db.get_all_db_rows_by_state(self.db_session, 'pending') db.update_pending_db_row_processing(self.db_session, row[0]) # Create the object_type database row and process. # Verify that object request is not processed because the # dependent row has not been marked as 'completed'. self._test_thread_processing(odl_const.ODL_CREATE, object_type, expected_calls=0) # Verify that row is still set at 'processing'. rows = db.get_all_db_rows_by_state(self.db_session, 'processing') self.assertEqual(1, len(rows)) # Verify that the test row was processed and set back to 'pending' # to be processed again. rows = db.get_all_db_rows_by_state(self.db_session, 'pending') self.assertEqual(1, len(rows))
def _test_dependency_processing( self, test_operation, test_object, test_id, test_context, dep_operation, dep_object, dep_id, dep_context): # Mock sendjson to verify that it never gets called. mock_sendjson = mock.patch.object(client.OpenDaylightRestClient, 'sendjson').start() # Create dependency db row and mark as 'processing' so it won't # be processed by the journal thread. db.create_pending_row(self.db_session, dep_object, dep_id, dep_operation, dep_context) row = db.get_all_db_rows_by_state(self.db_session, 'pending') db.update_pending_db_row_processing(self.db_session, row[0]) # Create test row with dependent ID. db.create_pending_row(self.db_session, test_object, test_id, test_operation, test_context) # Call journal thread. with mock.patch.object(self.thread.event, 'wait', return_value=False): self.thread.sync_pending_row(exit_after_run=True) # Verify that dependency row is still set at 'processing'. rows = db.get_all_db_rows_by_state(self.db_session, 'processing') self.assertEqual(1, len(rows)) # Verify that the test row was processed and set back to 'pending' # to be processed again. rows = db.get_all_db_rows_by_state(self.db_session, 'pending') self.assertEqual(1, len(rows)) # Verify that _json_data was not called. self.assertFalse(mock_sendjson.call_count)
def _test_parent_delete_pending_child_delete(self, parent, child): # Delete a child (creates db row in pending state). self._call_operation_object(odl_const.ODL_DELETE, child) # Get pending child delete row and mark as processing so that # this row will not be processed by journal thread. row = db.get_all_db_rows_by_state(self.db_session, 'pending') db.update_pending_db_row_processing(self.db_session, row[0]) # Verify that parent delete request is not processed because the # dependent child delete row has not been marked as 'completed'. self._test_thread_processing(odl_const.ODL_DELETE, parent, expected_calls=0) # Verify that all rows are still in the database. rows = db.get_all_db_rows_by_state(self.db_session, 'processing') self.assertEqual(1, len(rows)) rows = db.get_all_db_rows_by_state(self.db_session, 'pending') self.assertEqual(1, len(rows))
def _test_object_operation_pending_object_operation( self, object_type, operation, pending_operation): # Create the object_type (creates db row in pending state). self._call_operation_object(pending_operation, object_type) # Get pending row and mark as processing so that # this row will not be processed by journal thread. row = db.get_all_db_rows_by_state(self.db_session, 'pending') db.update_pending_db_row_processing(self.db_session, row[0]) # Create the object_type database row and process. # Verify that object request is not processed because the # dependent object operation has not been marked as 'completed'. self._test_thread_processing(operation, object_type, expected_calls=0) # Verify that all rows are still in the database. rows = db.get_all_db_rows_by_state(self.db_session, 'processing') self.assertEqual(1, len(rows)) rows = db.get_all_db_rows_by_state(self.db_session, 'pending') self.assertEqual(1, len(rows))