Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prow testing #26

Merged
merged 38 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cc564f9
verify-subtree.sh: relax check and ignore old content
pohly Mar 6, 2019
849db0a
Merge pull request #8 from pohly/subtree-check-relax
k8s-ci-robot Mar 6, 2019
94fc1e3
build.make: avoid unit-testing E2E test suite
pohly Mar 15, 2019
fb13c51
verify-shellcheck.sh: import from Kubernetes
pohly Mar 15, 2019
e6db50d
check vendor directory
pohly Mar 27, 2019
34010e7
Merge pull request #10 from pohly/vendor-check
k8s-ci-robot Mar 27, 2019
104a1ac
build.make: avoid unit-testing E2E test suite
pohly Mar 15, 2019
3b6af7b
Merge pull request #12 from pohly/local-e2e-suite
k8s-ci-robot Mar 29, 2019
b2d25d4
verify-shellcheck.sh: make it usable in csi-release-tools
pohly Mar 15, 2019
6c7ba1b
build.make: integrate shellcheck into "make test"
pohly Mar 26, 2019
55212ff
initial Prow test job
pohly Mar 15, 2019
2069a0a
Merge pull request #11 from pohly/verify-shellcheck
k8s-ci-robot Apr 2, 2019
0a0fd49
prow.sh: comment clarification
pohly Apr 2, 2019
429581c
prow.sh: pull Go version from travis.yml
pohly Apr 2, 2019
29545bb
prow.sh: take Go version from Kubernetes source
pohly Apr 3, 2019
741319b
prow.sh: improve building Kubernetes from source
pohly Apr 3, 2019
6602d38
prow.sh: different E2E suite depending on Kubernetes version
pohly Apr 3, 2019
d87eccb
prow.sh: switch back to upstream csi-driver-host-path
pohly Apr 3, 2019
95ae9de
Merge pull request #9 from pohly/prow
k8s-ci-robot Apr 3, 2019
2f3433d
.prow.sh: enable testing with Prow script from csi-release-tools
pohly Apr 8, 2019
79f8893
rpc: fix gofmt error
pohly Apr 8, 2019
f501443
prow.sh: AllAlpha=true for unknown Kubernetes versions
pohly Apr 5, 2019
31dfaf3
prow.sh: fix running of just "alpha" tests
pohly Apr 8, 2019
f3d1d2d
prow.sh: fix hostpath driver version check
pohly Apr 8, 2019
aa45a1c
prow.sh: more efficient execution of individual tests
pohly Apr 8, 2019
9b0d9cd
build.make: skip shellcheck if Docker is not available
pohly Apr 8, 2019
546d550
prow.sh: debug failing KinD cluster creation
pohly Apr 8, 2019
cda2fc5
prow.sh: avoid AllAlpha=true
pohly Apr 8, 2019
6617773
Merge pull request #13 from pohly/prow
k8s-ci-robot Apr 9, 2019
7aaac22
prow.sh: remove AllAlpha=all, part II
pohly Apr 10, 2019
c60f382
Merge pull request #14 from pohly/prow
k8s-ci-robot Apr 10, 2019
f14bbd6
Merge commit 'c60f3823c09a501b1cc12b97b20eb05cec9f822e' into prow
pohly Apr 11, 2019
ff9bce4
Replace 'return' to 'exit' to fix shellcheck error
pengzhisun Apr 11, 2019
0c2677e
Merge pull request #15 from pengzhisun/master
k8s-ci-robot Apr 11, 2019
16ca5ce
Merge commit '0c2677e8fecad9bf904fca32b0319068d3eaa186' into prow
pohly Apr 11, 2019
0b10f6a
prow.sh: update csi-driver-host-path
pohly Apr 11, 2019
bcac1c1
Merge pull request #16 from pohly/prow
k8s-ci-robot Apr 11, 2019
881e737
Merge commit 'bcac1c1fb6d791fe54a84716a5fdcccd0987a351' into prow
pohly Apr 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .prow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash

