2020-03-04 09:35:06 +00:00
#!/usr/bin/env bash
2021-10-17 18:13:06 +02:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-04-09 19:39:41 +02:00
set -eux
2019-07-07 17:30:15 +02:00
set -o pipefail
# Check if homectl is installed, and if it isn't bail out early instead of failing
if ! test -x /usr/bin/homectl ; then
2021-12-16 19:32:01 +01:00
echo "no homed" >/skipped
2019-07-07 17:30:15 +02:00
exit 0
fi
inspect( ) {
2021-04-08 10:34:53 +02:00
# As updating disk-size-related attributes can take some time on some
# filesystems, let's drop these fields before comparing the outputs to
# avoid unexpected fails. To see the full outputs of both homectl &
# userdbctl (for debugging purposes) drop the fields just before the
# comparison.
2022-05-04 08:24:06 +02:00
local USERNAME = " ${ 1 : ? } "
2021-04-09 19:49:32 +02:00
homectl inspect " $USERNAME " | tee /tmp/a
userdbctl user " $USERNAME " | tee /tmp/b
2021-04-08 10:34:53 +02:00
2021-11-18 17:19:03 +01:00
# diff uses the grep BREs for pattern matching
diff -I '^\s*Disk \(Size\|Free\|Floor\|Ceiling\):' /tmp/{ a,b}
2021-04-08 10:34:53 +02:00
rm /tmp/{ a,b}
2021-11-25 10:48:52 +01:00
homectl inspect --json= pretty " $USERNAME "
2019-07-07 17:30:15 +02:00
}
2021-12-22 15:43:05 +09:00
wait_for_state( ) {
2022-06-14 21:05:10 +09:00
for ( ( i = 0; i < 10; i++) ) ; do
2021-12-22 15:43:05 +09:00
homectl inspect " $1 " | grep -qF " State: $2 " && break
sleep .5
done
}
2019-07-07 17:30:15 +02:00
systemd-analyze log-level debug
2021-11-25 14:32:19 +01:00
systemctl service-log-level systemd-homed debug
2019-07-07 17:30:15 +02:00
2021-11-17 10:22:20 +01:00
# Create a tmpfs to use as backing store for the home dir. That way we can enforce a size limit nicely.
2021-11-25 10:48:52 +01:00
mkdir -p /home
mount -t tmpfs tmpfs /home -o size = 290M
2021-11-17 10:22:20 +01:00
2021-11-15 16:21:37 +01:00
# we enable --luks-discard= since we run our tests in a tight VM, hence don't
2021-11-17 10:22:20 +01:00
# needlessly pressure for storage. We also set the cheapest KDF, since we don't
# want to waste CI CPU cycles on it.
NEWPASSWORD = xEhErW0ndafV4s homectl create test-user \
2021-11-19 09:58:50 +01:00
--disk-size= min \
2021-11-17 10:22:20 +01:00
--luks-discard= yes \
2021-11-25 10:48:52 +01:00
--image-path= /home/test-user.home \
2021-11-17 10:22:20 +01:00
--luks-pbkdf-type= pbkdf2 \
--luks-pbkdf-time-cost= 1ms
2019-07-07 17:30:15 +02:00
inspect test-user
PASSWORD = xEhErW0ndafV4s homectl authenticate test-user
PASSWORD = xEhErW0ndafV4s homectl activate test-user
inspect test-user
PASSWORD = xEhErW0ndafV4s homectl update test-user --real-name= "Inline test"
inspect test-user
homectl deactivate test-user
inspect test-user
PASSWORD = xEhErW0ndafV4s NEWPASSWORD = yPN4N0fYNKUkOq homectl passwd test-user
inspect test-user
PASSWORD = yPN4N0fYNKUkOq homectl activate test-user
inspect test-user
SYSTEMD_LOG_LEVEL = debug PASSWORD = yPN4N0fYNKUkOq NEWPASSWORD = xEhErW0ndafV4s homectl passwd test-user
inspect test-user
homectl deactivate test-user
inspect test-user
PASSWORD = xEhErW0ndafV4s homectl activate test-user
inspect test-user
2021-11-25 10:58:50 +01:00
homectl deactivate test-user
2019-07-07 17:30:15 +02:00
inspect test-user
PASSWORD = xEhErW0ndafV4s homectl update test-user --real-name= "Offline test"
inspect test-user
PASSWORD = xEhErW0ndafV4s homectl activate test-user
inspect test-user
2021-11-25 10:58:50 +01:00
homectl deactivate test-user
2019-07-07 17:30:15 +02:00
inspect test-user
2021-11-16 10:51:35 +01:00
# Do some resize tests, but only if we run on real kernels, as quota inside of containers will fail
if ! systemd-detect-virt -cq ; then
# grow while inactive
PASSWORD = xEhErW0ndafV4s homectl resize test-user 300M
inspect test-user
# minimize while inactive
2021-10-29 14:34:24 +02:00
PASSWORD = xEhErW0ndafV4s homectl resize test-user min
2021-11-16 10:51:35 +01:00
inspect test-user
PASSWORD = xEhErW0ndafV4s homectl activate test-user
inspect test-user
# grow while active
2021-10-29 14:34:24 +02:00
PASSWORD = xEhErW0ndafV4s homectl resize test-user max
2021-11-16 10:51:35 +01:00
inspect test-user
# minimize while active
PASSWORD = xEhErW0ndafV4s homectl resize test-user 0
inspect test-user
# grow while active
PASSWORD = xEhErW0ndafV4s homectl resize test-user 300M
inspect test-user
# shrink to original size while active
PASSWORD = xEhErW0ndafV4s homectl resize test-user 256M
inspect test-user
2021-11-25 10:48:52 +01:00
# minimize again
PASSWORD = xEhErW0ndafV4s homectl resize test-user min
inspect test-user
# Increase space, so that we can reasonably rebalance free space between to home dirs
mount /home -o remount,size= 800M
# create second user
NEWPASSWORD = uuXoo8ei homectl create test-user2 \
--disk-size= min \
--luks-discard= yes \
--image-path= /home/test-user2.home \
--luks-pbkdf-type= pbkdf2 \
--luks-pbkdf-time-cost= 1ms
inspect test-user2
# activate second user
PASSWORD = uuXoo8ei homectl activate test-user2
inspect test-user2
# set second user's rebalance weight to 100
PASSWORD = uuXoo8ei homectl update test-user2 --rebalance-weight= 100
inspect test-user2
# set first user's rebalance weight to quarter of that of the second
PASSWORD = xEhErW0ndafV4s homectl update test-user --rebalance-weight= 25
inspect test-user
# synchronously rebalance
homectl rebalance
2021-11-16 10:51:35 +01:00
inspect test-user
2021-11-25 10:48:52 +01:00
inspect test-user2
2021-11-16 10:51:35 +01:00
fi
2021-04-08 10:34:28 +02:00
PASSWORD = xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz
PASSWORD = xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \
&& { echo 'unexpected success' ; exit 1; }
2019-07-07 17:30:15 +02:00
PASSWORD = xEhErW0ndafV4s homectl with test-user -- touch /home/test-user/xyz
PASSWORD = xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz
PASSWORD = xEhErW0ndafV4s homectl with test-user -- rm /home/test-user/xyz
2021-04-08 10:34:28 +02:00
PASSWORD = xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz
PASSWORD = xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz \
&& { echo 'unexpected success' ; exit 1; }
2019-07-07 17:30:15 +02:00
2021-12-22 15:43:05 +09:00
wait_for_state test-user inactive
2019-07-07 17:30:15 +02:00
homectl remove test-user
2021-12-22 15:43:05 +09:00
if ! systemd-detect-virt -cq ; then
wait_for_state test-user2 active
homectl deactivate test-user2
wait_for_state test-user2 inactive
homectl remove test-user2
fi
2019-07-07 17:30:15 +02:00
systemd-analyze log-level info
2021-04-08 00:09:55 +02:00
echo OK >/testok
2019-07-07 17:30:15 +02:00
exit 0