From 2c1a2d9af2955e266be32c5be275726d4e1408dd Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 16 Feb 2021 17:42:55 -0800 Subject: [PATCH 1/8] ci/gha: add go 1.16 Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c8196f0..77f7a5cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.14.x, 1.15.x] + go-version: [1.14.x, 1.15.x, 1.16.x] platform: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: From 5c50a3f8046daeaf133c96f809bfd40e2c8a6e76 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 16 Feb 2021 17:50:08 -0800 Subject: [PATCH 2/8] ci/gha: bump ubuntu to 20.04 Otherwise GHA complains: > Ubuntu-latest workflows will use Ubuntu-20.04 soon. For more details, > see https://github.com/actions/virtual-environments/issues/1816 Apparently, despite the wording, it is already using 20.04, but it is nice to silence the warning regardless. Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77f7a5cf..0f0e449c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: matrix: go-version: [1.14.x, 1.15.x, 1.16.x] - platform: [ubuntu-latest, windows-latest] + platform: [ubuntu-20.04, windows-latest] runs-on: ${{ matrix.platform }} steps: - name: Install Go From 7fa61227fff225fb772ba5ae298545048f80f785 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 23 Feb 2021 19:59:23 -0800 Subject: [PATCH 3/8] ci/gha: bump actions/setup-go to v2 Changes: https://github.com/actions/setup-go/tree/v2.1.3#v2 Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f0e449c..073dc088 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v2 with: go-version: ${{ matrix.go-version }} - name: Checkout code From c8bf7242b5ebbd72db0b0d9be75a5bed8e1e6eda Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 23 Feb 2021 20:14:03 -0800 Subject: [PATCH 4/8] ci/gha: move make test to after lint/cross The idea is not to run any tests if the linter fails. Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 073dc088..c166982e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,10 +14,10 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v2 - - name: Test - run: make test - name: Lint run: make lint - name: Cross build if: ${{ runner.os == 'Linux' }} run: make cross + - name: Test + run: make test From ce8f425e79a74602c4055fb1776f38043d56827b Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 16 Feb 2021 17:55:56 -0800 Subject: [PATCH 5/8] mountinfo/TestMountedBy*: add missing pre-checks Both tests need (1) root (2) openat2. Do skip if those are not available. Signed-off-by: Kir Kolyshkin --- mountinfo/mounted_linux_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mountinfo/mounted_linux_test.go b/mountinfo/mounted_linux_test.go index 96b39b5b..d9f9a16c 100644 --- a/mountinfo/mounted_linux_test.go +++ b/mountinfo/mounted_linux_test.go @@ -174,10 +174,20 @@ func cleanupMounts(t *testing.T, dir string, mounts []string) { } } -func TestMountedBy(t *testing.T) { +func requireOpenat2(t *testing.T) { + t.Helper() if os.Getuid() != 0 { t.Skip("requires root") } + fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY}) + if err != nil { + t.Skipf("openat2: %v (old kernel? need Linux 5.6+)", err) + } + unix.Close(fd) +} + +func TestMountedBy(t *testing.T) { + requireOpenat2(t) dir, mounts, err := prepareMounts(t) defer cleanupMounts(t, dir, mounts) @@ -224,11 +234,7 @@ func TestMountedBy(t *testing.T) { } func TestMountedByOpenat2VsMountinfo(t *testing.T) { - fd, err := unix.Openat2(unix.AT_FDCWD, ".", &unix.OpenHow{Flags: unix.O_RDONLY}) - if err != nil { - t.Skipf("openat2: %v (old kernel? need Linux 5.6+)", err) - } - unix.Close(fd) + requireOpenat2(t) mounts, err := GetMounts(nil) if err != nil { From 732a5af0e5fe4083b372d18ccdca84e1d61ba042 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 25 Feb 2021 10:45:34 -0800 Subject: [PATCH 6/8] mount: fix tests for kernel 5.9+ I am seeing the following failures on my machine (running): === RUN TestMount/none-remount,size=128k mounter_linux_test.go:203: unexpected vfs option "inode64", expected "rw,size=128k" === RUN TestMount/none-remount,ro,size=128k mounter_linux_test.go:203: unexpected vfs option "inode64", expected "ro,size=128k" --- FAIL: TestMount (0.06s) Looking into /proc/self/mountinfo, I see that all tmpfs mounts have this option. Looking into the kernel, it was added by commit ea3271f7196c6 ("tmpfs: support 64-bit inums per-sb", 2020-08-06), which made its way into v5.9-rc1. Ignore the option, as well as "inode32". Signed-off-by: Kir Kolyshkin --- mount/mounter_linux_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mount/mounter_linux_test.go b/mount/mounter_linux_test.go index 92f6a44c..323bc2eb 100644 --- a/mount/mounter_linux_test.go +++ b/mount/mounter_linux_test.go @@ -199,7 +199,9 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) { if mi.VFSOptions != "" { for _, opt := range strings.Split(mi.VFSOptions, ",") { opt = clean(opt) - if !has(wantedVFS, opt) && opt != "seclabel" { // can be added by selinux + if !has(wantedVFS, opt) && + opt != "seclabel" && // can be added by selinux + opt != "inode64" && opt != "inode32" { // can be added by kernel 5.9+ t.Errorf("unexpected vfs option %q, expected %q", opt, vfs) } delete(wantedVFS, opt) From ce49bfe0365f181fd06e85029cb8278e5dd48be2 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 16 Feb 2021 18:20:26 -0800 Subject: [PATCH 7/8] ci/gha: add fedora job Some recently added features require openat2 support to be tested. We used Travis for that, but it's not available now, so let's use a GHA VM. Code mostly copied from github.com/opencontainers/runc. Signed-off-by: Kir Kolyshkin --- ...rantfile.fedora32 => Vagrantfile.fedora33} | 2 +- .ci/install-vagrant.sh | 20 ------------------- .github/workflows/test.yml | 19 ++++++++++++++++++ .travis.yml | 15 -------------- 4 files changed, 20 insertions(+), 36 deletions(-) rename .ci/{Vagrantfile.fedora32 => Vagrantfile.fedora33} (94%) delete mode 100755 .ci/install-vagrant.sh delete mode 100644 .travis.yml diff --git a/.ci/Vagrantfile.fedora32 b/.ci/Vagrantfile.fedora33 similarity index 94% rename from .ci/Vagrantfile.fedora32 rename to .ci/Vagrantfile.fedora33 index 68325f3a..169122e5 100644 --- a/.ci/Vagrantfile.fedora32 +++ b/.ci/Vagrantfile.fedora33 @@ -3,7 +3,7 @@ Vagrant.configure("2") do |config| # Fedora box is used for testing cgroup v2 support - config.vm.box = "fedora/32-cloud-base" + config.vm.box = "fedora/33-cloud-base" config.vm.provider :virtualbox do |v| v.memory = 2048 v.cpus = 2 diff --git a/.ci/install-vagrant.sh b/.ci/install-vagrant.sh deleted file mode 100755 index f4aa05ae..00000000 --- a/.ci/install-vagrant.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -eux -o pipefail -VAGRANT_VERSION="2.2.10" - -# Based on code from https://github.com/opencontainers/runc -DEB="vagrant_${VAGRANT_VERSION}_$(uname -m).deb" -wget "https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/$DEB" -apt-get update -apt-get install -q -y \ - bridge-utils \ - dnsmasq-base \ - ebtables \ - libvirt-bin \ - libvirt-dev \ - qemu-kvm \ - qemu-utils \ - ruby-dev \ - ./"$DEB" -rm -f "$DEB" -vagrant plugin install vagrant-libvirt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c166982e..a7df845e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,3 +21,22 @@ jobs: run: make cross - name: Test run: make test + + # some features, like openat2, require a newer kernel + fedora: + # nested virtualization is only available on macOS hosts + runs-on: macos-10.15 + steps: + - uses: actions/checkout@v2 + - name: prepare vagrant + run: | + ln -sf .ci/Vagrantfile.fedora33 Vagrantfile + # Retry if it fails (download.fedoraproject.org returns 404 sometimes) + vagrant up || vagrant up + vagrant ssh-config >> ~/.ssh/config + + - name: system info + run: ssh default 'sh -exc "uname -a && df -T"' + + - name: tests + run: ssh default 'cd /vagrant && sudo -E PATH=$PATH make test' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bcf2819a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -dist: bionic -os: linux -language: minimal -cache: - directories: - - /home/travis/.vagrant.d/boxes -jobs: - include: - - name: "Fedora 32" - before_install: - - sudo .ci/install-vagrant.sh - - ln -sf .ci/Vagrantfile.fedora32 Vagrantfile - - sudo vagrant up && sudo mkdir -p /root/.ssh && sudo sh -c "vagrant ssh-config >> /root/.ssh/config" - script: - - sudo ssh default -t 'cd /vagrant && sudo make' From eb2a60af0392e6d9c5a48df12265c3d33383d911 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 16 Feb 2021 17:51:39 -0800 Subject: [PATCH 8/8] make test: run tests as root if possible Some tests (those that do mounts etc.) require root. Amend the Makefile to check if sudo -n (non-interactive) works, and if yes, add -exec sudo to "go test" arguments. This trick makes test compile as normal user but run as root, eliminating the need to preserve environment (-E) and path (PATH=$PATH) when using sudo, as well as avoiding potential ownership problems after running something like compiling test binaries under sudo. With this, tests are run as root in GHA. Signed-off-by: Kir Kolyshkin --- .github/workflows/test.yml | 2 +- Makefile | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a7df845e..2dc6daa9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,4 +39,4 @@ jobs: run: ssh default 'sh -exc "uname -a && df -T"' - name: tests - run: ssh default 'cd /vagrant && sudo -E PATH=$PATH make test' + run: ssh default 'cd /vagrant && make test' diff --git a/Makefile b/Makefile index 50c4089d..3342a7b4 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,16 @@ PACKAGES ?= mountinfo mount symlink BINDIR ?= _build/bin CROSS ?= linux/arm linux/arm64 linux/ppc64le linux/s390x \ freebsd/amd64 openbsd/amd64 darwin/amd64 darwin/arm64 windows/amd64 +SUDO ?= sudo -n .PHONY: all all: lint test cross .PHONY: test +test: RUN_VIA_SUDO = $(shell $(SUDO) true && echo -exec \"$(SUDO)\") test: for p in $(PACKAGES); do \ - (cd $$p && go test -v .); \ + (cd $$p && go test $(RUN_VIA_SUDO) -v .); \ done .PHONY: lint