# A Prow job can override these defaults, but this shouldn't be necessary.

# Only these tests make sense for csi-sanity.
: ${CSI_PROW_TESTS:="unit"}

. release-tools/prow.sh

main
7 changes: 7 additions & 0 deletions release-tools/.prow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash -e
#
# This is for testing csi-release-tools itself in Prow. All other
# repos use prow.sh for that, but as csi-release-tools isn't a normal
# repo with some Go code in it, it has a custom Prow test script.

./verify-shellcheck.sh "$(pwd)"
57 changes: 57 additions & 0 deletions release-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,60 @@ Cheat sheet:
- `git subtree add --prefix=release-tools https://github.com/kubernetes-csi/csi-release-tools.git master` - add release tools to a repo which does not have them yet (only once)
- `git subtree pull --prefix=release-tools https://github.com/kubernetes-csi/csi-release-tools.git master` - update local copy to latest upstream (whenever upstream changes)
- edit, `git commit`, `git subtree push --prefix=release-tools [email protected]:<user>/csi-release-tools.git <my-new-or-existing-branch>` - push to a new branch before submitting a PR

verify-shellcheck.sh
--------------------

The [verify-shellcheck.sh](./verify-shellcheck.sh) script in this repo
is a stripped down copy of the [corresponding
script](https://github.com/kubernetes/kubernetes/blob/release-1.14/hack/verify-shellcheck.sh)
in the Kubernetes repository. It can be used to check for certain
errors shell scripts, like missing quotation marks. The default
`test-shellcheck` target in [build.make](./build.make) only checks the
scripts in this directory. Components can add more directories to
`TEST_SHELLCHECK_DIRS` to check also other scripts.

End-to-end testing
------------------

A repo that wants to opt into testing via Prow must set up a top-level
`.prow.sh`. Typically that will source `prow.sh` and then transfer
control to it:

``` bash
#! /bin/bash -e

. release-tools/prow.sh
main
```

All Kubernetes-CSI repos are expected to switch to Prow. For details
on what is enabled in Prow, see
https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-csi

Test results for periodic jobs are visible in
https://testgrid.k8s.io/sig-storage-csi

It is possible to reproduce the Prow testing locally on a suitable machine:
- Linux host
- Docker installed
- code to be tested checkout out in `$GOPATH/src/<import path>`
- `cd $GOPATH/src/<import path> && ./.prow.sh`

Beware that the script intentionally doesn't clean up after itself and
modifies the content of `$GOPATH`, in particular the `kubernetes` and
`kind` repositories there. Better run it in an empty, disposable
`$GOPATH`.

When it terminates, the following command can be used to get access to
the Kubernetes cluster that was brought up for testing (assuming that
this step succeeded):

export KUBECONFIG="$(kind get kubeconfig-path --name="csi-prow")"

It is possible to control the execution via environment variables. See
`prow.sh` for details. Particularly useful is testing against different
Kubernetes releases:

CSI_PROW_KUBERNETES_VERSION=1.13.3 ./.prow.sh
CSI_PROW_KUBERNETES_VERSION=latest ./.prow.sh
31 changes: 30 additions & 1 deletion release-tools/build.make
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test:
test: test-go
test-go:
@ echo; echo "### $@:"
go test `go list ./... | grep -v 'vendor' $(TEST_GO_FILTER_CMD)` $(TESTARGS)
go test `go list ./... | grep -v -e 'vendor' -e '/test/e2e$$' $(TEST_GO_FILTER_CMD)` $(TESTARGS)

.PHONY: test-vet
test: test-vet
Expand All @@ -117,8 +117,37 @@ test-fmt:
false; \
fi

# This test only runs when dep >= 0.5 is installed, which is the case for the CI setup.
.PHONY: test-vendor
test: test-vendor
test-vendor:
@ echo; echo "### $@:"
@ case "$$(dep version 2>/dev/null | grep 'version *:')" in \
*v0.[56789]*) dep check && echo "vendor up-to-date" || false;; \
*) echo "skipping check, dep >= 0.5 required";; \
esac

