summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/apiv2/10-images.at4
-rw-r--r--test/apiv2/20-containers.at4
-rw-r--r--test/apiv2/python/rest_api/test_v2_0_0_system.py13
-rwxr-xr-xtest/apiv2/test-apiv21
-rw-r--r--test/buildah-bud/buildah-tests.diff20
-rw-r--r--test/e2e/pod_create_test.go34
-rw-r--r--test/e2e/run_cgroup_parent_test.go32
-rw-r--r--test/e2e/run_test.go30
-rw-r--r--test/system/070-build.bats2
-rw-r--r--test/system/500-networking.bats119
10 files changed, 168 insertions, 91 deletions
diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at
index abc8d44b7..d3fde9f9d 100644
--- a/test/apiv2/10-images.at
+++ b/test/apiv2/10-images.at
@@ -94,6 +94,10 @@ t GET libpod/images/json?filters='garb1age}' 500 \
t GET libpod/images/json?filters='{"label":["testl' 500 \
.cause="unexpected end of JSON input"
+# Prune images - bad all input
+t POST libpod/images/prune?all='garb1age' 500 \
+ .cause="schema: error converting value for \"all\""
+
# Prune images - bad filter input
t POST images/prune?filters='garb1age}' 500 \
.cause="invalid character 'g' looking for beginning of value"
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index 8fdecb4bd..afff68c22 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -22,6 +22,10 @@ podman run $IMAGE true
t GET libpod/containers/json 200 length=0
+# bad all input
+t GET libpod/containers/json?all='garb1age' 500 \
+ .cause="schema: error converting value for \"all\""
+
t GET libpod/containers/json?all=true 200 \
length=1 \
.[0].Id~[0-9a-f]\\{64\\} \
diff --git a/test/apiv2/python/rest_api/test_v2_0_0_system.py b/test/apiv2/python/rest_api/test_v2_0_0_system.py
index 8171abb84..1140d09cf 100644
--- a/test/apiv2/python/rest_api/test_v2_0_0_system.py
+++ b/test/apiv2/python/rest_api/test_v2_0_0_system.py
@@ -30,13 +30,12 @@ class SystemTestCase(APITestCase):
# Actor.ID is uppercase for compatibility
self.assertIn("ID", obj["Actor"])
# Verify 1.22+ deprecated variants are present if current originals are
- if (obj["Actor"]["ID"]):
- self.assertEqual(obj["Actor"]["ID"], obj["id"])
- if (obj["Action"]):
- self.assertEqual(obj["Action"], obj["status"])
- if (obj["Actor"].get("Attributes") and obj["Actor"]["Attributes"].get("image")):
- self.assertEqual(obj["Actor"]["Attributes"]["image"], obj["from"])
-
+ if obj["Actor"]["ID"]:
+ self.assertEqual(obj["Actor"]["ID"], obj["id"])
+ if obj["Action"]:
+ self.assertEqual(obj["Action"], obj["status"])
+ if obj["Actor"].get("Attributes") and obj["Actor"]["Attributes"].get("image"):
+ self.assertEqual(obj["Actor"]["Attributes"]["image"], obj["from"])
def test_ping(self):
required_headers = (
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index e1bf28bae..c644b9578 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -327,6 +327,7 @@ function start_service() {
die "Cannot start service on non-localhost ($HOST)"
fi
+ echo $WORKDIR
$PODMAN_BIN --root $WORKDIR/server_root --syslog=true \
system service \
--time 15 \
diff --git a/test/buildah-bud/buildah-tests.diff b/test/buildah-bud/buildah-tests.diff
index 66d470648..87923484f 100644
--- a/test/buildah-bud/buildah-tests.diff
+++ b/test/buildah-bud/buildah-tests.diff
@@ -1,4 +1,4 @@
-From d684753d6f00ee95720d8fb2e09c7ac19b37b01e Mon Sep 17 00:00:00 2001
+From 5baab334cac9853c1d4bae9466d46dbbe5ff7158 Mon Sep 17 00:00:00 2001
From: Ed Santiago <santiago@redhat.com>
Date: Tue, 9 Feb 2021 17:28:05 -0700
Subject: [PATCH] tweaks for running buildah tests under podman
@@ -9,10 +9,10 @@ Signed-off-by: Ed Santiago <santiago@redhat.com>
1 file changed, 67 insertions(+), 4 deletions(-)
diff --git a/tests/helpers.bash b/tests/helpers.bash
-index 11deb367..44c71dad 100644
+index 166316d5..775d7c9b 100644
--- a/tests/helpers.bash
+++ b/tests/helpers.bash
-@@ -34,6 +34,23 @@ function setup() {
+@@ -43,6 +43,23 @@ EOF
ROOTDIR_OPTS="--root ${TESTDIR}/root --runroot ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER}"
BUILDAH_REGISTRY_OPTS="--registries-conf ${TESTSDIR}/registries.conf --registries-conf-dir ${TESTDIR}/registries.d --short-name-alias-conf ${TESTDIR}/cache/shortnames.conf"
PODMAN_REGISTRY_OPTS="--registries-conf ${TESTSDIR}/registries.conf"
@@ -36,8 +36,8 @@ index 11deb367..44c71dad 100644
}
function starthttpd() {
-@@ -57,6 +74,12 @@ function stophttpd() {
- function teardown() {
+@@ -84,6 +101,12 @@ function teardown(){
+ function teardown_tests() {
stophttpd
+ if [[ -n "$PODMAN_SERVER_PID" ]]; then
@@ -49,7 +49,7 @@ index 11deb367..44c71dad 100644
# Workaround for #1991 - buildah + overlayfs leaks mount points.
# Many tests leave behind /var/tmp/.../root/overlay and sub-mounts;
# let's find those and clean them up, otherwise 'rm -rf' fails.
-@@ -129,7 +152,13 @@ function copy() {
+@@ -156,7 +179,13 @@ function copy() {
}
function podman() {
@@ -64,13 +64,13 @@ index 11deb367..44c71dad 100644
}
#################
-@@ -164,15 +193,40 @@ function run_buildah() {
+@@ -191,15 +220,40 @@ function run_buildah() {
--retry) retry=3; shift;; # retry network flakes
esac
+ local podman_or_buildah=${BUILDAH_BINARY}
+ local _opts="${ROOTDIR_OPTS} ${BUILDAH_REGISTRY_OPTS}"
-+ if [[ $1 == "bud" || $1 == "build-using-dockerfile" ]]; then
++ if [[ $1 == "build" || $1 == "build-using-dockerfile" ]]; then
+ shift
+ # podman defaults to --layers=true; buildah to --false.
+ # If command line includes explicit --layers, leave it untouched,
@@ -108,7 +108,7 @@ index 11deb367..44c71dad 100644
# without "quotes", multiple lines are glommed together into one
if [ -n "$output" ]; then
echo "$output"
-@@ -396,3 +450,12 @@ function skip_if_no_docker() {
+@@ -477,3 +531,12 @@ function skip_if_no_docker() {
skip "this test needs actual docker, not podman-docker"
fi
}
@@ -122,5 +122,5 @@ index 11deb367..44c71dad 100644
+ fi
+}
--
-2.31.1
+2.25.1
diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go
index 7297bfc6e..7d40d36dd 100644
--- a/test/e2e/pod_create_test.go
+++ b/test/e2e/pod_create_test.go
@@ -850,4 +850,38 @@ ENTRYPOINT ["sleep","99999"]
Expect(ok).To(BeTrue())
})
+ It("podman pod create --volume", func() {
+ volName := "testVol"
+ volCreate := podmanTest.Podman([]string{"volume", "create", volName})
+ volCreate.WaitWithDefaultTimeout()
+ Expect(volCreate).Should(Exit(0))
+ podName := "testPod"
+ podCreate := podmanTest.Podman([]string{"pod", "create", "--volume", volName + ":/tmp1", "--name", podName})
+ podCreate.WaitWithDefaultTimeout()
+ Expect(podCreate).Should(Exit(0))
+ podInspect := podmanTest.Podman([]string{"pod", "inspect", podName})
+ podInspect.WaitWithDefaultTimeout()
+ Expect(podInspect).Should(Exit(0))
+ data := podInspect.InspectPodToJSON()
+ Expect(data.Mounts[0].Name).To(Equal(volName))
+ ctrName := "testCtr"
+ ctrCreate := podmanTest.Podman([]string{"create", "--pod", podName, "--name", ctrName, ALPINE})
+ ctrCreate.WaitWithDefaultTimeout()
+ Expect(ctrCreate).Should(Exit(0))
+ ctrInspect := podmanTest.Podman([]string{"inspect", ctrName})
+ ctrInspect.WaitWithDefaultTimeout()
+ Expect(ctrInspect).Should(Exit(0))
+ ctrData := ctrInspect.InspectContainerToJSON()
+ Expect(ctrData[0].Mounts[0].Name).To(Equal(volName))
+
+ ctr2 := podmanTest.Podman([]string{"run", "--pod", podName, ALPINE, "sh", "-c", "echo hello >> " + "/tmp1/test"})
+ ctr2.WaitWithDefaultTimeout()
+ Expect(ctr2).Should(Exit(0))
+
+ ctr3 := podmanTest.Podman([]string{"run", "--pod", podName, ALPINE, "cat", "/tmp1/test"})
+ ctr3.WaitWithDefaultTimeout()
+ Expect(ctr3.OutputToString()).To(ContainSubstring("hello"))
+
+ })
+
})
diff --git a/test/e2e/run_cgroup_parent_test.go b/test/e2e/run_cgroup_parent_test.go
index 82b6c3057..e0e1d4b1d 100644
--- a/test/e2e/run_cgroup_parent_test.go
+++ b/test/e2e/run_cgroup_parent_test.go
@@ -13,6 +13,8 @@ import (
. "github.com/onsi/gomega/gexec"
)
+const cgroupRoot = "/sys/fs/cgroup"
+
var _ = Describe("Podman run with --cgroup-parent", func() {
var (
tempdir string
@@ -64,7 +66,6 @@ var _ = Describe("Podman run with --cgroup-parent", func() {
})
Specify("always honor --cgroup-parent", func() {
- Skip("https://github.com/containers/podman/issues/11165")
SkipIfCgroupV1("test not supported in cgroups v1")
if Containerized() || podmanTest.CgroupManager == "cgroupfs" {
Skip("Requires Systemd cgroup manager support")
@@ -78,36 +79,31 @@ var _ = Describe("Podman run with --cgroup-parent", func() {
Expect(run).Should(Exit(0))
cid := run.OutputToString()
- exec := podmanTest.Podman([]string{"exec", cid, "cat", "/proc/self/cgroup"})
+ exec := podmanTest.Podman([]string{"exec", cid, "cat", "/proc/1/cgroup"})
exec.WaitWithDefaultTimeout()
Expect(exec).Should(Exit(0))
containerCgroup := strings.TrimRight(strings.Replace(exec.OutputToString(), "0::", "", -1), "\n")
- content, err := ioutil.ReadFile(filepath.Join("/sys/fs/cgroup", containerCgroup, "cgroup.procs"))
- Expect(err).To(BeNil())
-
// Move the container process to a sub cgroup
- subCgroupPath := filepath.Join(filepath.Join("/sys/fs/cgroup", containerCgroup, "old-container"))
-
- err = os.MkdirAll(subCgroupPath, 0755)
+ content, err := ioutil.ReadFile(filepath.Join(cgroupRoot, containerCgroup, "cgroup.procs"))
Expect(err).To(BeNil())
-
- err = ioutil.WriteFile(filepath.Join(subCgroupPath, "cgroup.procs"), content, 0644)
+ oldSubCgroupPath := filepath.Join(filepath.Join(cgroupRoot, containerCgroup, "old-container"))
+ err = os.MkdirAll(oldSubCgroupPath, 0755)
+ Expect(err).To(BeNil())
+ err = ioutil.WriteFile(filepath.Join(oldSubCgroupPath, "cgroup.procs"), content, 0644)
Expect(err).To(BeNil())
- cgroup := filepath.Dir(containerCgroup)
+ newCgroup := fmt.Sprintf("%s/new-container", containerCgroup)
+ err = os.MkdirAll(filepath.Join(cgroupRoot, newCgroup), 0755)
+ Expect(err).To(BeNil())
- run = podmanTest.Podman([]string{"--cgroup-manager=cgroupfs", "run", "-d", fmt.Sprintf("--cgroup-parent=%s", cgroup), fedoraMinimal, "sleep", "100"})
+ run = podmanTest.Podman([]string{"--cgroup-manager=cgroupfs", "run", "--rm", "--cgroupns=host", fmt.Sprintf("--cgroup-parent=%s", newCgroup), fedoraMinimal, "cat", "/proc/self/cgroup"})
run.WaitWithDefaultTimeout()
Expect(run).Should(Exit(0))
+ cgroupEffective := strings.TrimRight(strings.Replace(run.OutputToString(), "0::", "", -1), "\n")
- exec = podmanTest.Podman([]string{"exec", cid, "cat", "/proc/self/cgroup"})
- exec.WaitWithDefaultTimeout()
- Expect(exec).Should(Exit(0))
- cgroupEffective := filepath.Dir(strings.TrimRight(strings.Replace(exec.OutputToString(), "0::", "", -1), "\n"))
-
- Expect(cgroupEffective).To(Equal(cgroup))
+ Expect(newCgroup).To(Equal(filepath.Dir(cgroupEffective)))
})
Specify("valid --cgroup-parent using slice", func() {
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index b91b8a3b2..ec4b0d997 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -11,6 +11,7 @@ import (
"syscall"
"time"
+ "github.com/containers/podman/v3/pkg/cgroups"
. "github.com/containers/podman/v3/test/utils"
"github.com/containers/storage/pkg/stringid"
"github.com/mrunalp/fileutils"
@@ -1334,35 +1335,36 @@ USER mail`, BB)
})
It("podman run with cgroups=disabled runs without cgroups", func() {
- SkipIfRootless("FIXME: I believe this should work but need to fix this test")
SkipIfRootlessCgroupsV1("Disable cgroups not supported on cgroupv1 for rootless users")
// Only works on crun
if !strings.Contains(podmanTest.OCIRuntime, "crun") {
Skip("Test only works on crun")
}
+ ownsCgroup, err := cgroups.UserOwnsCurrentSystemdCgroup()
+ Expect(err).ShouldNot(HaveOccurred())
+ if !ownsCgroup {
+ // Podman moves itself to a new cgroup if it doesn't own the current cgroup
+ Skip("Test only works when Podman owns the current cgroup")
+ }
+
+ trim := func(i string) string {
+ return strings.TrimSuffix(i, "\n")
+ }
+
curCgroupsBytes, err := ioutil.ReadFile("/proc/self/cgroup")
Expect(err).ShouldNot(HaveOccurred())
- var curCgroups = string(curCgroupsBytes)
+ curCgroups := trim(string(curCgroupsBytes))
fmt.Printf("Output:\n%s\n", curCgroups)
Expect(curCgroups).ToNot(Equal(""))
- ctrName := "testctr"
- container := podmanTest.Podman([]string{"run", "--name", ctrName, "-d", "--cgroups=disabled", ALPINE, "top"})
+ container := podmanTest.Podman([]string{"run", "--cgroupns=host", "--cgroups=disabled", ALPINE, "cat", "/proc/self/cgroup"})
container.WaitWithDefaultTimeout()
Expect(container).Should(Exit(0))
- // Get PID and get cgroups of that PID
- inspectOut := podmanTest.InspectContainer(ctrName)
- Expect(len(inspectOut)).To(Equal(1))
- pid := inspectOut[0].State.Pid
- Expect(pid).ToNot(Equal(0))
- Expect(inspectOut[0].HostConfig.CgroupParent).To(Equal(""))
-
- ctrCgroupsBytes, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cgroup", pid))
- Expect(err).ShouldNot(HaveOccurred())
- var ctrCgroups = string(ctrCgroupsBytes)
+ ctrCgroups := trim(container.OutputToString())
fmt.Printf("Output\n:%s\n", ctrCgroups)
+
Expect(ctrCgroups).To(Equal(curCgroups))
})
diff --git a/test/system/070-build.bats b/test/system/070-build.bats
index 47db08eb1..03c7984e2 100644
--- a/test/system/070-build.bats
+++ b/test/system/070-build.bats
@@ -464,7 +464,7 @@ Labels.$label_name | $label_value
local -a files=(
-test1 -test1.txt
test2 test2.txt
- subdir/sub1 subdir/sub1.txt
+ -subdir/sub1 -subdir/sub1.txt
-subdir/sub2 -subdir/sub2.txt
this-file-does-not-match-anything-in-ignore-file
comment
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index ad5891dd9..bdedfae19 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -32,7 +32,6 @@ load helpers
# Bind-mount this file with a different name to a container running httpd
run_podman run -d --name myweb -p "$HOST_PORT:80" \
- --restart always \
-v $INDEX1:/var/www/index.txt:Z \
-w /var/www \
$IMAGE /bin/busybox-extras httpd -f -p 80
@@ -67,46 +66,6 @@ load helpers
run_podman 125 port myweb 99/tcp
is "$output" 'Error: failed to find published port "99/tcp"'
- # Tests #10310: podman will restart slirp4netns on container restart
- run_podman container inspect --format "{{.State.Pid}}" $cid
- pid=$output
-
- # Kill the process; podman restart policy will bring up a new container.
- # -9 is crucial: busybox httpd ignores all other signals.
- kill -9 $pid
- # Wait for process to exit
- retries=30
- while kill -0 $pid; do
- sleep 0.5
- retries=$((retries - 1))
- if [[ $retries -eq 0 ]]; then
- die "Process $pid (container $cid) refused to die"
- fi
- done
-
- # Wait for container to restart
- retries=20
- while :;do
- run_podman container inspect --format "{{.State.Pid}}" myweb
- # pid is 0 as long as the container is not running
- if [[ $output -ne 0 ]]; then
- if [[ $output == $pid ]]; then
- die "This should never happen! Restarted container has same PID ($output) as killed one!"
- fi
- break
- fi
- sleep 0.5
- retries=$((retries - 1))
- if [[ $retries -eq 0 ]]; then
- die "Timed out waiting for container to restart"
- fi
- done
-
- # Verify http contents again: curl from localhost
- # Use retry since it can take a moment until the new container is ready
- run curl --retry 2 -s $SERVER/index.txt
- is "$output" "$random_1" "curl 127.0.0.1:/index.txt after restart"
-
# Clean up
run_podman stop -t 1 myweb
run_podman rm myweb
@@ -476,4 +435,82 @@ load helpers
run_podman network rm -f $netname $netname2
}
+@test "podman network after restart" {
+ random_1=$(random_string 30)
+
+ HOST_PORT=$(random_free_port)
+ SERVER=http://127.0.0.1:$HOST_PORT
+
+ # Create a test file with random content
+ INDEX1=$PODMAN_TMPDIR/hello.txt
+ echo $random_1 > $INDEX1
+
+ local netname=testnet-$(random_string 10)
+ run_podman network create $netname
+ is "$output" ".*/cni/net.d/$netname.conflist" "output of 'network create'"
+
+ for network in "slirp4netns" "$netname"; do
+ # Start container with the restart always policy
+ run_podman run -d --name myweb -p "$HOST_PORT:80" \
+ --restart always \
+ --network $network \
+ -v $INDEX1:/var/www/index.txt:Z \
+ -w /var/www \
+ $IMAGE /bin/busybox-extras httpd -f -p 80
+ cid=$output
+
+ # Tests #10310: podman will restart slirp4netns on container restart
+ run_podman container inspect --format "{{.State.Pid}}" $cid
+ pid=$output
+
+ # Kill the process; podman restart policy will bring up a new container.
+ # -9 is crucial: busybox httpd ignores all other signals.
+ kill -9 $pid
+ # Wait for process to exit
+ retries=30
+ while kill -0 $pid; do
+ sleep 0.5
+ retries=$((retries - 1))
+ if [[ $retries -eq 0 ]]; then
+ die "Process $pid (container $cid) refused to die"
+ fi
+ done
+
+ # Wait for container to restart
+ retries=20
+ while :;do
+ run_podman container inspect --format "{{.State.Pid}}" $cid
+ # pid is 0 as long as the container is not running
+ if [[ $output -ne 0 ]]; then
+ if [[ $output == $pid ]]; then
+ die "This should never happen! Restarted container has same PID ($output) as killed one!"
+ fi
+ break
+ fi
+ sleep 0.5
+ retries=$((retries - 1))
+ if [[ $retries -eq 0 ]]; then
+ die "Timed out waiting for container to restart"
+ fi
+ done
+
+ # Verify http contents again: curl from localhost
+ # Use retry since it can take a moment until the new container is ready
+ run curl --retry 2 -s $SERVER/index.txt
+ is "$output" "$random_1" "curl 127.0.0.1:/index.txt after auto restart"
+
+ run_podman restart $cid
+ # Verify http contents again: curl from localhost
+ # Use retry since it can take a moment until the new container is ready
+ run curl --retry 2 -s $SERVER/index.txt
+ is "$output" "$random_1" "curl 127.0.0.1:/index.txt after podman restart"
+
+ run_podman stop -t 0 $cid
+ run_podman rm -f $cid
+ done
+
+ # Cleanup network
+ run_podman network rm $netname
+}
+
# vim: filetype=sh