Allow e2e test to pick up test VM image using image family

This commit is contained in:
Xuewei Zhang
2019-09-18 16:09:14 -07:00
parent 9828ab7f06
commit 1989ab3681
3 changed files with 11 additions and 1 deletions
+1
View File
@@ -38,6 +38,7 @@ const junitFileName = "junit.xml"
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 imageFamily = flag.String("image-family", "", "image family to pick up the test image. Ignored when -image is set.")
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.")
+9
View File
@@ -37,6 +37,15 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
var err error
// TODO(xueweiz): Creating instance for each test case is slow. We should either reuse the instance
// between tests, or have a way to run these tests in parallel.
if *imageFamily != "" && *image == "" {
gceImage, err := computeService.Images.GetFromFamily(*imageProject, *imageFamily).Do()
if err != nil {
ginkgo.Fail(fmt.Sprintf("Unable to get image from family %s at project %s: %v",
*imageFamily, *imageProject, err))
}
*image = gceImage.Name
fmt.Printf("Using image %s from image family %s at project %s\n", *image, *imageFamily, *imageProject)
}
instance, err = gce.CreateInstance(
gce.Instance{
Name: "npd-metrics-" + *image + "-" + uuid.NewUUID().String()[:8],