Commit Graph

123 Commits

Author SHA1 Message Date
Félix Baylac-Jacqué 15d1e0badf
wip 2021-01-10 22:45:49 +01:00
Yu Watanabe 84a1ff9457 tree-wide: fix typo 2020-12-16 18:30:15 +01:00
Yu Watanabe 8d80f27530 sd-device: make TAGS= property prefixed and suffixed with ":"
The commit 6f3ac0d517 drops the prefix and
suffix in TAGS= property. But there exists several rules that have like
`TAGS=="*:tag:*"`. So, the property must be always prefixed and suffixed
with ":".

Fixes #17930.
2020-12-14 14:04:53 +09:00
Yu Watanabe 6f3ac0d517 sd-device: use set_strjoin()
This slightly changes TAGS= and CURRENT_TAGS= properties:

Before
E: TAGS=:aaa:bbb:

After
E: TAGS=aaa:bbb
2020-12-08 12:28:58 +09:00
Anita Zhang 14d044da23 test: fix TEST-56-OOMD thresholds for linux 5.9 changes
Fixes #17533

The memory pressure values of the units in TEST-56-OOMD seemed to be a
lot lower after updating to linux 5.9. This is likely due to a fix from
e22c6ed90a.

To account for this, I lowered memory.high on testbloat.service to
throttle it even more. This was enough to generate the 50%+ value to trigger
oomd for the test, but as an extra precaution I also lowered the oomd
threshold to 1% so it's certain to try and kill testbloat.service.
2020-12-02 15:27:15 -08:00
Yu Watanabe da115b935a tree-wide: fix typos 2020-12-02 10:53:33 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Anita Zhang 311e3d4637 test: make TEST-56-OOMD service unit files static 2020-10-23 15:59:00 -07:00
Zbigniew Jędrzejewski-Szmek 15a6c4bf8b
Merge pull request #17417 from anitazha/more_systoomd
More systemd-oomd tweaks
2020-10-23 13:06:51 +02:00
Anita Zhang e4ff80404a test: add basic memory pressure extended test for oomd
Simple test to generate a lot of pressure in one unit and assert that
systemd-oomd kills the right one.
2020-10-22 17:04:22 -07:00
Zbigniew Jędrzejewski-Szmek 28c48f4d78 tests: replace the few remaining Type=simple with Type=exec
Except for the places where we explicitly want to test Type=simple,
we should use Type=exec.
2020-10-22 11:05:17 +02:00
Luca Boccassi 9198752738 test: account for non-x86-64 archs in TEST-50-DISSECT 2020-10-18 15:41:34 +01:00
Luca Boccassi 7580a64766 test: increase size of verity partition in TEST-50-DISSECT GPT image
On Ubuntu it seems there's some padding added
2020-10-18 11:44:18 +01:00
Lennart Poettering fc8bc57f6b
Merge pull request #16968 from yuwata/remove-old-device-on-move-event
core, udev: remove old device on move event
2020-10-14 17:49:37 +02:00
Lennart Poettering 36296ae2ad
Merge pull request #17152 from keszybz/make-mountapivfs-default
Make MountAPIVFS=yes default
2020-10-01 11:00:02 +02:00
Zbigniew Jędrzejewski-Szmek 9309a23b95 test: switch TEST-02-CRYPTSETUP and TEST-24-UNITTESTS
When tests are executed serially (the default), it seems better to launch
the fairly generic test that runs the unittests early in the sequence.
Right now the tests are ordered based on when they were written, but
this doesn't make much sense.
2020-09-24 17:02:20 +02:00
Zbigniew Jędrzejewski-Szmek d583cf45b6 TEST-50-DISSECT: drop now-unneeded MountAPIVFS=yes and full paths to executables
With the previous changes we can simplify the invocations in the test a bit.
2020-09-24 10:03:18 +02:00
Yu Watanabe efdaeb88f0 test: add test for device renaming issue #16967 2020-09-15 11:29:38 +09:00
Lennart Poettering 31abedbb03 test: add test for new "sticky" tags logic 2020-09-01 17:40:12 +02:00
Zbigniew Jędrzejewski-Szmek ae6c598791 tests/TEST-50: support the case when /etc/os-release is present
We have four legal cases:
1. /usr/lib/os-release exists and /etc/os-release is a symlink to it
2. both exist but /etc/os-release is not a symlink to /usr/lib/os-release
3. only /usr/lib/os-release exists
4. only /etc/os-release exists

