Skip to content

Commit 59b9599

Browse files
authored
Merge pull request #3965 from apostasie/fix-alma
CI: fix alma targets
2 parents 67969b6 + d80c2cf commit 59b9599

File tree

3 files changed

+128
-61
lines changed

3 files changed

+128
-61
lines changed

.github/workflows/test.yml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ jobs:
429429
matrix:
430430
mode: ["rootful", "rootless"]
431431
runs-on: ubuntu-24.04
432+
env:
433+
MODE: ${{ matrix.mode }}
434+
# FIXME: this is only necessary to access the build cache. To remove with build cleanup.
435+
CONTAINERD_VERSION: v2.0.3
432436
steps:
433437
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
434438
with:
@@ -490,20 +494,44 @@ jobs:
490494
echo "DOCKER_HOST=${DOCKER_HOST}" >>$GITHUB_ENV
491495
docker info
492496
docker version
497+
- name: "Expose GitHub Runtime variables for gha"
498+
uses: crazy-max/ghaction-github-runtime@b3a9207c0e1ef41f4cf215303c976869d0c2c1c4 # v3.0.0
493499
- name: "Prepare integration tests"
494-
env:
495-
MODE: ${{ matrix.mode }}
496500
run: |
497501
set -eux
498-
TARGET=test-integration
499-
[ "$MODE" = "rootless" ] && TARGET=test-integration-rootless
500-
docker build -t test-integration --target "${TARGET}" .
501-
# losetup not working as expected on EL8?
502-
# > === FAIL: cmd/nerdctl/container TestRunDevice (0.44s)
503-
# > container_run_cgroup_linux_test.go:236: assertion failed: error is not nil: loopback setup failed ([losetup --find --show /tmp/containerd-test-loopback3931357228]):
504-
# > stdout="", stderr="losetup: /tmp/containerd-test-loopback3931357228: failed to set up loop device: No such file or directory\n": exit status 1
505-
# https://github.com/containerd/nerdctl/pull/3904#issuecomment-2670917820
502+
506503
sudo losetup -Dv
507504
sudo losetup -lv
505+
506+
TARGET=test-integration
507+
[ "$MODE" = "rootless" ] && TARGET=test-integration-rootless
508+
docker buildx create --name with-gha --use
509+
docker buildx build \
510+
--output=type=docker \
511+
--cache-from type=gha,scope=amd64-${CONTAINERD_VERSION} \
512+
-t test-integration --target "${TARGET}" \
513+
.
514+
508515
- name: "Run integration tests"
509-
run: docker run -t --rm --privileged test-integration
516+
# Presumably, something is broken with the way docker exposes /dev to the container, as it appears to only
517+
# randomly work. Mounting /dev does workaround the issue.
518+
# This might be due to the old kernel shipped with Alma (4.18), or something else between centos/docker.
519+
run: |
520+
set -eux
521+
[ "$MODE" = "rootless" ] && {
522+
echo "rootless"
523+
docker run -t -v /dev:/dev --rm --privileged test-integration /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky=false
524+
} || {
525+
echo "rootful"
526+
docker run -t -v /dev:/dev --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=false
527+
}
528+
- name: "Run integration tests (flaky)"
529+
run: |
530+
set -eux
531+
[ "$MODE" = "rootless" ] && {
532+
echo "rootless"
533+
docker run -t -v /dev:/dev --rm --privileged test-integration /test-integration-rootless.sh ./hack/test-integration.sh -test.only-flaky=true
534+
} || {
535+
echo "rootful"
536+
docker run -t -v /dev:/dev --rm --privileged test-integration ./hack/test-integration.sh -test.only-flaky=true
537+
}

cmd/nerdctl/container/container_run_cgroup_linux_test.go

