2014-11-20 05:19:16 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-04-13 02:45:42 +00:00
|
|
|
"fmt"
|
2015-05-16 18:04:25 +00:00
|
|
|
"io/ioutil"
|
2014-11-20 05:19:16 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2016-01-28 14:19:25 +00:00
|
|
|
"strings"
|
2014-11-20 05:19:16 +00:00
|
|
|
|
2015-10-10 07:16:42 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2015-06-04 16:02:14 +00:00
|
|
|
"github.com/kr/pty"
|
2014-11-20 05:19:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// save a repo and try to load it using stdout
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
2015-05-16 14:59:53 +00:00
|
|
|
name := "test-save-and-load-repo-stdout"
|
2015-07-21 18:01:24 +00:00
|
|
|
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
2014-11-20 05:19:16 +00:00
|
|
|
|
|
|
|
repoName := "foobar-save-load-test"
|
2015-11-18 22:20:54 +00:00
|
|
|
before, _ := dockerCmd(c, "commit", name, repoName)
|
2016-01-28 14:19:25 +00:00
|
|
|
before = strings.TrimRight(before, "\n")
|
2014-11-20 05:19:16 +00:00
|
|
|
|
2015-05-16 18:04:25 +00:00
|
|
|
tmpFile, err := ioutil.TempFile("", "foobar-save-load-test.tar")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
defer os.Remove(tmpFile.Name())
|
|
|
|
|
|
|
|
saveCmd := exec.Command(dockerBinary, "save", repoName)
|
|
|
|
saveCmd.Stdout = tmpFile
|
|
|
|
|
2015-10-10 07:16:42 +00:00
|
|
|
_, err = runCommand(saveCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
2014-11-20 05:19:16 +00:00
|
|
|
|
2015-05-16 18:04:25 +00:00
|
|
|
tmpFile, err = os.Open(tmpFile.Name())
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2014-11-20 05:19:16 +00:00
|
|
|
deleteImages(repoName)
|
|
|
|
|
2015-05-16 18:04:25 +00:00
|
|
|
loadCmd := exec.Command(dockerBinary, "load")
|
|
|
|
loadCmd.Stdin = tmpFile
|
|
|
|
|
2015-11-18 22:20:54 +00:00
|
|
|
out, _, err := runCommandWithOutput(loadCmd)
|
2015-10-10 07:16:42 +00:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf(out))
|
2014-11-20 05:19:16 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
after := inspectField(c, repoName, "Id")
|
|
|
|
after = strings.TrimRight(after, "\n")
|
2014-11-20 05:19:16 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
c.Assert(after, check.Equals, before) //inspect is not the same after a save / load
|
2014-11-20 05:19:16 +00:00
|
|
|
|
|
|
|
deleteImages(repoName)
|
|
|
|
|
|
|
|
pty, tty, err := pty.Open()
|
2015-10-10 07:16:42 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
2014-11-20 05:19:16 +00:00
|
|
|
cmd := exec.Command(dockerBinary, "save", repoName)
|
|
|
|
cmd.Stdin = tty
|
|
|
|
cmd.Stdout = tty
|
|
|
|
cmd.Stderr = tty
|
2015-10-10 07:16:42 +00:00
|
|
|
c.Assert(cmd.Start(), check.IsNil)
|
|
|
|
c.Assert(cmd.Wait(), check.NotNil) //did not break writing to a TTY
|
2014-11-20 05:19:16 +00:00
|
|
|
|
|
|
|
buf := make([]byte, 1024)
|
|
|
|
|
|
|
|
n, err := pty.Read(buf)
|
2015-10-10 07:16:42 +00:00
|
|
|
c.Assert(err, check.IsNil) //could not read tty output
|
|
|
|
c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out))
|
2014-11-20 05:19:16 +00:00
|
|
|
}
|
2016-04-13 02:45:42 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) {
|
|
|
|
name := "test-load"
|
|
|
|
_, err := buildImage(name, `
|
|
|
|
FROM busybox
|
|
|
|
RUN touch aa
|
|
|
|
`, true)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
tmptar := name + ".tar"
|
|
|
|
dockerCmd(c, "save", "-o", tmptar, name)
|
|
|
|
defer os.Remove(tmptar)
|
|
|
|
|
|
|
|
dockerCmd(c, "rmi", name)
|
|
|
|
dockerCmd(c, "tag", "busybox", name)
|
|
|
|
out, _ := dockerCmd(c, "load", "-i", tmptar)
|
|
|
|
expected := fmt.Sprintf("The image %s:latest already exists, renaming the old one with ID", name)
|
|
|
|
c.Assert(out, checker.Contains, expected)
|
|
|
|
}
|