The generic setup code in test-functions and create-busybox-image didn't handle
case 3.

The test-specific code in TEST-50 didn't handle 2 (because the general setup
code would only install /etc/os-release in the image and
grep -f /usr/lib/os-release would not work) and 4 (same reason) and would fail
in case 3 in generic setup.
2020-08-27 13:08:14 +02:00
Lennart Poettering 30dd9f7391 test: add test suite for new credentials logic 2020-08-25 19:46:36 +02:00
Zbigniew Jędrzejewski-Szmek 3fb01017ee
Merge pull request #16686 from bluca/mount_images_opts
core: add mount options support for MountImages
2020-08-21 10:11:08 +02:00
Luca Boccassi 427353f668 core: add mount options support for MountImages
Follow the same model established for RootImage and RootImageOptions,
and allow to either append a single list of options or tuples of
partition_number:options.
2020-08-20 14:45:40 +01:00
Luca Boccassi 9ece644435 core: change RootImageOptions to use names instead of partition numbers
Follow the designations from the Discoverable Partitions Specification
2020-08-20 13:58:02 +01:00
Lennart Poettering e96ceabac9 nspawn: move $NOTIFY_SOCKET into /run/host/ too
The sd_notify() socket that nspawn binds that the payload can use to
talk to it was previously stored in /run/systemd/nspawn/notify, which is
weird (as in the previous commit) since this makes /run/systemd
something that is cooperatively maintained by systemd inside the
container and nspawn outside of it.

We now have a better place where container managers can put the stuff
they want to pass to the payload: /run/host/, hence let's make use of
that.

This is not a compat breakage, since the sd_notify() protocol is based
on the $NOTIFY_SOCKET env var, where we place the new socket path.
2020-08-20 10:17:48 +02:00
Lennart Poettering 35afe47abe test: update tests to use new JSON output instead of human readable output 2020-08-12 22:39:43 +02:00
Luca Boccassi b3d133148e core: new feature MountImages
Follows the same pattern and features as RootImage, but allows an
arbitrary mount point under / to be specified by the user, and
multiple values - like BindPaths.

Original implementation by @topimiettinen at:
https://github.com/systemd/systemd/pull/14451
Reworked to use dissect's logic instead of bare libmount() calls
and other review comments.
Thanks Topi for the initial work to come up with and implement
this useful feature.
2020-08-05 21:34:55 +01:00
Elisei Roca 491b736a49 test: adapt TEST-13-NSPAWN-SMOKE for SUSE 2020-08-03 17:41:29 +02:00
Luca Boccassi 18d7370587 service: add new RootImageOptions feature
Allows to specify mount options for RootImage.
In case of multi-partition images, the partition number can be prefixed
followed by colon. Eg:

RootImageOptions=1:ro,dev 2:nosuid nodev

In absence of a partition number, 0 is assumed.
2020-07-29 17:17:32 +01:00
Lennart Poettering d64e32c245 nspawn: rework how /run/host/ is set up
Let's find the right os-release file on the host side, and only mount
the one that matters, i.e. /etc/os-release if it exists and
/usr/lib/os-release otherwise. Use the fixed path /run/host/os-release
for that.

Let's also mount /run/host as a bind mount on itself before we set up
/run/host, and let's mount it MS_RDONLY after we are done, so that it
remains immutable as a whole.
2020-07-23 18:47:38 +02:00
Luca Boccassi ac1f3ad05f verity: re-use already open devices if the hashes match
Opening a verity device is an expensive operation. The kernelspace operations
are mostly sequential with a global lock held regardless of which device
is being opened. In userspace jumps in and out of multiple libraries are
required. When signatures are used, there's the additional cryptographic
checks.

We know when two devices are identical: they have the same root hash.
If libcrypsetup returns EEXIST, double check that the hashes are really
the same, and that either both or none have a signature, and if everything
matches simply remount the already open device. The kernel will do
reference counting for us.

In order to quickly and reliably discover if a device is already open,
change the node naming scheme from '/dev/mapper/major:minor-verity' to
'/dev/mapper/$roothash-verity'.

