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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
summary: Check that timezone interface works
details: |
This test makes sure that a snap using the timezone-control interface
can access timezone information and update it.
prepare: |
# Install a snap declaring a plug on timezone-control
if systemctl is-enabled systemd-timesyncd.service ; then
# Install the base core24 variant with timedatectl that supports systemd-timesyncd commands.
"$TESTSTOOLS"/snaps-state install-local-variant test-snapd-timedate-control-consumer-core24 \
test-snapd-timedate-control-consumer
else
# Install the default version.
"$TESTSTOOLS"/snaps-state install-local test-snapd-timedate-control-consumer
fi
restore: |
# Restore the initial timezone
if [ -f timezone.txt ]; then
timedatectl set-timezone "$(cat timezone.txt)"
fi
# This is skipped because after regenerate the link changes to
# localtime -> ../usr/share/zoneinfo/Etc/UTC but originally was
# localtime -> /usr/share/zoneinfo/Etc/UTC
"$TESTSTOOLS"/fs-state skip-monitor /etc/localtime
execute: |
echo "The interface is disconnected by default"
snap interfaces -i timezone-control | MATCH -- '^- +test-snapd-timedate-control-consumer:timezone-control'
echo "When the interface is connected"
snap connect test-snapd-timedate-control-consumer:timezone-control
# Read timezones information should be allowed (unless running with old
# systemd where timesyncd had no org.freedesktop.timedate1.ListTimezones
# method yet)
if not os.query is-ubuntu || os.query is-ubuntu-ge 20.04; then
timezone1=$(test-snapd-timedate-control-consumer.timedatectl-timezone list-timezones | sed -n 1p)
timezone2=$(test-snapd-timedate-control-consumer.timedatectl-timezone list-timezones | sed -n 2p)
else
timezone1=$(timedatectl list-timezones | sed -n 1p)
timezone2=$(timedatectl list-timezones | sed -n 2p)
fi
# Save the default timezone to be restored at the end
"${TESTSLIB}"/get-timezone.sh >timezone.txt
# Set the timezone1 as timezone and check the status
test-snapd-timedate-control-consumer.timedatectl-timezone set-timezone "$timezone1"
test "$(test-snapd-timedate-control-consumer.timedatectl-timezone status | grep -oP 'Time zone: \K(.*)(?= \()')" = "$timezone1"
# Set the timezone2 as timezone and check the status
test-snapd-timedate-control-consumer.timedatectl-timezone set-timezone "$timezone2"
test "$(test-snapd-timedate-control-consumer.timedatectl-timezone status | grep -oP 'Time zone: \K(.*)(?= \()')" = "$timezone2"
# reset the timezone to the original
test-snapd-timedate-control-consumer.timedatectl-timezone set-timezone "$(cat timezone.txt)"
test "$(test-snapd-timedate-control-consumer.timedatectl-timezone status | grep -oP 'Time zone: \K(.*)(?= \()')" = "$(cat timezone.txt)"
rm timezone.txt
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
fi
echo "When the plug is disconnected"
snap disconnect test-snapd-timedate-control-consumer:timezone-control
echo "The timedatectl status cannot be retrieved"
if test-snapd-timedate-control-consumer.timedatectl-timezone status 2> call.error; then
echo "Expected permission error calling timedatectl status with disconnected plug"
exit 1
fi
MATCH "Permission denied" < call.error
|