Skip to content

Commit 262c5e5

Browse files
author
Zhou Hao
authored
Merge pull request #687 from giuseppe/fix
validation-tests: fix several tests
2 parents bcea291 + 0d022f7 commit 262c5e5

File tree

11 files changed

+56
-11
lines changed

11 files changed

+56
-11
lines changed

Diff for: Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ validation-executables: $(VALIDATION_TESTS)
5858
$(VALIDATION_TESTS): %.t: %.go
5959
go build -tags "$(BUILDTAGS)" ${TESTFLAGS} -o $@ $<
6060

61-
.PHONY: test .gofmt .govet .golint
61+
print-validation-tests:
62+
@echo $(VALIDATION_TESTS)
63+
64+
.PHONY: test .gofmt .govet .golint print-validation-tests
6265

6366
PACKAGES = $(shell go list ./... | grep -v vendor)
6467
test: .gofmt .govet .golint .gotest

Diff for: cmd/runtimetest/main.go

+10
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,16 @@ func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error {
12161216
}
12171217

12181218
for _, mount := range spec.Mounts {
1219+
isBind := false
1220+
for _, opt := range mount.Options {
1221+
if opt == "bind" || opt == "rbind" {
1222+
isBind = true
1223+
break
1224+
}
1225+
}
1226+
if !isBind {
1227+
continue
1228+
}
12191229
fileLabel, err := label.FileLabel(mount.Destination)
12201230
if err != nil {
12211231
return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination)

Diff for: validation/delete/delete.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
func main() {
1717
t := tap.New()
1818
t.Header(0)
19+
defer t.AutoPlan()
20+
1921
bundleDir, err := util.PrepareBundle()
2022
if err != nil {
2123
util.Fatal(err)
@@ -72,7 +74,7 @@ func main() {
7274

7375
if c.effectCheck {
7476
// waiting for the error of State, just in case the delete operation takes time
75-
util.WaitingForStatus(testRuntime, util.LifecycleActionNone, time.Second*10, time.Second*1)
77+
util.WaitingForStatus(testRuntime, util.LifecycleActionNone, time.Second*3, time.Second/2)
7678
_, err = testRuntime.State()
7779
// err == nil means the 'delete' operation does NOT take effect
7880
util.SpecErrorOK(t, err == nil, specerror.NewError(specerror.DeleteNonStopHaveNoEffect, fmt.Errorf("attempting to `delete` a container that is not `stopped` MUST have no effect on the container"), rspecs.Version), err)
@@ -89,6 +91,4 @@ func main() {
8991
}
9092
}
9193
}
92-
93-
t.AutoPlan()
9494
}

Diff for: validation/kill/kill.go

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ func main() {
7070
// KILL MUST be supported and KILL cannot be trapped
7171
err = r.Kill("KILL")
7272
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
73+
if err != nil {
74+
//Be sure to not leave the container around
75+
r.Delete()
76+
}
7377
return err
7478
},
7579
}

Diff for: validation/linux_seccomp/linux_seccomp.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package main
22

33
import (
4+
tap "github.com/mndrix/tap-go"
45
"github.com/opencontainers/runtime-tools/generate/seccomp"
56
"github.com/opencontainers/runtime-tools/validation/util"
67
)
78

89
func main() {
10+
t := tap.New()
11+
t.Header(0)
12+
defer t.AutoPlan()
913
g, err := util.GetDefaultGenerator()
1014
if err != nil {
1115
util.Fatal(err)
@@ -16,8 +20,10 @@ func main() {
1620
}
1721
g.SetDefaultSeccompAction("allow")
1822
g.SetSyscallAction(syscallArgs)
19-
err = util.RuntimeInsideValidate(g, nil, nil)
23+
err = util.RuntimeInsideValidate(g, t, nil)
24+
t.Ok(err == nil, "seccomp action is added correctly")
2025
if err != nil {
21-
util.Fatal(err)
26+
t.Fail(err.Error())
2227
}
28+
2329
}

Diff for: validation/misc_props/misc_props.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ func main() {
4545
util.Fatal(err)
4646
}
4747
basicConfig.SetProcessArgs([]string{"true"})
48-
annotationConfig := basicConfig
48+
annotationConfig, err := util.GetDefaultGenerator()
49+
if err != nil {
50+
util.Fatal(err)
51+
}
4952
annotationConfig.AddAnnotation(fmt.Sprintf("org.%s", containerID), "")
50-
invalidConfig := basicConfig
53+
invalidConfig, err := util.GetDefaultGenerator()
54+
if err != nil {
55+
util.Fatal(err)
56+
}
5157
invalidConfig.SetVersion("invalid")
5258

5359
cases := []struct {

Diff for: validation/pidfile/pidfile.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"path/filepath"
99
"strconv"
10+
"time"
1011

1112
tap "github.com/mndrix/tap-go"
1213
"github.com/opencontainers/runtime-tools/validation/util"
@@ -31,7 +32,7 @@ func main() {
3132
g.SetProcessArgs([]string{"true"})
3233
config := util.LifecycleConfig{
3334
Config: g,
34-
Actions: util.LifecycleActionCreate | util.LifecycleActionDelete,
35+
Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete,
3536
PreCreate: func(r *util.Runtime) error {
3637
r.SetID(uuid.NewV4().String())
3738
r.PidFile = tempPidFile
@@ -55,6 +56,13 @@ func main() {
5556
}
5657
return nil
5758
},
59+
PreDelete: func(r *util.Runtime) error {
60+
util.WaitingForStatus(*r, util.LifecycleStatusRunning, time.Second*10, time.Second*1)
61+
err = r.Kill("KILL")
62+
// wait before the container been deleted
63+
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
64+
return err
65+
},
5866
}
5967

6068
err = util.RuntimeLifecycleValidate(config)

Diff for: validation/process_capabilities_fail/process_capabilities_fail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func main() {
2020
if err != nil {
2121
util.Fatal(err)
2222
}
23-
g.AddProcessCapabilityBounding("CAP_TEST")
23+
g.Config.Process.Capabilities.Bounding = append(g.Config.Process.Capabilities.Bounding, "CAP_TEST")
2424
err = util.RuntimeInsideValidate(g, nil, nil)
2525
if err == nil {
2626
util.Fatal(specerror.NewError(specerror.LinuxProcCapError, fmt.Errorf("Any value which cannot be mapped to a relevant kernel interface MUST cause an error"), rspecs.Version))

Diff for: validation/state/state.go

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os/exec"
6+
"time"
67

78
"github.com/mndrix/tap-go"
89
rspecs "github.com/opencontainers/runtime-spec/specs-go"
@@ -44,6 +45,8 @@ func main() {
4445
},
4546
PostCreate: func(r *util.Runtime) error {
4647
_, err = r.State()
48+
r.Kill("KILL")
49+
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second)
4750
return err
4851
},
4952
}

Diff for: validation/util/container.go

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12+
"time"
1213

1314
rspecs "github.com/opencontainers/runtime-spec/specs-go"
1415
"github.com/opencontainers/runtime-tools/generate"
@@ -197,6 +198,9 @@ func (r *Runtime) Delete() (err error) {
197198
// forceRemoveBundle is true, after the deletion attempt regardless of
198199
// whether it was successful or not.
199200
func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) error {
201+
r.Kill("KILL")
202+
WaitingForStatus(*r, LifecycleStatusStopped, time.Second*10, time.Second/10)
203+
200204
err := r.Delete()
201205

202206
if removeBundle && (err == nil || forceRemoveBundle) {

Diff for: validation/util/test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ func RuntimeLifecycleValidate(config LifecycleConfig) error {
350350
if _, err := r.State(); err != nil {
351351
return
352352
}
353-
err := WaitingForStatus(r, LifecycleStatusCreated|LifecycleStatusStopped, time.Second*10, time.Second*1)
353+
r.Kill("KILL")
354+
err := WaitingForStatus(r, LifecycleStatusStopped, time.Second*10, time.Second*1)
354355
if err == nil {
355356
r.Delete()
356357
} else {

0 commit comments

Comments
 (0)