test: Some enhancements to make test stable

1. Checking FDO user created before running ansible playbook
2. Wait 10 seconds before and after VM rebooting to make VM stable
This commit is contained in:
Xiaofeng Wang 2023-06-15 18:56:40 +08:00 committed by Alexander Todorov
parent eb5dd8ae1b
commit ae04d807a3
2 changed files with 29 additions and 16 deletions

View file

@ -250,6 +250,16 @@ wait_for_ssh_up () {
fi
}
# Wait for FDO onboarding finished.
wait_for_fdo () {
SSH_STATUS=$(sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@"${1}" "id -u ${ANSIBLE_USER} > /dev/null 2>&1 && echo -n READY")
if [[ $SSH_STATUS == READY ]]; then
echo 1
else
echo 0
fi
}
# Clean up our mess.
clean_up () {
greenprint "🧼 Cleaning up"
@ -656,6 +666,20 @@ for LOOP_COUNTER in $(seq 0 30); do
sleep 10
done
# Workaround to fix edge-simplified-installer test failure (ansible runs before fdouser is created)
# Bug link: https://github.com/osbuild/osbuild-composer/pull/3378#issuecomment-1502633131
if [[ "${ANSIBLE_USER}" == "fdouser" ]]; then
greenprint "Waiting for FDO user onboarding finished"
for _ in $(seq 0 30); do
RESULTS=$(wait_for_fdo "$PUB_KEY_GUEST_ADDRESS")
if [[ $RESULTS == 1 ]]; then
echo "FDO user is ready to use! 🥳"
break
fi
sleep 10
done
fi
# With new ostree-libs-2022.6-3, edge vm needs to reboot twice to make the /sysroot readonly
sudo ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" "admin@${PUB_KEY_GUEST_ADDRESS}" 'nohup sudo systemctl reboot &>/dev/null & exit'
# Sleep 10 seconds here to make sure vm restarted already
@ -669,22 +693,6 @@ for _ in $(seq 0 30); do
sleep 10
done
# Workaround to fix edge-simplified-installer test failure (ansible runs before fdouser is created)
# Bug link: https://github.com/osbuild/osbuild-composer/pull/3378#issuecomment-1502633131
if [[ "${ANSIBLE_USER}" == "fdouser" ]]; then
greenprint "🕹 Check if user 'fdouser' exist in edge vm"
for _ in $(seq 0 30); do
FDOUSER_EXIST=$(ssh "${SSH_OPTIONS[@]}" -i "${SSH_KEY}" admin@$PUB_KEY_GUEST_ADDRESS "grep fdouser /etc/passwd || true")
if [[ ${FDOUSER_EXIST} =~ "fdouser" ]]; then
echo "fdouser has been created"
break
else
echo "fdouser has not been created yet"
sleep 10
fi
done
fi
# Check image installation result
check_result