summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/e2e/generate_kube_test.go36
-rw-r--r--test/e2e/play_kube_test.go129
-rw-r--r--test/e2e/run_volume_test.go26
-rw-r--r--test/system/030-run.bats11
-rw-r--r--test/system/120-load.bats11
-rw-r--r--test/system/450-interactive.bats92
6 files changed, 262 insertions, 43 deletions
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index 9cfda0e75..1c53307bd 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -155,6 +155,23 @@ var _ = Describe("Podman generate kube", func() {
Expect(numContainers).To(Equal(1))
})
+ It("podman generate kube multiple pods", func() {
+ pod1 := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:pod1", ALPINE, "top"})
+ pod1.WaitWithDefaultTimeout()
+ Expect(pod1.ExitCode()).To(Equal(0))
+
+ pod2 := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:pod2", ALPINE, "top"})
+ pod2.WaitWithDefaultTimeout()
+ Expect(pod2.ExitCode()).To(Equal(0))
+
+ kube := podmanTest.Podman([]string{"generate", "kube", "pod1", "pod2"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ Expect(string(kube.Out.Contents())).To(ContainSubstring(`name: pod1`))
+ Expect(string(kube.Out.Contents())).To(ContainSubstring(`name: pod2`))
+ })
+
It("podman generate kube on pod with host network", func() {
podSession := podmanTest.Podman([]string{"pod", "create", "--name", "testHostNetwork", "--network", "host"})
podSession.WaitWithDefaultTimeout()
@@ -537,21 +554,6 @@ var _ = Describe("Podman generate kube", func() {
Expect(inspect.OutputToString()).To(ContainSubstring(`"pid"`))
})
- It("podman generate kube multiple pods should fail", func() {
- SkipIfRootlessCgroupsV1("Not supported for rootless + CGroupsV1")
- pod1 := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:pod1", ALPINE, "top"})
- pod1.WaitWithDefaultTimeout()
- Expect(pod1.ExitCode()).To(Equal(0))
-
- pod2 := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:pod2", ALPINE, "top"})
- pod2.WaitWithDefaultTimeout()
- Expect(pod2.ExitCode()).To(Equal(0))
-
- kube := podmanTest.Podman([]string{"generate", "kube", "pod1", "pod2"})
- kube.WaitWithDefaultTimeout()
- Expect(kube.ExitCode()).ToNot(Equal(0))
- })
-
It("podman generate kube with pods and containers should fail", func() {
pod1 := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:pod1", ALPINE, "top"})
pod1.WaitWithDefaultTimeout()
@@ -594,7 +596,7 @@ var _ = Describe("Podman generate kube", func() {
Expect(kube.ExitCode()).To(Equal(0))
})
- It("podman generate kube with containers in a pod should fail", func() {
+ It("podman generate kube with containers in pods should fail", func() {
pod1 := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:pod1", "--name", "top1", ALPINE, "top"})
pod1.WaitWithDefaultTimeout()
Expect(pod1.ExitCode()).To(Equal(0))
@@ -603,7 +605,7 @@ var _ = Describe("Podman generate kube", func() {
pod2.WaitWithDefaultTimeout()
Expect(pod2.ExitCode()).To(Equal(0))
- kube := podmanTest.Podman([]string{"generate", "kube", "pod1", "pod2"})
+ kube := podmanTest.Podman([]string{"generate", "kube", "top1", "top2"})
kube.WaitWithDefaultTimeout()
Expect(kube.ExitCode()).ToNot(Equal(0))
})
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 9260d6cd2..cc4450379 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -357,7 +357,8 @@ func writeYaml(content string, fileName string) error {
return nil
}
-func generateKubeYaml(kind string, object interface{}, pathname string) error {
+// getKubeYaml returns a kubernetes YAML document.
+func getKubeYaml(kind string, object interface{}) (string, error) {
var yamlTemplate string
templateBytes := &bytes.Buffer{}
@@ -369,19 +370,41 @@ func generateKubeYaml(kind string, object interface{}, pathname string) error {
case "deployment":
yamlTemplate = deploymentYamlTemplate
default:
- return fmt.Errorf("unsupported kubernetes kind")
+ return "", fmt.Errorf("unsupported kubernetes kind")
}
t, err := template.New(kind).Parse(yamlTemplate)
if err != nil {
- return err
+ return "", err
}
if err := t.Execute(templateBytes, object); err != nil {
+ return "", err
+ }
+
+ return templateBytes.String(), nil
+}
+
+// generateKubeYaml writes a kubernetes YAML document.
+func generateKubeYaml(kind string, object interface{}, pathname string) error {
+ k, err := getKubeYaml(kind, object)
+ if err != nil {
return err
}
- return writeYaml(templateBytes.String(), pathname)
+ return writeYaml(k, pathname)
+}
+
+// generateMultiDocKubeYaml writes multiple kube objects in one Yaml document.
+func generateMultiDocKubeYaml(kubeObjects []string, pathname string) error {
+ var multiKube string
+
+ for _, k := range kubeObjects {
+ multiKube += "---\n"
+ multiKube += k
+ }
+
+ return writeYaml(multiKube, pathname)
}
// ConfigMap describes the options a kube yaml can be configured at configmap level
@@ -1698,4 +1721,102 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
Expect(inspect.ExitCode()).To(Equal(0))
Expect(inspect.OutputToString()).To(Equal("true"))
})
+
+ // Multi doc related tests
+ It("podman play kube multi doc yaml", func() {
+ yamlDocs := []string{}
+ podNames := []string{}
+
+ serviceTemplate := `apiVersion: v1
+kind: Service
+metadata:
+ name: %s
+spec:
+ ports:
+ - port: 80
+ protocol: TCP
+ targetPort: 9376
+ selector:
+ app: %s
+`
+ // generate servies, pods and deployments
+ for i := 0; i < 2; i++ {
+ podName := fmt.Sprintf("testPod%d", i)
+ deploymentName := fmt.Sprintf("testDeploy%d", i)
+ deploymentPodName := fmt.Sprintf("%s-pod-0", deploymentName)
+
+ podNames = append(podNames, podName)
+ podNames = append(podNames, deploymentPodName)
+
+ pod := getPod(withPodName(podName))
+ podDeployment := getPod(withPodName(deploymentName))
+ deployment := getDeployment(withPod(podDeployment))
+ deployment.Name = deploymentName
+
+ // add services
+ yamlDocs = append([]string{
+ fmt.Sprintf(serviceTemplate, podName, podName),
+ fmt.Sprintf(serviceTemplate, deploymentPodName, deploymentPodName)}, yamlDocs...)
+
+ // add pods
+ k, err := getKubeYaml("pod", pod)
+ Expect(err).To(BeNil())
+ yamlDocs = append(yamlDocs, k)
+
+ // add deployments
+ k, err = getKubeYaml("deployment", deployment)
+ Expect(err).To(BeNil())
+ yamlDocs = append(yamlDocs, k)
+ }
+
+ // generate multi doc yaml
+ err = generateMultiDocKubeYaml(yamlDocs, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(0))
+
+ for _, n := range podNames {
+ inspect := podmanTest.Podman([]string{"inspect", n, "--format", "'{{ .State }}'"})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect.ExitCode()).To(Equal(0))
+ Expect(inspect.OutputToString()).To(ContainSubstring(`Running`))
+ }
+ })
+
+ It("podman play kube invalid multi doc yaml", func() {
+ yamlDocs := []string{}
+
+ serviceTemplate := `apiVersion: v1
+kind: Service
+metadata:
+ name: %s
+spec:
+ ports:
+ - port: 80
+ protocol: TCP
+ targetPort: 9376
+ selector:
+ app: %s
+---
+invalid kube kind
+`
+ // add invalid multi doc yaml
+ yamlDocs = append(yamlDocs, fmt.Sprintf(serviceTemplate, "foo", "foo"))
+
+ // add pod
+ pod := getPod()
+ k, err := getKubeYaml("pod", pod)
+ Expect(err).To(BeNil())
+ yamlDocs = append(yamlDocs, k)
+
+ // generate multi doc yaml
+ err = generateMultiDocKubeYaml(yamlDocs, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Not(Equal(0)))
+ })
})
diff --git a/test/e2e/run_volume_test.go b/test/e2e/run_volume_test.go
index 454dfdc83..85a4d6d52 100644
--- a/test/e2e/run_volume_test.go
+++ b/test/e2e/run_volume_test.go
@@ -643,4 +643,30 @@ VOLUME /test/`
found, _ = session.GrepString("888:888")
Expect(found).Should(BeTrue())
})
+
+ It("volume permissions after run", func() {
+ imgName := "testimg"
+ dockerfile := `FROM fedora-minimal
+RUN useradd -m testuser -u 1005
+USER testuser`
+ podmanTest.BuildImage(dockerfile, imgName, "false")
+
+ testString := "testuser testuser"
+
+ test1 := podmanTest.Podman([]string{"run", "-v", "testvol1:/test", imgName, "bash", "-c", "ls -al /test | grep -v root | grep -v total"})
+ test1.WaitWithDefaultTimeout()
+ Expect(test1.ExitCode()).To(Equal(0))
+ Expect(strings.Contains(test1.OutputToString(), testString)).To(BeTrue())
+
+ volName := "testvol2"
+ vol := podmanTest.Podman([]string{"volume", "create", volName})
+ vol.WaitWithDefaultTimeout()
+ Expect(vol.ExitCode()).To(Equal(0))
+
+ test2 := podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:/test", volName), imgName, "bash", "-c", "ls -al /test | grep -v root | grep -v total"})
+ test2.WaitWithDefaultTimeout()
+ Expect(test2.ExitCode()).To(Equal(0))
+ Expect(strings.Contains(test2.OutputToString(), testString)).To(BeTrue())
+
+ })
})
diff --git a/test/system/030-run.bats b/test/system/030-run.bats
index 39ade22af..b2999a9e7 100644
--- a/test/system/030-run.bats
+++ b/test/system/030-run.bats
@@ -668,15 +668,4 @@ json-file | f
is "$output" ".*HOME=/.*"
}
-@test "podman run --tty -i failure with no tty" {
- run_podman run --tty -i --rm $IMAGE echo hello < /dev/null
- is "$output" ".*The input device is not a TTY.*"
-
- run_podman run --tty=false -i --rm $IMAGE echo hello < /dev/null
- is "$output" "hello"
-
- run_podman run --tty -i=false --rm $IMAGE echo hello < /dev/null
- is "$output" "hello"
-}
-
# vim: filetype=sh
diff --git a/test/system/120-load.bats b/test/system/120-load.bats
index d29be462d..67687a5b0 100644
--- a/test/system/120-load.bats
+++ b/test/system/120-load.bats
@@ -126,17 +126,6 @@ verify_iid_and_name() {
verify_iid_and_name $img_name
}
-@test "podman load - will not read from tty" {
- if [ ! -t 0 ]; then
- skip "STDIN is not a tty"
- fi
-
- run_podman 125 load
- is "$output" \
- "Error: cannot read from terminal. Use command-line redirection" \
- "Diagnostic from 'podman load' without redirection or -i"
-}
-
@test "podman load - redirect corrupt payload" {
run_podman 125 load <<< "Danger, Will Robinson!! This is a corrupt tarball!"
is "$output" \
diff --git a/test/system/450-interactive.bats b/test/system/450-interactive.bats
new file mode 100644
index 000000000..33841bc16
--- /dev/null
+++ b/test/system/450-interactive.bats
@@ -0,0 +1,92 @@
+# -*- bats -*-
+#
+# tests of podman commands that require an interactive pty
+#
+
+load helpers
+
+###############################################################################
+# BEGIN setup/teardown
+
+# Each test runs with its own PTY, managed by socat.
+PODMAN_TEST_PTY=$(mktemp -u --tmpdir=${BATS_TMPDIR:-/tmp} podman_pty.XXXXXX)
+PODMAN_DUMMY=$(mktemp -u --tmpdir=${BATS_TMPDIR:-/tmp} podman_dummy.XXXXXX)
+PODMAN_SOCAT_PID=
+
+function setup() {
+ basic_setup
+
+ # Create a pty. Run under 'timeout' because BATS reaps child processes
+ # and if we exit before killing socat, bats will hang forever.
+ timeout 10 socat \
+ PTY,link=$PODMAN_TEST_PTY,raw,echo=0 \
+ PTY,link=$PODMAN_DUMMY,raw,echo=0 &
+ PODMAN_SOCAT_PID=$!
+
+ # Wait for pty
+ retries=5
+ while [[ ! -e $PODMAN_TEST_PTY ]]; do
+ retries=$(( retries - 1 ))
+ if [[ $retries -eq 0 ]]; then
+ die "Timed out waiting for $PODMAN_TEST_PTY"
+ fi
+ sleep 0.5
+ done
+}
+
+function teardown() {
+ if [[ -n $PODMAN_SOCAT_PID ]]; then
+ kill $PODMAN_SOCAT_PID
+ PODMAN_SOCAT_PID=
+ fi
+ rm -f $PODMAN_TEST_PTY $PODMAN_DUMMY_PTY
+
+ basic_teardown
+}
+
+# END setup/teardown
+###############################################################################
+# BEGIN tests
+
+@test "podman detects correct tty size" {
+ skip_if_remote "FIXME: resolved in #9782"
+
+ # Set the pty to a random size. Make rows/columns odd/even, to guarantee
+ # that they can never be the same
+ rows=$(( 15 + RANDOM % 60 | 1 ))
+ cols=$(( 15 + RANDOM % 60 & 126 ))
+ stty rows $rows cols $cols <$PODMAN_TEST_PTY
+
+ # ...and make sure stty under podman reads that.
+ # FIXME: 'sleep 1' is needed for podman-remote; without it, there's
+ # a race condition resulting in the following warning:
+ # WARN[0000] failed to resize TTY: container "xx" in wrong state "stopped"
+ # (also "created")
+ run_podman run -it --name mystty $IMAGE sh -c 'sleep 1;stty size' <$PODMAN_TEST_PTY
+ is "$output" "$rows $cols" "stty under podman reads the correct dimensions"
+}
+
+
+@test "podman load - will not read from tty" {
+ run_podman 125 load <$PODMAN_TEST_PTY
+ is "$output" \
+ "Error: cannot read from terminal. Use command-line redirection" \
+ "Diagnostic from 'podman load' without redirection or -i"
+}
+
+
+@test "podman run --tty -i failure with no tty" {
+ run_podman run --tty -i --rm $IMAGE echo hello < /dev/null
+ is "$output" ".*The input device is not a TTY.*" "-it _without_ a tty"
+
+ run_podman run --tty -i --rm $IMAGE echo hello <$PODMAN_TEST_PTY
+ is "$output" "hello" "-it _with_ a pty"
+
+ run_podman run --tty=false -i --rm $IMAGE echo hello < /dev/null
+ is "$output" "hello" "-tty=false: no warning"
+
+ run_podman run --tty -i=false --rm $IMAGE echo hello < /dev/null
+ is "$output" "hello" "-i=false: no warning"
+}
+
+# vim: filetype=sh