Replace gcutil with gcloud usage

This commit is contained in:
Victor Marmol 2015-05-06 16:29:50 -07:00
parent e44420e887
commit e6ba228815
3 changed files with 24 additions and 17 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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.