def datastore(datastore_connection, filestore): ds = datastore_connection try: random_data.create_heuristics(ds, heuristics_count=10) random_data.create_services(ds) random_data.create_signatures(ds) random_data.create_users(ds) random_data.create_workflows(ds) submissions = [] for _ in range(2): submissions.append(random_data.create_submission( ds, filestore)) random_data.create_alerts(ds, alert_count=10, submission_list=submissions) yield ds finally: # Cleanup test data random_data.wipe_alerts(ds) random_data.wipe_heuristics(ds) random_data.wipe_services(ds) random_data.wipe_signatures(ds) random_data.wipe_submissions(ds, filestore) random_data.wipe_users(ds) random_data.wipe_workflows(ds)
def datastore(datastore_connection, filestore): try: create_users(datastore_connection) create_submission(datastore_connection, filestore) yield datastore_connection finally: wipe_users(datastore_connection) wipe_submissions(datastore_connection, filestore)
def purge_data(ds, fs): wipe_alerts(ds) wipe_heuristics(ds) wipe_services(ds) wipe_signatures(ds) wipe_submissions(ds, fs) wipe_users(ds) wipe_workflows(ds)
def datastore(request, datastore_connection, fs): for _ in range(NUM_SUBMISSIONS): all_submissions.append(create_submission(datastore_connection, fs)) try: yield datastore_connection finally: wipe_submissions(datastore_connection, fs) datastore_connection.alert.wipe()
def datastore(datastore_connection, filestore): global submission try: create_users(datastore_connection) submission = create_submission(datastore_connection, filestore) yield datastore_connection finally: wipe_users(datastore_connection) wipe_submissions(datastore_connection, filestore) sq.delete()
def datastore(datastore_connection, filestore): try: create_users(datastore_connection) for _ in range(NUM_SUBMISSIONS): create_submission(datastore_connection, filestore) yield datastore_connection finally: wipe_users(datastore_connection) wipe_submissions(datastore_connection, filestore)
def datastore(datastore_connection, filestore): try: create_users(datastore_connection) submission = create_submission(datastore_connection, filestore) alert = random_model_obj(Alert) alert.alert_id = ALERT_ID alert.sid = submission.sid datastore_connection.alert.save(ALERT_ID, alert) yield datastore_connection finally: wipe_users(datastore_connection) wipe_submissions(datastore_connection, filestore) datastore_connection.alert.delete(ALERT_ID)
def datastore(request, datastore_connection, fs): wipe_alerts(datastore_connection) wipe_submissions(datastore_connection, fs) for _ in range(NUM_SUBMISSIONS): all_submissions.append(create_submission(datastore_connection, fs)) create_alerts(datastore_connection, alert_count=NUM_ALERTS, submission_list=all_submissions) for alert in datastore_connection.alert.stream_search("id:*", fl="*"): all_alerts.append(alert) try: yield datastore_connection finally: wipe_alerts(datastore_connection) wipe_submissions(datastore_connection, fs) datastore_connection.alert.wipe()
def test_restore(datastore, cli, fs): # Get a temp directory temp_dir = tempfile.mkdtemp() os.rmdir(temp_dir) # Calculate the numbers of items in each collections result_len = datastore.result.search("id:*", rows=0)['total'] submission_len = datastore.submission.search("id:*", rows=0)['total'] error_len = datastore.error.search("id:*", rows=0)['total'] file_len = datastore.file.search("id:*", rows=0)['total'] # Do a backup reset_logger() cli.do_backup(f"{temp_dir} submission follow force id:*") print(LOGS) # Wipe the database wipe_submissions(datastore, fs) # Test that the DB is empty assert datastore.result.search("id:*", rows=0)['total'] == 0 assert datastore.submission.search("id:*", rows=0)['total'] == 0 assert datastore.error.search("id:*", rows=0)['total'] == 0 assert datastore.file.search("id:*", rows=0)['total'] == 0 # Restore the backup cli.do_restore(temp_dir) # Refresh the indices datastore.submission.commit() datastore.file.commit() datastore.result.commit() datastore.error.commit() # Test that the DB is not empty anymore assert result_len == datastore.result.search("id:*", rows=0)['total'] assert submission_len == datastore.submission.search("id:*", rows=0)['total'] assert error_len == datastore.error.search("id:*", rows=0)['total'] assert file_len >= datastore.file.search("id:*", rows=0)['total'] > 0
def cleanup(ds, fs): wipe_users(ds) wipe_submissions(ds, fs) wipe_alerts(ds)
def purge_alert(ds, fs): wipe_users(ds) wipe_submissions(ds, fs) ds.alert.wipe()
def purge_alert(ds, fs): wipe_alerts(ds) wipe_submissions(ds, fs)