Merge lp:~fgimenez/snappy/filter-tests into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Federico Gimenez
Status: Superseded
Proposed branch: lp:~fgimenez/snappy/filter-tests
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~fgimenez/snappy/cross-compile-debs
Diff against target: 217 lines (+80/-45)
4 files modified
_integration-tests/data/tpl/control (+10/-0)
_integration-tests/main.go (+66/-33)
debian/integration-tests/control (+0/-11)
debian/integration-tests/snappy-test (+4/-1)
To merge this branch: bzr merge lp:~fgimenez/snappy/filter-tests
Reviewer Review Type Date Requested Status
Leo Arias (community) Approve
John Lenton (community) Approve
Review via email: mp+263222@code.launchpad.net

This proposal has been superseded by a proposal from 2015-07-06.

Commit message

Allow filter tests from the command line.

Description of the change

Allow filter tests from the command line.

The filter flag has been added:

$ go run _integration-tests/main-.go -filter installSuite

The filtering itself is done by generating an adt-run control file on the fly, based on a template.

The same approach could be useful for other use cases too. For instance, when we will have different test binaries, with a template we don't need them to be defined both in the wrapper and in the control file.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

Shouldn't we have a default control file?
I'm thinking about the future when we can specify the requirements as test classes in the control file, so the runner can call adt-run directly without using our main.go.

So I like this a lot, but I was thinking about also parsing the control file to look for test bed requirements. We can talk tomorrow to figure out how to have both, filtering and test bed specs.

Also, remember that we can't call the test binary directly because the reboot will kill it and we'll lose the results. We need to merge this with the approach in https://code.launchpad.net/~elopio/snappy/upgrade-test/+merge/262657 , that uses a bash script that runs the test binary.

Revision history for this message
John Lenton (chipaca) wrote :

lgtm :)

review: Approve
Revision history for this message
Leo Arias (elopio) wrote :

Awesome! No complaints from my side, but I still can't test it because of the udf bug. I'll hold the top-approve until I can give it a successful run.

review: Approve
Revision history for this message
Leo Arias (elopio) wrote :

Successfully ran with udf from the proposed ppa.a

Revision history for this message
Snappy Tarmac (snappydevtarmac) wrote :

Attempt to merge into lp:snappy failed due to conflicts:

duplicate in _integration-tests/data.moved

lp:~fgimenez/snappy/filter-tests updated
529. By Federico Gimenez

merged trunk

530. By Federico Gimenez

merged prerequisite

531. By Federico Gimenez

merged prerequisite

532. By Federico Gimenez

