Skip to content

Commit

Permalink
Add logic for renting test project from Boscos
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuewei Zhang committed Sep 14, 2019
1 parent c576c0b commit 5bac900
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/e2e/metriconly/e2e_npd_test.go
Expand Up @@ -17,25 +17,35 @@ 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"
compute "google.golang.org/api/compute/v1"
)

const junitFileName = "junit.xml"
const boskosServerURL = "http://boskos.test-pods.svc.cluster.local"
const projectType = "gci-qa-project"
// const projectType = "gce-project"
// const boskosServerURL = "http://boskos"

const boskosTimeoutMinutes = 5

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.")
Expand All @@ -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) {
Expand All @@ -60,6 +77,35 @@ func TestNPD(t *testing.T) {
ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "NPD Metric-only Suite", []ginkgo.Reporter{junitReporter})
}

func acquireProjectOrDie(boskosClient *client.Client) string {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
p, err := boskosClient.AcquireWait(ctx, projectType, "free", "busy")
if err != nil {
panic(fmt.Sprintf("Unable to rent project from Boskos: %v", err))
}

go func(boskosClient *client.Client, projectName string) {
for range time.Tick(time.Minute * 5) {
if err := boskosClient.UpdateOne(projectName, "busy", nil); err != nil {
fmt.Printf("Failed to update status for project %s with Boskos: %v", 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()

Expand Down

0 comments on commit 5bac900

Please sign in to comment.