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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
summary: Ensure "snap set core" works
details: |
Check that through the command `snap set core` the config
"service.rsyslog.disable" can be used to enable and disable the
systemd rsyslog service. Also verify that work the configs
system.power-key-action, ctrl-alt-del-action and
proxy.${proto} among others
systems: [ubuntu-core-*]
# TODO: use `snap set system` instead of `snap set core`
prepare: |
rc=0
systemctl status rsyslog.service || rc=$?
if [ $rc = 4 ]; then
# systemctl(1) exit code 4: no such unit
# start fake rsyslog service
printf '[Unit]\nDescription=test %s\n[Service]\nType=simple\nExecStart=%s\n' "${SPREAD_JOB:-unknown}" "/bin/sleep 2h" > /run/systemd/system/rsyslog.service
systemctl daemon-reload
systemctl start rsyslog
# create a flag to indicate the ryslog service is fake
touch rsyslog.fake
fi
# hostname is modified during the tests
hostnamectl status --static > hostname
restore: |
if [ -f rsyslog.fake ]; then
systemctl stop rsyslog
rm /run/systemd/system/rsyslog.service
systemctl daemon-reload
else
systemctl enable rsyslog.service
systemctl start rsyslog.service
fi
rm -f /etc/systemd/login.conf.d/00-snap-core.conf
# restore hostname
hostnamectl set-hostname "$(cat hostname)"
rm -f "$HOME"/.ssh/id_rsa*
printf "" > /home/ubuntu/.ssh/authorized_keys
execute: |
echo "Check that service disable works"
systemctl status rsyslog.service|MATCH "Active: active"
snap set core service.rsyslog.disable=true
systemctl status rsyslog.service|MATCH "Active: inactive"
systemctl status rsyslog.service|MATCH "Loaded: masked"
snap set core service.rsyslog.disable=false
echo "Check that powerkey handling works"
snap set core system.power-key-action=reboot
MATCH HandlePowerKey=reboot < /etc/systemd/logind.conf.d/00-snap-core.conf
echo "Ensure unsetting cleans the file again"
snap set core system.power-key-action=""
if test -f /etc/systemd/logind.conf.d/00-snap-core.conf; then
echo "unsetting system.power-key-action did not cleanup correctly"
exit 1
fi
echo "Check that ctrl-alt-del-action=none works"
snap set core system.ctrl-alt-del-action=none
systemctl show --property=LoadState ctrl-alt-del.target | MATCH "LoadState=masked"
echo "Check that ctrl-alt-del-action=reboot works"
snap set core system.ctrl-alt-del-action=reboot
systemctl show --property=UnitFileState ctrl-alt-del.target | MATCH "UnitFileState=disabled"
systemctl show --property=LoadState ctrl-alt-del.target | MATCH "LoadState=loaded"
echo "Check that pi config handline works"
if [ -e /boot/uboot/config.txt ]; then
cp /boot/uboot/config.txt config.txt.save
snap set core pi-config.hdmi-mode=1
MATCH ^hdmi_mode=1 < /boot/uboot/config.txt
snap set core pi-config.hdmi-mode=""
MATCH ^#hdmi_mode=1 < /boot/uboot/config.txt
echo "Ensure the config.txt are fully undo when an option is unset"
if ! diff -u /boot/uboot/config.txt config.txt.save; then
echo "error: unexpected diff in /boot/uboot/config.txt"
exit 1
fi
fi
echo "Check that the proxy config handling works"
for proto in http https ftp; do
snap set core proxy.${proto}=http://example.com:8021/
MATCH "^${proto}_proxy=http://example.com:8021" < /etc/environment
snap set core proxy.${proto}=""
if grep "^{proto}_proxy=" /etc/environment; then
echo "proxy setting was not properly cleaned up"
cat /etc/environment
exit 1
fi
done
echo "Check that the no_proxy config handling works"
snap set core proxy.no-proxy="example.com,bar.com"
MATCH "^no_proxy=example.com,bar.com" < /etc/environment
snap set core proxy.no-proxy=""
if grep "^no_proxy=" /etc/environment ; then
echo "proxy setting was not properly cleaned up"
cat /etc/environment
exit 1
fi
echo "Changing 'service.console-conf.disable' at runtime does not work"
console_conf_disabled="false"
if [ -e /var/lib/console-conf/complete ]; then
console_conf_disabled="true"
fi
if [ "$console_conf_disabled" = "true" ]; then
not snap set system service.console-conf.disable=false 2>stderr
MATCH "cannot toggle console-conf at runtime, but only initially via gadget defaults" < stderr
# and the console-conf complete file is unchanged
test -e /var/lib/console-conf/complete
# but setting to again (without changing) is fine
snap set system service.console-conf.disable=true
elif [ "$console_conf_disabled" = "false" ]; then
not snap set system service.console-conf.disable=true 2>stderr
MATCH "cannot toggle console-conf at runtime, but only initially via gadget defaults" < stderr
# and the console-conf complete file is unchanged
not test -e /var/lib/console-conf/complete
# but setting to again (without changing) is fine
snap set system service.console-conf.disable=false
else
echo "internal error: $console_conf_disabled var has unexpected setting"
fi
echo "Check that 'system.kernel.printk.console-loglevel' handling works"
snap set system system.kernel.printk.console-loglevel=7
test -e /etc/sysctl.d/99-snapd.conf
sysctl -n kernel.printk|MATCH "^7\s+"
snap unset system system.kernel.printk.console-loglevel
not test -e /etc/sysctl.d/99-snapd.conf
sysctl -n kernel.printk|MATCH "^4\s+"
echo "setting the timezone works"
tests.cleanup defer timedatectl set-timezone "$("${TESTSLIB}"/get-timezone.sh)"
snap set system system.timezone=Europe/Malta
test "$(readlink -f /etc/localtime)" = "/usr/share/zoneinfo/Europe/Malta"
echo "and timezone setting shows up in the document"
snap get system -d | MATCH "Europe/Malta"
echo "but the timezone is not stored in the config state"
python3 -c 'import json,sys; j=json.loads(sys.stdin.read()); print(j["data"]["config"]);' < /var/lib/snapd/state.json | NOMATCH Europe/Malta
echo "and setting it again in snapd also works"
snap set system system.timezone=America/Lima
test "$(readlink -f /etc/localtime)" = "/usr/share/zoneinfo/America/Lima"
echo "and setting the timezone outside of snapd is reflected by snap get"
timedatectl set-timezone "America/Denver"
snap get system system.timezone | MATCH "America/Denver"
snap get system -d | MATCH "America/Denver"
echo "setting the hostname works"
tests.cleanup defer hostnamectl set-hostname "$(hostname)"
snap set system system.hostname=foo
hostname | MATCH foo
snap set system system.hostname=F00
hostnamectl status | MATCH F00
echo "configuring ssh access"
ssh-keygen -t rsa -N "" -f "$HOME"/.ssh/id_rsa
mkdir -p /home/ubuntu/.ssh
chmod 700 /home/ubuntu/.ssh
cat "$HOME"/.ssh/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys
# If the .ssh directory didn't exist, then the .ssh
# directory is now owned by root. Change owner to ubuntu
chown -R ubuntu:ubuntu /home/ubuntu/.ssh
# For some reason this directory has the wrong user on UC18
chown ubuntu:ubuntu /home/ubuntu
echo "ssh is enabled and works by default"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@localhost pwd
echo "ssh can be disabled"
snap set system service.ssh.disable=true
not ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@localhost pwd
echo "ssh can be re-enabled"
# TODO "snap set system service.ssh.disable!" does not seem to remove
# the /etc/ssh/sshd_not_to_be_run file
snap set system service.ssh.disable=false
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@localhost pwd
|