6 from subprocess import check_call, Popen, PIPE
8 log = logging.getLogger(__name__)
11 @contextlib.contextmanager
12 def task(ctx, config):
14 Execute an aver assertion
18 input: file containing data referred to by the assertions. File name is
19 relative to the job's archive path
20 validations: list of validations in the Aver language
24 input: bench_output.csv
26 - expect performance(alg='ceph') > performance(alg='raw')
27 - for size > 3 expect avg_throughput > 2000
29 log.info('Beginning aver...')
30 assert isinstance(config, dict), 'expecting dictionary for configuration'
32 if 'input' not in config:
33 raise Exception("Expecting 'input' option")
34 if len(config.get('validations', [])) < 1:
35 raise Exception("Expecting at least one entry in 'validations'")
37 url = ('https://github.com/ivotron/aver/releases/download/'
38 'v0.3.0/aver-linux-amd64.tar.bz2')
40 aver_path = ctx.archive + '/aver'
43 check_call(['wget', '-O', aver_path + '.tbz', url])
44 check_call(['tar', 'xfj', aver_path + '.tbz', '-C', ctx.archive])
47 process = Popen([aver_path, '-v'], stdout=PIPE)
48 log.info(process.communicate()[0])
51 for validation in config['validations']:
52 cmd = (aver_path + ' -s -i ' + (ctx.archive + '/' + config['input']) +
53 ' "' + validation + '"')
54 log.info("executing: " + cmd)
55 process = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
56 (stdout, stderr) = process.communicate()
58 log.info('aver stderr: ' + stderr)
59 log.info('aver result: ' + stdout)
60 if stdout.strip(' \t\n\r') != 'true':
61 raise Exception('Failed validation: ' + validation)
66 log.info('Removing aver binary...')
67 check_call(['rm', aver_path, aver_path + '.tbz'])