Lines changed: 89 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ import (
2222
"fmt"
2323
"os"
2424
"path/filepath"
25-
"strings"
25+
"strconv"
2626
"testing"
2727

28-
"github.com/moby/sys/userns"
2928
"gotest.tools/v3/assert"
3029

3130
"github.com/containerd/cgroups/v3"
3231
containerd "github.com/containerd/containerd/v2/client"
3332
"github.com/containerd/continuity/testutil/loopback"
33+
"github.com/containerd/nerdctl/mod/tigron/expect"
3434
"github.com/containerd/nerdctl/mod/tigron/require"
35+
"github.com/containerd/nerdctl/mod/tigron/test"
3536

3637
"github.com/containerd/nerdctl/v2/pkg/cmd/container"
3738
"github.com/containerd/nerdctl/v2/pkg/idutil/containerwalker"
38-
"github.com/containerd/nerdctl/v2/pkg/infoutil"
3939
"github.com/containerd/nerdctl/v2/pkg/testutil"
4040
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
4141
)
@@ -224,53 +224,99 @@ func TestIssue3781(t *testing.T) {
224224
}
225225

226226
func TestRunDevice(t *testing.T) {
227-
if os.Geteuid() != 0 || userns.RunningInUserNS() {
228-
t.Skip("test requires the root in the initial user namespace")
229-
}
227+
testCase := nerdtest.Setup()
230228

231-
if unameR := infoutil.UnameR(); strings.Contains(unameR, ".el8") {
232-
t.Logf("Assuming to be running on EL8 (kernel release %q)", unameR)
233-
t.Skip("FIXME: loopback.New fails on EL8 (when the test is executed inside a container) https://github.com/containerd/nerdctl/pull/3904#issuecomment-2670917820")
234-
// > === FAIL: cmd/nerdctl/container TestRunDevice (0.44s)
235-
// > container_run_cgroup_linux_test.go:236: assertion failed: error is not nil: loopback setup failed ([losetup --find --show /tmp/containerd-test-loopback3931357228]):
236-
// > stdout="", stderr="losetup: /tmp/containerd-test-loopback3931357228: failed to set up loop device: No such file or directory\n": exit status 1
237-
}
229+
testCase.Require = nerdtest.Rootful
238230

239231
const n = 3
240232
lo := make([]*loopback.Loopback, n)
241-
loContent := make([]string, n)
242233

243-
for i := 0; i < n; i++ {
244-
var err error
245-
lo[i], err = loopback.New(4096)
246-
assert.NilError(t, err)
247-
t.Logf("lo[%d] = %+v", i, lo[i])
248-
defer lo[i].Close()
249-
loContent[i] = fmt.Sprintf("lo%d-content", i)
250-
assert.NilError(t, os.WriteFile(lo[i].Device, []byte(loContent[i]), 0700))
234+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
235+
236+
for i := 0; i < n; i++ {
237+
var err error
238+
lo[i], err = loopback.New(4096)
239+
assert.NilError(t, err)
240+
t.Logf("lo[%d] = %+v", i, lo[i])
241+
loContent := fmt.Sprintf("lo%d-content", i)
242+
assert.NilError(t, os.WriteFile(lo[i].Device, []byte(loContent), 0o700))
243+
data.Set("loContent"+strconv.Itoa(i), loContent)
244+
}
245+
246+
// lo0 is readable but not writable.
247+
// lo1 is readable and writable
248+
// lo2 is not accessible.
249+
helpers.Ensure("run",
250+
"-d",
251+
"--name", data.Identifier(),
252+
"--device", lo[0].Device+":r",
253+
"--device", lo[1].Device,
254+
testutil.AlpineImage, "sleep", nerdtest.Infinity)
255+
data.Set("id", data.Identifier())
256+
}
257+
258+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
259+
for i := 0; i < n; i++ {
260+
if lo[i] != nil {
261+
_ = lo[i].Close()
262+
}
263+
}
264+
helpers.Anyhow("rm", "-f", data.Identifier())
251265
}
252266

