Skip to content

Commit 4760fcb

Browse files
committed
Testing commit
1 parent bf8f83f commit 4760fcb

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

test/remote/run_remote/run_remote.go

+59-19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"math/rand"
2525
"net/http"
2626
"os"
27+
"os/exec"
2728
"strings"
2829
"sync"
2930
"time"
@@ -110,7 +111,9 @@ func main() {
110111
glog.Fatal("You must specify a service account to create an instance under that has at least OWNERS permissions on disks and READER on instances.")
111112
}
112113

113-
if *project == "" {
114+
// TODO: OVERWRITE PROJECT FOR TEST PURPOSES ONLY
115+
if true /* *project == "" */ {
116+
// TODO: Check if we're on CI and just overwrite project anyway if we are.
114117
// Try get a Boskos Project
115118
glog.Infof("--project is missing, trying to fetch a project from boskos.\n" +
116119
"(for local runs please set --project to your dev project)")
@@ -126,6 +129,8 @@ func main() {
126129

127130
*project = p.GetName()
128131

132+
glog.Infof("Fetched project from Boskos: %v", *project)
133+
129134
go func(c *client.Client, proj string) {
130135
for range time.Tick(time.Minute * 5) {
131136
if err := c.UpdateOne(p.Name, "busy", nil); err != nil {
@@ -300,7 +305,7 @@ func createInstance(serviceAccount string) (string, error) {
300305
myuuid := string(uuid.NewUUID())
301306
glog.V(2).Infof("Creating instance: %v", name)
302307

303-
imageURL := "https://www.googleapis.com/compute/v1/projects/ml-images/global/images/debian-9-tf-1-9-v20180626"
308+
imageURL := "projects/ml-images/global/images/family/tf-1-9"
304309
i := &compute.Instance{
305310
Name: name,
306311
MachineType: machineType(""),
@@ -326,18 +331,33 @@ func createInstance(serviceAccount string) (string, error) {
326331
},
327332
}
328333

329-
if serviceAccount != "" {
330-
saObj := &compute.ServiceAccount{
331-
Email: serviceAccount,
332-
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
334+
// TODO: OVERWRITE SERVICEACCOUNT FOR TEST PURPOSES ONLY
335+
if true /* serviceAccount == "" */ {
336+
// TODO: Check if on CI
337+
// Assume we are on CI and grab service account from gcloud
338+
glog.Infof("Running on CI, getting gcloud account")
339+
cmd := exec.Command("gcloud", "config", "get-value", "account")
340+
out, err := cmd.Output()
341+
342+
if err != nil {
343+
return "", fmt.Errorf("Failed to get current gclou account: %v", err)
333344
}
334-
i.ServiceAccounts = []*compute.ServiceAccount{saObj}
345+
346+
serviceAccount = string(out)
347+
glog.Infof("Got service account: %v", serviceAccount)
348+
335349
}
336350

351+
saObj := &compute.ServiceAccount{
352+
Email: serviceAccount,
353+
Scopes: []string{"https://www.googleapis.com/auth/compute"},
354+
}
355+
i.ServiceAccounts = []*compute.ServiceAccount{saObj}
356+
337357
var err error
338358
if gotInstance, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil {
339359
op, err := computeService.Instances.Insert(*project, *zone, i).Do()
340-
glog.V(4).Infof("Inserted instance in project %v, zone %v: %#v", *project, *zone, i)
360+
glog.Infof("Inserted instance in project %v, zone %v: %#v", *project, *zone, i)
341361
if err != nil {
342362
ret := fmt.Sprintf("could not create instance %s: API error: %v", name, err)
343363
if op != nil {
@@ -347,21 +367,37 @@ func createInstance(serviceAccount string) (string, error) {
347367
} else if op.Error != nil {
348368
return "", fmt.Errorf("could not create instance %s: %+v", name, op.Error)
349369
}
370+
371+
// WAIT FOR OP
372+
wait.Poll(3*time.Second, 5*time.Minute, func() (bool, error) {
373+
pollOp, err := computeService.ZoneOperations.Get(*project, *zone, op.Name).Do()
374+
if err != nil {
375+
glog.Errorf("WaitForOp(op: %#v, zone: %#v) failed to poll the operation: %v", op, zone, err)
376+
return false, err
377+
}
378+
glog.Infof("Insert Op data: %#v", pollOp)
379+
glog.Infof("Op Error: %v", pollOp.Error)
380+
done := opIsDone(pollOp)
381+
return done, err
382+
})
383+
350384
} else {
351-
glog.V(4).Infof("Compute service GOT instance %v, skipping instance creation: %#v", i.Name, gotInstance)
385+
glog.Infof("Compute service GOT instance %v, skipping instance creation: %#v", i.Name, gotInstance)
352386
}
353387

354-
pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE")
355-
if ok {
356-
glog.Infof("Running on Jenkins and JENKINS_GCE_SSH_PUBLIC_KEY_FILE set")
357-
// If we're on CI add public SSH keys to the instance
358-
err = addPubKeyToInstance(*project, *zone, i.Name, pubkey)
359-
if err != nil {
360-
return "", fmt.Errorf("could not add Jenkins public key %v to instance %v: %v", pubkey, i.Name, err)
388+
/*
389+
pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE")
390+
if ok {
391+
glog.Infof("Running on Jenkins and JENKINS_GCE_SSH_PUBLIC_KEY_FILE set")
392+
// If we're on CI add public SSH keys to the instance
393+
err = addPubKeyToInstance(*project, *zone, i.Name, pubkey)
394+
if err != nil {
395+
return "", fmt.Errorf("could not add Jenkins public key %v to instance %v: %v", pubkey, i.Name, err)
396+
}
397+
} else {
398+
glog.Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
361399
}
362-
} else {
363-
glog.V(4).Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
364-
}
400+
*/
365401

366402
then := time.Now()
367403
err = wait.Poll(10*time.Second, 5*time.Minute, func() (bool, error) {
@@ -521,3 +557,7 @@ func testsToGinkgoFocus(tests []string) string {
521557
}
522558
return focus + "\""
523559
}
560+
561+
func opIsDone(op *compute.Operation) bool {
562+
return op != nil && op.Status == "DONE"
563+
}

0 commit comments

Comments
 (0)