Skip to content

Commit 2940fa0

Browse files
committed
Testing commit
1 parent bf8f83f commit 2940fa0

File tree

4 files changed

+9923
-12
lines changed

4 files changed

+9923
-12
lines changed

Gopkg.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/remote/run_remote/run_remote.go

+53-11
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"
@@ -36,6 +37,7 @@ import (
3637

3738
"github.com/golang/glog"
3839
"golang.org/x/oauth2/google"
40+
"google.golang.org/api/cloudresourcemanager/v1"
3941
compute "google.golang.org/api/compute/v0.beta"
4042
)
4143

@@ -110,7 +112,9 @@ func main() {
110112
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.")
111113
}
112114

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

127131
*project = p.GetName()
128132

133+
glog.Infof("Fetched project from Boskos: %v", *project)
134+
129135
go func(c *client.Client, proj string) {
130136
for range time.Tick(time.Minute * 5) {
131137
if err := c.UpdateOne(p.Name, "busy", nil); err != nil {
@@ -300,7 +306,8 @@ func createInstance(serviceAccount string) (string, error) {
300306
myuuid := string(uuid.NewUUID())
301307
glog.V(2).Infof("Creating instance: %v", name)
302308

303-
imageURL := "https://www.googleapis.com/compute/v1/projects/ml-images/global/images/debian-9-tf-1-9-v20180626"
309+
// TODO: Pick a better boot disk image
310+
imageURL := "projects/ml-images/global/images/family/tf-1-9"
304311
i := &compute.Instance{
305312
Name: name,
306313
MachineType: machineType(""),
@@ -326,18 +333,49 @@ func createInstance(serviceAccount string) (string, error) {
326333
},
327334
}
328335

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

337-
var err error
353+
c, err := google.DefaultClient(context.TODO(), cloudresourcemanager.CloudPlatformScope)
354+
if err != nil {
355+
glog.Fatal(err)
356+
}
357+
358+
cloudresourcemanagerService, err := cloudresourcemanager.New(c)
359+
if err != nil {
360+
glog.Fatal(err)
361+
}
362+
363+
resp, err := cloudresourcemanagerService.Projects.Get(*project).Do()
364+
if err != nil {
365+
glog.Fatal(err)
366+
}
367+
368+
// TODO: Somehow need to get that one default Compute Engine service account
369+
// [PROJECT_NUMBER][email protected]
370+
saObj := &compute.ServiceAccount{
371+
Email: fmt.Sprintf("%[email protected]", resp.ProjectNumber),
372+
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
373+
}
374+
i.ServiceAccounts = []*compute.ServiceAccount{saObj}
375+
338376
if gotInstance, err := computeService.Instances.Get(*project, *zone, i.Name).Do(); err != nil {
339377
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)
378+
glog.Infof("Inserted instance in project %v, zone %v: %#v", *project, *zone, i)
341379
if err != nil {
342380
ret := fmt.Sprintf("could not create instance %s: API error: %v", name, err)
343381
if op != nil {
@@ -348,7 +386,7 @@ func createInstance(serviceAccount string) (string, error) {
348386
return "", fmt.Errorf("could not create instance %s: %+v", name, op.Error)
349387
}
350388
} else {
351-
glog.V(4).Infof("Compute service GOT instance %v, skipping instance creation: %#v", i.Name, gotInstance)
389+
glog.Infof("Compute service GOT instance %v, skipping instance creation: %#v", i.Name, gotInstance)
352390
}
353391

354392
pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE")
@@ -360,7 +398,7 @@ func createInstance(serviceAccount string) (string, error) {
360398
return "", fmt.Errorf("could not add Jenkins public key %v to instance %v: %v", pubkey, i.Name, err)
361399
}
362400
} else {
363-
glog.V(4).Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
401+
glog.Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE not set, not adding SSH public key to instance")
364402
}
365403

366404
then := time.Now()
@@ -521,3 +559,7 @@ func testsToGinkgoFocus(tests []string) string {
521559
}
522560
return focus + "\""
523561
}
562+
563+
func opIsDone(op *compute.Operation) bool {
564+
return op != nil && op.Status == "DONE"
565+
}

0 commit comments

Comments
 (0)