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>
This commit is contained in:
Radostin Stoyanov 2025-10-21 12:11:45 +01:00 committed by Andrei Vagin
parent f824dc735b
commit f74e68daf9
2 changed files with 40 additions and 27 deletions

View file

@ -1,41 +1,54 @@
#!/usr/bin/env python3
import sys
import os
import sys
EXPECTED_ACTIONS = [
'pre-dump',
'network-lock',
'post-dump',
'pre-restore',
'setup-namespaces',
'post-setup-namespaces',
'post-restore',
'network-unlock',
'pre-resume',
'post-resume',
]
actions = set(['pre-dump', 'pre-restore', 'post-dump', 'setup-namespaces', \
'post-setup-namespaces', 'post-restore', 'post-resume', \
'network-lock', 'network-unlock' ])
errors = []
af = os.path.dirname(os.path.abspath(__file__)) + '/actions_called.txt'
actions_called = []
actions_called_file = os.path.join(os.path.dirname(__file__), 'actions_called.txt')
for act in open(af):
act = act.strip().split()
act.append('EMPTY')
act.append('EMPTY')
with open(actions_called_file) as f:
for index, line in enumerate(f):
parts = line.strip().split()
parts += ['EMPTY'] * (3 - len(parts))
action_hook, image_dir, pid = parts
if act[0] == 'EMPTY':
raise Exception("Error in test, bogus actions line")
if action_hook == 'EMPTY':
raise ValueError("Error in test: bogus actions line")
if act[1] == 'EMPTY':
errors.append('Action %s misses CRTOOLS_IMAGE_DIR' % act[0])
expected_action = EXPECTED_ACTIONS[index] if index < len(EXPECTED_ACTIONS) else None
if action_hook != expected_action:
raise ValueError(f"Invalid action: {action_hook} != {expected_action}")
if act[0] in ('post-dump', 'setup-namespaces', 'post-setup-namespaces', \
'post-restore', 'post-resume', 'network-lock', 'network-unlock'):
if act[2] == 'EMPTY':
errors.append('Action %s misses CRTOOLS_INIT_PID' % act[0])
elif not act[2].isdigit() or int(act[2]) == 0:
errors.append('Action %s PID is not number (%s)' %
(act[0], act[2]))
if image_dir == 'EMPTY':
errors.append(f'Action {action_hook} misses CRTOOLS_IMAGE_DIR')
actions -= set([act[0]])
if action_hook != 'pre-restore':
if pid == 'EMPTY':
errors.append(f'Action {action_hook} misses CRTOOLS_INIT_PID')
elif not pid.isdigit() or int(pid) == 0:
errors.append(f'Action {action_hook} PID is not a valid number ({pid})')
if actions:
errors.append('Not all actions called: %r' % actions)
actions_called.append(action_hook)
if actions_called != EXPECTED_ACTIONS:
errors.append(f'Not all actions called: {actions_called!r}')
if errors:
for x in errors:
print(x)
print('\n'.join(errors))
sys.exit(1)
print('PASS')
print('Check Actions PASS')

View file

@ -5,7 +5,7 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
rm -f "${SCRIPT_DIR}"/actions_called.txt
"${SCRIPT_DIR}"/../../zdtm.py run -t zdtm/static/env00 --script "$SCRIPT_DIR/show_action.sh" || exit 1
"${SCRIPT_DIR}"/../../zdtm.py run -t zdtm/static/env00 -f ns --script "$SCRIPT_DIR/show_action.sh" || exit 1
"${SCRIPT_DIR}"/check_actions.py || exit 1
exit 0