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-08-09 16:16:18 +00:00
|
|
|
export PYTHONPATH=$PWD:$PWD/probert:$PWD/curtin
|
2022-03-08 10:23:50 +00:00
|
|
|
export PYTHONTRACEMALLOC=3
|
2021-03-03 18:25:23 +00:00
|
|
|
|
2021-09-09 09:48:16 +00:00
|
|
|
RELEASE=$(lsb_release -rs)
|
|
|
|
|
2022-03-18 17:32:09 +00:00
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
|
2020-04-29 02:50:39 +00:00
|
|
|
validate () {
|
2021-08-31 10:10:25 +00:00
|
|
|
mode="install"
|
|
|
|
[ $# -gt 0 ] && mode="$1"
|
|
|
|
|
2022-03-18 17:32:09 +00:00
|
|
|
if [ -d $tmpdir/var/crash -a -n "$(ls -A $tmpdir/var/crash)" ] ; then
|
|
|
|
echo "error: subiquity crashed"
|
2021-10-12 22:22:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-03-18 17:32:09 +00:00
|
|
|
if [ -s $tmpdir/server-stderr ]; then
|
|
|
|
echo "error: unexpected output on stderr"
|
|
|
|
cat $tmpdir/server-stderr
|
2022-03-08 10:20:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-09-20 22:42:47 +00:00
|
|
|
if [ "${mode}" = "install" ]; then
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 scripts/validate-yaml.py $tmpdir/var/log/installer/subiquity-curtin-install.conf
|
|
|
|
if [ ! -e $tmpdir/subiquity-client-debug.log ] || [ ! -e $tmpdir/subiquity-server-debug.log ]; then
|
2021-08-31 10:10:25 +00:00
|
|
|
echo "log file not created"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 scripts/validate-autoinstall-user-data.py < $tmpdir/var/log/installer/autoinstall-user-data
|
|
|
|
if grep passw0rd $tmpdir/subiquity-client-debug.log $tmpdir/subiquity-server-debug.log | grep -v "Loaded answers" | grep -v "answers_action"; then
|
2021-08-31 10:10:25 +00:00
|
|
|
echo "password leaked into log file"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
netplan generate --root $tmpdir
|
2021-08-31 10:10:25 +00:00
|
|
|
elif [ "${mode}" = "system_setup" ]; then
|
2021-10-06 15:00:06 +00:00
|
|
|
setup_mode="$2"
|
2022-03-18 17:32:09 +00:00
|
|
|
launcher_cmds="$tmpdir/run/launcher-command"
|
2021-10-06 15:00:06 +00:00
|
|
|
echo "system setup validation for $setup_mode"
|
2021-12-14 15:04:38 +00:00
|
|
|
echo "checking ${launcher_cmds}"
|
|
|
|
if [ ! -f ${launcher_cmds} ]; then
|
|
|
|
echo "Expected launcher commands to be written to the file."
|
|
|
|
exit 1
|
|
|
|
elif [ -z "$(grep action ${launcher_cmds})" ] && [ "${setup_mode}" != "autoinstall-no-shutdown" ]; then
|
|
|
|
echo "Expected action to be set in launcher commands."
|
|
|
|
exit 1
|
|
|
|
elif [ -z "$(grep defaultUid ${launcher_cmds})" ] && [ "${setup_mode}" != "answers-reconf" ]; then
|
|
|
|
echo "Expected defaultUid to be set in launcher commands."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
cat ${launcher_cmds}
|
|
|
|
fi
|
2021-10-15 08:29:35 +00:00
|
|
|
expected_status="reboot"
|
|
|
|
if [ "${setup_mode}" = "autoinstall-full" ]; then
|
|
|
|
expected_status="shutdown"
|
|
|
|
elif [ "${setup_mode}" = "autoinstall-no-shutdown" ]; then
|
2021-12-14 15:04:38 +00:00
|
|
|
expected_status=""
|
2021-10-15 08:29:35 +00:00
|
|
|
fi
|
2021-12-14 15:04:38 +00:00
|
|
|
result_status="$(cat ${launcher_cmds} | grep action | cut -d = -f 2)"
|
2021-10-15 08:29:35 +00:00
|
|
|
if [ "${result_status}" != "${expected_status}" ]; then
|
2021-12-14 15:04:38 +00:00
|
|
|
echo "incorrect ${launcher_cmds}: expect ${expected_status}, got ${result_status}"
|
2021-10-15 08:29:35 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-15 16:50:06 +00:00
|
|
|
echo "checking generated config"
|
2022-03-18 17:32:09 +00:00
|
|
|
[ -d "$tmpdir/etc/" ] || (echo "etc/ dir not created for config"; exit 1)
|
2021-10-15 08:29:35 +00:00
|
|
|
if [ "${setup_mode}" = "autoinstall-no-shutdown" ]; then
|
|
|
|
setup_mode="autoinstall"
|
|
|
|
fi
|
2021-10-06 15:00:06 +00:00
|
|
|
[ -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})
|
2022-03-18 17:32:09 +00:00
|
|
|
conf_filepath="$tmpdir/etc/${filename}"
|
2021-12-14 15:04:38 +00:00
|
|
|
diff -NBup "${file}" "${conf_filepath}" || exit 1
|
2021-10-06 15:00:06 +00:00
|
|
|
done
|
2021-10-15 16:50:06 +00:00
|
|
|
if [ "${setup_mode}" != "answers-reconf" ]; then
|
|
|
|
echo "checking user created"
|
2022-03-18 17:32:09 +00:00
|
|
|
[ -d "$tmpdir/home/" ] || (echo "home/ dir not created for the environment"; exit 1)
|
|
|
|
[ -d "$tmpdir/home/ubuntu" ] || (echo "home folder not created for the user"; exit 1)
|
|
|
|
if grep -v ubuntu $tmpdir/etc/passwd ; then
|
2021-10-15 16:50:06 +00:00
|
|
|
echo "user definition not included in etc/passwd"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
if grep -v Ubuntu $tmpdir/etc/passwd ; then
|
2021-10-15 16:50:06 +00:00
|
|
|
echo "username not added in etc/passwd"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
if grep -v ubuntu $tmpdir/etc/shadow ; then
|
2021-10-15 16:50:06 +00:00
|
|
|
echo "user definition not included in etc/shadow"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
if ! grep -q sudo $tmpdir/etc/group ; then
|
2021-10-15 16:50:06 +00:00
|
|
|
echo "expected group sudo not included in etc/group"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
if ! (grep sudo $tmpdir/etc/group | grep -q ubuntu) ; then
|
2021-10-15 16:50:06 +00:00
|
|
|
echo "user not assigned with the expected group sudo"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-01-06 10:59:30 +00:00
|
|
|
# Extract value of the LANG variable from etc/default/locale (with or without quotes)
|
2022-03-18 17:32:09 +00:00
|
|
|
lang="$(grep -Eo 'LANG=([^.@ _]+)' $tmpdir/etc/default/locale | cut -d= -f 2- | cut -d\" -f 2-)"
|
2022-03-22 22:00:12 +00:00
|
|
|
if ! ls $tmpdir/var/cache/apt/archives/*.log | grep --fixed-strings --quiet -- "$lang"; then
|
2021-11-22 15:16:01 +00:00
|
|
|
echo "expected $lang language packs in directory var/cache/apt/archives/"
|
2021-11-09 21:10:44 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-03-22 22:00:12 +00:00
|
|
|
for f in $tmpdir/var/cache/apt/archives/*.log ; do
|
|
|
|
if ! [ -s $f ]; then
|
|
|
|
echo "apt failed for package $f"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2022-03-18 17:32:09 +00:00
|
|
|
if [ -z "$( diff -Nup $tmpdir/etc/locale.gen $tmpdir/etc/locale.gen.test)" ] ; then
|
2021-11-09 21:10:44 +00:00
|
|
|
echo "expected changes in etc/locale.gen"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-15 16:50:06 +00:00
|
|
|
fi
|
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 () {
|
2022-03-18 17:32:09 +00:00
|
|
|
[ -d "$tmpdir" ] && rm -fr $tmpdir
|
|
|
|
tmpdir=$(mktemp -d)
|
2020-04-29 02:50:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 16:48:36 +00:00
|
|
|
on_exit () {
|
|
|
|
ec=$?
|
|
|
|
set +x # show PASS/FAIL in the last lines of output
|
|
|
|
if [[ $ec = 0 ]] ; then
|
|
|
|
echo 'Runtests all PASSED'
|
|
|
|
else
|
|
|
|
echo 'Runtests FAILURE'
|
|
|
|
echo "Output from the last run is at $tmpdir"
|
|
|
|
fi
|
|
|
|
exit $ec
|
2021-08-09 16:16:18 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 16:48:36 +00:00
|
|
|
trap on_exit 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
|
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)
|
2022-04-19 12:27:11 +00:00
|
|
|
opts=()
|
2021-08-31 10:10:25 +00:00
|
|
|
if [ -n "$serial" ]; then
|
2022-04-19 12:27:11 +00:00
|
|
|
opts+=(--serial)
|
2021-08-31 10:10:25 +00:00
|
|
|
fi
|
|
|
|
# The --foreground is important to avoid subiquity getting SIGTTOU-ed.
|
2022-04-19 12:27:11 +00:00
|
|
|
LANG=C.UTF-8 timeout --foreground 60 \
|
|
|
|
python3 -m subiquity.cmd.tui < "$tty" \
|
|
|
|
--dry-run \
|
|
|
|
--output-base "$tmpdir" \
|
2022-04-22 09:41:25 +00:00
|
|
|
--answers "$answers" \
|
|
|
|
"${opts[@]}" \
|
|
|
|
--machine-config "$config" \
|
|
|
|
--bootloader uefi \
|
2022-04-19 12:50:52 +00:00
|
|
|
--snaps-from-examples \
|
|
|
|
--source-catalog examples/install-sources.yaml
|
2021-08-31 10:10:25 +00:00
|
|
|
validate
|
2022-03-18 17:32:09 +00:00
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades: SUCCESS: downloading and installing security updates' $tmpdir/subiquity-server-debug.log
|
2021-08-31 10:10:25 +00:00
|
|
|
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
|
2022-04-19 12:27:11 +00:00
|
|
|
DRYRUN_RECONFIG="$reconf_settings" LANG=C.UTF-8 timeout --foreground 60 \
|
|
|
|
python3 -m system_setup.cmd.tui < "$tty" \
|
2022-04-22 09:41:25 +00:00
|
|
|
--dry-run \
|
2022-04-19 12:27:11 +00:00
|
|
|
--answers "$answers" \
|
2022-04-22 09:41:25 +00:00
|
|
|
--output-base "$tmpdir"
|
2021-10-06 15:00:06 +00:00
|
|
|
validate "system_setup" "$validate_subtype"
|
2021-09-09 09:48:16 +00:00
|
|
|
fi
|
2021-05-04 00:38:19 +00:00
|
|
|
fi
|
2022-03-18 17:32:09 +00:00
|
|
|
clean
|
2018-06-14 23:43:06 +00:00
|
|
|
done
|
2020-04-29 02:50:39 +00:00
|
|
|
|
2022-04-19 12:27:11 +00:00
|
|
|
LANG=C.UTF-8 timeout --foreground 60 \
|
|
|
|
python3 -m subiquity.cmd.tui \
|
|
|
|
--dry-run \
|
2022-04-22 09:41:25 +00:00
|
|
|
--output-base "$tmpdir" \
|
2022-04-19 12:27:11 +00:00
|
|
|
--machine-config examples/existing-partitions.json \
|
|
|
|
--bootloader bios \
|
2022-04-22 09:41:25 +00:00
|
|
|
--autoinstall examples/autoinstall.yaml \
|
2022-04-19 12:27:11 +00:00
|
|
|
--kernel-cmdline autoinstall \
|
2022-04-22 09:41:25 +00:00
|
|
|
--source-catalog examples/install-sources.yaml
|
2020-04-29 02:50:39 +00:00
|
|
|
validate
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 scripts/check-yaml-fields.py $tmpdir/var/log/installer/subiquity-curtin-apt.conf \
|
2022-01-05 15:54:11 +00:00
|
|
|
apt.disable_components='[non-free, restricted]' \
|
|
|
|
apt.preferences[0].pin-priority=200 \
|
|
|
|
apt.preferences[0].pin='"origin *ubuntu.com*"' \
|
|
|
|
apt.preferences[1].package='"python-*"' \
|
|
|
|
apt.preferences[1].pin-priority=-1
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 scripts/check-yaml-fields.py $tmpdir/var/log/installer/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"'
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py $tmpdir/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"' \
|
2022-01-05 14:53:19 +00:00
|
|
|
ubuntu_advantage.token='"C1NWcZTHLteJXGVMM6YhvHDpGrhyy7"' \
|
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' \
|
2022-03-18 17:32:09 +00:00
|
|
|
$tmpdir/subiquity-server-debug.log
|
2020-10-12 01:23:50 +00:00
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/install_package2: SUCCESS: installing package2' \
|
2022-03-18 17:32:09 +00:00
|
|
|
$tmpdir/subiquity-server-debug.log
|
|
|
|
grep -q 'switching subiquity to edge' $tmpdir/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' \
|
2022-03-18 17:32:09 +00:00
|
|
|
$tmpdir/subiquity-server-debug.log
|
2020-04-19 09:44:09 +00:00
|
|
|
|
2020-04-29 02:50:39 +00:00
|
|
|
clean
|
2022-04-19 12:27:11 +00:00
|
|
|
LANG=C.UTF-8 timeout --foreground 60 \
|
|
|
|
python3 -m subiquity.cmd.tui \
|
|
|
|
--dry-run \
|
2022-04-22 09:41:25 +00:00
|
|
|
--output-base "$tmpdir" \
|
2022-04-19 12:27:11 +00:00
|
|
|
--machine-config examples/simple.json \
|
2022-04-22 09:41:25 +00:00
|
|
|
--autoinstall examples/autoinstall-user-data.yaml \
|
2022-04-19 12:27:11 +00:00
|
|
|
--kernel-cmdline autoinstall
|
2020-04-29 02:50:39 +00:00
|
|
|
validate
|
2022-03-18 17:32:09 +00:00
|
|
|
grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades: SUCCESS: downloading and installing security updates' $tmpdir/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
|
2022-06-07 16:41:27 +00:00
|
|
|
# Test TCP connectivity (system_setup only)
|
|
|
|
clean
|
|
|
|
port=50321
|
|
|
|
LANG=C.UTF-8 timeout --foreground 60 \
|
|
|
|
python3 -m system_setup.cmd.server --dry-run --tcp-port=$port &
|
|
|
|
subiquity_pid=$!
|
|
|
|
next_time=3
|
|
|
|
until [ $next_time -eq 0 ] || [ ! -z "$(ss -Hlt sport = $port)" ]; do
|
|
|
|
sleep $(( next_time-- ))
|
|
|
|
done
|
|
|
|
if [ $next_time -eq 0 ]; then
|
|
|
|
echo "Timeout reached before Subiquity TCP socket started listening"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-06-07 21:22:30 +00:00
|
|
|
loopback_failed=0
|
|
|
|
unallowed_failed=0
|
|
|
|
# Assert that only loopback interface is accepted.
|
|
|
|
interfaces=($(ip --json link show up | jq -r '.[]["ifname"] | select ( . != null )'))
|
|
|
|
for if in ${interfaces[@]}; do
|
2022-06-08 15:17:23 +00:00
|
|
|
for ipv in 4 6; do
|
|
|
|
curl_ec=0
|
|
|
|
timeout 10s \
|
|
|
|
curl -$ipv "http://localhost:$port/meta/status" --interface $if \
|
|
|
|
|| curl_ec=$?
|
|
|
|
# Loopback should exit 0 on IPv4
|
|
|
|
if [ $if = "lo" ]; then
|
|
|
|
if [ $curl_ec -ne 0 -a $ipv -eq 4 ]; then
|
|
|
|
loopback_failed=1
|
|
|
|
fi
|
|
|
|
# Everything else should not.
|
|
|
|
else
|
|
|
|
if [ $curl_ec -eq 0 ]; then
|
|
|
|
unallowed_failed=1
|
|
|
|
fi
|
2022-06-07 21:22:30 +00:00
|
|
|
fi
|
2022-06-08 15:17:23 +00:00
|
|
|
done
|
2022-06-07 21:22:30 +00:00
|
|
|
done
|
2022-06-07 16:41:27 +00:00
|
|
|
kill $subiquity_pid
|
2022-06-07 21:22:30 +00:00
|
|
|
if [ $loopback_failed -ne 0 ]; then
|
|
|
|
echo "Loopback was expected to connect"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ $unallowed_failed -ne 0 ]; then
|
|
|
|
echo "Only the loopback interface should be allowed."
|
2022-06-07 16:41:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test system_setup autoinstall.
|
2021-10-15 08:29:35 +00:00
|
|
|
for mode in "" "-full" "-no-shutdown"; do
|
|
|
|
clean
|
2022-04-19 12:27:11 +00:00
|
|
|
LANG=C.UTF-8 timeout --foreground 60 \
|
|
|
|
python3 -m system_setup.cmd.tui \
|
2022-04-22 09:41:25 +00:00
|
|
|
--dry-run \
|
2022-04-19 12:27:11 +00:00
|
|
|
--output-base "$tmpdir" \
|
2022-04-22 09:41:25 +00:00
|
|
|
--autoinstall "examples/autoinstall-system-setup${mode}.yaml"
|
2021-10-15 08:29:35 +00:00
|
|
|
validate "system_setup" "autoinstall${mode}"
|
|
|
|
done
|
2021-10-08 12:21:16 +00:00
|
|
|
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 -m system_setup.cmd.schema > $tmpdir/test-schema.json
|
|
|
|
diff -u "autoinstall-system-setup-schema.json" $tmpdir/test-schema.json
|
2021-09-09 09:48:16 +00:00
|
|
|
fi
|
2021-09-08 15:54:34 +00:00
|
|
|
|
2022-03-18 17:32:09 +00:00
|
|
|
python3 -m subiquity.cmd.schema > $tmpdir/test-schema.json
|
|
|
|
diff -u "autoinstall-schema.json" $tmpdir/test-schema.json
|
2021-09-08 15:54:34 +00:00
|
|
|
|
2022-03-18 17:32:09 +00:00
|
|
|
clean
|