2018-02-28 00:42:47 +00:00
|
|
|
#!/bin/bash
|
2018-06-14 23:43:06 +00:00
|
|
|
set -eux
|
2020-04-29 02:50:39 +00:00
|
|
|
|
2021-03-03 18:25:23 +00:00
|
|
|
testschema=.subiquity/test-autoinstall-schema.json
|
2021-08-09 16:16:18 +00:00
|
|
|
export PYTHONPATH=$PWD:$PWD/probert:$PWD/curtin
|
2021-03-03 18:25:23 +00:00
|
|
|
|
2021-09-09 09:48:16 +00:00
|
|
|
RELEASE=$(lsb_release -rs)
|
|
|
|
|
2020-04-29 02:50:39 +00:00
|
|
|
validate () {
|
2021-08-31 10:10:25 +00:00
|
|
|
mode="install"
|
|
|
|
[ $# -gt 0 ] && mode="$1"
|
|
|
|
|
2021-09-20 22:42:47 +00:00
|
|
|
if [ "${mode}" = "install" ]; then
|
2021-08-31 10:10:25 +00:00
|
|
|
python3 scripts/validate-yaml.py .subiquity/subiquity-curtin-install.conf
|
|
|
|
if [ ! -e .subiquity/subiquity-client-debug.log ] || [ ! -e .subiquity/subiquity-server-debug.log ]; then
|
|
|
|
echo "log file not created"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if grep passw0rd .subiquity/subiquity-client-debug.log .subiquity/subiquity-server-debug.log | grep -v "Loaded answers" | grep -v "answers_action"; then
|
|
|
|
echo "password leaked into log file"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
netplan generate --root .subiquity
|
|
|
|
elif [ "${mode}" = "system_setup" ]; then
|
2021-10-06 15:00:06 +00:00
|
|
|
setup_mode="$2"
|
|
|
|
echo "system setup validation for $setup_mode"
|
|
|
|
[ -d ".subiquity/etc/" ] || (echo "etc/ dir not created for config"; exit 1)
|
|
|
|
[ -d "system_setup/tests/golden/${setup_mode}" ] || (echo "tests/golden not found in system_setup"; exit 1)
|
|
|
|
for file in system_setup/tests/golden/${setup_mode}/*.conf; do
|
|
|
|
filename=$(basename ${file})
|
|
|
|
conf_filepath=".subiquity/etc/${filename}"
|
|
|
|
diff -Nup "${file}" "${conf_filepath}" || exit 1
|
|
|
|
done
|
2021-08-31 10:10:25 +00:00
|
|
|
else
|
|
|
|
echo "W: Unknown validation mode: ${mode}"
|
2019-02-20 14:09:28 +00:00
|
|
|
fi
|
2020-04-29 02:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clean () {
|
|
|
|
rm -f .subiquity/subiquity-curtin-install.conf
|
2020-10-12 01:23:50 +00:00
|
|
|
rm -f .subiquity/subiquity-*.log
|
2021-03-03 18:25:23 +00:00
|
|
|
rm -f "$testschema"
|
2020-04-29 07:31:30 +00:00
|
|
|
rm -rf .subiquity/run/
|
2021-10-06 15:00:06 +00:00
|
|
|
rm -rf .subiquity/etc/*.conf
|
2021-06-08 22:54:29 +00:00
|
|
|
rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg
|
2020-04-29 02:50:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 16:16:18 +00:00
|
|
|
error () {
|
|
|
|
set +x # show PASS/FAIL as the last line of output
|
|
|
|
echo 'Runtests FAILURE'
|
|
|
|
}
|
|
|
|
|
|
|
|
trap error ERR
|
|
|
|
trap clean EXIT
|
2021-02-17 21:34:56 +00:00
|
|
|
tty=$(tty) || tty=/dev/console
|
|
|
|
|
2020-04-29 02:50:39 +00:00
|
|
|
export SUBIQUITY_REPLAY_TIMESCALE=100
|
|
|
|
for answers in examples/answers*.yaml; do
|
|
|
|
clean
|
2021-08-31 10:10:25 +00:00
|
|
|
if echo $answers|grep -vq system-setup; then
|
|
|
|
config=$(sed -n 's/^#machine-config: \(.*\)/\1/p' $answers || true)
|
|
|
|
if [ -z "$config" ]; then
|
|
|
|
config=examples/simple.json
|
|
|
|
fi
|
|
|
|
serial=$(sed -n 's/^#serial/x/p' $answers || true)
|
|
|
|
opts=''
|
|
|
|
if [ -n "$serial" ]; then
|
|
|
|
opts='--serial'
|
|
|
|
fi
|
|
|
|
# The --foreground is important to avoid subiquity getting SIGTTOU-ed.
|
|
|
|
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m subiquity.cmd.tui --bootloader uefi --answers $answers --dry-run --snaps-from-examples --machine-config $config $opts" < $tty
|
|
|
|
validate
|
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades: SUCCESS: downloading and installing security updates' .subiquity/subiquity-server-debug.log
|
|
|
|
else
|
2021-09-09 09:48:16 +00:00
|
|
|
# The OOBE doesn't exist in WSL < 20.04
|
|
|
|
if [ "${RELEASE%.*}" -ge 20 ]; then
|
2021-10-06 15:00:06 +00:00
|
|
|
# check if it is reconf
|
|
|
|
reconf_settings="false"
|
|
|
|
validate_subtype="answers"
|
|
|
|
if echo $answers|grep -q reconf; then
|
|
|
|
reconf_settings="true"
|
|
|
|
validate_subtype="answers-reconf"
|
|
|
|
fi
|
|
|
|
timeout --foreground 60 sh -c "DRYRUN_RECONFIG=$reconf_settings LANG=C.UTF-8 python3 -m system_setup.cmd.tui --answers $answers --dry-run " < $tty
|
|
|
|
validate "system_setup" "$validate_subtype"
|
2021-09-09 09:48:16 +00:00
|
|
|
fi
|
2021-05-04 00:38:19 +00:00
|
|
|
fi
|
2018-06-14 23:43:06 +00:00
|
|
|
done
|
2020-04-29 02:50:39 +00:00
|
|
|
|
|
|
|
clean
|
2020-04-01 21:47:47 +00:00
|
|
|
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m subiquity.cmd.tui --autoinstall examples/autoinstall.yaml \
|
2020-05-04 03:28:42 +00:00
|
|
|
--dry-run --machine-config examples/existing-partitions.json --bootloader bios \
|
2020-10-12 01:23:50 +00:00
|
|
|
--kernel-cmdline 'autoinstall'"
|
2020-04-29 02:50:39 +00:00
|
|
|
validate
|
2020-04-20 07:37:34 +00:00
|
|
|
python3 scripts/check-yaml-fields.py .subiquity/subiquity-curtin-install.conf \
|
2021-09-20 22:42:47 +00:00
|
|
|
debconf_selections.subiquity='"eek"' \
|
2021-04-05 21:16:55 +00:00
|
|
|
storage.config[-1].options='"errors=remount-ro"'
|
2020-06-16 00:25:09 +00:00
|
|
|
python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \
|
2021-06-08 22:54:29 +00:00
|
|
|
locale='"en_GB.UTF-8"' \
|
2021-07-15 13:30:22 +00:00
|
|
|
timezone='"Pacific/Guam"' \
|
2021-06-08 22:54:29 +00:00
|
|
|
'snap.commands=[snap install --channel=3.2/stable etcd]'
|
2020-10-12 01:23:50 +00:00
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \
|
|
|
|
.subiquity/subiquity-server-debug.log
|
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/install_package2: SUCCESS: installing package2' \
|
|
|
|
.subiquity/subiquity-server-debug.log
|
|
|
|
grep -q 'switching subiquity to edge' .subiquity/subiquity-server-debug.log
|
2021-06-28 23:11:49 +00:00
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades: SUCCESS: downloading and installing all updates' \
|
2021-03-31 19:57:53 +00:00
|
|
|
.subiquity/subiquity-server-debug.log
|
2020-04-19 09:44:09 +00:00
|
|
|
|
2020-04-29 02:50:39 +00:00
|
|
|
clean
|
2020-04-19 09:44:09 +00:00
|
|
|
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m subiquity.cmd.tui --autoinstall examples/autoinstall-user-data.yaml \
|
2020-10-12 01:23:50 +00:00
|
|
|
--dry-run --machine-config examples/simple.json --kernel-cmdline 'autoinstall'"
|
2020-04-29 02:50:39 +00:00
|
|
|
validate
|
2021-06-28 23:11:49 +00:00
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades: SUCCESS: downloading and installing security updates' .subiquity/subiquity-server-debug.log
|
2021-03-03 18:25:23 +00:00
|
|
|
|
2021-09-09 09:48:16 +00:00
|
|
|
# The OOBE doesn't exist in WSL < 20.04
|
|
|
|
if [ "${RELEASE%.*}" -ge 20 ]; then
|
|
|
|
# NOTE:
|
|
|
|
# This test doesnt do much ATM but it will be useful when we have more complex scenarios to test with the server and client code.
|
|
|
|
# Like generating a wsl.conf file and comparing it to the oracle.
|
|
|
|
clean
|
|
|
|
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m system_setup.cmd.tui --autoinstall examples/autoinstall-system-setup.yaml --dry-run"
|
2021-10-06 15:00:06 +00:00
|
|
|
validate "system_setup" "autoinstall"
|
2021-09-09 09:48:16 +00:00
|
|
|
|
|
|
|
python3 -m system_setup.cmd.schema > "$testschema"
|
|
|
|
scripts/schema-cmp.py "autoinstall-system-setup-schema.json" "$testschema" --ignore-tz
|
|
|
|
fi
|
2021-09-08 15:54:34 +00:00
|
|
|
|
2021-07-14 00:13:46 +00:00
|
|
|
python3 -m subiquity.cmd.schema > "$testschema"
|
|
|
|
scripts/schema-cmp.py "autoinstall-schema.json" "$testschema"
|
2021-08-09 16:16:18 +00:00
|
|
|
|
2021-09-08 15:54:34 +00:00
|
|
|
|
2021-08-09 16:16:18 +00:00
|
|
|
set +x # show PASS/FAIL as the last line of output
|
|
|
|
echo 'Runtests all PASSED'
|