]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | """ |
2 | Aver wrapper task | |
3 | """ | |
4 | import contextlib | |
5 | import logging | |
6 | from subprocess import check_call, Popen, PIPE | |
7 | ||
8 | log = logging.getLogger(__name__) | |
9 | ||
10 | ||
11 | @contextlib.contextmanager | |
12 | def task(ctx, config): | |
13 | """ | |
14 | Execute an aver assertion | |
15 | ||
16 | Parameters: | |
17 | ||
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 | |
21 | ||
22 | Example: | |
23 | - aver: | |
24 | input: bench_output.csv | |
25 | validations: | |
26 | - expect performance(alg='ceph') > performance(alg='raw') | |
27 | - for size > 3 expect avg_throughput > 2000 | |
28 | """ | |
29 | log.info('Beginning aver...') | |
30 | assert isinstance(config, dict), 'expecting dictionary for configuration' | |
31 | ||
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'") | |
36 | ||
37 | url = ('https://github.com/ivotron/aver/releases/download/' | |
38 | 'v0.3.0/aver-linux-amd64.tar.bz2') | |
39 | ||
40 | aver_path = ctx.archive + '/aver' | |
41 | ||
42 | # download binary | |
43 | check_call(['wget', '-O', aver_path + '.tbz', url]) | |
44 | check_call(['tar', 'xfj', aver_path + '.tbz', '-C', ctx.archive]) | |
45 | ||
46 | # print version | |
47 | process = Popen([aver_path, '-v'], stdout=PIPE) | |
48 | log.info(process.communicate()[0]) | |
49 | ||
50 | # validate | |
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() | |
57 | if stderr: | |
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) | |
62 | ||
63 | try: | |
64 | yield | |
65 | finally: | |
66 | log.info('Removing aver binary...') | |
67 | check_call(['rm', aver_path, aver_path + '.tbz']) |