2024-08-15 15:12:37 +02:00
|
|
|
//go:build linux || freebsd
|
|
|
|
|
|
2018-02-02 11:02:09 -06:00
|
|
|
package integration
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
2020-03-12 10:46:44 -04:00
|
|
|
"path/filepath"
|
2022-02-22 22:10:34 +05:30
|
|
|
"strings"
|
2018-02-02 11:02:09 -06:00
|
|
|
|
2025-10-23 08:18:28 -04:00
|
|
|
. "github.com/containers/podman/v6/test/utils"
|
2023-04-12 15:32:02 +02:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2018-02-02 11:02:09 -06:00
|
|
|
. "github.com/onsi/gomega"
|
e2e tests: use Should(Exit()) and ExitWithError()
e2e test failures are rife with messages like:
Expected 1 to equal 0
These make me cry. They're anti-helpful, requiring the reader
to dive into the source code to figure out what those numbers
mean.
Solution: Go tests have a '.Should(Exit(NNN))' mechanism. I
don't know if it spits out a better diagnostic (I have no way
to run e2e tests on my laptop), but I have to fantasize that
it will, and given the state of our flakes I assume that at
least one test will fail and give me the opportunity to see
what the error message looks like.
THIS IS NOT REVIEWABLE CODE. There is no way for a human
to review it. Don't bother. Maybe look at a few random
ones for sanity. If you want to really review, here is
a reproducer of what I did:
cd test/e2e
! positive assertions. The second is the same as the first,
! with the addition of (unnecessary) parentheses because
! some invocations were written that way. The third is BeZero().
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\d+)\)\)/Expect($1).Should(Exit($2))/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(\(Equal\((\d+)\)\)\)/Expect($1).Should(Exit($2))/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(BeZero\(\)\)/Expect($1).Should(Exit(0))/' *_test.go
! Same as above, but handles three non-numeric exit codes
! in run_exit_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\S+)\)\)/Expect($1).Should(Exit($2))/' *_test.go
! negative assertions. Difference is the spelling of 'To(Not)',
! 'ToNot', and 'NotTo'. I assume those are all the same.
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Not\(Equal\((0)\)\)\)/Expect($1).To(ExitWithError())/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.NotTo\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go
! negative, old use of BeZero()
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(BeZero\(\)\)/Expect($1).Should(ExitWithError())/' *_test.go
Run those on a clean copy of main branch (at the same branch
point as my PR, of course), then diff against a checked-out
copy of my PR. There should be no differences. Then all you
have to review is that my replacements above are sane.
UPDATE: nope, that's not enough, you also need to add gomega/gexec
to the files that don't have it:
perl -pi -e '$_ .= "$1/gexec\"\n" if m!^(.*/onsi/gomega)"!' $(grep -L gomega/gexec $(git log -1 --stat | awk '$1 ~ /test\/e2e\// { print $1}'))
UPDATE 2: hand-edit run_volume_test.go
UPDATE 3: sigh, add WaitWithDefaultTimeout() to a couple of places
UPDATE 4: skip a test due to bug #10935 (race condition)
Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-07-14 13:55:00 -06:00
|
|
|
. "github.com/onsi/gomega/gexec"
|
2018-02-02 11:02:09 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = Describe("Podman commit", func() {
|
|
|
|
|
It("podman commit container", func() {
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-10-31 15:21:15 -04:00
|
|
|
session := podmanTest.Podman([]string{"commit", "test1", "--change", "BOGUS=foo", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2024-04-04 08:26:03 -06:00
|
|
|
Expect(session).Should(ExitWithError(125, `applying changes: processing change "BOGUS foo": did not understand change instruction "BOGUS foo"`))
|
2023-10-31 15:21:15 -04:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"commit", "test1", "foobar.com/test1-image:latest"})
|
2018-02-02 11:02:09 -06:00
|
|
|
session.WaitWithDefaultTimeout()
|
e2e tests: use Should(Exit()) and ExitWithError()
e2e test failures are rife with messages like:
Expected 1 to equal 0
These make me cry. They're anti-helpful, requiring the reader
to dive into the source code to figure out what those numbers
mean.
Solution: Go tests have a '.Should(Exit(NNN))' mechanism. I
don't know if it spits out a better diagnostic (I have no way
to run e2e tests on my laptop), but I have to fantasize that
it will, and given the state of our flakes I assume that at
least one test will fail and give me the opportunity to see
what the error message looks like.
THIS IS NOT REVIEWABLE CODE. There is no way for a human
to review it. Don't bother. Maybe look at a few random
ones for sanity. If you want to really review, here is
a reproducer of what I did:
cd test/e2e
! positive assertions. The second is the same as the first,
! with the addition of (unnecessary) parentheses because
! some invocations were written that way. The third is BeZero().
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\d+)\)\)/Expect($1).Should(Exit($2))/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(\(Equal\((\d+)\)\)\)/Expect($1).Should(Exit($2))/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(BeZero\(\)\)/Expect($1).Should(Exit(0))/' *_test.go
! Same as above, but handles three non-numeric exit codes
! in run_exit_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Equal\((\S+)\)\)/Expect($1).Should(Exit($2))/' *_test.go
! negative assertions. Difference is the spelling of 'To(Not)',
! 'ToNot', and 'NotTo'. I assume those are all the same.
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.To\(Not\(Equal\((0)\)\)\)/Expect($1).To(ExitWithError())/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.NotTo\(Equal\((0)\)\)/Expect($1).To(ExitWithError())/' *_test.go
! negative, old use of BeZero()
perl -pi -e 's/Expect\((\S+)\.ExitCode\(\)\)\.ToNot\(BeZero\(\)\)/Expect($1).Should(ExitWithError())/' *_test.go
Run those on a clean copy of main branch (at the same branch
point as my PR, of course), then diff against a checked-out
copy of my PR. There should be no differences. Then all you
have to review is that my replacements above are sane.
UPDATE: nope, that's not enough, you also need to add gomega/gexec
to the files that don't have it:
perl -pi -e '$_ .= "$1/gexec\"\n" if m!^(.*/onsi/gomega)"!' $(grep -L gomega/gexec $(git log -1 --stat | awk '$1 ~ /test\/e2e\// { print $1}'))
UPDATE 2: hand-edit run_volume_test.go
UPDATE 3: sigh, add WaitWithDefaultTimeout() to a couple of places
UPDATE 4: skip a test due to bug #10935 (race condition)
Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-07-14 13:55:00 -06:00
|
|
|
Expect(session).Should(Exit(0))
|
2018-02-02 11:02:09 -06:00
|
|
|
|
2023-10-31 15:21:15 -04:00
|
|
|
messages := session.ErrorToString()
|
|
|
|
|
Expect(messages).To(ContainSubstring("Getting image source signatures"))
|
|
|
|
|
Expect(messages).To(ContainSubstring("Copying blob"))
|
|
|
|
|
Expect(messages).To(ContainSubstring("Writing manifest to image destination"))
|
|
|
|
|
Expect(messages).To(Not(ContainSubstring("level=")), "Unexpected logrus messages in stderr")
|
2023-09-11 06:40:31 -06:00
|
|
|
|
2018-02-02 11:02:09 -06:00
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2021-11-23 06:49:49 -07:00
|
|
|
Expect(data[0].RepoTags).To(ContainElement("foobar.com/test1-image:latest"))
|
2023-10-31 15:21:15 -04:00
|
|
|
|
|
|
|
|
// commit second time with --quiet, should not write to stderr
|
|
|
|
|
session = podmanTest.Podman([]string{"commit", "--quiet", "test1", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
|
|
|
|
Expect(session).Should(Exit(0))
|
|
|
|
|
Expect(session.ErrorToString()).To(BeEmpty())
|
|
|
|
|
|
|
|
|
|
// commit second time with --quiet, should not write to stderr
|
|
|
|
|
session = podmanTest.Podman([]string{"commit", "--quiet", "bogus", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2024-04-04 08:26:03 -06:00
|
|
|
Expect(session).Should(ExitWithError(125, `no container with name or ID "bogus" found: no such container`))
|
2018-02-02 11:02:09 -06:00
|
|
|
})
|
|
|
|
|
|
2020-07-30 14:00:44 -04:00
|
|
|
It("podman commit single letter container", func() {
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "test1", "a"})
|
2020-07-30 14:00:44 -04:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2020-07-30 14:00:44 -04:00
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "localhost/a:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2021-11-23 06:49:49 -07:00
|
|
|
Expect(data[0].RepoTags).To(ContainElement("localhost/a:latest"))
|
2020-07-30 14:00:44 -04:00
|
|
|
})
|
|
|
|
|
|
2019-02-28 16:30:56 -05:00
|
|
|
It("podman container commit container", func() {
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"container", "commit", "-q", "test1", "foobar.com/test1-image:latest"})
|
2019-02-28 16:30:56 -05:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2019-02-28 16:30:56 -05:00
|
|
|
|
2019-03-12 15:59:45 -06:00
|
|
|
check := podmanTest.Podman([]string{"image", "inspect", "foobar.com/test1-image:latest"})
|
2019-02-28 16:30:56 -05:00
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2021-11-23 06:49:49 -07:00
|
|
|
Expect(data[0].RepoTags).To(ContainElement("foobar.com/test1-image:latest"))
|
2019-02-28 16:30:56 -05:00
|
|
|
})
|
|
|
|
|
|
2018-02-02 11:02:09 -06:00
|
|
|
It("podman commit container with message", func() {
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "-f", "docker", "--message", "testing-commit", "test1", "foobar.com/test1-image:latest"})
|
2018-02-02 11:02:09 -06:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2018-02-02 11:02:09 -06:00
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2022-04-27 14:58:46 -06:00
|
|
|
Expect(data[0]).To(HaveField("Comment", "testing-commit"))
|
2018-02-02 11:02:09 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("podman commit container with author", func() {
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--author", "snoopy", "test1", "foobar.com/test1-image:latest"})
|
2018-02-02 11:02:09 -06:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2018-02-02 11:02:09 -06:00
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2022-04-27 14:58:46 -06:00
|
|
|
Expect(data[0]).To(HaveField("Author", "snoopy"))
|
2018-02-02 11:02:09 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("podman commit container with change flag", func() {
|
2018-07-31 09:05:48 -05:00
|
|
|
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
2018-02-02 11:02:09 -06:00
|
|
|
test.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(test).Should(ExitCleanly())
|
2018-02-02 11:02:09 -06:00
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--change", "LABEL=image=blue", "test1", "foobar.com/test1-image:latest"})
|
2018-02-02 11:02:09 -06:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2018-02-02 11:02:09 -06:00
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
2023-04-18 06:11:56 -06:00
|
|
|
inspectResults := check.InspectImageJSON()
|
|
|
|
|
Expect(inspectResults[0].Labels).To(HaveKeyWithValue("image", "blue"))
|
2018-02-02 11:02:09 -06:00
|
|
|
})
|
|
|
|
|
|
2023-11-10 16:26:18 -05:00
|
|
|
It("podman commit container with --config flag", func() {
|
|
|
|
|
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
|
|
|
|
test.WaitWithDefaultTimeout()
|
|
|
|
|
Expect(test).Should(ExitCleanly())
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
|
|
|
|
configFile, err := os.CreateTemp(podmanTest.TempDir, "")
|
|
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
|
_, err = configFile.WriteString(`{"Labels":{"image":"green"}}`)
|
|
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
|
configFile.Close()
|
|
|
|
|
|
|
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--config", configFile.Name(), "test1", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
|
|
|
|
Expect(session).Should(ExitCleanly())
|
|
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
inspectResults := check.InspectImageJSON()
|
|
|
|
|
Expect(inspectResults[0].Labels).To(HaveKeyWithValue("image", "green"))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("podman commit container with --config pointing to trash", func() {
|
|
|
|
|
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
|
|
|
|
test.WaitWithDefaultTimeout()
|
|
|
|
|
Expect(test).Should(ExitCleanly())
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
|
|
|
|
configFile, err := os.CreateTemp(podmanTest.TempDir, "")
|
|
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
|
_, err = configFile.WriteString("this is not valid JSON\n")
|
|
|
|
|
Expect(err).Should(Succeed())
|
|
|
|
|
configFile.Close()
|
|
|
|
|
|
|
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--config", configFile.Name(), "test1", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
|
|
|
|
Expect(session).Should(Not(ExitCleanly()))
|
|
|
|
|
})
|
|
|
|
|
|
2022-02-22 22:10:34 +05:30
|
|
|
It("podman commit container with --squash", func() {
|
|
|
|
|
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
|
|
|
|
test.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(test).Should(ExitCleanly())
|
2022-02-22 22:10:34 +05:30
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--squash", "test1", "foobar.com/test1-image:latest"})
|
2022-02-22 22:10:34 +05:30
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2022-02-22 22:10:34 +05:30
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2022-02-22 22:10:34 +05:30
|
|
|
// Check for one layers
|
|
|
|
|
Expect(strings.Fields(session.OutputToString())).To(HaveLen(1))
|
|
|
|
|
})
|
|
|
|
|
|
2020-02-10 15:29:36 -05:00
|
|
|
It("podman commit container with change flag and JSON entrypoint with =", func() {
|
|
|
|
|
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
|
|
|
|
test.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(test).Should(ExitCleanly())
|
2020-02-10 15:29:36 -05:00
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--change", `ENTRYPOINT ["foo", "bar=baz"]`, "test1", "foobar.com/test1-image:latest"})
|
2020-02-10 15:29:36 -05:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2020-02-10 15:29:36 -05:00
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2021-12-01 08:49:55 -07:00
|
|
|
Expect(data).To(HaveLen(1))
|
|
|
|
|
Expect(data[0].Config.Entrypoint).To(HaveLen(2))
|
2020-02-10 15:29:36 -05:00
|
|
|
Expect(data[0].Config.Entrypoint[0]).To(Equal("foo"))
|
|
|
|
|
Expect(data[0].Config.Entrypoint[1]).To(Equal("bar=baz"))
|
|
|
|
|
})
|
|
|
|
|
|
2019-04-16 06:26:47 -04:00
|
|
|
It("podman commit container with change CMD flag", func() {
|
|
|
|
|
test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", ALPINE, "ls"})
|
|
|
|
|
test.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(test).Should(ExitCleanly())
|
2019-04-16 06:26:47 -04:00
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--change", "CMD a b c", "test1", "foobar.com/test1-image:latest"})
|
2019-04-16 06:26:47 -04:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2019-04-16 06:26:47 -04:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"inspect", "--format", "{{.Config.Cmd}}", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2019-04-16 06:26:47 -04:00
|
|
|
Expect(session.OutputToString()).To(ContainSubstring("sh -c a b c"))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session = podmanTest.Podman([]string{"commit", "-q", "--change", "CMD=[\"a\",\"b\",\"c\"]", "test1", "foobar.com/test1-image:latest"})
|
2019-04-16 06:26:47 -04:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2019-04-16 06:26:47 -04:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"inspect", "--format", "{{.Config.Cmd}}", "foobar.com/test1-image:latest"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2019-04-16 06:26:47 -04:00
|
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring("sh -c")))
|
|
|
|
|
})
|
|
|
|
|
|
2018-02-02 11:02:09 -06:00
|
|
|
It("podman commit container with pause flag", func() {
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "--pause=false", "test1", "foobar.com/test1-image:latest"})
|
2018-02-02 11:02:09 -06:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2018-02-02 11:02:09 -06:00
|
|
|
|
|
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(check).Should(ExitCleanly())
|
2018-02-02 11:02:09 -06:00
|
|
|
})
|
2018-04-30 08:26:31 -05:00
|
|
|
|
2019-04-10 16:00:47 -04:00
|
|
|
It("podman commit with volumes mounts and no include-volumes", func() {
|
2018-04-30 08:26:31 -05:00
|
|
|
s := podmanTest.Podman([]string{"run", "--name", "test1", "-v", "/tmp:/foo", "alpine", "date"})
|
|
|
|
|
s.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(s).Should(ExitCleanly())
|
2018-04-30 08:26:31 -05:00
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
c := podmanTest.Podman([]string{"commit", "-q", "test1", "newimage"})
|
2018-04-30 08:26:31 -05:00
|
|
|
c.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(c).Should(ExitCleanly())
|
2018-04-30 08:26:31 -05:00
|
|
|
|
2019-04-10 16:00:47 -04:00
|
|
|
inspect := podmanTest.Podman([]string{"inspect", "newimage"})
|
|
|
|
|
inspect.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(inspect).Should(ExitCleanly())
|
2019-04-10 16:00:47 -04:00
|
|
|
image := inspect.InspectImageJSON()
|
2021-11-30 13:14:56 -07:00
|
|
|
Expect(image[0].Config.Volumes).To(Not(HaveKey("/foo")))
|
2019-04-10 16:00:47 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("podman commit with volume mounts and --include-volumes", func() {
|
2019-04-25 13:58:25 -05:00
|
|
|
// We need to figure out how volumes are going to work correctly with the remote
|
|
|
|
|
// client. This does not currently work.
|
2020-09-23 08:09:31 -06:00
|
|
|
SkipIfRemote("--testing Remote Volumes")
|
2019-04-10 16:00:47 -04:00
|
|
|
s := podmanTest.Podman([]string{"run", "--name", "test1", "-v", "/tmp:/foo", "alpine", "date"})
|
|
|
|
|
s.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(s).Should(ExitCleanly())
|
2019-04-10 16:00:47 -04:00
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
c := podmanTest.Podman([]string{"commit", "-q", "--include-volumes", "test1", "newimage"})
|
2019-04-10 16:00:47 -04:00
|
|
|
c.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(c).Should(ExitCleanly())
|
2019-04-10 16:00:47 -04:00
|
|
|
|
2018-04-30 08:26:31 -05:00
|
|
|
inspect := podmanTest.Podman([]string{"inspect", "newimage"})
|
|
|
|
|
inspect.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(inspect).Should(ExitCleanly())
|
2018-04-30 08:26:31 -05:00
|
|
|
image := inspect.InspectImageJSON()
|
2021-11-30 13:14:56 -07:00
|
|
|
Expect(image[0].Config.Volumes).To(HaveKey("/foo"))
|
2018-04-30 08:26:31 -05:00
|
|
|
|
|
|
|
|
r := podmanTest.Podman([]string{"run", "newimage"})
|
|
|
|
|
r.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(r).Should(ExitCleanly())
|
2018-04-30 08:26:31 -05:00
|
|
|
})
|
|
|
|
|
|
2019-05-16 20:57:39 +05:30
|
|
|
It("podman commit container check env variables", func() {
|
2023-04-25 07:09:05 -06:00
|
|
|
s := podmanTest.Podman([]string{"run", "--name", "test1", "-e", "TEST=1=1-01=9.01", "alpine", "true"})
|
2019-05-16 20:57:39 +05:30
|
|
|
s.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(s).Should(ExitCleanly())
|
2019-05-16 20:57:39 +05:30
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
c := podmanTest.Podman([]string{"commit", "-q", "test1", "newimage"})
|
2019-05-16 20:57:39 +05:30
|
|
|
c.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(c).Should(ExitCleanly())
|
2019-05-16 20:57:39 +05:30
|
|
|
|
|
|
|
|
inspect := podmanTest.Podman([]string{"inspect", "newimage"})
|
|
|
|
|
inspect.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(inspect).Should(ExitCleanly())
|
2019-05-16 20:57:39 +05:30
|
|
|
image := inspect.InspectImageJSON()
|
|
|
|
|
|
|
|
|
|
envMap := make(map[string]bool)
|
|
|
|
|
for _, v := range image[0].Config.Env {
|
|
|
|
|
envMap[v] = true
|
|
|
|
|
}
|
2021-11-30 13:14:56 -07:00
|
|
|
Expect(envMap).To(HaveKey("TEST=1=1-01=9.01"))
|
2019-05-16 20:57:39 +05:30
|
|
|
})
|
2020-03-12 10:46:44 -04:00
|
|
|
|
|
|
|
|
It("podman commit container and print id to external file", func() {
|
|
|
|
|
// Switch to temp dir and restore it afterwards
|
|
|
|
|
cwd, err := os.Getwd()
|
2022-11-24 17:59:50 +01:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
Expect(os.Chdir(os.TempDir())).To(Succeed())
|
2023-04-17 12:16:20 +02:00
|
|
|
targetPath := podmanTest.TempDir
|
2020-03-12 10:46:44 -04:00
|
|
|
targetFile := filepath.Join(targetPath, "idFile")
|
|
|
|
|
defer Expect(os.Chdir(cwd)).To(BeNil())
|
|
|
|
|
|
|
|
|
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
|
|
|
|
Expect(ec).To(Equal(0))
|
|
|
|
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session := podmanTest.Podman([]string{"commit", "-q", "test1", "foobar.com/test1-image:latest", "--iidfile", targetFile})
|
2020-03-12 10:46:44 -04:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2020-03-12 10:46:44 -04:00
|
|
|
|
2022-09-20 09:59:28 -04:00
|
|
|
id, _ := os.ReadFile(targetFile)
|
2020-03-12 10:46:44 -04:00
|
|
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
|
|
|
|
check.WaitWithDefaultTimeout()
|
|
|
|
|
data := check.InspectImageJSON()
|
2022-04-27 14:58:46 -06:00
|
|
|
Expect(data[0]).To(HaveField("ID", string(id)))
|
2020-03-12 10:46:44 -04:00
|
|
|
})
|
2021-01-15 01:27:23 -05:00
|
|
|
|
|
|
|
|
It("podman commit should not commit secret", func() {
|
|
|
|
|
secretsString := "somesecretdata"
|
|
|
|
|
secretFilePath := filepath.Join(podmanTest.TempDir, "secret")
|
2025-10-15 09:39:18 -04:00
|
|
|
err := os.WriteFile(secretFilePath, []byte(secretsString), 0o755)
|
2022-11-24 17:59:50 +01:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-01-15 01:27:23 -05:00
|
|
|
|
|
|
|
|
session := podmanTest.Podman([]string{"secret", "create", "mysecret", secretFilePath})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2021-01-15 01:27:23 -05:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"run", "--secret", "mysecret", "--name", "secr", ALPINE, "cat", "/run/secrets/mysecret"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2021-01-15 01:27:23 -05:00
|
|
|
Expect(session.OutputToString()).To(Equal(secretsString))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session = podmanTest.Podman([]string{"commit", "-q", "secr", "foobar.com/test1-image:latest"})
|
2021-01-15 01:27:23 -05:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2021-01-15 01:27:23 -05:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"run", "foobar.com/test1-image:latest", "cat", "/run/secrets/mysecret"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2024-04-04 08:26:03 -06:00
|
|
|
Expect(session).To(ExitWithError(1, "can't open '/run/secrets/mysecret': No such file or directory"))
|
2021-01-15 01:27:23 -05:00
|
|
|
})
|
2021-05-05 10:34:13 -04:00
|
|
|
|
|
|
|
|
It("podman commit should not commit env secret", func() {
|
|
|
|
|
secretsString := "somesecretdata"
|
|
|
|
|
secretFilePath := filepath.Join(podmanTest.TempDir, "secret")
|
2025-10-15 09:39:18 -04:00
|
|
|
err := os.WriteFile(secretFilePath, []byte(secretsString), 0o755)
|
2022-11-24 17:59:50 +01:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2021-05-05 10:34:13 -04:00
|
|
|
|
|
|
|
|
session := podmanTest.Podman([]string{"secret", "create", "mysecret", secretFilePath})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2021-05-05 10:34:13 -04:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"run", "--secret", "source=mysecret,type=env", "--name", "secr", ALPINE, "printenv", "mysecret"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2021-05-05 10:34:13 -04:00
|
|
|
Expect(session.OutputToString()).To(Equal(secretsString))
|
|
|
|
|
|
2023-09-11 06:40:31 -06:00
|
|
|
session = podmanTest.Podman([]string{"commit", "-q", "secr", "foobar.com/test1-image:latest"})
|
2021-05-05 10:34:13 -04:00
|
|
|
session.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(session).Should(ExitCleanly())
|
2021-05-05 10:34:13 -04:00
|
|
|
|
|
|
|
|
session = podmanTest.Podman([]string{"run", "foobar.com/test1-image:latest", "printenv", "mysecret"})
|
|
|
|
|
session.WaitWithDefaultTimeout()
|
|
|
|
|
Expect(session.OutputToString()).To(Not(ContainSubstring(secretsString)))
|
|
|
|
|
})
|
2021-08-24 10:23:10 +02:00
|
|
|
|
|
|
|
|
It("podman commit adds exposed ports", func() {
|
|
|
|
|
name := "testcon"
|
Eighty-six eighty-eighty
(Sorry, couldn't resist).
CI flakes have been coming down - thank you to everyone who has
been making them a priority.
This leaves a noisy subset that I've just been ignoring for months:
Running: podman ... -p 8080:something
...cannot listen on the TCP port: listen tcp4 :8080: bind: address already in use
Sometimes these are one-time errors resolved on 2nd try; sometimes
they fail three times, forcing CI user to hit Rerun. In all cases
they make noise in my flake logs, which costs me time.
My assumption is that this has to do with ginkgo running random
tests in parallel. Since many e2e tests simplemindedly use 8080,
collisions are inevitable.
Solution: simplemindedly replace 8080 with other (also arbitrarily
picked) numbers. This is imperfect -- it requires human developers
to pick a number NNNN and 'grep NNNN test/e2e/*' before adding
new tests, which I am 100% confident ain't gonna happen -- but
it's better than what we have now.
Side note: I considered writing and using a RandomAvailablePort()
helper, but that would still be racy. Plus, it would be a pain
to interpolate strings into so many places. Finally, with this
hand-tooled approach, if/when we _do_ get conflicts on port NNNN,
it should be very easy to grep for NNNN, find the offending tests
that reuse that port, and fix one of them.
Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-09-22 07:30:03 -06:00
|
|
|
s := podmanTest.Podman([]string{"run", "--name", name, "-p", "8585:80", ALPINE, "true"})
|
2021-08-24 10:23:10 +02:00
|
|
|
s.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(s).Should(ExitCleanly())
|
2021-08-24 10:23:10 +02:00
|
|
|
|
|
|
|
|
newImageName := "newimage"
|
2023-09-11 06:40:31 -06:00
|
|
|
c := podmanTest.Podman([]string{"commit", "-q", name, newImageName})
|
2021-08-24 10:23:10 +02:00
|
|
|
c.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(c).Should(ExitCleanly())
|
2021-08-24 10:23:10 +02:00
|
|
|
|
|
|
|
|
inspect := podmanTest.Podman([]string{"inspect", newImageName})
|
|
|
|
|
inspect.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(inspect).Should(ExitCleanly())
|
2021-08-24 10:23:10 +02:00
|
|
|
images := inspect.InspectImageJSON()
|
|
|
|
|
Expect(images).To(HaveLen(1))
|
|
|
|
|
Expect(images[0].Config.ExposedPorts).To(HaveKey("80/tcp"))
|
|
|
|
|
|
|
|
|
|
name = "testcon2"
|
2022-07-05 14:50:04 -06:00
|
|
|
s = podmanTest.Podman([]string{"run", "--name", name, "-d", NGINX_IMAGE})
|
2021-08-24 10:23:10 +02:00
|
|
|
s.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(s).Should(ExitCleanly())
|
2021-08-24 10:23:10 +02:00
|
|
|
|
|
|
|
|
newImageName = "newimage2"
|
2023-09-11 06:40:31 -06:00
|
|
|
c = podmanTest.Podman([]string{"commit", "-q", name, newImageName})
|
2021-08-24 10:23:10 +02:00
|
|
|
c.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(c).Should(ExitCleanly())
|
2021-08-24 10:23:10 +02:00
|
|
|
|
|
|
|
|
inspect = podmanTest.Podman([]string{"inspect", newImageName})
|
|
|
|
|
inspect.WaitWithDefaultTimeout()
|
2023-09-11 06:40:31 -06:00
|
|
|
Expect(inspect).Should(ExitCleanly())
|
2021-08-24 10:23:10 +02:00
|
|
|
images = inspect.InspectImageJSON()
|
|
|
|
|
Expect(images).To(HaveLen(1))
|
|
|
|
|
Expect(images[0].Config.ExposedPorts).To(HaveKey("80/tcp"))
|
|
|
|
|
})
|
2018-02-02 11:02:09 -06:00
|
|
|
})
|