@@ -17,13 +17,16 @@ limitations under the License.
17
17
package e2e_metric_only
18
18
19
19
import (
20
+ "context"
20
21
"flag"
21
22
"fmt"
22
23
"os"
23
24
"path"
24
25
"testing"
26
+ "time"
25
27
26
28
"k8s.io/node-problem-detector/test/e2e/lib/gce"
29
+ "k8s.io/test-infra/boskos/client"
27
30
28
31
"github.com/onsi/ginkgo"
29
32
"github.com/onsi/ginkgo/reporters"
@@ -36,10 +39,17 @@ var zone = flag.String("zone", "", "gce zone the hosts live in")
36
39
var project = flag .String ("project" , "" , "gce project the hosts live in" )
37
40
var image = flag .String ("image" , "" , "image to test" )
38
41
var imageProject = flag .String ("image-project" , "" , "gce project of the OS image" )
42
+ var jobName = flag .String ("job-name" , "" , "name of the Prow job running the test" )
39
43
var sshKey = flag .String ("ssh-key" , "" , "path to ssh private key." )
40
44
var sshUser = flag .String ("ssh-user" , "" , "use predefined user for ssh." )
41
45
var npdBuildTar = flag .String ("npd-build-tar" , "" , "tarball containing NPD to be tested." )
42
46
var artifactsDir = flag .String ("artifacts-dir" , "" , "local directory to save test artifacts into." )
47
+ var boskosProjectType = flag .String ("boskos-project-type" , "gce-project" ,
48
+ "specifies which project type to select from Boskos." )
49
+ var boskosServerURL = flag .String ("boskos-server-url" , "http://boskos.test-pods.svc.cluster.local" ,
50
+ "specifies Boskos server URL." )
51
+ var boskosWaitDuration = flag .Duration ("boskos-wait-duration" , 5 * time .Minute ,
52
+ "Duration to wait before quitting getting Boskos resource." )
43
53
44
54
var computeService * compute.Service
45
55
@@ -48,6 +58,13 @@ func TestNPD(t *testing.T) {
48
58
t .Skip ("skipping test in short mode." )
49
59
}
50
60
61
+ if * project == "" {
62
+ boskosClient := client .NewClient (* jobName , * boskosServerURL )
63
+ * project = acquireProjectOrDie (boskosClient )
64
+
65
+ defer releaseProjectOrDie (boskosClient )
66
+ }
67
+
51
68
if * artifactsDir != "" {
52
69
_ , err := os .Stat (* artifactsDir )
53
70
if err != nil && os .IsNotExist (err ) {
@@ -60,6 +77,37 @@ func TestNPD(t *testing.T) {
60
77
ginkgo .RunSpecsWithDefaultAndCustomReporters (t , "NPD Metric-only Suite" , []ginkgo.Reporter {junitReporter })
61
78
}
62
79
80
+ func acquireProjectOrDie (boskosClient * client.Client ) string {
81
+ fmt .Printf ("Renting project from Boskos\n " )
82
+ ctx , cancel := context .WithTimeout (context .Background (), * boskosWaitDuration )
83
+ defer cancel ()
84
+ p , err := boskosClient .AcquireWait (ctx , * boskosProjectType , "free" , "busy" )
85
+ if err != nil {
86
+ panic (fmt .Sprintf ("Unable to rent project from Boskos: %v\n " , err ))
87
+ }
88
+ fmt .Printf ("Rented project %s from Boskos" , p .Name )
89
+
90
+ go func (boskosClient * client.Client , projectName string ) {
91
+ for range time .Tick (5 * time .Minute ) {
92
+ if err := boskosClient .UpdateOne (projectName , "busy" , nil ); err != nil {
93
+ fmt .Printf ("Failed to update status for project %s with Boskos: %v\n " , projectName , err )
94
+ }
95
+ }
96
+ }(boskosClient , p .Name )
97
+
98
+ return p .Name
99
+ }
100
+
101
+ func releaseProjectOrDie (boskosClient * client.Client ) {
102
+ if ! boskosClient .HasResource () {
103
+ return
104
+ }
105
+ err := boskosClient .ReleaseAll ("dirty" )
106
+ if err != nil {
107
+ panic (fmt .Sprintf ("Failed to release project to Boskos: %v" , err ))
108
+ }
109
+ }
110
+
63
111
func TestMain (m * testing.M ) {
64
112
flag .Parse ()
65
113
0 commit comments