tests/staged-deploy.sh: Hack around cosa systemd unit check
authorColin Walters <walters@verbum.org>
Thu, 23 Jun 2022 21:23:45 +0000 (17:23 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Fri, 24 Jun 2022 14:18:53 +0000 (10:18 -0400)
https://github.com/coreos/coreos-assembler/pull/2921 broke this
test which is intentionally causing a systemd unit to fail.

As they say, necessity is the mother of invention.  They don't
say though that need always causes particularly *beautiful* things
to be invented...

tests/kolainst/destructive/staged-deploy.sh

index 7e1991bb58ad313dfeac21ed8b4a03c2a997d9e7..af31078a6d61a788f5eb1e35da41cf36ba96cbc2 100755 (executable)
@@ -150,13 +150,27 @@ EOF
     # Now finally, try breaking staged updates and verify that ostree-boot-complete fails on the next boot
     unshare -m /bin/sh -c 'mount -o remount,rw /boot; chattr +i /boot'
     rpm-ostree kargs --append=foo=bar
+
+    # Hack around https://github.com/coreos/coreos-assembler/pull/2921#issuecomment-1156592723
+    # where coreos-assembler/kola check systemd unit status right after ssh.
+    cat >/etc/systemd/system/hackaround-cosa-systemd-unit-checks.service << 'EOF'
+[Unit]
+Before=systemd-user-sessions.service
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c '(systemctl status ostree-boot-complete.service || true) | tee /run/ostree-boot-complete-status.txt'
+ExecStart=/bin/systemctl reset-failed ostree-boot-complete.service
+
+[Install]
+WantedBy=multi-user.target
+EOF
+    systemctl enable hackaround-cosa-systemd-unit-checks.service
+
     /tmp/autopkgtest-reboot "3"
     ;;
   "3") 
-    (systemctl status ostree-boot-complete.service || true) | tee out.txt
-    assert_file_has_content out.txt 'error: ostree-finalize-staged.service failed on previous boot.*Operation not permitted'
-    systemctl show -p Result ostree-boot-complete.service > out.txt
-    assert_file_has_content out.txt='Result=exit-code'
+    assert_file_has_content /run/ostree-boot-complete-status.txt 'error: ostree-finalize-staged.service failed on previous boot.*Operation not permitted'
     echo "ok boot-complete.service"
     ;;
   *) fatal "Unexpected AUTOPKGTEST_REBOOT_MARK=${AUTOPKGTEST_REBOOT_MARK}" ;;