Unfortunately libdevmapper is not 100% reliable, so in some case it
will say that the device already exists and it is active, but in
reality it is not usable. Fallback to an individually-activated
unique device name in those cases for robustness.
2020-07-21 23:42:03 +01:00
Luca Boccassi 08de6f945d test: run systemd-dissect and systemd-run with log level debug in TEST-50-DISSECT 2020-07-21 10:03:10 +09:00
Zbigniew Jędrzejewski-Szmek 4c0668bc14
Merge pull request #16478 from bluca/dissect_tests
Expand TEST-50-DISSECT to cover dm-verity features
2020-07-20 12:59:56 +02:00
Luca Boccassi 14f1c47a0c nspawn: mount os-release in two steps to make it read-only
The kernel interface requires setting up read-only bind-mounts in
two steps, the bind first and then a read-only remount.
Fix nspawn-mount, and cover this case in the integration test.

Fixes #16484
2020-07-16 09:59:59 +01:00
Luca Boccassi 2bc148add0 test: exercise RootImage, RootHash and RootVerity in TEST-50-DISSECT
Run with both the single-filesystem image and the GPT image
2020-07-15 19:40:42 +01:00
Luca Boccassi 0f5d24a8b9 test: pre-assemble minimal image for TEST-50-DISSECT at build time
Easier than in the limited VM environment
2020-07-15 19:40:42 +01:00
Luca Boccassi a5f1d665d7 test: exercise systemd-dissect with GPT and verity in TEST-50-DISSECT 2020-07-15 19:35:40 +01:00
Luca Boccassi 6939873412 test: exercise systemd-dissect --mount in TEST-50-DISSECT 2020-07-15 19:35:40 +01:00
Filipe Brandenburger 26698337f3 timer: Adjust calendar timers based on monotonic timer instead of realtime
When the RTC time at boot is off in the future by a few days, OnCalendar=
timers will be scheduled based on the time at boot. But if the time has been
adjusted since boot, the timers will end up scheduled way in the future, which
may cause them not to fire as shortly or often as expected.

Update the logic so that the time will be adjusted based on monotonic time.
We do that by calculating the adjusted manager startup realtime from the
monotonic time stored at that time, by comparing that time with the realtime
and monotonic time of the current time.

Added a test case to validate this works as expected. The test case creates a
QEMU virtual machine with the clock 3 days in the future. Then we adjust the
clock back 3 days, and test creating a timer with an OnCalendar= for every 15
minutes. We also check the manager startup timestamp from both `systemd-analyze
dump` and from D-Bus.

Test output without the corresponding code changes that fix the issue:

  Timer elapse outside of the expected 20 minute window.
    next_elapsed=1594686119
    now=1594426921
    time_delta=259198

With the code changes in, the test passes as expected.
2020-07-15 09:23:09 +02:00
Zbigniew Jędrzejewski-Szmek 55aacd502b
Merge pull request #15891 from bluca/host_os_release
Container Interface: expose the host's os-release metadata to nspawn and portable guests
2020-07-08 23:52:13 +02:00
Frantisek Sumsal 2e7090e94d test: bump the TEST-47 sleeps once again
Several recent failed runs show that the test is still racy in two ways:

1) Sometimes it takes a while before the PID file is created, leading
   to:

```
[   10.950540] testsuite-47.sh[308]: ++ cat /leakedtestpid
[   10.959712] testsuite-47.sh[308]: cat: /leakedtestpid: No such file or directory
[   10.959824] testsuite-47.sh[298]: + leaked_pid=
```

2) Again, sometimes we check the leaked PID before the unit is actually
   stopped, leading to a false negative:

```
[   18.099599] testsuite-47.sh[346]: ++ cat /leakedtestpid
[   18.116462] testsuite-47.sh[333]: + leaked_pid=342
[   18.117101] testsuite-47.sh[333]: + systemctl stop testsuite-47-repro
...
[   20.033907] testsuite-47.sh[333]: + ps -p 342
[   20.080050] testsuite-47.sh[351]:     PID TTY          TIME CMD
[   20.080050] testsuite-47.sh[351]:     342 ?        00:00:00 sleep
[   20.082040] testsuite-47.sh[333]: + exit 42
```
2020-07-08 22:09:55 +02:00
Luca Boccassi cda667722c core: refresh unit cache when building a transaction if UNIT_NOT_FOUND
When a command asks to load a unit directly and it is in state
UNIT_NOT_FOUND, and the cache is outdated, we refresh it and
attempto to load again.
Use the same logic when building up a transaction and a dependency in
UNIT_NOT_FOUND state is encountered.
Update the unit test to exercise this code path.
2020-07-07 10:09:24 +02:00
Frantisek Sumsal bf795c47bc test: use KILL instead of SIGKILL in TEST-52-HONORFIRSTSHUTDOWN
SIG-prefixed signals for `kill` are not POSIX compliant, so on Ubuntu CI
(which defaults to dash instead of bash) the TEST-52 contains following
error:

