More cleanup: volumes: do not export to stdout

This one got complicated, and deserves its own commit.

Problem: ginkgo logs have a lot of NUL characters, making them
difficult for logformatter to process and for humans to read.

Cause: Paul tracked it down to "podman volume export" without "-o"
(hence spitting out tar data to stdout).

Solution: add "-o tmpfile" to named podman-volume-export. In
the process, fix all sorts of other problems with that test.
And, since the e2e test no longer tests "volume export" by
itself, add a system test that does.

It is possible that there are other places that emit NULs.
One step at a time.

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago 2023-04-18 13:04:00 -06:00
parent 3050a64373
commit fbe62f329a
2 changed files with 49 additions and 8 deletions

View File

@ -85,18 +85,30 @@ var _ = Describe("Podman volume create", func() {
Skip("Volume export check does not work with a remote client")
}
session := podmanTest.Podman([]string{"volume", "create", "myvol"})
volName := "my_vol_" + RandomString(10)
session := podmanTest.Podman([]string{"volume", "create", volName})
session.WaitWithDefaultTimeout()
volName := session.OutputToString()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal(volName))
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"})
helloString := "hello-" + RandomString(20)
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo " + helloString + " >> /data/test"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
check := podmanTest.Podman([]string{"volume", "export", volName})
// export to tar file...
helloTar := filepath.Join(podmanTest.TempDir, "hello.tar")
check := podmanTest.Podman([]string{"volume", "export", "-o", helloTar, volName})
check.WaitWithDefaultTimeout()
Expect(check.OutputToString()).To(ContainSubstring("hello"))
Expect(check).Should(Exit(0))
// ...then confirm that tar file has our desired content.
// These flags emit filename to stderr (-v), contents to stdout
tar := SystemExec("tar", []string{"-x", "-v", "--to-stdout", "-f", helloTar})
tar.WaitWithDefaultTimeout()
Expect(tar).To(Exit(0))
Expect(tar.ErrorToString()).To(Equal("test"))
Expect(tar.OutputToString()).To(Equal(helloString))
})
It("podman create and import volume", func() {
@ -104,12 +116,13 @@ var _ = Describe("Podman volume create", func() {
Skip("Volume export check does not work with a remote client")
}
session := podmanTest.Podman([]string{"volume", "create", "my_vol"})
volName := "my_vol_" + RandomString(10)
session := podmanTest.Podman([]string{"volume", "create", volName})
session.WaitWithDefaultTimeout()
volName := session.OutputToString()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal(volName))
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"})
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> /data/test"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

View File

@ -258,6 +258,34 @@ EOF
run_podman volume rm my_vol2
}
# stdout with NULs is easier to test here than in ginkgo
@test "podman volume export to stdout" {
skip_if_remote "N/A on podman-remote"
local volname="myvol_$(random_string 10)"
local mountpoint="/data$(random_string 8)"
run_podman volume create $volname
assert "$output" == "$volname" "volume create emits the name it was given"
local content="mycontent-$(random_string 20)-the-end"
run_podman run --rm --volume "$volname:$mountpoint" $IMAGE \
sh -c "echo $content >$mountpoint/testfile"
assert "$output" = ""
# We can't use run_podman because bash can't handle NUL characters.
# Can't even store them in variables, so we need immediate redirection
# The "-v" is only for debugging: tar will emit the filename to stderr.
# If this test ever fails, that may give a clue.
echo "$_LOG_PROMPT $PODMAN volume export $volname | tar -x ..."
tar_output="$($PODMAN volume export $volname | tar -x -v --to-stdout)"
echo "$tar_output"
assert "$tar_output" == "$content" "extracted content"
# Clean up
run_podman volume rm $volname
}
# Podman volume user test
@test "podman volume user test" {
is_rootless || skip "only meaningful when run rootless"