From e6ba228815c71ae21a74f12949ca8fa044d8b678 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Wed, 6 May 2015 16:29:50 -0700 Subject: [PATCH] Replace gcutil with gcloud usage --- integration/common/gce.go | 15 +++++++++++---- integration/framework/framework.go | 4 ++-- integration/runner/runner.go | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/integration/common/gce.go b/integration/common/gce.go index c563a5b7..8f4edd5c 100644 --- a/integration/common/gce.go +++ b/integration/common/gce.go @@ -15,6 +15,7 @@ package common import ( + "flag" "fmt" "os/exec" "regexp" @@ -22,8 +23,10 @@ import ( "github.com/GoogleCloudPlatform/gcloud-golang/compute/metadata" ) -var gceInternalIpRegexp = regexp.MustCompile(" +ip +\\| +([0-9.:]+) +") -var gceExternalIpRegexp = regexp.MustCompile("external-ip +\\| +([0-9.:]+) +") +var zone = flag.String("zone", "us-central1-f", "Zone the instances are running in") + +var gceInternalIpRegexp = regexp.MustCompile(" +networkIP: +([0-9.:]+)\n") +var gceExternalIpRegexp = regexp.MustCompile(" +natIP: +([0-9.:]+)\n") // Gets the IP of the specified GCE instance. func GetGceIp(hostname string) (string, error) { @@ -31,9 +34,9 @@ func GetGceIp(hostname string) (string, error) { return "127.0.0.1", nil } - out, err := exec.Command("gcutil", "getinstance", hostname).CombinedOutput() + out, err := exec.Command("gcloud", "compute", "instances", "describe", GetZoneFlag(), hostname).CombinedOutput() if err != nil { - return "", err + return "", fmt.Errorf("failed to get instance information for %q with error %v and output %s", hostname, err, string(out)) } // Use the internal IP within GCE and the external one outside. @@ -48,3 +51,7 @@ func GetGceIp(hostname string) (string, error) { } return matches[1], nil } + +func GetZoneFlag() string { + return fmt.Sprintf("--zone=%s", *zone) +} diff --git a/integration/framework/framework.go b/integration/framework/framework.go index e5992c98..f2e80155 100644 --- a/integration/framework/framework.go +++ b/integration/framework/framework.go @@ -265,7 +265,7 @@ func (self shellActions) Run(command string, args ...string) (string, string) { cmd = exec.Command(command, args...) } else { // We must SSH to the remote machine and run the command. - cmd = exec.Command("gcutil", append([]string{"ssh", self.fm.Hostname().GceInstanceName, command}, args...)...) + cmd = exec.Command("gcloud", append([]string{"compute", "ssh", common.GetZoneFlag(), self.fm.Hostname().GceInstanceName, "--", command}, args...)...) } var stdout bytes.Buffer var stderr bytes.Buffer @@ -286,7 +286,7 @@ func (self shellActions) RunStress(command string, args ...string) (string, stri cmd = exec.Command(command, args...) } else { // We must SSH to the remote machine and run the command. - cmd = exec.Command("gcutil", append([]string{"ssh", self.fm.Hostname().GceInstanceName, command}, args...)...) + cmd = exec.Command("gcloud", append([]string{"compute", "ssh", common.GetZoneFlag(), self.fm.Hostname().GceInstanceName, "--", command}, args...)...) } var stdout bytes.Buffer var stderr bytes.Buffer diff --git a/integration/runner/runner.go b/integration/runner/runner.go index 59787754..1e00ee96 100644 --- a/integration/runner/runner.go +++ b/integration/runner/runner.go @@ -49,19 +49,19 @@ func RunCommand(cmd string, args ...string) error { func PushAndRunTests(host, testDir string) error { // Push binary. glog.Infof("Pushing cAdvisor binary to %q...", host) - err := RunCommand("gcutil", "ssh", host, "mkdir", "-p", testDir) + err := RunCommand("gcloud", "compute", "ssh", common.GetZoneFlag(), host, "--", "mkdir", "-p", testDir) if err != nil { - return err + return fmt.Errorf("failed to make remote testing directory: %v", err) } defer func() { - err := RunCommand("gcutil", "ssh", host, "rm", "-rf", testDir) + err := RunCommand("gcloud", "compute", "ssh", common.GetZoneFlag(), host, "--", "rm", "-rf", testDir) if err != nil { - glog.Error(err) + glog.Errorf("Failed to cleanup test directory: %v", err) } }() - err = RunCommand("gcutil", "push", host, cadvisorBinary, testDir) + err = RunCommand("gcloud", "compute", "copy-files", common.GetZoneFlag(), cadvisorBinary, fmt.Sprintf("%s:%s", host, testDir)) if err != nil { - return err + return fmt.Errorf("failed to copy binary: %v", err) } // TODO(vmarmol): Get logs in case of failures. @@ -70,21 +70,21 @@ func PushAndRunTests(host, testDir string) error { portStr := strconv.Itoa(*port) errChan := make(chan error) go func() { - err = RunCommand("gcutil", "ssh", host, "sudo", path.Join(testDir, cadvisorBinary), "--port", portStr, "--logtostderr") + err = RunCommand("gcloud", "compute", "ssh", common.GetZoneFlag(), host, "--command", fmt.Sprintf("sudo %s --port %s --logtostderr", path.Join(testDir, cadvisorBinary), portStr)) if err != nil { - errChan <- err + errChan <- fmt.Errorf("error running cAdvisor: %v", err) } }() defer func() { - err := RunCommand("gcutil", "ssh", host, "sudo", "pkill", cadvisorBinary) + err := RunCommand("gcloud", "compute", "ssh", common.GetZoneFlag(), host, "--", "sudo", "pkill", cadvisorBinary) if err != nil { - glog.Error(err) + glog.Errorf("Failed to cleanup: %v", err) } }() ipAddress, err := common.GetGceIp(host) if err != nil { - return err + return fmt.Errorf("failed to get GCE IP: %v", err) } // Wait for cAdvisor to come up.