mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 04:06:24 +00:00
Add logic for renting test project from Boskos
This commit is contained in:
@@ -17,13 +17,16 @@ limitations under the License.
|
||||
package e2e_metric_only
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/node-problem-detector/test/e2e/lib/gce"
|
||||
"k8s.io/test-infra/boskos/client"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/onsi/ginkgo/reporters"
|
||||
@@ -36,10 +39,17 @@ var zone = flag.String("zone", "", "gce zone the hosts live in")
|
||||
var project = flag.String("project", "", "gce project the hosts live in")
|
||||
var image = flag.String("image", "", "image to test")
|
||||
var imageProject = flag.String("image-project", "", "gce project of the OS image")
|
||||
var jobName = flag.String("job-name", "", "name of the Prow job running the test")
|
||||
var sshKey = flag.String("ssh-key", "", "path to ssh private key.")
|
||||
var sshUser = flag.String("ssh-user", "", "use predefined user for ssh.")
|
||||
var npdBuildTar = flag.String("npd-build-tar", "", "tarball containing NPD to be tested.")
|
||||
var artifactsDir = flag.String("artifacts-dir", "", "local directory to save test artifacts into.")
|
||||
var boskosProjectType = flag.String("boskos-project-type", "gce-project",
|
||||
"specifies which project type to select from Boskos.")
|
||||
var boskosServerURL = flag.String("boskos-server-url", "http://boskos.test-pods.svc.cluster.local",
|
||||
"specifies Boskos server URL.")
|
||||
var boskosWaitDuration = flag.Duration("boskos-wait-duration", 5*time.Minute,
|
||||
"Duration to wait before quitting getting Boskos resource.")
|
||||
|
||||
var computeService *compute.Service
|
||||
|
||||
@@ -48,6 +58,13 @@ func TestNPD(t *testing.T) {
|
||||
t.Skip("skipping test in short mode.")
|
||||
}
|
||||
|
||||
if *project == "" {
|
||||
boskosClient := client.NewClient(*jobName, *boskosServerURL)
|
||||
*project = acquireProjectOrDie(boskosClient)
|
||||
|
||||
defer releaseProjectOrDie(boskosClient)
|
||||
}
|
||||
|
||||
if *artifactsDir != "" {
|
||||
_, err := os.Stat(*artifactsDir)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
@@ -60,6 +77,37 @@ func TestNPD(t *testing.T) {
|
||||
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "NPD Metric-only Suite", []ginkgo.Reporter{junitReporter})
|
||||
}
|
||||
|
||||
func acquireProjectOrDie(boskosClient *client.Client) string {
|
||||
fmt.Printf("Renting project from Boskos\n")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *boskosWaitDuration)
|
||||
defer cancel()
|
||||
p, err := boskosClient.AcquireWait(ctx, *boskosProjectType, "free", "busy")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Unable to rent project from Boskos: %v\n", err))
|
||||
}
|
||||
fmt.Printf("Rented project %s from Boskos", p.Name)
|
||||
|
||||
go func(boskosClient *client.Client, projectName string) {
|
||||
for range time.Tick(5 * time.Minute) {
|
||||
if err := boskosClient.UpdateOne(projectName, "busy", nil); err != nil {
|
||||
fmt.Printf("Failed to update status for project %s with Boskos: %v\n", projectName, err)
|
||||
}
|
||||
}
|
||||
}(boskosClient, p.Name)
|
||||
|
||||
return p.Name
|
||||
}
|
||||
|
||||
func releaseProjectOrDie(boskosClient *client.Client) {
|
||||
if !boskosClient.HasResource() {
|
||||
return
|
||||
}
|
||||
err := boskosClient.ReleaseAll("dirty")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Failed to release project to Boskos: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
flag.Parse()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user