.PHONY: test-subtree
test: test-subtree
test-subtree:
@ echo; echo "### $@:"
./release-tools/verify-subtree.sh release-tools

# Components can extend the set of directories which must pass shellcheck.
# The default is to check only the release-tools directory itself.
TEST_SHELLCHECK_DIRS=release-tools
.PHONY: test-shellcheck
test: test-shellcheck
test-shellcheck:
@ echo; echo "### $@:"
@ ret=0; \
if ! command -v docker; then \
echo "skipped, no Docker"; \
exit 0; \
fi; \
for dir in $(abspath $(TEST_SHELLCHECK_DIRS)); do \
echo; \
echo "$$dir:"; \
./release-tools/verify-shellcheck.sh "$$dir" || ret=1; \
done; \
exit $$ret
133 changes: 133 additions & 0 deletions release-tools/filter-junit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/*
* This command filters a JUnit file such that only tests with a name
* matching a regular expression are passed through. By concatenating
* multiple input files it is possible to merge them into a single file.
*/
package main

import (
"encoding/xml"
"flag"
"io/ioutil"
"os"
"regexp"
)

var (
output = flag.String("o", "-", "junit file to write, - for stdout")
tests = flag.String("t", "", "regular expression matching the test names that are to be included in the output")
)

/*
* TestSuite represents a JUnit file. Due to how encoding/xml works, we have
* represent all fields that we want to be passed through. It's therefore
* not a complete solution, but good enough for Ginkgo + Spyglass.
*/
type TestSuite struct {
XMLName string `xml:"testsuite"`
TestCases []TestCase `xml:"testcase"`
}

type TestCase struct {
Name string `xml:"name,attr"`
Time string `xml:"time,attr"`
SystemOut string `xml:"system-out,omitempty"`
Failure string `xml:"failure,omitempty"`
Skipped SkipReason `xml:"skipped,omitempty"`
}

// SkipReason deals with the special <skipped></skipped>:
// if present, we must re-encode it, even if empty.
type SkipReason string

func (s *SkipReason) UnmarshalText(text []byte) error {
*s = SkipReason(text)
if *s == "" {
*s = " "
}
return nil
}

func (s SkipReason) MarshalText() ([]byte, error) {
if s == " " {
return []byte{}, nil
}
return []byte(s), nil
}

func main() {
var junit TestSuite
var data []byte

flag.Parse()

re := regexp.MustCompile(*tests)

// Read all input files.
for _, input := range flag.Args() {
if input == "-" {
if _, err := os.Stdin.Read(data); err != nil {
panic(err)
}
} else {
var err error
data, err = ioutil.ReadFile(input)
if err != nil {
panic(err)
}
}
if err := xml.Unmarshal(data, &junit); err != nil {
panic(err)
}
}

// Keep only matching testcases. Testcases skipped in all test runs are only stored once.
filtered := map[string]TestCase{}
for _, testcase := range junit.TestCases {
if !re.MatchString(testcase.Name) {
continue
}
entry, ok := filtered[testcase.Name]
if !ok || // not present yet
entry.Skipped != "" && testcase.Skipped == "" { // replaced skipped test with real test run
filtered[testcase.Name] = testcase
}
}
junit.TestCases = nil
for _, testcase := range filtered {
junit.TestCases = append(junit.TestCases, testcase)
}

// Re-encode.
data, err := xml.MarshalIndent(junit, "", " ")
if err != nil {
panic(err)
}

// Write to output.
if *output == "-" {
if _, err := os.Stdout.Write(data); err != nil {
panic(err)
}
} else {
if err := ioutil.WriteFile(*output, data, 0644); err != nil {
panic(err)
}
}
}
Loading