Skip to content

Commit fab2dcf

Browse files
committed
Improve systemd packaging smoke tests and stabilize lock contention tests
1 parent 76dcaa1 commit fab2dcf

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

docs/STATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
binary starts, boots a transient systemd instance with a drop-in override to
8282
confirm the packaged unit launches successfully, and confirms assets land at
8383
the expected paths while gracefully skipping when no container runtime is
84-
available.
84+
available. The harness now shares the host cgroup namespace so systemd boots
85+
reliably on modern cgroup v2 hosts.
8586
- A top-level `Makefile` now standardises local builds, cross-compilation for
8687
`amd64`/`arm64`, and wraps `nfpm` so developers can reproducibly stage
8788
binaries in `dist/` and generate `.deb`/`.rpm` packages without ad-hoc

packaging/smoke_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ func TestPackagesInstallInContainers(t *testing.T) {
2727

2828
packages := buildSmokeTestPackages(t)
2929

30+
cgroupMount := testutil.ContainerMount{Source: "/sys/fs/cgroup", Target: "/sys/fs/cgroup"}
31+
if _, err := os.Stat(cgroupMount.Source); err != nil {
32+
t.Skipf("skipping container smoke tests: cgroup filesystem not accessible: %v", err)
33+
}
34+
35+
systemdExtraArgs := []string{"--tmpfs", "/run", "--tmpfs", "/run/lock"}
36+
switch runtime.Name() {
37+
case "docker", "podman":
38+
systemdExtraArgs = append([]string{"--cgroupns=host"}, systemdExtraArgs...)
39+
}
40+
3041
type testCase struct {
3142
name string
3243
image string
@@ -36,6 +47,7 @@ func TestPackagesInstallInContainers(t *testing.T) {
3647
timeout time.Duration
3748
privileged bool
3849
extraArgs []string
50+
mounts []testutil.ContainerMount
3951
}
4052

4153
cases := []testCase{
@@ -91,7 +103,8 @@ wait "$sd_pid" || true
91103
`,
92104
timeout: 4 * time.Minute,
93105
privileged: true,
94-
extraArgs: []string{"--tmpfs", "/run", "--tmpfs", "/run/lock", "-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro"},
106+
extraArgs: append([]string(nil), systemdExtraArgs...),
107+
mounts: []testutil.ContainerMount{cgroupMount},
95108
},
96109
{
97110
name: "ubuntu-22.04",
@@ -145,7 +158,8 @@ wait "$sd_pid" || true
145158
`,
146159
timeout: 4 * time.Minute,
147160
privileged: true,
148-
extraArgs: []string{"--tmpfs", "/run", "--tmpfs", "/run/lock", "-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro"},
161+
extraArgs: append([]string(nil), systemdExtraArgs...),
162+
mounts: []testutil.ContainerMount{cgroupMount},
149163
},
150164
{
151165
name: "rockylinux-9",
@@ -197,7 +211,8 @@ wait "$sd_pid" || true
197211
`,
198212
timeout: 5 * time.Minute,
199213
privileged: true,
200-
extraArgs: []string{"--tmpfs", "/run", "--tmpfs", "/run/lock", "-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro"},
214+
extraArgs: append([]string(nil), systemdExtraArgs...),
215+
mounts: []testutil.ContainerMount{cgroupMount},
201216
},
202217
}
203218

@@ -208,10 +223,11 @@ wait "$sd_pid" || true
208223
defer cancel()
209224

210225
mount := testutil.ContainerMount{Source: packages[tc.format], Target: tc.mountPath, ReadOnly: true}
226+
mounts := append([]testutil.ContainerMount{mount}, tc.mounts...)
211227
output, err := runtime.Run(ctx, testutil.ContainerRunOptions{
212228
Image: tc.image,
213229
Cmd: []string{"bash", "-lc", tc.script},
214-
Mounts: []testutil.ContainerMount{mount},
230+
Mounts: mounts,
215231
Privileged: tc.privileged,
216232
ExtraArgs: tc.extraArgs,
217233
})

pkg/orchestrator/runner_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ func TestRunnerEtcdLockPreventsConcurrentReadyNodes(t *testing.T) {
997997
lockKey := "/cluster/reboot"
998998
nodeNames := []string{"node-a", "node-b"}
999999
executor := newTrackingExecutor(len(nodeNames))
1000+
const lockHoldBeforeAllow = 150 * time.Millisecond
10001001

10011002
type nodeHarness struct {
10021003
name string
@@ -1102,6 +1103,8 @@ func TestRunnerEtcdLockPreventsConcurrentReadyNodes(t *testing.T) {
11021103
if err != nil {
11031104
t.Fatalf("waiting for first reboot command: %v", err)
11041105
}
1106+
// Hold the lock briefly so the waiting node attempts acquisition and records contention.
1107+
time.Sleep(lockHoldBeforeAllow)
11051108
executor.Allow(first)
11061109
if completed, err := executor.WaitForCompletion(5 * time.Second); err != nil {
11071110
t.Fatalf("waiting for %s completion: %v", first, err)
@@ -1116,6 +1119,7 @@ func TestRunnerEtcdLockPreventsConcurrentReadyNodes(t *testing.T) {
11161119
if second == first {
11171120
t.Fatalf("expected distinct nodes to execute sequentially, both were %s", second)
11181121
}
1122+
time.Sleep(lockHoldBeforeAllow)
11191123
executor.Allow(second)
11201124
if completed, err := executor.WaitForCompletion(5 * time.Second); err != nil {
11211125
t.Fatalf("waiting for %s completion: %v", second, err)
@@ -1181,6 +1185,7 @@ func TestRunnerEtcdLockSerializesThreeNodes(t *testing.T) {
11811185

11821186
nodeNames := []string{"node-a", "node-b", "node-c"}
11831187
executor := newTrackingExecutor(len(nodeNames))
1188+
const lockHoldBeforeAllow = 150 * time.Millisecond
11841189

11851190
type nodeHarness struct {
11861191
name string
@@ -1295,6 +1300,12 @@ func TestRunnerEtcdLockSerializesThreeNodes(t *testing.T) {
12951300
seen[node] = struct{}{}
12961301
order = append(order, node)
12971302

1303+
if len(order) < len(harnesses) {
1304+
// Hold the lock briefly so peers attempt acquisition and record contention
1305+
// before the current node completes its simulated reboot.
1306+
time.Sleep(lockHoldBeforeAllow)
1307+
}
1308+
12981309
executor.Allow(node)
12991310
if completed, err := executor.WaitForCompletion(5 * time.Second); err != nil {
13001311
t.Fatalf("waiting for %s completion: %v", node, err)

0 commit comments

Comments
 (0)