1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
summary: Ensure network retry works correctly
details: |
Snapd has certain capability to retry failed network operations, as network
in never perfectly reliable. The test creates an environment where the DNS
system is broken, attempts to install a snap from the store, fixes the DNS
environment and ensures that the snap is installed correctly.
environment:
# on core systems, the test was seen to misbehave when memory limit is set
SNAPD_NO_MEMORY_LIMIT: 1
prepare: |
echo "Break DNS"
if os.query is-core; then
resolvConf=$(realpath /etc/resolv.conf)
mv "${resolvConf}" "${resolvConf}.save"
echo "${resolvConf}" > resolvConf.txt
else
mv /etc/resolv.conf /etc/resolv.conf.save
fi
systemctl stop snapd.service
if systemctl is-active systemd-resolved; then
systemctl stop systemd-resolved
touch resolved.active
fi
restore: |
echo "Unbreak DNS"
if os.query is-core; then
resolvConf=$(cat resolvConf.txt)
mv "${resolvConf}.save" "${resolvConf}"
else
mv /etc/resolv.conf.save /etc/resolv.conf
fi
if [ -e resolved.active ]; then
systemctl start systemd-resolved
fi
systemctl stop snapd.service
execute: |
if [ -n "${http_proxy:-}" ] || [ -n "${https_proxy:-}" ] ||
[ -n "${HTTPS_PROXY:-}" ] || [ -n "${HTTPS_PROXY:-}" ]; then
# all queries will go through the proxy so breaking DNS will not work
echo "SKIP: cannot run when there is a http proxy set"
exit 0
fi
echo "Try to install a snap with broken DNS"
if snap install test-snapd-sh; then
echo "Installing test-snapd-sh with broken DNS should not work"
echo "Test broken"
exit 1
fi
echo "Ensure we tried to retry this operation"
"$TESTSTOOLS"/journal-state match-log 'Retrying because of temporary net error'
|