Skip to content

Commit fb7fd23

Browse files
author
Xuewei Zhang
committed
Add logic for renting test project from Boskos
1 parent e1939eb commit fb7fd23

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ e2e-test: vet fmt build-tar
115115
-image=$(VM_IMAGE) -image-project=$(IMAGE_PROJECT) \
116116
-ssh-user=$(SSH_USER) -ssh-key=$(SSH_KEY) \
117117
-npd-build-tar=`pwd`/$(TARBALL) \
118+
-boskos-project-type=$(BOSKOS_PROJECT_TYPE) -job-name=$(JOB_NAME) \
118119
-artifacts-dir=$(ARTIFACTS)
119120

120121
build-binaries: ./bin/node-problem-detector ./bin/log-counter

test/e2e/metriconly/e2e_npd_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ limitations under the License.
1717
package e2e_metric_only
1818

1919
import (
20+
"context"
2021
"flag"
2122
"fmt"
2223
"os"
2324
"path"
2425
"testing"
26+
"time"
2527

2628
"k8s.io/node-problem-detector/test/e2e/lib/gce"
29+
"k8s.io/test-infra/boskos/client"
2730

2831
"github.com/onsi/ginkgo"
2932
"github.com/onsi/ginkgo/reporters"
@@ -36,10 +39,17 @@ var zone = flag.String("zone", "", "gce zone the hosts live in")
3639
var project = flag.String("project", "", "gce project the hosts live in")
3740
var image = flag.String("image", "", "image to test")
3841
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")
3943
var sshKey = flag.String("ssh-key", "", "path to ssh private key.")
4044
var sshUser = flag.String("ssh-user", "", "use predefined user for ssh.")
4145
var npdBuildTar = flag.String("npd-build-tar", "", "tarball containing NPD to be tested.")
4246
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.")
4353

4454
var computeService *compute.Service
4555

@@ -48,6 +58,13 @@ func TestNPD(t *testing.T) {
4858
t.Skip("skipping test in short mode.")
4959
}
5060

61+
if *project == "" {
62+
boskosClient := client.NewClient(*jobName, *boskosServerURL)
63+
*project = acquireProjectOrDie(boskosClient)
64+
65+
defer releaseProjectOrDie(boskosClient)
66+
}
67+
5168
if *artifactsDir != "" {
5269
_, err := os.Stat(*artifactsDir)
5370
if err != nil && os.IsNotExist(err) {
@@ -60,6 +77,37 @@ func TestNPD(t *testing.T) {
6077
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "NPD Metric-only Suite", []ginkgo.Reporter{junitReporter})
6178
}
6279

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+
63111
func TestMain(m *testing.M) {
64112
flag.Parse()
65113

0 commit comments

Comments
 (0)