[ 9693.549638] sh[51]: + systemctl poweroff --no-block
[ 9693.553130] systemd-logind[26]: System is powering down.
[ 9693.608911] sh[54]: /bin/sh: 1: kill: Illegal option -S

This can be reproduced manually as well, either by running dash, or bash
in POSIX mode:

$ dash -c 'kill -SIGKILL 123'
dash: 1: kill: Illegal option -S

$ bash --posix -c 'kill -SIGKILL 123'
bash: line 0: kill: SIGKILL: invalid signal specification
2020-07-05 11:00:57 +01:00
Luca Boccassi 7233e91af0 core: store timestamps of unit load attempts
When the system is under heavy load, it can happen that the unit cache
is refreshed for an unrelated reason (in the test I simulate this by
attempting to start a non-existing unit). The new unit is found and
accounted for in the cache, but it's ignored since we are loading
something else.
When we actually look for it, by attempting to start it, the cache is
up to date so no refresh happens, and starting fails although we have
it loaded in the cache.

When the unit state is set to UNIT_NOT_FOUND, mark the timestamp in
u->fragment_loadtime. Then when attempting to load again we can check
both if the cache itself needs a refresh, OR if it was refreshed AFTER
the last failed attempt that resulted in the state being
UNIT_NOT_FOUND.

Update the test so that this issue reproduces more often.
2020-06-30 16:50:00 +02:00
Gaoyi 0090b551e6 Add quotes for -n
According to SC2070, -n doesn't work with unquoted arguments
https://github.com/koalaman/shellcheck/wiki/SC2070

Signed-off-by: Gaoyi <ymuemc@163.com>
2020-06-26 15:12:29 +02:00
Jay Burger a1ba8c5b71 feature to honor first shutdown request to completion
Create unit tests per established norm at position 52

check in_set first before getting unit
2020-06-24 09:42:01 +02:00
Luca Boccassi e1bb4b0d1d nspawn: implement container host os-release interface 2020-06-23 12:58:21 +01:00
Frantisek Sumsal e47add9edc test: make TEST-02-CRYPTSETUP a bit more robust
Prompted by systemd/systemd#16111.

* check if /var is a mountpoint - if not, something went wrong. In case
  of systemd/systemd#16111 the /failed file was created, because
  systemd-cryptsetup failed, but it ended up being empty, making the result
  check incorrectly pass
* forward journal messages to console - if we fail to mount /var,
  journald won't flush logs to the persistent storage and we end up
  empty handed and with no clue what went wrong

For example, without systemd/systemd#16111 and with this patch:
...
[FAILED] Failed to start systemd-cryptsetup@varcrypt.service.
See 'systemctl status systemd-cryptsetup@varcrypt.service' for details.
[DEPEND] Dependency failed for cryptsetup.target.
...
[    3.882451] systemd-cryptsetup[581]: Key file /etc/varkey is world-readable. This is not a good idea!
[    3.883946] systemd-cryptsetup[581]: WARNING: Locking directory /run/cryptsetup is missing!
[    3.884846] systemd-cryptsetup[581]: Failed to load Bitlocker superblock on device /dev/disk/by-uuid/180ba5ef-873b-4018-9968-47c23431f71a: Invalid argument
...
[    4.099451] sh[606]: + mountpoint /var
[    4.100025] sh[603]: + systemctl poweroff --no-block
[    4.101636] systemd[1]: Finished systemd-user-sessions.service.
[    4.102598] sh[608]: /var is not a mountpoint
[FAILED] Failed to start testsuite-02.service.
2020-06-10 17:42:25 +02:00
Anita Zhang bb9244781c core: don't consider SERVICE_SKIP_CONDITION for abnormal or failure restarts
Fixes: #16115
2020-06-10 17:12:55 +02:00
Lennart Poettering 4f4f37b20d
Merge pull request #16046 from bluca/dissect_squashfs_verity
dissect: single-filesystem verity images with external hashdevice
2020-06-09 19:52:21 +02:00