Skip to content

Commit 82410e1

Browse files
committed
kola/multipath: wait for systemd firstboot target
Although `mpath-var-lib-containers.service` is set to only run on first boot, it sometime runs twice when the system reboots too early. Sometimes, in low load CI environement, the reboot in this test happens before systemd's `first-boot-complete.target` is reached. This make `ConditionFirstBoot` to still be true at the next boot, causing the mpath service to fail, because it already ran during the actual first boot. A previous attempt[1] at fixing this improved the flake but this happened again and i noticed that systemd didn't reach this target before the reboot: `Reached target first-boot-complete.target - First Boot Complete` is only shown after the second boot in the logs. Likely fixes coreos/rhel-coreos-config#66 [1] abd0c18
1 parent ca8e932 commit 82410e1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

mantle/kola/tests/misc/multipath.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
package misc
1616

1717
import (
18+
"fmt"
1819
"strings"
20+
"time"
1921

2022
coreosarch "github.com/coreos/stream-metadata-go/arch"
2123

2224
"github.com/coreos/coreos-assembler/mantle/kola/cluster"
2325
"github.com/coreos/coreos-assembler/mantle/kola/register"
2426
"github.com/coreos/coreos-assembler/mantle/platform"
2527
"github.com/coreos/coreos-assembler/mantle/platform/conf"
28+
"github.com/coreos/coreos-assembler/mantle/util"
2629
)
2730

2831
var (
@@ -168,6 +171,8 @@ func verifyMultipath(c cluster.TestCluster, m platform.Machine, path string) {
168171
func runMultipathDay1(c cluster.TestCluster) {
169172
m := c.Machines()[0]
170173
verifyMultipathBoot(c, m)
174+
// wait until first-boot-complete.target is reached
175+
waitForCompleteFirstboot(c)
171176
if err := m.Reboot(); err != nil {
172177
c.Fatalf("Failed to reboot the machine: %v", err)
173178
}
@@ -188,8 +193,33 @@ func runMultipathDay2(c cluster.TestCluster) {
188193
func runMultipathPartition(c cluster.TestCluster) {
189194
m := c.Machines()[0]
190195
verifyMultipath(c, m, "/var/lib/containers")
196+
// wait until first-boot-complete.target is reached
197+
waitForCompleteFirstboot(c)
191198
if err := m.Reboot(); err != nil {
192199
c.Fatalf("Failed to reboot the machine: %v", err)
193200
}
194201
verifyMultipath(c, m, "/var/lib/containers")
195202
}
203+
204+
func waitForCompleteFirstboot(c cluster.TestCluster) {
205+
m := c.Machines()[0]
206+
err := util.WaitUntilReady(2*time.Minute, 10*time.Second, func() (bool, error) {
207+
208+
_, err := c.SSH(m, "sudo systemd-run --wait --quiet --property='After=first-boot-complete.target' echo 'firstboot complete'")
209+
if err != nil {
210+
return false, err
211+
}
212+
// get the actual target state to double check
213+
firstbootTargetState, err := c.SSH(m, "systemctl is-active first-boot-complete.target")
214+
215+
if err != nil {
216+
return false, err
217+
} else if string(firstbootTargetState) != "active" {
218+
return false, fmt.Errorf("first-boot-complete.target state: %s.", string(firstbootTargetState))
219+
}
220+
return true, nil
221+
})
222+
if err != nil {
223+
c.Fatalf("Timed out while waiting for first-boot-complete.target to be ready: %v", err)
224+
}
225+
}

0 commit comments

Comments
 (0)