summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/apiv2/20-containers.at2
-rwxr-xr-xtest/apiv2/test-apiv244
-rw-r--r--test/checkseccomp/checkseccomp.go1
-rw-r--r--test/e2e/generate_systemd_test.go52
-rw-r--r--test/e2e/libpod_suite_test.go1
-rw-r--r--test/e2e/play_build_test.go1
-rw-r--r--test/e2e/run_apparmor_test.go1
-rw-r--r--test/e2e/systemd_activate_test.go107
-rw-r--r--test/system/010-images.bats3
-rw-r--r--test/system/070-build.bats11
-rw-r--r--test/system/200-pod.bats8
-rw-r--r--test/system/helpers.bash9
-rw-r--r--test/utils/utils.go2
13 files changed, 215 insertions, 27 deletions
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index 49f8fb3fc..94de2cf24 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -280,7 +280,7 @@ t DELETE containers/$cid_top 204
t POST containers/create \
Image=$ENV_WORKDIR_IMG \
WorkingDir=/dataDir \
- StopSignal=9 \
+ StopSignal=\"9\" \
201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index ff328cfc8..c3545522e 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -194,8 +194,16 @@ function jsonify() {
local rhs
IFS='=' read lhs rhs <<<"$i"
- # If right-hand side already includes double quotes, do nothing
- if [[ ! $rhs =~ \" ]]; then
+ if [[ $rhs =~ \" || $rhs == true || $rhs == false || $rhs =~ ^-?[0-9]+$ ]]; then
+ # rhs has been pre-formatted for JSON or a non-string, do not change it
+ :
+ elif [[ $rhs == False ]]; then
+ # JSON boolean is lowercase only
+ rhs=false
+ elif [[ $rhs == True ]]; then
+ # JSON boolean is lowercase only
+ rhs=true
+ else
rhs="\"${rhs}\""
fi
settings_out+=("\"${lhs}\":${rhs}")
@@ -241,26 +249,30 @@ function t() {
# entrypoint path can include a descriptive comment; strip it off
path=${path%% *}
- # path may include JSONish params that curl will barf on; url-encode them
- path="${path//'['/%5B}"
- path="${path//']'/%5D}"
- path="${path//'{'/%7B}"
- path="${path//'}'/%7D}"
- path="${path//':'/%3A}"
+ local url=$path
+ if ! [[ $path =~ ^'http://' ]]; then
+ # path may include JSONish params that curl will barf on; url-encode them
+ path="${path//'['/%5B}"
+ path="${path//']'/%5D}"
+ path="${path//'{'/%7B}"
+ path="${path//'}'/%7D}"
+ path="${path//':'/%3A}"
+
+ # If given path begins with /, use it as-is; otherwise prepend /version/
+ url=http://$HOST:$PORT
+ case "$path" in
+ /*) url="$url$path" ;;
+ libpod/*) url="$url/v4.0.0/$path" ;;
+ *) url="$url/v1.41/$path" ;;
+ esac
+ fi
# curl -X HEAD but without --head seems to wait for output anyway
if [[ $method == "HEAD" ]]; then
curl_args="--head"
fi
- local expected_code=$1; shift
- # If given path begins with /, use it as-is; otherwise prepend /version/
- local url=http://$HOST:$PORT
- case "$path" in
- /*) url="$url$path" ;;
- libpod/*) url="$url/v4.0.0/$path" ;;
- *) url="$url/v1.41/$path" ;;
- esac
+ local expected_code=$1; shift
# Log every action we do
echo "-------------------------------------------------------------" >>$LOG
diff --git a/test/checkseccomp/checkseccomp.go b/test/checkseccomp/checkseccomp.go
index 9046e0955..6c188ec0d 100644
--- a/test/checkseccomp/checkseccomp.go
+++ b/test/checkseccomp/checkseccomp.go
@@ -1,3 +1,4 @@
+//go:build seccomp
// +build seccomp
package main
diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go
index 55b9a8037..e4b854332 100644
--- a/test/e2e/generate_systemd_test.go
+++ b/test/e2e/generate_systemd_test.go
@@ -423,6 +423,20 @@ var _ = Describe("Podman generate systemd", func() {
})
+ It("podman generate systemd --container-prefix ''", func() {
+ n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"})
+ n.WaitWithDefaultTimeout()
+ Expect(n).Should(Exit(0))
+
+ session := podmanTest.Podman([]string{"generate", "systemd", "--name", "--container-prefix", "", "foo"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ // Grepping the output (in addition to unit tests)
+ Expect(session.OutputToString()).To(ContainSubstring("# foo.service"))
+
+ })
+
It("podman generate systemd --separator _", func() {
n := podmanTest.Podman([]string{"create", "--name", "foo", "alpine", "top"})
n.WaitWithDefaultTimeout()
@@ -485,6 +499,44 @@ var _ = Describe("Podman generate systemd", func() {
Expect(session.OutputToString()).To(ContainSubstring("BindsTo=p_foo.service"))
})
+ It("podman generate systemd pod --pod-prefix '' --container-prefix '' --separator _ change all prefixes/separator", func() {
+ n := podmanTest.Podman([]string{"pod", "create", "--name", "foo"})
+ n.WaitWithDefaultTimeout()
+ Expect(n).Should(Exit(0))
+
+ n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-1", "alpine", "top"})
+ n.WaitWithDefaultTimeout()
+ Expect(n).Should(Exit(0))
+
+ n = podmanTest.Podman([]string{"create", "--pod", "foo", "--name", "foo-2", "alpine", "top"})
+ n.WaitWithDefaultTimeout()
+ Expect(n).Should(Exit(0))
+
+ // test systemd generate with empty pod prefix
+ session1 := podmanTest.Podman([]string{"generate", "systemd", "--pod-prefix", "", "--name", "foo"})
+ session1.WaitWithDefaultTimeout()
+ Expect(session1).Should(Exit(0))
+
+ // Grepping the output (in addition to unit tests)
+ Expect(session1.OutputToString()).To(ContainSubstring("# foo.service"))
+ Expect(session1.OutputToString()).To(ContainSubstring("Requires=container-foo-1.service container-foo-2.service"))
+ Expect(session1.OutputToString()).To(ContainSubstring("# container-foo-1.service"))
+ Expect(session1.OutputToString()).To(ContainSubstring("BindsTo=foo.service"))
+
+ // test systemd generate with empty container and pod prefix
+ session2 := podmanTest.Podman([]string{"generate", "systemd", "--container-prefix", "", "--pod-prefix", "", "--separator", "_", "--name", "foo"})
+ session2.WaitWithDefaultTimeout()
+ Expect(session2).Should(Exit(0))
+
+ // Grepping the output (in addition to unit tests)
+ Expect(session2.OutputToString()).To(ContainSubstring("# foo.service"))
+ Expect(session2.OutputToString()).To(ContainSubstring("Requires=foo-1.service foo-2.service"))
+ Expect(session2.OutputToString()).To(ContainSubstring("# foo-1.service"))
+ Expect(session2.OutputToString()).To(ContainSubstring("# foo-2.service"))
+ Expect(session2.OutputToString()).To(ContainSubstring("BindsTo=foo.service"))
+
+ })
+
It("podman generate systemd pod with containers --new", func() {
tmpDir, err := ioutil.TempDir("", "")
Expect(err).To(BeNil())
diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go
index ccd7c771e..cf81a0348 100644
--- a/test/e2e/libpod_suite_test.go
+++ b/test/e2e/libpod_suite_test.go
@@ -1,3 +1,4 @@
+//go:build !remote
// +build !remote
package integration
diff --git a/test/e2e/play_build_test.go b/test/e2e/play_build_test.go
index 849ba7162..96785c569 100644
--- a/test/e2e/play_build_test.go
+++ b/test/e2e/play_build_test.go
@@ -1,3 +1,4 @@
+//go:build !remote
// +build !remote
// build for play kube is not supported on remote yet.
diff --git a/test/e2e/run_apparmor_test.go b/test/e2e/run_apparmor_test.go
index e6526217a..64a01deb7 100644
--- a/test/e2e/run_apparmor_test.go
+++ b/test/e2e/run_apparmor_test.go
@@ -1,3 +1,4 @@
+//go:build !remote
// +build !remote
package integration
diff --git a/test/e2e/systemd_activate_test.go b/test/e2e/systemd_activate_test.go
new file mode 100644
index 000000000..d5434868d
--- /dev/null
+++ b/test/e2e/systemd_activate_test.go
@@ -0,0 +1,107 @@
+package integration
+
+import (
+ "errors"
+ "fmt"
+ "io/fs"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "syscall"
+ "time"
+
+ testUtils "github.com/containers/podman/v4/test/utils"
+ podmanUtils "github.com/containers/podman/v4/utils"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
+)
+
+var _ = Describe("Systemd activate", func() {
+ var tempDir string
+ var err error
+ var podmanTest *PodmanTestIntegration
+
+ BeforeEach(func() {
+ tempDir, err = testUtils.CreateTempDirInTempDir()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%v\n", err)
+ os.Exit(1)
+ }
+
+ podmanTest = PodmanTestCreate(tempDir)
+ podmanTest.Setup()
+ podmanTest.SeedImages()
+ })
+
+ AfterEach(func() {
+ podmanTest.Cleanup()
+ processTestResult(CurrentGinkgoTestDescription())
+ })
+
+ It("stop podman.service", func() {
+ SkipIfRemote("Testing stopped service requires both podman and podman-remote binaries")
+
+ activate, err := exec.LookPath("systemd-socket-activate")
+ if err != nil {
+ activate = "/usr/bin/systemd-socket-activate"
+ }
+ stat, err := os.Stat(activate)
+ switch {
+ case errors.Is(err, fs.ErrNotExist):
+ Skip(activate + " required for systemd activation tests")
+ case stat.Mode()&0111 == 0:
+ Skip("Unable to execute " + activate)
+ case err != nil:
+ Skip(err.Error())
+ }
+
+ // systemd-socket-activate does not support DNS lookups
+ host := "127.0.0.1"
+ port, err := podmanUtils.GetRandomPort()
+ Expect(err).ToNot(HaveOccurred())
+
+ activateSession := testUtils.StartSystemExec(activate, []string{
+ fmt.Sprintf("--listen=%s:%d", host, port),
+ podmanTest.PodmanBinary,
+ "--root=" + filepath.Join(tempDir, "server_root"),
+ "system", "service",
+ "--time=0",
+ })
+ Expect(activateSession.Exited).ShouldNot(Receive(), "Failed to start podman service")
+
+ // Curried functions for specialized podman calls
+ podmanRemote := func(args ...string) *testUtils.PodmanSession {
+ args = append([]string{"--url", fmt.Sprintf("tcp://%s:%d", host, port)}, args...)
+ return testUtils.SystemExec(podmanTest.RemotePodmanBinary, args)
+ }
+
+ podman := func(args ...string) *testUtils.PodmanSession {
+ args = append([]string{"--root", filepath.Join(tempDir, "server_root")}, args...)
+ return testUtils.SystemExec(podmanTest.PodmanBinary, args)
+ }
+
+ containerName := "top_" + testUtils.RandomString(8)
+ apiSession := podmanRemote(
+ "create", "--tty", "--name", containerName, "--entrypoint", "top",
+ "quay.io/libpod/alpine_labels:latest",
+ )
+ Expect(apiSession).Should(Exit(0))
+
+ apiSession = podmanRemote("start", containerName)
+ Expect(apiSession).Should(Exit(0))
+
+ apiSession = podmanRemote("inspect", "--format={{.State.Running}}", containerName)
+ Expect(apiSession).Should(Exit(0))
+ Expect(apiSession.OutputToString()).To(Equal("true"))
+
+ // Emulate 'systemd stop podman.service'
+ activateSession.Signal(syscall.SIGTERM)
+ time.Sleep(2)
+ Eventually(activateSession).Should(Exit(0))
+
+ abiSession := podman("inspect", "--format={{.State.Running}}", containerName)
+ Expect(abiSession).To(Exit(0))
+ Expect(abiSession.OutputToString()).To(Equal("true"))
+ })
+})
diff --git a/test/system/010-images.bats b/test/system/010-images.bats
index ebd71450f..dbf4b2828 100644
--- a/test/system/010-images.bats
+++ b/test/system/010-images.bats
@@ -248,8 +248,7 @@ Labels.created_at | 20[0-9-]\\\+T[0-9:]\\\+Z
run_podman inspect --format '{{.ID}}' $IMAGE
imageID=$output
- run_podman version --format "{{.Server.Version}}-{{.Server.Built}}"
- pauseImage=localhost/podman-pause:$output
+ pauseImage=$(pause_image)
run_podman inspect --format '{{.ID}}' $pauseImage
pauseID=$output
diff --git a/test/system/070-build.bats b/test/system/070-build.bats
index e47d66542..7466c3b74 100644
--- a/test/system/070-build.bats
+++ b/test/system/070-build.bats
@@ -605,7 +605,7 @@ EOF
done
}
-# Regression test for #9867
+# Regression test for #9867 and #13529
# Make sure that if you exclude everything in context dir, that
# the Containerfile/Dockerfile in the context dir are used
@test "podman build with ignore '*'" {
@@ -620,6 +620,15 @@ cat >$tmpdir/.dockerignore <<EOF
*
EOF
+ # Prior to the fix for #13529, pod-create would fail with 'error building
+ # at STEP COPY .../catatonit' because of the local .dockerignore file was
+ # used.
+ pushd "${tmpdir}"
+ run_podman pod create
+ run_podman pod rm $output
+ run_podman rmi $(pause_image)
+ popd
+
run_podman build -t build_test $tmpdir
# Rename Containerfile to Dockerfile
diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats
index 34dfaa8f6..ca931e244 100644
--- a/test/system/200-pod.bats
+++ b/test/system/200-pod.bats
@@ -6,13 +6,7 @@ load helpers
function teardown() {
run_podman pod rm -f -t 0 -a
run_podman rm -f -t 0 -a
- run_podman image list --format '{{.ID}} {{.Repository}}'
- while read id name; do
- if [[ "$name" =~ /podman-pause ]]; then
- run_podman rmi $id
- fi
- done <<<"$output"
-
+ run_podman ? rmi $(pause_image)
basic_teardown
}
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 221315b97..0d336592f 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -383,6 +383,15 @@ function journald_unavailable() {
return 1
}
+# Returns the name of the local pause image.
+function pause_image() {
+ # This function is intended to be used as '$(pause_image)', i.e.
+ # our caller wants our output. run_podman() messes with output because
+ # it emits the command invocation to stdout, hence the redirection.
+ run_podman version --format "{{.Server.Version}}-{{.Server.Built}}" >/dev/null
+ echo "localhost/podman-pause:$output"
+}
+
###########################
# _add_label_if_missing # make sure skip messages include rootless/remote
###########################
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 14092a2a5..8fe45dca0 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -368,6 +368,7 @@ func CreateTempDirInTempDir() (string, error) {
// SystemExec is used to exec a system command to check its exit code or output
func SystemExec(command string, args []string) *PodmanSession {
c := exec.Command(command, args...)
+ fmt.Println("Execing " + c.String() + "\n")
session, err := Start(c, GinkgoWriter, GinkgoWriter)
if err != nil {
Fail(fmt.Sprintf("unable to run command: %s %s", command, strings.Join(args, " ")))
@@ -379,6 +380,7 @@ func SystemExec(command string, args []string) *PodmanSession {
// StartSystemExec is used to start exec a system command
func StartSystemExec(command string, args []string) *PodmanSession {
c := exec.Command(command, args...)
+ fmt.Println("Execing " + c.String() + "\n")
session, err := Start(c, GinkgoWriter, GinkgoWriter)
if err != nil {
Fail(fmt.Sprintf("unable to run command: %s %s", command, strings.Join(args, " ")))