]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: wait until `lvm-activate-$vgroup.service` finishes
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 5 Nov 2021 17:57:26 +0000 (18:57 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 5 Nov 2021 22:48:38 +0000 (22:48 +0000)
The new lvm autoactivation method runs `vgchange` via
`systemd-run --no-block`[0], which means that checking if the unit
is in the `active` state is not enough, since the main binary might
still be running. Let's fix this by waiting until the unit reaches
the `exited` sub state.

Follow-up to:
  * 29f8bef05eb9a4bb7f578b31409ca38ec1b1a069
  * e50d743f99fa66c9f55e534c4e109a2cf6323f04

[0] https://sourceware.org/git/?p=lvm2.git;a=blob;f=udev/69-dm-lvm.rules.in;h=39e5b98074010745f78a7a86a05929700c9cd690;hb=67722b312390cdab29c076c912e14bd739c5c0f6#l83

Example:
```
[   17.102002] systemd-udevd[282]: sdf: '/usr/bin/systemd-run -r --no-block --property DefaultDependencies=no --unit lvm-activate-iscsi_lvm2212 /usr/bin/lvm vgchange -aay --nohints iscsi_lvm2212'(err) 'Running as unit: lvm-activate-iscsi_>
[   17.102522] systemd-udevd[282]: sdf: Process '/usr/bin/systemd-run -r --no-block --property DefaultDependencies=no --unit lvm-activate-iscsi_lvm2212 /usr/bin/lvm vgchange -aay --nohints iscsi_lvm2212' succeeded.
[   17.102697] systemd-udevd[282]: sdf: Adding watch on '/dev/sdf'
[   17.104944] systemd[1]: lvm-activate-iscsi_lvm2212.service: Changed dead -> running
...
[   17.105434] systemd[1]: Started /usr/bin/lvm vgchange -aay --nohints iscsi_lvm2212.
[   17.105601] systemd[931]: lvm-activate-iscsi_lvm2212.service: Executing: /usr/bin/lvm vgchange -aay --nohints iscsi_lvm2212
...
[   17.420228] testsuite-64.sh[268]: + systemctl -q is-active lvm-activate-iscsi_lvm2212.service
[   17.420228] testsuite-64.sh[268]: + return 0
[   17.420228] testsuite-64.sh[268]: + test -e /dev/disk/by-path/ip-127.0.0.1:3260-iscsi-iqn.2021-09.com.example:iscsi.lvm.test-lun-4
[   17.420228] testsuite-64.sh[268]: + udevadm settle
[   17.420228] testsuite-64.sh[268]: + test -e /dev/iscsi_lvm2212/mypart1
...
[   17.451313] systemd[1]: testsuite-64.service: Main process exited, code=exited, status=1/FAILURE
[   17.451475] systemd[1]: testsuite-64.service: Failed with result 'exit-code'.
...
[   17.555759] systemd[1]: Starting End the test...
[   17.556972] sh[941]: + systemctl poweroff --no-block
...
[   17.688923] lvm[931]:   2 logical volume(s) in volume group "iscsi_lvm2212" now active
...
[   17.838484] systemd[1]: lvm-activate-iscsi_lvm2212.service: Child 931 belongs to lvm-activate-iscsi_lvm2212.service.
[   17.838718] systemd[1]: lvm-activate-iscsi_lvm2212.service: Main process exited, code=exited, status=0/SUCCESS (success)

```

test/units/testsuite-64.sh

index b3c05a2b687fd9959c0281dafafebeb0bdcd8ca0..d41e807ef568a175937f109b9c50071f06b89d22 100755 (executable)
@@ -85,10 +85,19 @@ helper_wait_for_vgroup() {
 helper_wait_for_lvm_activate() {
     local vgroup="${1:?}"
     local ntries="${2:-10}"
-    local i
+    local i lvm_activate_svc
 
+    lvm_activate_svc="lvm-activate-$vgroup.service"
     for ((i = 0; i < ntries; i++)); do
-        ! systemctl -q is-active "lvm-activate-$vgroup.service" || return 0
+        if systemctl -q is-active "$lvm_activate_svc"; then
+            # Since the service is started via `systemd-run --no-block`, we need
+            # to wait until it finishes, otherwise we might continue while
+            # `vgchange` is still running
+            if [[ "$(systemctl show -P SubState "$lvm_activate_svc")" == exited ]]; then
+                return 0
+            fi
+        fi
+
         sleep .5
     done