diff --git a/integration/framework/framework.go b/integration/framework/framework.go index a2d9b781..ffec41e4 100644 --- a/integration/framework/framework.go +++ b/integration/framework/framework.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/golang/glog" "github.com/google/cadvisor/client" "github.com/google/cadvisor/client/v2" ) @@ -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. @@ -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...) @@ -309,6 +309,16 @@ 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" { @@ -316,16 +326,13 @@ 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. - 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()) @@ -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 diff --git a/integration/tests/api/docker_test.go b/integration/tests/api/docker_test.go index 0b53b7b0..8279a148 100644 --- a/integration/tests/api/docker_test.go +++ b/integration/tests/api/docker_test.go @@ -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, @@ -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)