Skip to content

Commit

Permalink
Merge pull request #1144 from vishh/disk-e2e
Browse files Browse the repository at this point in the history
Fix test commands that are currently failing over ssh.
  • Loading branch information
Phillip Wittrock committed Mar 1, 2016
2 parents 8b2e8bd + 6556ce2 commit 1b64deb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
29 changes: 16 additions & 13 deletions integration/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

"github.com/golang/glog"
"github.com/google/cadvisor/client"
"github.com/google/cadvisor/client/v2"
)
Expand Down Expand Up @@ -239,8 +240,8 @@ type DockerRunArgs struct {
// RunDockerContainer(DockerRunArgs{Image: "busybox"}, "ping", "www.google.com")
// -> docker run busybox ping www.google.com
func (self dockerActions) Run(args DockerRunArgs, cmd ...string) string {
dockerCommand := append(append(append([]string{"docker", "run", "-d"}, args.Args...), args.Image), cmd...)

dockerCommand := append(append([]string{"docker", "run", "-d"}, args.Args...), args.Image)
dockerCommand = append(dockerCommand, cmd...)
output, _ := self.fm.Shell().Run("sudo", dockerCommand...)

// The last line is the container ID.
Expand All @@ -252,7 +253,6 @@ func (self dockerActions) Run(args DockerRunArgs, cmd ...string) string {
})
return containerId
}

func (self dockerActions) Version() []string {
dockerCommand := []string{"docker", "version", "-f", "'{{.Server.Version}}'"}
output, _ := self.fm.Shell().Run("sudo", dockerCommand...)
Expand Down Expand Up @@ -309,23 +309,30 @@ func (self dockerActions) RunStress(args DockerRunArgs, cmd ...string) string {
return containerId
}

func (self shellActions) wrapSsh(command string, args ...string) *exec.Cmd {
cmd := []string{self.fm.Hostname().Host, "--", "sh", "-c", "\"", command}
cmd = append(cmd, args...)
cmd = append(cmd, "\"")
if *sshOptions != "" {
cmd = append(strings.Split(*sshOptions, " "), cmd...)
}
return exec.Command("ssh", cmd...)
}

func (self shellActions) Run(command string, args ...string) (string, string) {
var cmd *exec.Cmd
if self.fm.Hostname().Host == "localhost" {
// Just run locally.
cmd = exec.Command(command, args...)
} else {
// We must SSH to the remote machine and run the command.
args = append([]string{self.fm.Hostname().Host, "--", command}, args...)
if *sshOptions != "" {
args = append(strings.Split(*sshOptions, " "), args...)
}
cmd = exec.Command("ssh", args...)
cmd = self.wrapSsh(command, args...)
}
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
glog.Errorf("About to run - %v", cmd.Args)
err := cmd.Run()
if err != nil {
self.fm.T().Fatalf("Failed to run %q %v in %q with error: %q. Stdout: %q, Stderr: %s", command, args, self.fm.Hostname().Host, err, stdout.String(), stderr.String())
Expand All @@ -341,11 +348,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.
args = append([]string{self.fm.Hostname().Host, "--", command}, args...)
if *sshOptions != "" {
args = append(strings.Split(*sshOptions, " "), args...)
}
cmd = exec.Command("ssh", args...)
cmd = self.wrapSsh(command, args...)
}
var stdout bytes.Buffer
var stderr bytes.Buffer
Expand Down
11 changes: 9 additions & 2 deletions integration/tests/api/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,14 @@ func TestDockerFilesystemStats(t *testing.T) {
sleepDuration = 10 * time.Second
)
// Wait for the container to show up.
containerId := fm.Docker().RunBusybox("/bin/sh", "-c", fmt.Sprintf("'dd if=/dev/zero of=/file count=2 bs=%d & sleep 10000'", ddUsage))
// FIXME: Tests should be bundled and run on the remote host instead of being run over ssh.
// Escaping bash over ssh is ugly.
// Once github issue 1130 is fixed, this logic can be removed.
dockerCmd := fmt.Sprintf("dd if=/dev/zero of=/file count=2 bs=%d & ping google.com", ddUsage)
if fm.Hostname().Host != "localhost" {
dockerCmd = fmt.Sprintf("'%s'", dockerCmd)
}
containerId := fm.Docker().RunBusybox("/bin/sh", "-c", dockerCmd)
waitForContainer(containerId, fm)
request := &v2.RequestOptions{
IdType: v2.TypeDocker,
Expand All @@ -317,7 +324,7 @@ func TestDockerFilesystemStats(t *testing.T) {
for i := 0; i < 10; i++ {
containerInfo, err := fm.Cadvisor().ClientV2().Stats(containerId, request)
if err != nil {
t.Logf("stats unavailable - %v", err)
t.Logf("%v stats unavailable - %v", time.Now().String(), err)
t.Logf("retrying after %s...", sleepDuration.String())
time.Sleep(sleepDuration)

Expand Down

0 comments on commit 1b64deb

Please sign in to comment.