|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import sys |
4 | 3 | import os |
| 4 | +import sys |
| 5 | + |
| 6 | +EXPECTED_ACTIONS = [ |
| 7 | + 'pre-dump', |
| 8 | + 'network-lock', |
| 9 | + 'post-dump', |
| 10 | + 'pre-restore', |
| 11 | + 'setup-namespaces', |
| 12 | + 'post-setup-namespaces', |
| 13 | + 'post-restore', |
| 14 | + 'network-unlock', |
| 15 | + 'pre-resume', |
| 16 | + 'post-resume', |
| 17 | +] |
5 | 18 |
|
6 | | -actions = set(['pre-dump', 'pre-restore', 'post-dump', 'setup-namespaces', \ |
7 | | - 'post-setup-namespaces', 'post-restore', 'post-resume', \ |
8 | | - 'network-lock', 'network-unlock' ]) |
9 | 19 | errors = [] |
10 | | -af = os.path.dirname(os.path.abspath(__file__)) + '/actions_called.txt' |
| 20 | +actions_called = [] |
| 21 | +actions_called_file = os.path.join(os.path.dirname(__file__), 'actions_called.txt') |
| 22 | + |
| 23 | +with open(actions_called_file) as f: |
| 24 | + for index, line in enumerate(f): |
| 25 | + parts = line.strip().split() |
| 26 | + parts += ['EMPTY'] * (3 - len(parts)) |
| 27 | + action_hook, image_dir, pid = parts |
11 | 28 |
|
12 | | -for act in open(af): |
13 | | - act = act.strip().split() |
14 | | - act.append('EMPTY') |
15 | | - act.append('EMPTY') |
| 29 | + if action_hook == 'EMPTY': |
| 30 | + raise ValueError("Error in test: bogus actions line") |
16 | 31 |
|
17 | | - if act[0] == 'EMPTY': |
18 | | - raise Exception("Error in test, bogus actions line") |
| 32 | + expected_action = EXPECTED_ACTIONS[index] if index < len(EXPECTED_ACTIONS) else None |
| 33 | + if action_hook != expected_action: |
| 34 | + raise ValueError(f"Invalid action: {action_hook} != {expected_action}") |
19 | 35 |
|
20 | | - if act[1] == 'EMPTY': |
21 | | - errors.append('Action %s misses CRTOOLS_IMAGE_DIR' % act[0]) |
| 36 | + if image_dir == 'EMPTY': |
| 37 | + errors.append(f'Action {action_hook} misses CRTOOLS_IMAGE_DIR') |
22 | 38 |
|
23 | | - if act[0] in ('post-dump', 'setup-namespaces', 'post-setup-namespaces', \ |
24 | | - 'post-restore', 'post-resume', 'network-lock', 'network-unlock'): |
25 | | - if act[2] == 'EMPTY': |
26 | | - errors.append('Action %s misses CRTOOLS_INIT_PID' % act[0]) |
27 | | - elif not act[2].isdigit() or int(act[2]) == 0: |
28 | | - errors.append('Action %s PID is not number (%s)' % |
29 | | - (act[0], act[2])) |
| 39 | + if action_hook != 'pre-restore': |
| 40 | + if pid == 'EMPTY': |
| 41 | + errors.append(f'Action {action_hook} misses CRTOOLS_INIT_PID') |
| 42 | + elif not pid.isdigit() or int(pid) == 0: |
| 43 | + errors.append(f'Action {action_hook} PID is not a valid number ({pid})') |
30 | 44 |
|
31 | | - actions -= set([act[0]]) |
| 45 | + actions_called.append(action_hook) |
32 | 46 |
|
33 | | -if actions: |
34 | | - errors.append('Not all actions called: %r' % actions) |
| 47 | +if actions_called != EXPECTED_ACTIONS: |
| 48 | + errors.append(f'Not all actions called: {actions_called!r}') |
35 | 49 |
|
36 | 50 | if errors: |
37 | | - for x in errors: |
38 | | - print(x) |
| 51 | + print('\n'.join(errors)) |
39 | 52 | sys.exit(1) |
40 | 53 |
|
41 | | -print('PASS') |
| 54 | +print('Check Actions PASS') |
0 commit comments