diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..7fad24297 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,58 @@ +name: ci +on: + push: + tags: + - v* + branches: + - master + - release-* + pull_request: + +jobs: + + lint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: golangci/golangci-lint-action@v2 + with: + version: v1.42 + + commit: + runs-on: ubuntu-20.04 + # Only check commits on pull requests. + if: github.event_name == 'pull_request' + steps: + - name: get pr commits + id: 'get-pr-commits' + uses: tim-actions/get-pr-commits@v1.1.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: check subject line length + uses: tim-actions/commit-message-checker-with-regex@v0.3.1 + with: + commits: ${{ steps.get-pr-commits.outputs.commits }} + pattern: '^.{0,72}(\n.*)*$' + error: 'Subject too long (max 72)' + + test: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + go-version: [1.16.x, 1.17.x] + race: ["-race", ""] + + steps: + - name: checkout + uses: actions/checkout@v2 + - name: install go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + stable: '!contains(${{ matrix.go-version }}, "beta") && !contains(${{ matrix.go-version }}, "rc")' + go-version: ${{ matrix.go-version }} + - name: build + run: make EXTRA_FLAGS="${{ matrix.race }}" + - name: test + run: make TESTFLAGS="${{ matrix.race }}" test diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..3ee5b4bc3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +# For documentation, see https://golangci-lint.run/usage/configuration/ + +linters: + disable: + - errcheck diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1d5a62c24..000000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: go -go: - - 1.10.x - - 1.11.x - -sudo: false - -before_install: - - mkdir --parents $GOPATH/src/golang.org/x - && git clone --depth=1 https://go.googlesource.com/lint $GOPATH/src/golang.org/x/lint - && go get golang.org/x/lint/golint - - go get github.com/vbatts/git-validation - -install: true - -script: - - git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE} - - make - - make test diff --git a/Makefile b/Makefile index 87cfb4511..418d7bf56 100644 --- a/Makefile +++ b/Makefile @@ -4,18 +4,20 @@ TAP ?= tap BUILDTAGS= RUNTIME ?= runc -COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true) +COMMIT ?= $(shell git describe --dirty --long --always --tags 2> /dev/null) VERSION := ${shell cat ./VERSION} +BUILD_FLAGS := -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)" $(EXTRA_FLAGS) +STATIC_BUILD_FLAGS := -tags "$(BUILDTAGS) netgo osusergo" -ldflags "-extldflags -static -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)" $(EXTRA_FLAGS) VALIDATION_TESTS ?= $(patsubst %.go,%.t,$(shell find ./validation/ -name *.go | grep -v util)) all: tool runtimetest validation-executables tool: - go build -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o oci-runtime-tool ./cmd/oci-runtime-tool + go build $(BUILD_FLAGS) -o oci-runtime-tool ./cmd/oci-runtime-tool .PHONY: runtimetest runtimetest: - CGO_ENABLED=0 go build -installsuffix cgo -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o runtimetest ./cmd/runtimetest + go build $(STATIC_BUILD_FLAGS) -o runtimetest ./cmd/runtimetest .PHONY: man man: @@ -56,25 +58,18 @@ validation-executables: $(VALIDATION_TESTS) .PRECIOUS: $(VALIDATION_TESTS) .PHONY: $(VALIDATION_TESTS) $(VALIDATION_TESTS): %.t: %.go - go build -tags "$(BUILDTAGS)" ${TESTFLAGS} -o $@ $< + go build $(BUILD_FLAGS) -o $@ $< print-validation-tests: @echo $(VALIDATION_TESTS) -.PHONY: test .gofmt .govet .golint print-validation-tests +.PHONY: test .govet print-validation-tests PACKAGES = $(shell go list ./... | grep -v vendor) -test: .gofmt .govet .golint .gotest - -.gofmt: - OUT=$$(go fmt $(PACKAGES)); if test -n "$${OUT}"; then echo "$${OUT}" && exit 1; fi +test: .govet .gotest .govet: go vet -x $(PACKAGES) -.golint: - golint -set_exit_status $(PACKAGES) - -UTDIRS = ./filepath/... ./validate/... ./generate/... .gotest: - go test $(UTDIRS) + go test $(TESTFLAGS) ./... diff --git a/cmd/oci-runtime-tool/generate.go b/cmd/oci-runtime-tool/generate.go index 950b64136..af250ab4a 100644 --- a/cmd/oci-runtime-tool/generate.go +++ b/cmd/oci-runtime-tool/generate.go @@ -529,9 +529,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error { if err := json.Unmarshal([]byte(hook), &tmpHook); err != nil { return err } - if err := g.AddPostStartHook(tmpHook); err != nil { - return err - } + g.AddPostStartHook(tmpHook) } } @@ -546,9 +544,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error { if err := json.Unmarshal([]byte(hook), &tmpHook); err != nil { return err } - if err := g.AddPostStopHook(tmpHook); err != nil { - return err - } + g.AddPostStopHook(tmpHook) } } @@ -563,9 +559,7 @@ func setupSpec(g *generate.Generator, context *cli.Context) error { if err := json.Unmarshal([]byte(hook), &tmpHook); err != nil { return err } - if err := g.AddPreStartHook(tmpHook); err != nil { - return err - } + g.AddPreStartHook(tmpHook) } } diff --git a/cmd/runtimetest/main.go b/cmd/runtimetest/main.go index a45e441b1..d7df16a7e 100644 --- a/cmd/runtimetest/main.go +++ b/cmd/runtimetest/main.go @@ -159,14 +159,14 @@ func (c *complianceTester) validatePosixUser(spec *rspec.Spec) error { uid := uint32(os.Getuid()) c.harness.Ok(uid == spec.Process.User.UID, "has expected user ID") - c.harness.YAML(map[string]uint32{ + _ = c.harness.YAML(map[string]uint32{ "expected": spec.Process.User.UID, "actual": uid, }) gid := uint32(os.Getgid()) c.harness.Ok(gid == spec.Process.User.GID, "has expected group ID") - c.harness.YAML(map[string]uint32{ + _ = c.harness.YAML(map[string]uint32{ "expected": spec.Process.User.GID, "actual": gid, }) @@ -202,7 +202,7 @@ func (c *complianceTester) validateProcess(spec *rspec.Spec) error { return err } c.harness.Ok(cwd == spec.Process.Cwd, "has expected working directory") - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "expected": spec.Process.Cwd, "actual": cwd, }) @@ -214,7 +214,7 @@ func (c *complianceTester) validateProcess(spec *rspec.Spec) error { expectedValue := parts[1] actualValue := os.Getenv(key) c.harness.Ok(expectedValue == actualValue, fmt.Sprintf("has expected environment variable %v", key)) - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "variable": key, "expected": expectedValue, "actual": actualValue, @@ -237,13 +237,13 @@ func (c *complianceTester) validateLinuxProcess(spec *rspec.Spec) error { args := bytes.Split(bytes.Trim(cmdlineBytes, "\x00"), []byte("\x00")) c.harness.Ok(len(args) == len(spec.Process.Args), "has expected number of process arguments") - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "expected": spec.Process.Args, "actual": args, }) for i, a := range args { c.harness.Ok(string(a) == spec.Process.Args[i], fmt.Sprintf("has expected process argument %d", i)) - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "index": i, "expected": spec.Process.Args[i], "actual": string(a), @@ -337,7 +337,7 @@ func (c *complianceTester) validateHostname(spec *rspec.Spec) error { return err } c.harness.Ok(spec.Hostname == hostname, "has expected hostname") - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "expected": spec.Hostname, "actual": hostname, }) @@ -365,7 +365,7 @@ func (c *complianceTester) validateRlimits(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "type": r.Type, @@ -377,7 +377,7 @@ func (c *complianceTester) validateRlimits(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "type": r.Type, @@ -402,7 +402,7 @@ func (c *complianceTester) validateSysctls(spec *rspec.Spec) error { } value := strings.TrimSpace(string(bytes.Trim(vBytes, "\x00"))) c.harness.Ok(value == v, fmt.Sprintf("has expected sysctl %v", k)) - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "sysctl": k, "expected": v, "actual": value, @@ -522,7 +522,7 @@ func (c *complianceTester) validateRootFS(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "level": rfcError.Level.String(), "reference": rfcError.Reference, }) @@ -568,11 +568,11 @@ func (c *complianceTester) validateRootfsPropagation(spec *rspec.Spec) error { if err := unix.Mount("/", targetDir, "", unix.MS_BIND|unix.MS_REC, ""); err != nil { return err } - defer unix.Unmount(targetDir, unix.MNT_DETACH) + defer unix.Unmount(targetDir, unix.MNT_DETACH) //nolint:errcheck if err := unix.Mount(testDir, mountDir, "", unix.MS_BIND|unix.MS_REC, ""); err != nil { return err } - defer unix.Unmount(mountDir, unix.MNT_DETACH) + defer unix.Unmount(mountDir, unix.MNT_DETACH) //nolint:errcheck targetFile := filepath.Join(targetDir, filepath.Join(mountDir, filepath.Base(tmpfile.Name()))) var exposed bool _, err = os.Stat(targetFile) @@ -599,7 +599,7 @@ func (c *complianceTester) validateRootfsPropagation(spec *rspec.Spec) error { } else if err != nil { return err } - defer unix.Unmount(targetDir, unix.MNT_DETACH) + defer unix.Unmount(targetDir, unix.MNT_DETACH) //nolint:errcheck c.harness.Fail("root propagation is unbindable") return nil default: @@ -625,7 +625,7 @@ func (c *complianceTester) validateDefaultFS(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "mount": fs, @@ -671,7 +671,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -703,7 +703,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -722,7 +722,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -733,7 +733,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -751,7 +751,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -772,7 +772,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -788,7 +788,7 @@ func (c *complianceTester) validateDevice(device *rspec.LinuxDevice, condition s if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": device.Path, @@ -815,7 +815,7 @@ func (c *complianceTester) validateDefaultSymlinks(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": symlink, @@ -833,7 +833,7 @@ func (c *complianceTester) validateDefaultSymlinks(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": symlink, @@ -855,7 +855,7 @@ func (c *complianceTester) validateDefaultSymlinks(spec *rspec.Spec) error { if err != nil { return err } - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "path": symlink, @@ -982,11 +982,11 @@ func (c *complianceTester) validateOOMScoreAdj(spec *rspec.Spec) error { if err != nil { return err } - rfcError, err := c.Ok(actual == expected, specerror.LinuxProcOomScoreAdjSet, spec.Version, fmt.Sprintf("has expected OOM score adjustment")) + rfcError, err := c.Ok(actual == expected, specerror.LinuxProcOomScoreAdjSet, spec.Version, "has expected OOM score adjustment") if err != nil { return err } - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "level": rfcError.Level.String(), "reference": rfcError.Reference, "expected": expected, @@ -1047,7 +1047,7 @@ func (c *complianceTester) validateIDMappings(mappings []rspec.LinuxIDMapping, p return err } c.harness.Ok(len(idMaps) == len(mappings), fmt.Sprintf("%s has expected number of mappings", path)) - c.harness.YAML(map[string]interface{}{ + _ = c.harness.YAML(map[string]interface{}{ "expected": mappings, "actual": idMaps, }) @@ -1179,19 +1179,19 @@ func (c *complianceTester) validatePosixMounts(spec *rspec.Spec) error { rfcError, err = c.Ok(false, specerror.MountsInOrder, spec.Version, fmt.Sprintf("mounts[%d] (%s) found", i, configMount.Destination)) } else { rfcError, err = c.Ok(foundInOrder, specerror.MountsInOrder, spec.Version, fmt.Sprintf("mounts[%d] (%s) found in order", i, configMount.Destination)) - c.harness.YAML(map[string]interface{}{ - "level": rfcError.Level.String(), - "reference": rfcError.Reference, - "config": configMount, - "indexConfig": i, - "indexSystem": configSys[i], - "earlier": map[string]interface{}{ - "config": spec.Mounts[highestMatchedConfig], - "indexConfig": highestMatchedConfig, - "indexSystem": configSys[highestMatchedConfig], - }, - }) } + _ = c.harness.YAML(map[string]interface{}{ + "level": rfcError.Level.String(), + "reference": rfcError.Reference, + "config": configMount, + "indexConfig": i, + "indexSystem": configSys[i], + "earlier": map[string]interface{}{ + "config": spec.Mounts[highestMatchedConfig], + "indexConfig": highestMatchedConfig, + "indexSystem": configSys[highestMatchedConfig], + }, + }) } return mountErrs @@ -1231,7 +1231,7 @@ func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error { return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination) } c.harness.Ok(spec.Linux.MountLabel == fileLabel, "has expected mountlabel") - c.harness.YAML(map[string]string{ + _ = c.harness.YAML(map[string]string{ "expected": spec.Linux.MountLabel, "actual": fileLabel, }) diff --git a/generate/config.go b/generate/config.go index f68bdde37..9ae50fb8d 100644 --- a/generate/config.go +++ b/generate/config.go @@ -185,24 +185,3 @@ func (g *Generator) initConfigVM() { g.Config.VM = &rspec.VM{} } } - -func (g *Generator) initConfigVMHypervisor() { - g.initConfigVM() - if &g.Config.VM.Hypervisor == nil { - g.Config.VM.Hypervisor = rspec.VMHypervisor{} - } -} - -func (g *Generator) initConfigVMKernel() { - g.initConfigVM() - if &g.Config.VM.Kernel == nil { - g.Config.VM.Kernel = rspec.VMKernel{} - } -} - -func (g *Generator) initConfigVMImage() { - g.initConfigVM() - if &g.Config.VM.Image == nil { - g.Config.VM.Image = rspec.VMImage{} - } -} diff --git a/generate/generate.go b/generate/generate.go index b8433ce8f..8aba53f63 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -1025,10 +1025,9 @@ func (g *Generator) ClearPreStartHooks() { } // AddPreStartHook add a prestart hook into g.Config.Hooks.Prestart. -func (g *Generator) AddPreStartHook(preStartHook rspec.Hook) error { +func (g *Generator) AddPreStartHook(preStartHook rspec.Hook) { g.initConfigHooks() g.Config.Hooks.Prestart = append(g.Config.Hooks.Prestart, preStartHook) - return nil } // ClearPostStopHooks clear g.Config.Hooks.Poststop. @@ -1040,10 +1039,9 @@ func (g *Generator) ClearPostStopHooks() { } // AddPostStopHook adds a poststop hook into g.Config.Hooks.Poststop. -func (g *Generator) AddPostStopHook(postStopHook rspec.Hook) error { +func (g *Generator) AddPostStopHook(postStopHook rspec.Hook) { g.initConfigHooks() g.Config.Hooks.Poststop = append(g.Config.Hooks.Poststop, postStopHook) - return nil } // ClearPostStartHooks clear g.Config.Hooks.Poststart. @@ -1055,10 +1053,9 @@ func (g *Generator) ClearPostStartHooks() { } // AddPostStartHook adds a poststart hook into g.Config.Hooks.Poststart. -func (g *Generator) AddPostStartHook(postStartHook rspec.Hook) error { +func (g *Generator) AddPostStartHook(postStartHook rspec.Hook) { g.initConfigHooks() g.Config.Hooks.Poststart = append(g.Config.Hooks.Poststart, postStartHook) - return nil } // AddMount adds a mount into g.Config.Mounts. @@ -1560,12 +1557,8 @@ func (g *Generator) RemoveLinuxResourcesDevice(allow bool, devType string, major return } } - return } -// strPtr returns the pointer pointing to the string s. -func strPtr(s string) *string { return &s } - // SetSyscallAction adds rules for syscalls with the specified action func (g *Generator) SetSyscallAction(arguments seccomp.SyscallOpts) error { g.initConfigLinuxSeccomp() @@ -1691,14 +1684,14 @@ func (g *Generator) SetVMHypervisorPath(path string) error { if !strings.HasPrefix(path, "/") { return fmt.Errorf("hypervisorPath %v is not an absolute path", path) } - g.initConfigVMHypervisor() + g.initConfigVM() g.Config.VM.Hypervisor.Path = path return nil } // SetVMHypervisorParameters sets g.Config.VM.Hypervisor.Parameters func (g *Generator) SetVMHypervisorParameters(parameters []string) { - g.initConfigVMHypervisor() + g.initConfigVM() g.Config.VM.Hypervisor.Parameters = parameters } @@ -1707,14 +1700,14 @@ func (g *Generator) SetVMKernelPath(path string) error { if !strings.HasPrefix(path, "/") { return fmt.Errorf("kernelPath %v is not an absolute path", path) } - g.initConfigVMKernel() + g.initConfigVM() g.Config.VM.Kernel.Path = path return nil } // SetVMKernelParameters sets g.Config.VM.Kernel.Parameters func (g *Generator) SetVMKernelParameters(parameters []string) { - g.initConfigVMKernel() + g.initConfigVM() g.Config.VM.Kernel.Parameters = parameters } @@ -1723,7 +1716,7 @@ func (g *Generator) SetVMKernelInitRD(initrd string) error { if !strings.HasPrefix(initrd, "/") { return fmt.Errorf("kernelInitrd %v is not an absolute path", initrd) } - g.initConfigVMKernel() + g.initConfigVM() g.Config.VM.Kernel.InitRD = initrd return nil } @@ -1733,7 +1726,7 @@ func (g *Generator) SetVMImagePath(path string) error { if !strings.HasPrefix(path, "/") { return fmt.Errorf("imagePath %v is not an absolute path", path) } - g.initConfigVMImage() + g.initConfigVM() g.Config.VM.Image.Path = path return nil } @@ -1749,7 +1742,7 @@ func (g *Generator) SetVMImageFormat(format string) error { default: return fmt.Errorf("Commonly supported formats are: raw, qcow2, vdi, vmdk, vhd") } - g.initConfigVMImage() + g.initConfigVM() g.Config.VM.Image.Format = format return nil } diff --git a/generate/seccomp/consts.go b/generate/seccomp/consts.go index eade5718e..f28d8f587 100644 --- a/generate/seccomp/consts.go +++ b/generate/seccomp/consts.go @@ -4,9 +4,4 @@ const ( seccompOverwrite = "overwrite" seccompAppend = "append" nothing = "nothing" - kill = "kill" - trap = "trap" - trace = "trace" - allow = "allow" - errno = "errno" ) diff --git a/generate/seccomp/syscall_compare.go b/generate/seccomp/syscall_compare.go index dbf2aec1c..5e84653a9 100644 --- a/generate/seccomp/syscall_compare.go +++ b/generate/seccomp/syscall_compare.go @@ -92,22 +92,6 @@ func identical(config1, config2 *rspec.LinuxSyscall) bool { return reflect.DeepEqual(config1, config2) } -func identicalExceptAction(config1, config2 *rspec.LinuxSyscall) bool { - samename := sameName(config1, config2) - sameAction := sameAction(config1, config2) - sameArgs := sameArgs(config1, config2) - - return samename && !sameAction && sameArgs -} - -func identicalExceptArgs(config1, config2 *rspec.LinuxSyscall) bool { - samename := sameName(config1, config2) - sameAction := sameAction(config1, config2) - sameArgs := sameArgs(config1, config2) - - return samename && sameAction && !sameArgs -} - func sameName(config1, config2 *rspec.LinuxSyscall) bool { return reflect.DeepEqual(config1.Names, config2.Names) } diff --git a/validate/validate.go b/validate/validate.go index 9c3710529..a827f11f0 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -131,7 +131,7 @@ func JSONSchemaURL(version string) (url string, err error) { if err != nil { return "", specerror.NewError(specerror.SpecVersionInSemVer, err, rspec.Version) } - configRenamedToConfigSchemaVersion, err := semver.Parse("1.0.0-rc2") // config.json became config-schema.json in 1.0.0-rc2 + configRenamedToConfigSchemaVersion, _ := semver.Parse("1.0.0-rc2") // config.json became config-schema.json in 1.0.0-rc2 if ver.Compare(configRenamedToConfigSchemaVersion) == -1 { return "", fmt.Errorf("unsupported configuration version (older than %s)", configRenamedToConfigSchemaVersion) } diff --git a/validation/config_updates_without_affect/config_updates_without_affect.go b/validation/config_updates_without_affect/config_updates_without_affect.go index 77c02ed19..3c758049e 100644 --- a/validation/config_updates_without_affect/config_updates_without_affect.go +++ b/validation/config_updates_without_affect/config_updates_without_affect.go @@ -65,10 +65,9 @@ func main() { util.Fatal(err) } - spec := &rspec.Spec{ + g.Config = &rspec.Spec{ Version: "1.0.0", } - g.SetSpec(spec) err = r.SetConfig(g) if err != nil { util.Fatal(err) diff --git a/validation/create/create.go b/validation/create/create.go index a06715f69..34bed311f 100644 --- a/validation/create/create.go +++ b/validation/create/create.go @@ -66,13 +66,13 @@ func main() { } } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) if err == nil { state, err := r.State() t.Ok(err == nil && state.ID == c.id, "'state' MUST return the state of a container") if err == nil { - t.YAML(map[string]string{ + _ = t.YAML(map[string]string{ "container ID": c.id, "state ID": state.ID, }) @@ -85,7 +85,7 @@ func main() { diagnostic["stderr"] = string(e.Stderr) } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } } } diff --git a/validation/delete_resources/delete_resources.go b/validation/delete_resources/delete_resources.go index ff0e7d816..1dc0c6e3d 100644 --- a/validation/delete_resources/delete_resources.go +++ b/validation/delete_resources/delete_resources.go @@ -59,7 +59,7 @@ func main() { if err != nil { util.Fatal(err) } - if err := util.ValidateLinuxResourcesPids(g.Spec(), t, &state); err != nil { + if err := util.ValidateLinuxResourcesPids(g.Config, t, &state); err != nil { util.Fatal(err) } diff --git a/validation/hooks/hooks.go b/validation/hooks/hooks.go index 3b72085ee..4494e3ad6 100644 --- a/validation/hooks/hooks.go +++ b/validation/hooks/hooks.go @@ -27,62 +27,44 @@ func main() { if err != nil { util.Fatal(err) } - output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output") - shPath := filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh") - err = g.AddPreStartHook(rspec.Hook{ + output = filepath.Join(r.BundleDir, g.Config.Root.Path, "output") + shPath := filepath.Join(r.BundleDir, g.Config.Root.Path, "/bin/sh") + g.AddPreStartHook(rspec.Hook{ Path: shPath, Args: []string{ "sh", "-c", fmt.Sprintf("echo 'pre-start1 called' >> %s", output), }, }) - if err != nil { - return err - } - err = g.AddPreStartHook(rspec.Hook{ + g.AddPreStartHook(rspec.Hook{ Path: shPath, Args: []string{ "sh", "-c", fmt.Sprintf("echo 'pre-start2 called' >> %s", output), }, }) - if err != nil { - return err - } - err = g.AddPostStartHook(rspec.Hook{ + g.AddPostStartHook(rspec.Hook{ Path: shPath, Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-start1 called' >> %s", output), }, }) - if err != nil { - return err - } - err = g.AddPostStartHook(rspec.Hook{ + g.AddPostStartHook(rspec.Hook{ Path: shPath, Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-start2 called' >> %s", output), }, }) - if err != nil { - return err - } - err = g.AddPostStopHook(rspec.Hook{ + g.AddPostStopHook(rspec.Hook{ Path: shPath, Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-stop1 called' >> %s", output), }, }) - if err != nil { - return err - } - err = g.AddPostStopHook(rspec.Hook{ + g.AddPostStopHook(rspec.Hook{ Path: shPath, Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-stop2 called' >> %s", output), }, }) - if err != nil { - return err - } g.SetProcessArgs([]string{"true"}) return r.SetConfig(g) }, @@ -99,7 +81,7 @@ func main() { diagnostic := map[string]string{ "error": err.Error(), } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } else { diagnostic := map[string]string{ "error": err.Error(), @@ -109,7 +91,7 @@ func main() { diagnostic["stderr"] = string(e.Stderr) } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/hooks_stdin/hooks_stdin.go b/validation/hooks_stdin/hooks_stdin.go index 77777980d..b04a377f3 100644 --- a/validation/hooks_stdin/hooks_stdin.go +++ b/validation/hooks_stdin/hooks_stdin.go @@ -94,25 +94,25 @@ func main() { if err != nil { util.Fatal(err) } - outputDir := filepath.Join(bundleDir, g.Spec().Root.Path) + outputDir := filepath.Join(bundleDir, g.Config.Root.Path) timeout := 1 g.AddAnnotation(annotationKey, annotationValue) g.AddPreStartHook(rspecs.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/sh"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("cat > %s", filepath.Join(outputDir, "prestart")), }, Timeout: &timeout, }) g.AddPostStartHook(rspecs.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/sh"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("cat > %s", filepath.Join(outputDir, "poststart")), }, Timeout: &timeout, }) g.AddPostStopHook(rspecs.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/sh"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("cat > %s", filepath.Join(outputDir, "poststop")), }, diff --git a/validation/hostname/hostname.go b/validation/hostname/hostname.go index 543c3c713..02e01754f 100644 --- a/validation/hostname/hostname.go +++ b/validation/hostname/hostname.go @@ -31,7 +31,7 @@ func main() { defer t.AutoPlan() if "linux" != runtime.GOOS { - t.Skip(1, fmt.Sprintf("linux-specific namespace test")) + t.Skip(1, "linux-specific namespace test") } hostnames := []string{ diff --git a/validation/killsig/killsig.go b/validation/killsig/killsig.go index d0cde75d1..9d7c26192 100644 --- a/validation/killsig/killsig.go +++ b/validation/killsig/killsig.go @@ -34,7 +34,7 @@ func main() { os.RemoveAll(bundleDir) util.Fatal(err) } - rootDir := filepath.Join(bundleDir, sigConfig.Spec().Root.Path) + rootDir := filepath.Join(bundleDir, sigConfig.Config.Root.Path) for _, signal := range signals { sigConfig.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("trap 'touch /%s' %s; sleep 10 & wait $!", signal, signal)}) config := util.LifecycleConfig{ diff --git a/validation/linux_ns_itype/linux_ns_itype.go b/validation/linux_ns_itype/linux_ns_itype.go index 13b9adc6e..1b08b458b 100644 --- a/validation/linux_ns_itype/linux_ns_itype.go +++ b/validation/linux_ns_itype/linux_ns_itype.go @@ -22,7 +22,7 @@ func printDiag(t *tap.T, diagActual, diagExpected, diagNsType string, errNs erro "level": specErr.(*specerror.Error).Err.Level.String(), "reference": specErr.(*specerror.Error).Err.Reference, } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } func testNamespaceInheritType(t *tap.T) error { @@ -119,7 +119,7 @@ func main() { t.Header(0) if "linux" != runtime.GOOS { - t.Skip(1, fmt.Sprintf("linux-specific namespace test")) + t.Skip(1, "linux-specific namespace test") } err := testNamespaceInheritType(t) diff --git a/validation/linux_ns_nopath/linux_ns_nopath.go b/validation/linux_ns_nopath/linux_ns_nopath.go index ae6e8ec90..7aea78d01 100644 --- a/validation/linux_ns_nopath/linux_ns_nopath.go +++ b/validation/linux_ns_nopath/linux_ns_nopath.go @@ -22,7 +22,7 @@ func printDiag(t *tap.T, diagActual, diagExpected, diagNsType string, errNs erro "level": specErr.(*specerror.Error).Err.Level.String(), "reference": specErr.(*specerror.Error).Err.Reference, } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } func testNamespaceNoPath(t *tap.T) error { @@ -120,7 +120,7 @@ func main() { t.Header(0) if "linux" != runtime.GOOS { - t.Skip(1, fmt.Sprintf("linux-specific namespace test")) + t.Skip(1, "linux-specific namespace test") } err := testNamespaceNoPath(t) diff --git a/validation/linux_ns_path/linux_ns_path.go b/validation/linux_ns_path/linux_ns_path.go index 65db1997d..8744fb592 100644 --- a/validation/linux_ns_path/linux_ns_path.go +++ b/validation/linux_ns_path/linux_ns_path.go @@ -166,7 +166,7 @@ func main() { "level": rfcError.Level.String(), "reference": rfcError.Reference, } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } } diff --git a/validation/linux_ns_path_type/linux_ns_path_type.go b/validation/linux_ns_path_type/linux_ns_path_type.go index 7e903dc68..82846831f 100644 --- a/validation/linux_ns_path_type/linux_ns_path_type.go +++ b/validation/linux_ns_path_type/linux_ns_path_type.go @@ -42,7 +42,7 @@ func checkNSPathMatchType(t *tap.T, ns, wrongNs string) error { "level": rfcError.Level.String(), "reference": rfcError.Reference, } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) return fmt.Errorf("cannot validate path with wrong type") } diff --git a/validation/misc_props/misc_props.go b/validation/misc_props/misc_props.go index 5a6402e23..c99b8a973 100644 --- a/validation/misc_props/misc_props.go +++ b/validation/misc_props/misc_props.go @@ -62,9 +62,9 @@ func main() { errExpected bool err error }{ - {extendedSpec{Spec: *annotationConfig.Spec()}, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, true, specerror.NewError(specerror.AnnotationsKeyIgnoreUnknown, fmt.Errorf("implementations that are reading/processing this configuration file MUST NOT generate an error if they encounter an unknown annotation key"), rspecs.Version)}, - {extendedSpec{Spec: *basicConfig.Spec(), Unknown: "unknown"}, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, true, specerror.NewError(specerror.ExtensibilityIgnoreUnknownProp, fmt.Errorf("runtimes that are reading or processing this configuration file MUST NOT generate an error if they encounter an unknown property"), rspecs.Version)}, - {extendedSpec{Spec: *invalidConfig.Spec()}, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, false, specerror.NewError(specerror.ValidValues, fmt.Errorf("runtimes that are reading or processing this configuration file MUST generate an error when invalid or unsupported values are encountered"), rspecs.Version)}, + {extendedSpec{Spec: *annotationConfig.Config}, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, true, specerror.NewError(specerror.AnnotationsKeyIgnoreUnknown, fmt.Errorf("implementations that are reading/processing this configuration file MUST NOT generate an error if they encounter an unknown annotation key"), rspecs.Version)}, + {extendedSpec{Spec: *basicConfig.Config, Unknown: "unknown"}, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, true, specerror.NewError(specerror.ExtensibilityIgnoreUnknownProp, fmt.Errorf("runtimes that are reading or processing this configuration file MUST NOT generate an error if they encounter an unknown property"), rspecs.Version)}, + {extendedSpec{Spec: *invalidConfig.Config}, util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, false, specerror.NewError(specerror.ValidValues, fmt.Errorf("runtimes that are reading or processing this configuration file MUST generate an error when invalid or unsupported values are encountered"), rspecs.Version)}, } for _, c := range cases { diff --git a/validation/pidfile/pidfile.go b/validation/pidfile/pidfile.go index 8ec10df3e..ed7e3ea9b 100644 --- a/validation/pidfile/pidfile.go +++ b/validation/pidfile/pidfile.go @@ -76,7 +76,7 @@ func main() { diagnostic["stderr"] = string(e.Stderr) } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/poststart/poststart.go b/validation/poststart/poststart.go index 837cb01cf..08aa3e751 100644 --- a/validation/poststart/poststart.go +++ b/validation/poststart/poststart.go @@ -29,16 +29,13 @@ func main() { if err != nil { util.Fatal(err) } - output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output") - err = g.AddPostStartHook(rspec.Hook{ - Path: filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh"), + output = filepath.Join(r.BundleDir, g.Config.Root.Path, "output") + g.AddPostStartHook(rspec.Hook{ + Path: filepath.Join(r.BundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-start called' >> %s", output), }, }) - if err != nil { - return err - } g.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("echo 'process called' >> %s", "/output")}) return r.SetConfig(g) }, @@ -86,7 +83,7 @@ func main() { diagnostic["stderr"] = string(e.Stderr) } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/poststart_fail/poststart_fail.go b/validation/poststart_fail/poststart_fail.go index 10b5deec8..76487089c 100644 --- a/validation/poststart_fail/poststart_fail.go +++ b/validation/poststart_fail/poststart_fail.go @@ -28,14 +28,14 @@ func main() { if err != nil { util.Fatal(err) } - output := filepath.Join(bundleDir, g.Spec().Root.Path, "output") + output := filepath.Join(bundleDir, g.Config.Root.Path, "output") poststart := rspec.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/false"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/false"), Args: []string{"false"}, } g.AddPostStartHook(poststart) poststartOK := rspec.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/sh"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-start called' >> %s", output), }, @@ -66,7 +66,7 @@ func main() { diagnostic := map[string]string{ "error": err.Error(), } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/poststop/poststop.go b/validation/poststop/poststop.go index ccc151479..7da2be18a 100644 --- a/validation/poststop/poststop.go +++ b/validation/poststop/poststop.go @@ -30,16 +30,13 @@ func main() { if err != nil { util.Fatal(err) } - output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output") - err = g.AddPostStopHook(rspec.Hook{ - Path: filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh"), + output = filepath.Join(r.BundleDir, g.Config.Root.Path, "output") + g.AddPostStopHook(rspec.Hook{ + Path: filepath.Join(r.BundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-stop called' >> %s", output), }, }) - if err != nil { - return err - } g.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("echo 'process called' >> %s", "/output")}) return r.SetConfig(g) }, @@ -103,7 +100,7 @@ func main() { diagnostic["stderr"] = string(e.Stderr) } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/poststop_fail/poststop_fail.go b/validation/poststop_fail/poststop_fail.go index 63c7d4455..e7d5e851f 100644 --- a/validation/poststop_fail/poststop_fail.go +++ b/validation/poststop_fail/poststop_fail.go @@ -28,14 +28,14 @@ func main() { if err != nil { util.Fatal(err) } - output := filepath.Join(bundleDir, g.Spec().Root.Path, "output") + output := filepath.Join(bundleDir, g.Config.Root.Path, "output") poststop := rspec.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/false"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/false"), Args: []string{"false"}, } g.AddPostStopHook(poststop) poststopOK := rspec.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/sh"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("echo 'post-stop called' >> %s", output), }, @@ -66,7 +66,7 @@ func main() { diagnostic := map[string]string{ "error": err.Error(), } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/prestart/prestart.go b/validation/prestart/prestart.go index 03989475a..852ef4cb0 100644 --- a/validation/prestart/prestart.go +++ b/validation/prestart/prestart.go @@ -28,16 +28,13 @@ func main() { if err != nil { util.Fatal(err) } - output = filepath.Join(r.BundleDir, g.Spec().Root.Path, "output") - err = g.AddPreStartHook(rspec.Hook{ - Path: filepath.Join(r.BundleDir, g.Spec().Root.Path, "/bin/sh"), + output = filepath.Join(r.BundleDir, g.Config.Root.Path, "output") + g.AddPreStartHook(rspec.Hook{ + Path: filepath.Join(r.BundleDir, g.Config.Root.Path, "/bin/sh"), Args: []string{ "sh", "-c", fmt.Sprintf("echo 'pre-start called' >> %s", output), }, }) - if err != nil { - return err - } g.SetProcessArgs([]string{"sh", "-c", fmt.Sprintf("echo 'process called' >> %s", "/output")}) return r.SetConfig(g) }, @@ -85,7 +82,7 @@ func main() { diagnostic["stderr"] = string(e.Stderr) } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/prestart_fail/prestart_fail.go b/validation/prestart_fail/prestart_fail.go index aaa8fc5bc..3cf43e9f6 100644 --- a/validation/prestart_fail/prestart_fail.go +++ b/validation/prestart_fail/prestart_fail.go @@ -27,7 +27,7 @@ func main() { util.Fatal(err) } prestart := rspec.Hook{ - Path: filepath.Join(bundleDir, g.Spec().Root.Path, "/bin/false"), + Path: filepath.Join(bundleDir, g.Config.Root.Path, "/bin/false"), Args: []string{"false"}, } g.AddPreStartHook(prestart) @@ -45,7 +45,7 @@ func main() { } runErr := util.RuntimeLifecycleValidate(config) - _, outputErr := os.Stat(filepath.Join(bundleDir, g.Spec().Root.Path, "output")) + _, outputErr := os.Stat(filepath.Join(bundleDir, g.Config.Root.Path, "output")) // query the state r, _ := util.NewRuntime(util.RuntimeCommand, "") @@ -64,7 +64,7 @@ func main() { diagnostic := map[string]string{ "error": err.Error(), } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/start/start.go b/validation/start/start.go index 473f96a81..d4ffb1c34 100644 --- a/validation/start/start.go +++ b/validation/start/start.go @@ -40,7 +40,7 @@ func main() { if err != nil { util.Fatal(err) } - output := filepath.Join(bundleDir, g.Spec().Root.Path, "output") + output := filepath.Join(bundleDir, g.Config.Root.Path, "output") // start without id err = r.Start() @@ -98,7 +98,7 @@ func main() { return } - g.Spec().Process = nil + g.Config.Process = nil err = r.SetConfig(g) if err != nil { util.Fatal(err) diff --git a/validation/state/state.go b/validation/state/state.go index 986a52e05..170dd4fbc 100644 --- a/validation/state/state.go +++ b/validation/state/state.go @@ -57,7 +57,7 @@ func main() { "reference": e.Err.Reference, "error": e.Err.Error(), } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) continue } @@ -73,7 +73,7 @@ func main() { } } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } t.AutoPlan() diff --git a/validation/util/container.go b/validation/util/container.go index 1ba49844c..78f3ef5b3 100644 --- a/validation/util/container.go +++ b/validation/util/container.go @@ -1,11 +1,10 @@ package util import ( + "bytes" "encoding/json" "errors" "fmt" - "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -14,7 +13,6 @@ import ( rspecs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "github.com/opencontainers/runtime-tools/specerror" - "github.com/satori/go.uuid" ) // Runtime represents the basic requirement of a container runtime @@ -23,8 +21,8 @@ type Runtime struct { BundleDir string PidFile string ID string - stdout *os.File - stderr *os.File + stdout bytes.Buffer + stderr bytes.Buffer } // DefaultSignal represents the default signal sends to a container @@ -80,17 +78,10 @@ func (r *Runtime) Create() (err error) { args = append(args, r.ID) } cmd := exec.Command(r.RuntimeCommand, args...) - id := uuid.NewV4().String() - r.stdout, err = os.OpenFile(filepath.Join(r.bundleDir(), fmt.Sprintf("stdout-%s", id)), os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600) - if err != nil { - return err - } - cmd.Stdout = r.stdout - r.stderr, err = os.OpenFile(filepath.Join(r.bundleDir(), fmt.Sprintf("stderr-%s", id)), os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600) - if err != nil { - return err - } - cmd.Stderr = r.stderr + r.stdout.Reset() + cmd.Stdout = &r.stdout + r.stderr.Reset() + cmd.Stderr = &r.stderr err = cmd.Run() if err == nil { @@ -98,7 +89,7 @@ func (r *Runtime) Create() (err error) { } if e, ok := err.(*exec.ExitError); ok { - stdout, stderr, _ := r.ReadStandardStreams() + stdout, stderr := r.StandardStreams() if len(stderr) == 0 { stderr = stdout } @@ -108,19 +99,9 @@ func (r *Runtime) Create() (err error) { return err } -// ReadStandardStreams collects content from the stdout and stderr buffers. -func (r *Runtime) ReadStandardStreams() (stdout []byte, stderr []byte, err error) { - _, err = r.stdout.Seek(0, io.SeekStart) - stdout, err2 := ioutil.ReadAll(r.stdout) - if err == nil && err2 != nil { - err = err2 - } - _, err = r.stderr.Seek(0, io.SeekStart) - stderr, err2 = ioutil.ReadAll(r.stderr) - if err == nil && err2 != nil { - err = err2 - } - return stdout, stderr, err +// StandardStreams returns content from the stdout and stderr buffers. +func (r *Runtime) StandardStreams() (stdout, stderr []byte) { + return r.stdout.Bytes(), r.stderr.Bytes() } // Start a container @@ -197,20 +178,25 @@ func (r *Runtime) Delete() (err error) { // directory is removed after the container is deleted successfully or, if // forceRemoveBundle is true, after the deletion attempt regardless of // whether it was successful or not. -func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) error { - r.Kill("KILL") - WaitingForStatus(*r, LifecycleStatusStopped, time.Second*10, time.Second/10) +func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) { + if err := r.Kill("KILL"); err != nil { + fmt.Fprintf(os.Stderr, "Clean: Kill: %v", err) + } + if err := WaitingForStatus(*r, LifecycleStatusStopped, time.Second*10, time.Second/10); err != nil { + fmt.Fprintf(os.Stderr, "Clean: %v", err) + } err := r.Delete() + if err != nil { + fmt.Fprintf(os.Stderr, "Clean: Delete: %v", err) + } if removeBundle && (err == nil || forceRemoveBundle) { - err2 := os.RemoveAll(r.bundleDir()) - if err2 != nil && err == nil { - err = err2 + err := os.RemoveAll(r.bundleDir()) + if err != nil { + fmt.Fprintf(os.Stderr, "Clean: %v", err) } } - - return err } func execWithStderrFallbackToStdout(cmd *exec.Cmd) (err error) { diff --git a/validation/util/linux_resources_devices.go b/validation/util/linux_resources_devices.go index 43f8da8ac..ed7551688 100644 --- a/validation/util/linux_resources_devices.go +++ b/validation/util/linux_resources_devices.go @@ -26,7 +26,7 @@ func ValidateLinuxResourcesDevices(config *rspec.Spec, t *tap.T, state *rspec.St } for i, device := range config.Linux.Resources.Devices { - if device.Allow == true { + if device.Allow { found := false if lnd[i-1].Type == device.Type && *lnd[i-1].Major == *device.Major && *lnd[i-1].Minor == *device.Minor && lnd[i-1].Access == device.Access { found = true diff --git a/validation/util/test.go b/validation/util/test.go index 6f964a36d..0f21fb69e 100644 --- a/validation/util/test.go +++ b/validation/util/test.go @@ -100,7 +100,7 @@ func Skip(message string, diagnostic interface{}) { t.Header(1) t.Skip(1, message) if diagnostic != nil { - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } } @@ -119,7 +119,7 @@ func SpecErrorOK(t *tap.T, expected bool, specErr error, detailedErr error) { } } } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) } // PrepareBundle creates a test bundle in a temporary directory. @@ -228,16 +228,7 @@ func RuntimeInsideValidate(g *generate.Generator, t *tap.T, f PreFunc) (err erro return err } - stdout, stderr, err := r.ReadStandardStreams() - if err != nil { - if len(stderr) == 0 { - stderr = stdout - } - os.Stderr.WriteString("failed to read standard streams\n") - os.Stderr.Write(stderr) - return err - } - + stdout, stderr := r.StandardStreams() // Write stdout in the outter TAP if t != nil { diagnostic := map[string]string{ @@ -247,7 +238,7 @@ func RuntimeInsideValidate(g *generate.Generator, t *tap.T, f PreFunc) (err erro if err != nil { diagnostic["error"] = fmt.Sprintf("%v", err) } - t.YAML(diagnostic) + _ = t.YAML(diagnostic) t.Ok(err == nil && !strings.Contains(string(stdout), "not ok"), g.Config.Annotations["TestName"]) } else { if runtimeInsideValidateCalled { @@ -296,7 +287,7 @@ func RuntimeOutsideValidate(g *generate.Generator, t *tap.T, f AfterFunc) error if err != nil { return err } - if err := f(g.Spec(), t, &state); err != nil { + if err := f(g.Config, t, &state); err != nil { return err } }