Merge pull request #692 from vmarmol/e2e
Replace gcutil with gcloud usage
This commit is contained in:
commit
6fec570484
@ -15,6 +15,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -22,8 +23,10 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/gcloud-golang/compute/metadata"
|
"github.com/GoogleCloudPlatform/gcloud-golang/compute/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gceInternalIpRegexp = regexp.MustCompile(" +ip +\\| +([0-9.:]+) +")
|
var zone = flag.String("zone", "us-central1-f", "Zone the instances are running in")
|
||||||
var gceExternalIpRegexp = regexp.MustCompile("external-ip +\\| +([0-9.:]+) +")
|
|
||||||
|
var gceInternalIpRegexp = regexp.MustCompile(" +networkIP: +([0-9.:]+)\n")
|
||||||
|
var gceExternalIpRegexp = regexp.MustCompile(" +natIP: +([0-9.:]+)\n")
|
||||||
|
|
||||||
// Gets the IP of the specified GCE instance.
|
// Gets the IP of the specified GCE instance.
|
||||||
func GetGceIp(hostname string) (string, error) {
|
func GetGceIp(hostname string) (string, error) {
|
||||||
@ -31,9 +34,9 @@ func GetGceIp(hostname string) (string, error) {
|
|||||||
return "127.0.0.1", nil
|
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 {
|
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.
|
// 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
|
return matches[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetZoneFlag() string {
|
||||||
|
return fmt.Sprintf("--zone=%s", *zone)
|
||||||
|
}
|
||||||
|
@ -265,7 +265,7 @@ func (self shellActions) Run(command string, args ...string) (string, string) {
|
|||||||
cmd = exec.Command(command, args...)
|
cmd = exec.Command(command, args...)
|
||||||
} else {
|
} else {
|
||||||
// We must SSH to the remote machine and run the command.
|
// 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 stdout bytes.Buffer
|
||||||
var stderr 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...)
|
cmd = exec.Command(command, args...)
|
||||||
} else {
|
} else {
|
||||||
// We must SSH to the remote machine and run the command.
|
// 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 stdout bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
|
@ -49,19 +49,19 @@ func RunCommand(cmd string, args ...string) error {
|
|||||||
func PushAndRunTests(host, testDir string) error {
|
func PushAndRunTests(host, testDir string) error {
|
||||||
// Push binary.
|
// Push binary.
|
||||||
glog.Infof("Pushing cAdvisor binary to %q...", host)
|
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 {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to make remote testing directory: %v", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
err := RunCommand("gcutil", "ssh", host, "rm", "-rf", testDir)
|
err := RunCommand("gcloud", "compute", "ssh", common.GetZoneFlag(), host, "--", "rm", "-rf", testDir)
|
||||||
if err != nil {
|
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 {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to copy binary: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(vmarmol): Get logs in case of failures.
|
// TODO(vmarmol): Get logs in case of failures.
|
||||||
@ -70,21 +70,21 @@ func PushAndRunTests(host, testDir string) error {
|
|||||||
portStr := strconv.Itoa(*port)
|
portStr := strconv.Itoa(*port)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
go func() {
|
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 {
|
if err != nil {
|
||||||
errChan <- err
|
errChan <- fmt.Errorf("error running cAdvisor: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
defer func() {
|
defer func() {
|
||||||
err := RunCommand("gcutil", "ssh", host, "sudo", "pkill", cadvisorBinary)
|
err := RunCommand("gcloud", "compute", "ssh", common.GetZoneFlag(), host, "--", "sudo", "pkill", cadvisorBinary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error(err)
|
glog.Errorf("Failed to cleanup: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ipAddress, err := common.GetGceIp(host)
|
ipAddress, err := common.GetGceIp(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to get GCE IP: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for cAdvisor to come up.
|
// Wait for cAdvisor to come up.
|
||||||
|
Loading…
Reference in New Issue
Block a user