@@ -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 })
0 commit comments