Skip to content

Commit 9f15f4a

Browse files
committed
Merge commit '6602d38bfbce6a526f9225c39aa6b86adbd86978' into prow
2 parents 00fe576 + 6602d38 commit 9f15f4a

File tree

7 files changed

+1456
-1
lines changed

7 files changed

+1456
-1
lines changed

release-tools/.prow.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /bin/bash -e
2+
#
3+
# This is for testing csi-release-tools itself in Prow. All other
4+
# repos use prow.sh for that, but as csi-release-tools isn't a normal
5+
# repo with some Go code in it, it has a custom Prow test script.
6+
7+
./verify-shellcheck.sh "$(pwd)"

release-tools/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,60 @@ Cheat sheet:
4949
- `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)
5050
- `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)
5151
- 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
52+
53+
verify-shellcheck.sh
54+
--------------------
55+
56+
The [verify-shellcheck.sh](./verify-shellcheck.sh) script in this repo
57+
is a stripped down copy of the [corresponding
58+
script](https://github.com/kubernetes/kubernetes/blob/release-1.14/hack/verify-shellcheck.sh)
59+
in the Kubernetes repository. It can be used to check for certain
60+
errors shell scripts, like missing quotation marks. The default
61+
`test-shellcheck` target in [build.make](./build.make) only checks the
62+
scripts in this directory. Components can add more directories to
63+
`TEST_SHELLCHECK_DIRS` to check also other scripts.
64+
65+
End-to-end testing
66+
------------------
67+
68+
A repo that wants to opt into testing via Prow must set up a top-level
69+
`.prow.sh`. Typically that will source `prow.sh` and then transfer
70+
control to it:
71+
72+
``` bash
73+
#! /bin/bash -e
74+
75+
. release-tools/prow.sh
76+
main
77+
```
78+
79+
All Kubernetes-CSI repos are expected to switch to Prow. For details
80+
on what is enabled in Prow, see
81+
https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-csi
82+
83+
Test results for periodic jobs are visible in
84+
https://testgrid.k8s.io/sig-storage-csi
85+
86+
It is possible to reproduce the Prow testing locally on a suitable machine:
87+
- Linux host
88+
- Docker installed
89+
- code to be tested checkout out in `$GOPATH/src/<import path>`
90+
- `cd $GOPATH/src/<import path> && ./.prow.sh`
91+
92+
Beware that the script intentionally doesn't clean up after itself and
93+
modifies the content of `$GOPATH`, in particular the `kubernetes` and
94+
`kind` repositories there. Better run it in an empty, disposable
95+
`$GOPATH`.
96+
97+
When it terminates, the following command can be used to get access to
98+
the Kubernetes cluster that was brought up for testing (assuming that
99+
this step succeeded):
100+
101+
export KUBECONFIG="$(kind get kubeconfig-path --name="csi-prow")"
102+
103+
It is possible to control the execution via environment variables. See
104+
`prow.sh` for details. Particularly useful is testing against different
105+
Kubernetes releases:
106+
107+
CSI_PROW_KUBERNETES_VERSION=1.13.3 ./.prow.sh
108+
CSI_PROW_KUBERNETES_VERSION=latest ./.prow.sh

release-tools/build.make

+16-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test:
9898
test: test-go
9999
test-go:
100100
@ echo; echo "### $@:"
101-
go test `go list ./... | grep -v 'vendor' $(TEST_GO_FILTER_CMD)` $(TESTARGS)
101+
go test `go list ./... | grep -v -e 'vendor' -e '/test/e2e$$' $(TEST_GO_FILTER_CMD)` $(TESTARGS)
102102

103103
.PHONY: test-vet
104104
test: test-vet
@@ -132,3 +132,18 @@ test: test-subtree
132132
test-subtree:
133133
@ echo; echo "### $@:"
134134
./release-tools/verify-subtree.sh release-tools
135+
136+
# Components can extend the set of directories which must pass shellcheck.
137+
# The default is to check only the release-tools directory itself.
138+
TEST_SHELLCHECK_DIRS=release-tools
139+
.PHONY: test-shellcheck
140+
test: test-shellcheck
141+
test-shellcheck:
142+
@ echo; echo "### $@:"
143+
@ ret=0; \
144+
for dir in $(abspath $(TEST_SHELLCHECK_DIRS)); do \
145+
echo; \
146+
echo "$$dir:"; \
147+
./release-tools/verify-shellcheck.sh "$$dir" || ret=1; \
148+
done; \
149+
return $$ret

release-tools/filter-junit.go

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
* This command filters a JUnit file such that only tests with a name
19+
* matching a regular expression are passed through. By concatenating
20+
* multiple input files it is possible to merge them into a single file.
21+
*/
22+
package main
23+
24+
import (
25+
"encoding/xml"
26+
"flag"
27+
"io/ioutil"
28+
"os"
29+
"regexp"
30+
)
31+
32+
var (
33+
output = flag.String("o", "-", "junit file to write, - for stdout")
34+
tests = flag.String("t", "", "regular expression matching the test names that are to be included in the output")
35+
)
36+
37+
/*
38+
* TestSuite represents a JUnit file. Due to how encoding/xml works, we have
39+
* represent all fields that we want to be passed through. It's therefore
40+
* not a complete solution, but good enough for Ginkgo + Spyglass.
41+
*/
42+
type TestSuite struct {
43+
XMLName string `xml:"testsuite"`
44+
TestCases []TestCase `xml:"testcase"`
45+
}
46+
47+
type TestCase struct {
48+
Name string `xml:"name,attr"`
49+
Time string `xml:"time,attr"`
50+
SystemOut string `xml:"system-out,omitempty"`
51+
Failure string `xml:"failure,omitempty"`
52+
Skipped SkipReason `xml:"skipped,omitempty"`
53+
}
54+
55+
// SkipReason deals with the special <skipped></skipped>:
56+
// if present, we must re-encode it, even if empty.
57+
type SkipReason string
58+
59+
func (s *SkipReason) UnmarshalText(text []byte) error {
60+
*s = SkipReason(text)
61+
if *s == "" {
62+
*s = " "
63+
}
64+
return nil
65+
}
66+
67+
func (s SkipReason) MarshalText() ([]byte, error) {
68+
if s == " " {
69+
return []byte{}, nil
70+
}
71+
return []byte(s), nil
72+
}
73+
74+
func main() {
75+
var junit TestSuite
76+
var data []byte
77+
78+
flag.Parse()
79+
80+
re := regexp.MustCompile(*tests)
81+
82+
// Read all input files.
83+
for _, input := range flag.Args() {
84+
if input == "-" {
85+
if _, err := os.Stdin.Read(data); err != nil {
86+
panic(err)
87+
}
88+
} else {
89+
var err error
90+
data, err = ioutil.ReadFile(input)
91+
if err != nil {
92+
panic(err)
93+
}
94+
}
95+
if err := xml.Unmarshal(data, &junit); err != nil {
96+
panic(err)
97+
}
98+
}
99+
100+
// Keep only matching testcases. Testcases skipped in all test runs are only stored once.
101+
filtered := map[string]TestCase{}
102+
for _, testcase := range junit.TestCases {
103+
if !re.MatchString(testcase.Name) {
104+
continue
105+
}
106+
entry, ok := filtered[testcase.Name]
107+
if !ok || // not present yet
108+
entry.Skipped != "" && testcase.Skipped == "" { // replaced skipped test with real test run
109+
filtered[testcase.Name] = testcase
110+
}
111+
}
112+
junit.TestCases = nil
113+
for _, testcase := range filtered {
114+
junit.TestCases = append(junit.TestCases, testcase)
115+
}
116+
117+
// Re-encode.
118+
data, err := xml.MarshalIndent(junit, "", " ")
119+
if err != nil {
120+
panic(err)
121+
}
122+
123+
// Write to output.
124+
if *output == "-" {
125+
if _, err := os.Stdout.Write(data); err != nil {
126+
panic(err)
127+
}
128+
} else {
129+
if err := ioutil.WriteFile(*output, data, 0644); err != nil {
130+
panic(err)
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)