Skip to content

Commit 3ee3856

Browse files
rst0gitavagin
authored andcommitted
ci: verify call order of action-script hooks
The existing test collects all action-script hooks triggered during `h`, `ns`, and `uns` runs with ZDTM into `actions_called.txt`, then verifies that each hook appears at least once. However, the test does not verify that hooks are invoked *exactly once* or in *correct order*. This change updates the test to run ZDTM only with ns flavour as this seems to cover all action-script hooks, and checks that all hooks are called correctly. Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
1 parent caac2f7 commit 3ee3856

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed
Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
11
#!/usr/bin/env python3
22

3-
import sys
43
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+
]
518

6-
actions = set(['pre-dump', 'pre-restore', 'post-dump', 'setup-namespaces', \
7-
'post-setup-namespaces', 'post-restore', 'post-resume', \
8-
'network-lock', 'network-unlock' ])
919
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
1128

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")
1631

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}")
1935

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')
2238

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})')
3044

31-
actions -= set([act[0]])
45+
actions_called.append(action_hook)
3246

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}')
3549

3650
if errors:
37-
for x in errors:
38-
print(x)
51+
print('\n'.join(errors))
3952
sys.exit(1)
4053

41-
print('PASS')
54+
print('Check Actions PASS')

test/others/action-script/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
66

77
rm -f "${SCRIPT_DIR}"/actions_called.txt
8-
"${SCRIPT_DIR}"/../../zdtm.py run -t zdtm/static/env00 --script "$SCRIPT_DIR/show_action.sh" || exit 1
8+
"${SCRIPT_DIR}"/../../zdtm.py run -t zdtm/static/env00 -f ns --script "$SCRIPT_DIR/show_action.sh" || exit 1
99
"${SCRIPT_DIR}"/check_actions.py || exit 1
1010

1111
exit 0

0 commit comments

Comments
 (0)