253-
base := testutil.NewBase(t)
254-
containerName := testutil.Identifier(t)
255-
defer base.Cmd("rm", "-f", containerName).AssertOK()
256-
// lo0 is readable but not writable.
257-
// lo1 is readable and writable
258-
// lo2 is not accessible.
259-
base.Cmd("run",
260-
"-d",
261-
"--name", containerName,
262-
"--device", lo[0].Device+":r",
263-
"--device", lo[1].Device,
264-
testutil.AlpineImage, "sleep", nerdtest.Infinity).Run()
265-
266-
base.Cmd("exec", containerName, "cat", lo[0].Device).AssertOutContains(loContent[0])
267-
base.Cmd("exec", containerName, "cat", lo[1].Device).AssertOutContains(loContent[1])
268-
base.Cmd("exec", containerName, "cat", lo[2].Device).AssertFail()
269-
base.Cmd("exec", containerName, "sh", "-ec", "echo -n \"overwritten-lo0-content\">"+lo[0].Device).AssertFail()
270-
base.Cmd("exec", containerName, "sh", "-ec", "echo -n \"overwritten-lo1-content\">"+lo[1].Device).AssertOK()
271-
lo1Read, err := os.ReadFile(lo[1].Device)
272-
assert.NilError(t, err)
273-
assert.Equal(t, string(bytes.Trim(lo1Read, "\x00")), "overwritten-lo1-content")
267+
testCase.SubTests = []*test.Case{
268+
{
269+
Description: "can read lo0",
270+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
271+
return helpers.Command("exec", data.Get("id"), "cat", lo[0].Device)
272+
},
273+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
274+
return &test.Expected{
275+
Output: expect.Contains(data.Get("locontent0")),
276+
}
277+
},
278+
},
279+
{
280+
Description: "cannot write lo0",
281+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
282+
return helpers.Command("exec", data.Get("id"), "sh", "-ec", "echo -n \"overwritten-lo1-content\">"+lo[0].Device)
283+
},
284+
Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil),
285+
},
286+
{
287+
Description: "cannot read lo2",
288+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
289+
return helpers.Command("exec", data.Get("id"), "cat", lo[2].Device)
290+
},
291+
Expected: test.Expects(expect.ExitCodeGenericFail, nil, nil),
292+
},
293+
{
294+
Description: "can read lo1",
295+
NoParallel: true,
296+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
297+
return helpers.Command("exec", data.Get("id"), "cat", lo[1].Device)
298+
},
299+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
300+
return &test.Expected{
301+
Output: expect.Contains(data.Get("locontent1")),
302+
}
303+
},
304+
},
305+
{
306+
Description: "can write lo1 and read back updated value",
307+
NoParallel: true,
308+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
309+
return helpers.Command("exec", data.Get("id"), "sh", "-ec", "echo -n \"overwritten-lo1-content\">"+lo[1].Device)
310+
},
311+
Expected: test.Expects(expect.ExitCodeSuccess, nil, func(stdout string, info string, t *testing.T) {
312+
lo1Read, err := os.ReadFile(lo[1].Device)
313+
assert.NilError(t, err)
314+
assert.Equal(t, string(bytes.Trim(lo1Read, "\x00")), "overwritten-lo1-content")
315+
}),
316+
},
317+
}
318+
319+
testCase.Run(t)
274320
}
275321

276322
func TestParseDevice(t *testing.T) {

cmd/nerdctl/container/container_stats_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ package container
1818

1919
import (
2020
"runtime"
21-
"strings"
2221
"testing"
2322

2423
"github.com/containerd/nerdctl/mod/tigron/expect"
2524
"github.com/containerd/nerdctl/mod/tigron/require"
2625
"github.com/containerd/nerdctl/mod/tigron/test"
2726

28-
"github.com/containerd/nerdctl/v2/pkg/infoutil"
2927
"github.com/containerd/nerdctl/v2/pkg/testutil"
3028
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3129
)
@@ -45,11 +43,6 @@ func TestStats(t *testing.T) {
4543
)
4644
}
4745

48-
if unameR := infoutil.UnameR(); strings.Contains(unameR, ".el8") {
49-
t.Logf("Assuming to be running on EL8 (kernel release %q)", unameR)
50-
t.Skip("FIXME: the test seems to hang on EL8: https://github.com/containerd/nerdctl/pull/3904#issuecomment-2693931822")
51-
}
52-
5346
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
5447
helpers.Anyhow("rm", "-f", data.Identifier("container"))
5548
helpers.Anyhow("rm", "-f", data.Identifier("memlimited"))

0 commit comments

Comments
 (0)