merged prerequisite

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory '_integration-tests/data/tpl'
2=== added file '_integration-tests/data/tpl/control'
3--- _integration-tests/data/tpl/control 1970-01-01 00:00:00 +0000
4+++ _integration-tests/data/tpl/control 2015-07-06 07:48:48 +0000
5@@ -0,0 +1,10 @@
6+{{ $filter := .Filter }}
7+{{ range $element := .Tests }}
8+Test-Command: debian/integration-tests/snappy-test {{ $element }}.test {{ if $filter }}-gocheck.f {{ $filter }}{{ end }}
9+Restrictions: allow-stderr
10+{{ end }}
11+
12+{{ if .IncludeShell }}
13+Test-Command: ./_integration-tests/snappy-selftest --yes-really
14+Depends:
15+{{ end }}
16
17=== modified file '_integration-tests/main.go'
18--- _integration-tests/main.go 2015-07-01 08:51:59 +0000
19+++ _integration-tests/main.go 2015-07-06 07:48:48 +0000
20@@ -28,20 +28,19 @@
21 "path/filepath"
22 "strconv"
23 "strings"
24+ "text/template"
25 )
26
27 const (
28- baseDir = "/tmp/snappy-test"
29- testsBinDir = "_integration-tests/bin/"
30- defaultRelease = "rolling"
31- defaultChannel = "edge"
32- latestRevision = ""
33- defaultSSHPort = 22
34- defaultGoArm = "7"
35- latestTestName = "command1"
36- failoverTestName = "command2"
37- updateTestName = "command3"
38- shellTestName = "command4"
39+ baseDir = "/tmp/snappy-test"
40+ testsBinDir = "_integration-tests/bin/"
41+ defaultRelease = "rolling"
42+ defaultChannel = "edge"
43+ latestRevision = ""
44+ defaultSSHPort = 22
45+ defaultGoArm = "7"
46+ controlFile = "debian/integration-tests/control"
47+ controlTpl = "_integration-tests/data/tpl/control"
48 )
49
50 var (
51@@ -53,9 +52,12 @@
52 []string{
53 "-s", "/usr/share/autopkgtest/ssh-setup/snappy",
54 "--", "-i", imageTarget}...)
55+ testPackagesLatest = []string{"latest", "failover"}
56+ testPackagesPrevious = []string{"update"}
57+ testPackages = append(testPackagesLatest, testPackagesPrevious...)
58 )
59
60-func setupAndRunTests(useSnappyFromBranch bool, arch, testbedIP string, testbedPort int) {
61+func setupAndRunTests(useSnappyFromBranch bool, arch, testbedIP, testFilter string, testbedPort int) {
62 prepareTargetDir(testsBinDir)
63
64 if useSnappyFromBranch {
65@@ -66,21 +68,21 @@
66 buildTests(arch)
67
68 rootPath := getRootPath()
69+
70 if testbedIP == "" {
71+ var includeShell bool
72+ if testFilter == "" {
73+ includeShell = true
74+ }
75 createImage(defaultRelease, defaultChannel, latestRevision)
76- latestTests := []string{
77- latestTestName, failoverTestName, shellTestName}
78- for i := range latestTests {
79- adtRun(rootPath, kvmSSHOptions, latestTests[i])
80- }
81+ adtRun(rootPath, testFilter, testPackagesLatest, kvmSSHOptions, includeShell)
82
83 createImage(defaultRelease, defaultChannel, "-1")
84- adtRun(rootPath, kvmSSHOptions, updateTestName)
85+ adtRun(rootPath, testFilter, testPackagesPrevious, kvmSSHOptions, false)
86 } else {
87 execCommand("ssh-copy-id", "-p", strconv.Itoa(testbedPort),
88 "ubuntu@"+testbedIP)
89- adtRun(rootPath, remoteTestbedSSHOptions(testbedIP, testbedPort),
90- shellTestName)
91+ adtRun(rootPath, "", []string{}, remoteTestbedSSHOptions(testbedIP, testbedPort), true)
92 }
93 }
94
95@@ -103,9 +105,8 @@
96
97 func buildTests(arch string) {
98 fmt.Println("Building tests...")
99- tests := []string{"latest", "failover", "update"}
100- for i := range tests {
101- testName := tests[i]
102+
103+ for _, testName := range testPackages {
104 goCall(arch, "test", "-c",
105 "./_integration-tests/tests/"+testName)
106 // XXX Go test 1.3 does not have the output flag, so we move the
107@@ -143,26 +144,56 @@
108 execCommand(append(udfCommand, coreOptions...)...)
109 }
110
111-func adtRun(rootPath string, testbedOptions []string, testname string) {
112+func adtRun(rootPath, testFilter string, testList, testbedOptions []string, includeShell bool) {
113+ createControlFile(testFilter, testList, includeShell)
114+
115 fmt.Println("Calling adt-run...")
116- outputDir := filepath.Join(baseDir, "output")
117+ outputSubdir := getOutputSubdir(testList, includeShell)
118+ outputDir := filepath.Join(baseDir, "output", outputSubdir)
119 prepareTargetDir(outputDir)
120
121 cmd := []string{
122 "adt-run", "-B",
123- "--override-control", "debian/integration-tests/control"}
124-
125- cmd = append(cmd, "--testname", testname)
126-
127- cmd = append(cmd, []string{
128 "--setup-commands", "touch /run/autopkgtest_no_reboot.stamp",
129- "--override-control", "debian/integration-tests/control",
130+ "--override-control", controlFile,
131 "--built-tree", rootPath,
132- "--output-dir", outputDir}...)
133+ "--output-dir", outputDir}
134
135 execCommand(append(cmd, testbedOptions...)...)
136 }
137
138+func createControlFile(testFilter string, testList []string, includeShellTest bool) {
139+ type controlData struct {
140+ Filter string
141+ Tests []string
142+ IncludeShell bool
143+ }
144+
145+ tpl, err := template.ParseFiles(controlTpl)
146+ if err != nil {
147+ log.Fatalf("Error reading adt-run control template %s", controlTpl)
148+ }
149+
150+ outputFile, err := os.Create(controlFile)
151+ if err != nil {
152+ log.Fatalf("Error creating control file %s", controlFile)
153+ }
154+ defer outputFile.Close()
155+
156+ err = tpl.Execute(outputFile, controlData{Filter: testFilter, Tests: testList, IncludeShell: includeShellTest})
157+ if err != nil {
158+ log.Fatalf("execution: %s", err)
159+ }
160+}
161+
162+func getOutputSubdir(testList []string, includeShell bool) string {
163+ output := strings.Join(testList, "-")
164+ if includeShell {
165+ output = output + "-shell"
166+ }
167+ return output
168+}
169+
170 func remoteTestbedSSHOptions(testbedIP string, testbedPort int) []string {
171 options := []string{
172 "-H", testbedIP,
173@@ -199,9 +230,11 @@
174 "IP of the testbed. If no IP is passed, a virtual machine will be created for the test.")
175 testbedPort = flag.Int("port", defaultSSHPort,
176 "SSH port of the testbed. Defaults to use port "+strconv.Itoa(defaultSSHPort))
177+ testFilter = flag.String("filter", "",
178+ "Suites or tests to run, for instance MyTestSuite, MyTestSuite.FirstCustomTest or MyTestSuite.*CustomTest")
179 )
180
181 flag.Parse()
182
183- setupAndRunTests(*useSnappyFromBranch, *arch, *testbedIP, *testbedPort)
184+ setupAndRunTests(*useSnappyFromBranch, *arch, *testbedIP, *testFilter, *testbedPort)
185 }
186
187=== removed file 'debian/integration-tests/control'
188--- debian/integration-tests/control 2015-06-30 15:29:28 +0000
189+++ debian/integration-tests/control 1970-01-01 00:00:00 +0000
190@@ -1,11 +0,0 @@
191-Test-Command: debian/integration-tests/snappy-test latest.test
192-Restrictions: allow-stderr
193-
194-Test-Command: debian/integration-tests/snappy-test failover.test
195-Restrictions: allow-stderr
196-
197-Test-Command: debian/integration-tests/snappy-test update.test
198-Restrictions: allow-stderr
199-
200-Test-Command: ./_integration-tests/snappy-selftest --yes-really
201-Depends:
202
203=== modified file 'debian/integration-tests/snappy-test'
204--- debian/integration-tests/snappy-test 2015-07-03 11:04:00 +0000
205+++ debian/integration-tests/snappy-test 2015-07-06 07:48:48 +0000
206@@ -23,7 +23,10 @@
207
208 export PATH=$(pwd)/_integration-tests/bin:$PATH
209
210-${TEST} -check.vv -test.outputdir=$ADT_ARTIFACTS-$ADT_REBOOT_MARK
211+# shift to remove the test binary name (first argument) and be able to pass the rest
212+# of them to it
213+shift
214+${TEST} -check.vv -test.outputdir=$ADT_ARTIFACTS-$ADT_REBOOT_MARK "$@"
215
216 if [ -e ${NEEDS_REBOOT} ]; then
217 mark=`cat ${NEEDS_REBOOT}`

Subscribers

People subscribed via source and target branches