From d78e885326213e8ef89919c3cc6d16e712e852a8 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 30 Mar 2018 12:32:10 -0700 Subject: [PATCH] pkg/mount/TestMount: fix wrt selinux Sometimes docker-master CI fails on rhel4+selinux configuration, like this: --- FAIL: TestMount (0.12s) --- FAIL: TestMount/none-remount,size=128k (0.01s) mounter_linux_test.go:209: unexpected mount option "seclabel" expected "rw,size=128k" --- FAIL: TestMount/none-remount,ro,size=128k (0.01s) mounter_linux_test.go:209: unexpected mount option "seclabel" expected "ro,size=128k" Earlier, commit 8bebd42df2 (PR #34965) fixed this failure, but not entirely (i.e. the test is now flaky). It looks like either selinux detection code is not always working (it won't work in d-in-d), or the kernel might or might not add 'seclabel' option). As the subject of this test case is definitely not selinux, it can just ignore the option added by it. While at it, fix error messages: - add missing commas; - fix a typo; - allow for clear distinction between mount and vfs (per-superblock) options. Signed-off-by: Kir Kolyshkin Signed-off-by: Kir Kolyshkin --- pkg/mount/mounter_linux_test.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pkg/mount/mounter_linux_test.go b/pkg/mount/mounter_linux_test.go index 15f10593ac..336f3d5cdc 100644 --- a/pkg/mount/mounter_linux_test.go +++ b/pkg/mount/mounter_linux_test.go @@ -8,8 +8,6 @@ import ( "os" "strings" "testing" - - selinux "github.com/opencontainers/selinux/go-selinux" ) func TestMount(t *testing.T) { @@ -103,11 +101,7 @@ func TestMount(t *testing.T) { t.Fatal(err) } defer ensureUnmount(t, target) - expectedVFS := tc.expectedVFS - if selinux.GetEnabled() && expectedVFS != "" { - expectedVFS = expectedVFS + ",seclabel" - } - validateMount(t, target, tc.expectedOpts, tc.expectedOptional, expectedVFS) + validateMount(t, target, tc.expectedOpts, tc.expectedOptional, tc.expectedVFS) }) } } @@ -177,13 +171,13 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) { for _, opt := range strings.Split(mi.Opts, ",") { opt = clean(opt) if !has(wantedOpts, opt) && !has(pOpts, opt) { - t.Errorf("unexpected mount option %q expected %q", opt, opts) + t.Errorf("unexpected mount option %q, expected %q", opt, opts) } delete(wantedOpts, opt) } } for opt := range wantedOpts { - t.Errorf("missing mount option %q found %q", opt, mi.Opts) + t.Errorf("missing mount option %q, found %q", opt, mi.Opts) } // Validate Optional @@ -191,13 +185,13 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) { for _, field := range strings.Split(mi.Optional, ",") { field = clean(field) if !has(wantedOptional, field) && !has(pOptional, field) { - t.Errorf("unexpected optional failed %q expected %q", field, optional) + t.Errorf("unexpected optional field %q, expected %q", field, optional) } delete(wantedOptional, field) } } for field := range wantedOptional { - t.Errorf("missing optional field %q found %q", field, mi.Optional) + t.Errorf("missing optional field %q, found %q", field, mi.Optional) } // Validate VFS if set @@ -205,14 +199,14 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) { if mi.VfsOpts != "" { for _, opt := range strings.Split(mi.VfsOpts, ",") { opt = clean(opt) - if !has(wantedVFS, opt) { - t.Errorf("unexpected mount option %q expected %q", opt, vfs) + if !has(wantedVFS, opt) && opt != "seclabel" { // can be added by selinux + t.Errorf("unexpected vfs option %q, expected %q", opt, vfs) } delete(wantedVFS, opt) } } for opt := range wantedVFS { - t.Errorf("missing mount option %q found %q", opt, mi.VfsOpts) + t.Errorf("missing vfs option %q, found %q", opt, mi.VfsOpts) } }