// Run tests in archive against host func testHost(host string, deleteFiles bool, junitFileNum int, setupNode bool) *TestResult { instance, err := computeService.Instances.Get(*project, *zone, host).Do() if err != nil { return &TestResult{ err: err, host: host, exitOk: false, } } if strings.ToUpper(instance.Status) != "RUNNING" { err = fmt.Errorf("instance %s not in state RUNNING, was %s.", host, instance.Status) return &TestResult{ err: err, host: host, exitOk: false, } } externalIp := getExternalIp(instance) if len(externalIp) > 0 { e2e_node.AddHostnameIp(host, externalIp) } path, err := arc.getArchive() if err != nil { // Don't log fatal because we need to do any needed cleanup contained in "defer" statements return &TestResult{ err: fmt.Errorf("unable to create test archive %v.", err), } } output, exitOk, err := e2e_node.RunRemote(path, host, deleteFiles, junitFileNum, setupNode, *testArgs) return &TestResult{ output: output, err: err, host: host, exitOk: exitOk, } }
// Provision a gce instance using image func createInstance(image, imageProject string) (string, error) { name := imageToInstanceName(image) i := &compute.Instance{ Name: name, MachineType: machineType(), NetworkInterfaces: []*compute.NetworkInterface{ { AccessConfigs: []*compute.AccessConfig{ { Type: "ONE_TO_ONE_NAT", Name: "External NAT", }, }}, }, Disks: []*compute.AttachedDisk{ { AutoDelete: true, Boot: true, Type: "PERSISTENT", InitializeParams: &compute.AttachedDiskInitializeParams{ SourceImage: sourceImage(image, imageProject), }, }, }, } if *instanceMetadata != "" { raw := parseInstanceMetadata(*instanceMetadata) i.Metadata = &compute.Metadata{} metadata := []*compute.MetadataItems{} for k, v := range raw { val := v metadata = append(metadata, &compute.MetadataItems{ Key: k, Value: &val, }) } i.Metadata.Items = metadata } op, err := computeService.Instances.Insert(*project, *zone, i).Do() if err != nil { return "", err } if op.Error != nil { return "", fmt.Errorf("could not create instance %s: %+v", name, op.Error) } instanceRunning := false for i := 0; i < 30 && !instanceRunning; i++ { if i > 0 { time.Sleep(time.Second * 20) } var instance *compute.Instance instance, err = computeService.Instances.Get(*project, *zone, name).Do() if err != nil { continue } if strings.ToUpper(instance.Status) != "RUNNING" { err = fmt.Errorf("instance %s not in state RUNNING, was %s.", name, instance.Status) continue } externalIp := getExternalIp(instance) if len(externalIp) > 0 { e2e_node.AddHostnameIp(name, externalIp) } var output string output, err = e2e_node.RunSshCommand("ssh", e2e_node.GetHostnameOrIp(name), "--", "sudo", "docker", "version") if err != nil { err = fmt.Errorf("instance %s not running docker daemon - Command failed: %s", name, output) continue } if !strings.Contains(output, "Server") { err = fmt.Errorf("instance %s not running docker daemon - Server not found: %s", name, output) continue } instanceRunning = true } return name, err }