Skip to content

Commit afc7b0d

Browse files
committed
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 <kolyshkin@gmail.com> Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 1ee33f8 commit afc7b0d

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

mounter_linux_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"os"
99
"strings"
1010
"testing"
11-
12-
selinux "github.com/opencontainers/selinux/go-selinux"
1311
)
1412

1513
func TestMount(t *testing.T) {
@@ -103,11 +101,7 @@ func TestMount(t *testing.T) {
103101
t.Fatal(err)
104102
}
105103
defer ensureUnmount(t, target)
106-
expectedVFS := tc.expectedVFS
107-
if selinux.GetEnabled() && expectedVFS != "" {
108-
expectedVFS = expectedVFS + ",seclabel"
109-
}
110-
validateMount(t, target, tc.expectedOpts, tc.expectedOptional, expectedVFS)
104+
validateMount(t, target, tc.expectedOpts, tc.expectedOptional, tc.expectedVFS)
111105
})
112106
}
113107
}
@@ -177,42 +171,42 @@ func validateMount(t *testing.T, mnt string, opts, optional, vfs string) {
177171
for _, opt := range strings.Split(mi.Opts, ",") {
178172
opt = clean(opt)
179173
if !has(wantedOpts, opt) && !has(pOpts, opt) {
180-
t.Errorf("unexpected mount option %q expected %q", opt, opts)
174+
t.Errorf("unexpected mount option %q, expected %q", opt, opts)
181175
}
182176
delete(wantedOpts, opt)
183177
}
184178
}
185179
for opt := range wantedOpts {
186-
t.Errorf("missing mount option %q found %q", opt, mi.Opts)
180+
t.Errorf("missing mount option %q, found %q", opt, mi.Opts)
187181
}
188182

189183
// Validate Optional
190184
if mi.Optional != "" {
191185
for _, field := range strings.Split(mi.Optional, ",") {
192186
field = clean(field)
193187
if !has(wantedOptional, field) && !has(pOptional, field) {
194-
t.Errorf("unexpected optional failed %q expected %q", field, optional)
188+
t.Errorf("unexpected optional field %q, expected %q", field, optional)
195189
}
196190
delete(wantedOptional, field)
197191
}
198192
}
199193
for field := range wantedOptional {
200-
t.Errorf("missing optional field %q found %q", field, mi.Optional)
194+
t.Errorf("missing optional field %q, found %q", field, mi.Optional)
201195
}
202196

203197
// Validate VFS if set
204198
if vfs != "" {
205199
if mi.VfsOpts != "" {
206200
for _, opt := range strings.Split(mi.VfsOpts, ",") {
207201
opt = clean(opt)
208-
if !has(wantedVFS, opt) {
209-
t.Errorf("unexpected mount option %q expected %q", opt, vfs)
202+
if !has(wantedVFS, opt) && opt != "seclabel" { // can be added by selinux
203+
t.Errorf("unexpected vfs option %q, expected %q", opt, vfs)
210204
}
211205
delete(wantedVFS, opt)
212206
}
213207
}
214208
for opt := range wantedVFS {
215-
t.Errorf("missing mount option %q found %q", opt, mi.VfsOpts)
209+
t.Errorf("missing vfs option %q, found %q", opt, mi.VfsOpts)
216210
}
217211
}
218212

0 commit comments

Comments
 (0)