forked from kubernetes/test-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e.go
713 lines (634 loc) · 20.7 KB
/
e2e.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*
Copyright 2014 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.
*/
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"
"time"
"k8s.io/test-infra/kubetest/e2e"
"k8s.io/test-infra/kubetest/process"
"k8s.io/test-infra/kubetest/util"
)
// Add more default --test_args as we migrate them
func argFields(args, dump, ipRange string) []string {
f := strings.Fields(args)
if dump != "" {
f = util.SetFieldDefault(f, "--report-dir", dump)
// Disable logdump within ginkgo as it'll be done in kubetest anyway now.
f = util.SetFieldDefault(f, "--disable-log-dump", "true")
}
if ipRange != "" {
f = util.SetFieldDefault(f, "--cluster-ip-range", ipRange)
}
return f
}
func run(deploy deployer, o options) error {
cmd, err := deploy.KubectlCommand()
if err != nil {
return err
}
if cmd == nil {
cmd = exec.Command("./cluster/kubectl.sh")
}
if o.checkSkew {
cmd.Args = append(cmd.Args, "--match-server-version")
}
os.Setenv("KUBECTL", strings.Join(cmd.Args, " "))
os.Setenv("KUBE_CONFIG_FILE", "config-test.sh")
os.Setenv("KUBE_RUNTIME_CONFIG", o.runtimeConfig)
var errs []error
dump, err := util.OptionalAbsPath(o.dump)
if err != nil {
return fmt.Errorf("failed handling --dump path: %v", err)
}
dumpPreTestLogs, err := util.OptionalAbsPath(o.dumpPreTestLogs)
if err != nil {
return fmt.Errorf("failed handling --dump-pre-test-logs path: %v", err)
}
if o.up {
if err := control.XMLWrap(&suite, "TearDown Previous", deploy.Down); err != nil {
return fmt.Errorf("error tearing down previous cluster: %s", err)
}
}
// Ensures that the cleanup/down action is performed exactly once.
var (
downDone = false
)
var (
beforeResources []byte
upResources []byte
downResources []byte
afterResources []byte
)
if o.checkLeaks {
errs = util.AppendError(errs, control.XMLWrap(&suite, "listResources Before", func() error {
beforeResources, err = listResources()
return err
}))
}
if o.up {
// If we tried to bring the cluster up, make a courtesy
// attempt to bring it down so we're not leaving resources around.
if o.down {
defer control.XMLWrap(&suite, "Deferred TearDown", func() error {
if !downDone {
return deploy.Down()
}
return nil
})
}
// Start the cluster using this version.
if err := control.XMLWrap(&suite, "Up", deploy.Up); err != nil {
if dump != "" {
control.XMLWrap(&suite, "DumpClusterLogs (--up failed)", func() error {
// This frequently means the cluster does not exist.
// Thus DumpClusterLogs() typically fails.
// Therefore always return null for this scenarios.
// TODO(fejta): report a green E in testgrid if it errors.
deploy.DumpClusterLogs(dump, o.logexporterGCSPath)
return nil
})
}
return fmt.Errorf("starting e2e cluster: %s", err)
}
// If node testing is enabled, check that the api is reachable before
// proceeding with further steps. This is accomplished by listing the nodes.
if !o.nodeTests {
errs = util.AppendError(errs, control.XMLWrap(&suite, "Check APIReachability", func() error { return getKubectlVersion(deploy) }))
if dump != "" {
errs = util.AppendError(errs, control.XMLWrap(&suite, "list nodes", func() error {
return listNodes(deploy, dump)
}))
}
}
}
if o.checkLeaks {
errs = util.AppendError(errs, control.XMLWrap(&suite, "listResources Up", func() error {
upResources, err = listResources()
return err
}))
}
if o.upgradeArgs != "" {
if err := control.XMLWrap(&suite, "test setup", deploy.TestSetup); err != nil {
errs = util.AppendError(errs, err)
} else {
errs = util.AppendError(errs, control.XMLWrap(&suite, "UpgradeTest", func() error {
// upgrade tests really only run one spec
var env []string
for _, v := range os.Environ() {
if !strings.HasPrefix(v, "GINKGO_PARALLEL") {
env = append(env, v)
}
}
return skewTestEnv(env, argFields(o.upgradeArgs, dump, o.clusterIPRange), "upgrade", o.checkSkew)
}))
}
}
if dumpPreTestLogs != "" {
errs = append(errs, dumpRemoteLogs(deploy, o, dumpPreTestLogs, "pre-test")...)
}
testArgs := argFields(o.testArgs, dump, o.clusterIPRange)
if o.test {
if err := control.XMLWrap(&suite, "test setup", deploy.TestSetup); err != nil {
errs = util.AppendError(errs, err)
} else if o.nodeTests {
nodeArgs := strings.Fields(o.nodeArgs)
errs = util.AppendError(errs, control.XMLWrap(&suite, "Node Tests", func() error {
return nodeTest(nodeArgs, o.testArgs, o.nodeTestArgs, o.gcpProject, o.gcpZone)
}))
} else if err := control.XMLWrap(&suite, "IsUp", deploy.IsUp); err != nil {
errs = util.AppendError(errs, err)
} else {
if o.deployment != "conformance" {
errs = util.AppendError(errs, control.XMLWrap(&suite, "kubectl version", func() error { return getKubectlVersion(deploy) }))
}
if o.skew {
errs = util.AppendError(errs, control.XMLWrap(&suite, "SkewTest", func() error {
return skewTest(testArgs, "skew", o.checkSkew)
}))
} else {
var tester e2e.Tester
tester = &GinkgoScriptTester{}
if testBuilder, ok := deploy.(e2e.TestBuilder); ok {
tester, err = testBuilder.BuildTester(toBuildTesterOptions(&o))
errs = util.AppendError(errs, err)
}
if tester != nil {
errs = util.AppendError(errs, control.XMLWrap(&suite, "Test", func() error {
return tester.Run(control, testArgs)
}))
}
}
}
}
if o.kubemark {
errs = util.AppendError(errs, control.XMLWrap(&suite, "Kubemark Overall", func() error {
if err := kubemarkUp(dump, o, deploy); err != nil {
return err
}
// running test in clusterloader, or other custom commands, skip the ginkgo call
if o.testCmd != "" {
return nil
}
return kubemarkGinkgoTest(testArgs, dump)
}))
}
if o.testCmd != "" {
if err := control.XMLWrap(&suite, "test setup", deploy.TestSetup); err != nil {
errs = util.AppendError(errs, err)
} else {
errs = util.AppendError(errs, control.XMLWrap(&suite, o.testCmdName, func() error {
cmdLine := os.ExpandEnv(o.testCmd)
return control.FinishRunning(exec.Command(cmdLine, o.testCmdArgs...))
}))
}
}
// TODO: consider remapping charts, etc to testCmd
var kubemarkWg sync.WaitGroup
var kubemarkDownErr error
if o.kubemark {
kubemarkWg.Add(1)
go kubemarkDown(&kubemarkDownErr, &kubemarkWg, dump)
}
if o.charts {
errs = util.AppendError(errs, control.XMLWrap(&suite, "Helm Charts", chartsTest))
}
if dump != "" {
errs = append(errs, dumpRemoteLogs(deploy, o, dump, "")...)
}
if o.checkLeaks {
errs = util.AppendError(errs, control.XMLWrap(&suite, "listResources Down", func() error {
downResources, err = listResources()
return err
}))
}
if o.down {
errs = util.AppendError(errs, control.XMLWrap(&suite, "TearDown", func() error {
if !downDone {
err := deploy.Down()
if err != nil {
return err
}
downDone = true
}
return nil
}))
}
// Wait for kubemarkDown step to finish before going further.
kubemarkWg.Wait()
errs = util.AppendError(errs, kubemarkDownErr)
// Save the state if we upped a new cluster without downing it
if o.save != "" && ((!o.down && o.up) || (o.up && o.deployment != "none")) {
errs = util.AppendError(errs, control.XMLWrap(&suite, "Save Cluster State", func() error {
return saveState(o.save)
}))
}
if o.checkLeaks {
log.Print("Sleeping for 30 seconds...") // Wait for eventually consistent listing
time.Sleep(30 * time.Second)
if err := control.XMLWrap(&suite, "listResources After", func() error {
afterResources, err = listResources()
return err
}); err != nil {
errs = append(errs, err)
} else {
errs = util.AppendError(errs, control.XMLWrap(&suite, "diffResources", func() error {
return diffResources(beforeResources, upResources, downResources, afterResources, dump)
}))
}
}
if len(errs) == 0 {
if pub, ok := deploy.(publisher); ok {
errs = util.AppendError(errs, pub.Publish())
}
}
if len(errs) == 0 && o.publish != "" {
errs = util.AppendError(errs, control.XMLWrap(&suite, "Publish version", func() error {
// Use plaintext version file packaged with kubernetes.tar.gz
v, err := ioutil.ReadFile("version")
if err != nil {
return err
}
log.Printf("Set %s version to %s", o.publish, string(v))
return gcsWrite(o.publish, v)
}))
}
if len(errs) != 0 {
return fmt.Errorf("encountered %d errors: %v", len(errs), errs)
}
return nil
}
func getKubectlVersion(dp deployer) error {
cmd, err := dp.KubectlCommand()
if err != nil {
return err
}
if cmd == nil {
cmd = exec.Command("./cluster/kubectl.sh")
}
cmd.Args = append(cmd.Args, "--match-server-version=false", "version")
copied := *cmd
retries := 5
for {
_, err := control.Output(&copied)
if err == nil {
return nil
}
retries--
if retries == 0 {
return err
}
log.Printf("Failed to reach api. Sleeping for 10 seconds before retrying... (%v)", copied.Args)
time.Sleep(10 * time.Second)
}
}
func dumpRemoteLogs(deploy deployer, o options, path, reason string) []error {
if reason != "" {
reason += " "
}
var errs []error
errs = util.AppendError(errs, control.XMLWrap(&suite, reason+"DumpClusterLogs", func() error {
return deploy.DumpClusterLogs(path, o.logexporterGCSPath)
}))
return errs
}
func listNodes(dp deployer, dump string) error {
cmd, err := dp.KubectlCommand()
if err != nil {
return err
}
if cmd == nil {
cmd = exec.Command("./cluster/kubectl.sh")
}
cmd.Args = append(cmd.Args, "--match-server-version=false", "get", "nodes", "-oyaml")
b, err := control.Output(cmd)
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(dump, "nodes.yaml"), b, 0644)
}
func listKubemarkNodes(dp deployer, dump string) error {
cmd, err := dp.KubectlCommand()
if err != nil {
return err
}
if cmd == nil {
cmd = exec.Command("./cluster/kubectl.sh")
}
cmd.Args = append(cmd.Args, "--match-server-version=false", "--kubeconfig=./test/kubemark/resources/kubeconfig.kubemark", "get", "nodes", "-oyaml")
b, err := control.Output(cmd)
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(dump, "kubemark_nodes.yaml"), b, 0644)
}
func diffResources(before, clusterUp, clusterDown, after []byte, location string) error {
if location == "" {
var err error
location, err = ioutil.TempDir("", "e2e-check-resources")
if err != nil {
return fmt.Errorf("Could not create e2e-check-resources temp dir: %s", err)
}
}
var mode os.FileMode = 0664
bp := filepath.Join(location, "gcp-resources-before.txt")
up := filepath.Join(location, "gcp-resources-cluster-up.txt")
cdp := filepath.Join(location, "gcp-resources-cluster-down.txt")
ap := filepath.Join(location, "gcp-resources-after.txt")
dp := filepath.Join(location, "gcp-resources-diff.txt")
if err := ioutil.WriteFile(bp, before, mode); err != nil {
return err
}
if err := ioutil.WriteFile(up, clusterUp, mode); err != nil {
return err
}
if err := ioutil.WriteFile(cdp, clusterDown, mode); err != nil {
return err
}
if err := ioutil.WriteFile(ap, after, mode); err != nil {
return err
}
stdout, cerr := control.Output(exec.Command("diff", "-sw", "-U0", "-F^\\[.*\\]$", bp, ap))
if err := ioutil.WriteFile(dp, stdout, mode); err != nil {
return err
}
if cerr == nil { // No diffs
return nil
}
lines := strings.Split(string(stdout), "\n")
if len(lines) < 3 { // Ignore the +++ and --- header lines
return nil
}
lines = lines[2:]
var added, report []string
resourceTypeRE := regexp.MustCompile(`^@@.+\s(\[\s\S+\s\])$`)
for _, l := range lines {
if matches := resourceTypeRE.FindStringSubmatch(l); matches != nil {
report = append(report, matches[1])
}
if strings.HasPrefix(l, "+") && len(strings.TrimPrefix(l, "+")) > 0 {
added = append(added, l)
report = append(report, l)
}
}
if len(added) > 0 {
return fmt.Errorf("Error: %d leaked resources\n%v", len(added), strings.Join(report, "\n"))
}
return nil
}
func listResources() ([]byte, error) {
log.Printf("Listing resources...")
stdout, err := control.Output(exec.Command("./cluster/gce/list-resources.sh"))
if err != nil {
return stdout, fmt.Errorf("Failed to list resources (%s):\n%s", err, string(stdout))
}
return stdout, err
}
func clusterSize(deploy deployer) (int, error) {
if err := deploy.TestSetup(); err != nil {
return -1, err
}
o, err := control.Output(exec.Command("kubectl", "get", "nodes", "--no-headers"))
if err != nil {
log.Printf("kubectl get nodes failed: %s\n%s", wrapError(err).Error(), string(o))
return -1, err
}
stdout := strings.TrimSpace(string(o))
log.Printf("Cluster nodes:\n%s", stdout)
return len(strings.Split(stdout, "\n")), nil
}
// commandError will provide stderr output (if available) from structured
// exit errors
type commandError struct {
err error
}
func wrapError(err error) *commandError {
if err == nil {
return nil
}
return &commandError{err: err}
}
func (e *commandError) Error() string {
if e == nil {
return ""
}
exitErr, ok := e.err.(*exec.ExitError)
if !ok {
return e.err.Error()
}
stderr := ""
if exitErr.Stderr != nil {
stderr = string(stderr)
}
return fmt.Sprintf("%q: %q", exitErr.Error(), stderr)
}
func isUp(d deployer) error {
n, err := clusterSize(d)
if err != nil {
return err
}
if n <= 0 {
return fmt.Errorf("cluster found, but %d nodes reported", n)
}
return nil
}
func defaultDumpClusterLogs(localArtifactsDir, logexporterGCSPath string) error {
logDumpPath := "./cluster/log-dump/log-dump.sh"
// cluster/log-dump/log-dump.sh only exists in the Kubernetes tree
// post-1.3. If it doesn't exist, print a debug log but do not report an error.
if _, err := os.Stat(logDumpPath); err != nil {
log.Printf("Could not find %s. This is expected if running tests against a Kubernetes 1.3 or older tree.", logDumpPath)
if cwd, err := os.Getwd(); err == nil {
log.Printf("CWD: %v", cwd)
}
return nil
}
var cmd *exec.Cmd
if logexporterGCSPath != "" {
log.Printf("Dumping logs from nodes to GCS directly at path: %v", logexporterGCSPath)
cmd = exec.Command(logDumpPath, localArtifactsDir, logexporterGCSPath)
} else {
log.Printf("Dumping logs locally to: %v", localArtifactsDir)
cmd = exec.Command(logDumpPath, localArtifactsDir)
}
return control.FinishRunning(cmd)
}
func chartsTest() error {
// Run helm tests.
cmdline := util.K8s("charts", "test", "helm-test-e2e.sh")
return control.FinishRunning(exec.Command(cmdline))
}
func nodeTest(nodeArgs []string, testArgs, nodeTestArgs, project, zone string) error {
// Run node e2e tests.
// TODO(krzyzacy): remove once nodeTest is stable
if wd, err := os.Getwd(); err == nil {
log.Printf("cwd : %s", wd)
}
sshKeyPath := os.Getenv("JENKINS_GCE_SSH_PRIVATE_KEY_FILE")
if _, err := os.Stat(sshKeyPath); err != nil {
return fmt.Errorf("Cannot find ssh key from: %v, err : %v", sshKeyPath, err)
}
artifactsDir, ok := os.LookupEnv("ARTIFACTS")
if !ok {
// TODO(krzyzacy): old behavior, consider deprecate
artifactsDir = filepath.Join(os.Getenv("WORKSPACE"), "_artifacts")
}
// prep node args
runner := []string{
"run",
util.K8s("kubernetes", "test", "e2e_node", "runner", "remote", "run_remote.go"),
"--cleanup",
"--logtostderr",
"--vmodule=*=4",
"--ssh-env=gce",
fmt.Sprintf("--results-dir=%s", artifactsDir),
fmt.Sprintf("--project=%s", project),
fmt.Sprintf("--zone=%s", zone),
fmt.Sprintf("--ssh-user=%s", os.Getenv("USER")),
fmt.Sprintf("--ssh-key=%s", sshKeyPath),
fmt.Sprintf("--ginkgo-flags=%s", testArgs),
fmt.Sprintf("--test_args=%s", nodeTestArgs),
fmt.Sprintf("--test-timeout=%s", timeout.String()),
}
runner = append(runner, nodeArgs...)
return control.FinishRunning(exec.Command("go", runner...))
}
func kubemarkUp(dump string, o options, deploy deployer) error {
// Stop previously running kubemark cluster (if any).
if err := control.XMLWrap(&suite, "Kubemark TearDown Previous", func() error {
return control.FinishRunning(exec.Command("./test/kubemark/stop-kubemark.sh"))
}); err != nil {
return err
}
if err := control.XMLWrap(&suite, "IsUp", deploy.IsUp); err != nil {
return err
}
// Start kubemark cluster.
if err := control.XMLWrap(&suite, "Kubemark Up", func() error {
return control.FinishRunning(exec.Command("./test/kubemark/start-kubemark.sh"))
}); err != nil {
return err
}
// Check kubemark apiserver reachability by listing all nodes.
if dump != "" {
control.XMLWrap(&suite, "list kubemark nodes", func() error {
return listKubemarkNodes(deploy, dump)
})
}
// detect master IP
if err := os.Setenv("MASTER_NAME", os.Getenv("INSTANCE_PREFIX")+"-kubemark-master"); err != nil {
return err
}
masterIP, err := control.Output(exec.Command(
"gcloud", "compute", "addresses", "describe",
os.Getenv("MASTER_NAME")+"-ip",
"--project="+o.gcpProject,
"--region="+o.gcpZone[:len(o.gcpZone)-2],
"--format=value(address)"))
if err != nil {
return fmt.Errorf("failed to get masterIP: %v", err)
}
if err := os.Setenv("KUBE_MASTER_IP", strings.TrimSpace(string(masterIP))); err != nil {
return err
}
// MASTER_IP variable is required by the clusterloader. It requires to have master ip provided,
// due to master being unregistered.
if err := os.Setenv("MASTER_IP", strings.TrimSpace(string(masterIP))); err != nil {
return err
}
cwd, err := os.Getwd()
if err != nil {
return err
}
if err := os.Setenv("KUBECONFIG", fmt.Sprintf("%s/test/kubemark/resources/kubeconfig.kubemark", cwd)); err != nil {
return err
}
// 'Stop kubemark cluster' step has now been moved outside this function
// to make it asynchronous with other steps (to speed test execution).
return nil
}
func kubemarkGinkgoTest(testArgs []string, dump string) error {
if os.Getenv("ENABLE_KUBEMARK_CLUSTER_AUTOSCALER") == "true" {
testArgs = append(testArgs, "--kubemark-external-kubeconfig="+os.Getenv("DEFAULT_KUBECONFIG"))
}
// Run tests on the kubemark cluster.
return control.XMLWrap(&suite, "Kubemark Test", func() error {
testArgs = util.SetFieldDefault(testArgs, "--ginkgo.focus", "starting\\s30\\spods")
// TODO(krzyzacy): unsure if the envs in kubemark/util.sh makes a difference to e2e tests
// will verify and remove (or uncomment) next
//util := os.Getenv("WORKSPACE") + "/kubernetes/cluster/kubemark/util.sh"
//testArgs = append([]string{"-c", "source", util, " ; ./hack/ginkgo-e2e.sh"}, testArgs...)
cmd := exec.Command("./hack/ginkgo-e2e.sh", testArgs...)
cmd.Env = append(
os.Environ(),
"KUBERNETES_PROVIDER=kubemark",
"KUBE_CONFIG_FILE=config-default.sh",
"KUBE_MASTER_URL=https://"+os.Getenv("KUBE_MASTER_IP"),
)
return control.FinishRunning(cmd)
})
}
// Brings down the kubemark cluster.
func kubemarkDown(err *error, wg *sync.WaitGroup, dump string) {
defer wg.Done()
control.XMLWrap(&suite, "Kubemark MasterLogDump", func() error {
return control.FinishRunning(exec.Command("./test/kubemark/master-log-dump.sh", dump))
})
*err = control.XMLWrap(&suite, "Kubemark TearDown", func() error {
return control.FinishRunning(exec.Command("./test/kubemark/stop-kubemark.sh"))
})
}
// Runs tests in the kubernetes_skew directory, appending --report-prefix flag to the run
func skewTest(args []string, prefix string, checkSkew bool) error {
return skewTestEnv(nil, args, prefix, checkSkew)
}
// Runs tests in the kubernetes_skew directory, appending --report-prefix flag to the run
func skewTestEnv(env, args []string, prefix string, checkSkew bool) error {
// TODO(fejta): run this inside this kubetest process, do not spawn a new one.
popS, err := util.Pushd("../kubernetes_skew")
if err != nil {
return err
}
defer popS()
args = util.AppendField(args, "--report-prefix", prefix)
cmd := exec.Command(
"kubetest",
"--test",
"--test_args="+strings.Join(args, " "),
fmt.Sprintf("--check-version-skew=%t", checkSkew),
)
cmd.Env = env
return control.FinishRunning(cmd)
}
// GinkgoScriptTester implements Tester by calling the hack/ginkgo-e2e.sh script
type GinkgoScriptTester struct {
}
// Run executes ./hack/ginkgo-e2e.sh
func (t *GinkgoScriptTester) Run(control *process.Control, testArgs []string) error {
return control.FinishRunning(exec.Command("./hack/ginkgo-e2e.sh", testArgs...))
}
// toBuildTesterOptions builds the BuildTesterOptions data structure for passing to BuildTester
func toBuildTesterOptions(o *options) *e2e.BuildTesterOptions {
return &e2e.BuildTesterOptions{
FocusRegex: o.focusRegex,
SkipRegex: o.skipRegex,
Parallelism: o.ginkgoParallel.Get(),
}
}