# don't need that yet # from livy import LivySession import sys import boto3 import os import requests import time from integration_tests import conftest def post_livy_jobs(jar_name, class_path_name, args, timeout=3600): """POSTs a batch job.""" body = { 'file': 's3://qa-abacus-compute-test/code/{}'.format(jar_name), 'className': class_path_name, 'args': args.split(', ') } print('[INFO] Starting {} batch'.format(class_path_name)) r = requests.post(conftest.LIVY_URL + '/batches', json=body) if r.status_code != 201: sys.exit( '[ERROR] Batch POST didn\'t succeed, status code was: {}, message was: {}' .format(r.status_code, r.json()) ) batch_id = r.json()['id'] rewrite_batchId_file(batch_id) wait_for_batch_to_succeed(timeout) def delete_result_files_from_s3( prefix='acc_run_testing_', bucket='qa-abacus-compute-test' ): """Cleans up output test files from s3.""" s3 = boto3.resource('s3') bucket = s3.Bucket(bucket) bucket.objects.filter(Prefix=prefix).delete() def write_id_to_file(batch_id): """Writes a batch id to the file.""" f = open('batch_id.txt', 'w') f.write(str(batch_id)) f.close() def delete_batch_id_file(): """Deletes batch_id.txt file.""" try: os.remove('batch_id.txt') except OSError: pass def rewrite_batchId_file(value): """Deletes the old file and creates a new one.""" delete_batch_id_file() write_id_to_file(value) def read_batch_file(): """Reads a batch id from a file and returns it.""" file = open('batch_id.txt', 'r') value = file.readlines() file.close() return value[0] def wait_for_batch_to_succeed(timeout): """Waits for the batch to succeed by id.""" batch_id = read_batch_file() livy_path = f'{conftest.LIVY_URL}/batches/{format(batch_id)}' print(f'[INFO] Livy URL: {livy_path}') print('[INFO] Waiting for batch job to succeed') x = 0 while x != timeout: r = requests.get(livy_path) batch_status = r.json()['state'] if batch_status == 'success': print('[INFO] Batch succeeded!') break elif batch_status == 'dead': log = requests.get(f'{livy_path}/log') print(log.json()['log']) sys.exit('[ERROR] Batch failed') time.sleep(1) x += 1 if x == timeout: sys.exit('[ERROR] Timed out while waiting for batch to succeed') def test_verify_output(): """Verifies _SUCCESS file presence in CalculateTotals folder.""" s3 = boto3.resource('s3') bucket = s3.Bucket('qa-abacus-compute-test') objects = list( bucket.objects.filter( Prefix='acc_run_testing_results/calculate_totals/_SUCCESS' ) ) assert len(objects) == 1