summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/apiv2/20-containers.at18
-rw-r--r--test/e2e/checkpoint_test.go11
-rw-r--r--test/e2e/generate_kube_test.go113
-rw-r--r--test/e2e/network_create_test.go6
-rw-r--r--test/e2e/run_volume_test.go12
-rw-r--r--test/system/001-basic.bats9
6 files changed, 129 insertions, 40 deletions
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index afff68c22..748a0750f 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -379,3 +379,21 @@ t GET containers/$cid/json 200 \
.HostConfig.Tmpfs['"/mnt/scratch"']~.*mode=755.*
t DELETE containers/$cid?v=true 204
+
+# compat api: tmpfs without mount options
+payload='{"Mounts":[{"Type":"tmpfs","Target":"/mnt/scratch"}]}'
+t POST containers/create Image=$IMAGE HostConfig="$payload" 201 .Id~[0-9a-f]\\{64\\}
+cid=$(jq -r '.Id' <<<"$output")
+t GET containers/$cid/json 200 \
+ .HostConfig.Tmpfs['"/mnt/scratch"']~.*tmpcopyup.* \
+
+t DELETE containers/$cid?v=true 204
+
+# compat api: bind mount without mount options
+payload='{"Mounts":[{"Type":"bind","Source":"/tmp","Target":"/mnt"}]}'
+t POST containers/create Image=$IMAGE HostConfig="$payload" 201 .Id~[0-9a-f]\\{64\\}
+cid=$(jq -r '.Id' <<<"$output")
+t GET containers/$cid/json 200 \
+ .HostConfig.Binds[0]~/tmp:/mnt:.* \
+
+t DELETE containers/$cid?v=true 204
diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go
index 993987f34..770a7c7bd 100644
--- a/test/e2e/checkpoint_test.go
+++ b/test/e2e/checkpoint_test.go
@@ -249,16 +249,19 @@ var _ = Describe("Podman checkpoint", func() {
session := podmanTest.Podman(localRunString)
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
+ cid := session.OutputToString()
+ if !WaitContainerReady(podmanTest, cid, "Ready to accept connections", 20, 1) {
+ Fail("Container failed to get ready")
+ }
IP := podmanTest.Podman([]string{"inspect", "-l", "--format={{.NetworkSettings.IPAddress}}"})
IP.WaitWithDefaultTimeout()
Expect(IP).Should(Exit(0))
// Open a network connection to the redis server
- conn, err := net.Dial("tcp", IP.OutputToString()+":6379")
- if err != nil {
- os.Exit(1)
- }
+ conn, err := net.DialTimeout("tcp4", IP.OutputToString()+":6379", time.Duration(3)*time.Second)
+ Expect(err).To(BeNil())
+
// This should fail as the container has established TCP connections
result := podmanTest.Podman([]string{"container", "checkpoint", "-l"})
result.WaitWithDefaultTimeout()
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index 3e6f1e8c4..69941494b 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strconv"
+ "strings"
"github.com/containers/podman/v3/libpod/define"
@@ -119,20 +120,28 @@ var _ = Describe("Podman generate kube", func() {
Expect(kube.OutputToString()).To(ContainSubstring("type: foo_bar_t"))
})
- It("podman generate service kube on container", func() {
- session := podmanTest.RunTopContainer("top")
+ It("podman generate service kube on container - targetPort should match port name", func() {
+ session := podmanTest.Podman([]string{"create", "--name", "test-ctr", "-p", "3890:3890", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- kube := podmanTest.Podman([]string{"generate", "kube", "-s", "top"})
+ kube := podmanTest.Podman([]string{"generate", "kube", "-s", "test-ctr"})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))
- // TODO - test generated YAML - service produces multiple
- // structs.
- // pod := new(v1.Pod)
- // err := yaml.Unmarshal([]byte(kube.OutputToString()), pod)
- // Expect(err).To(BeNil())
+ // Separate out the Service and Pod yaml
+ arr := strings.Split(string(kube.Out.Contents()), "---")
+ Expect(len(arr)).To(Equal(2))
+
+ svc := new(v1.Service)
+ err := yaml.Unmarshal([]byte(arr[0]), svc)
+ Expect(err).To(BeNil())
+ Expect(len(svc.Spec.Ports)).To(Equal(1))
+ Expect(svc.Spec.Ports[0].TargetPort.IntValue()).To(Equal(3890))
+
+ pod := new(v1.Pod)
+ err = yaml.Unmarshal([]byte(arr[1]), pod)
+ Expect(err).To(BeNil())
})
It("podman generate kube on pod", func() {
@@ -315,21 +324,28 @@ var _ = Describe("Podman generate kube", func() {
})
It("podman generate service kube on pod", func() {
- _, rc, _ := podmanTest.CreatePod(map[string][]string{"--name": {"toppod"}})
- Expect(rc).To(Equal(0))
-
- session := podmanTest.RunTopContainerInPod("topcontainer", "toppod")
+ session := podmanTest.Podman([]string{"create", "--pod", "new:test-pod", "-p", "4000:4000/udp", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- kube := podmanTest.Podman([]string{"generate", "kube", "-s", "toppod"})
+ kube := podmanTest.Podman([]string{"generate", "kube", "-s", "test-pod"})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))
- // TODO: How do we test unmarshal with a service? We have two
- // structs that need to be unmarshalled...
- // _, err := yaml.Marshal(kube.OutputToString())
- // Expect(err).To(BeNil())
+ // Separate out the Service and Pod yaml
+ arr := strings.Split(string(kube.Out.Contents()), "---")
+ Expect(len(arr)).To(Equal(2))
+
+ svc := new(v1.Service)
+ err := yaml.Unmarshal([]byte(arr[0]), svc)
+ Expect(err).To(BeNil())
+ Expect(len(svc.Spec.Ports)).To(Equal(1))
+ Expect(svc.Spec.Ports[0].TargetPort.IntValue()).To(Equal(4000))
+ Expect(svc.Spec.Ports[0].Protocol).To(Equal(v1.ProtocolUDP))
+
+ pod := new(v1.Pod)
+ err = yaml.Unmarshal([]byte(arr[1]), pod)
+ Expect(err).To(BeNil())
})
It("podman generate kube on pod with restartPolicy", func() {
@@ -451,6 +467,10 @@ var _ = Describe("Podman generate kube", func() {
foundOtherPort := 0
for _, ctr := range pod.Spec.Containers {
for _, port := range ctr.Ports {
+ // Since we are using tcp here, the generated kube yaml shouldn't
+ // have anything for protocol under the ports as tcp is the default
+ // for k8s
+ Expect(port.Protocol).To(BeEmpty())
if port.HostPort == 4000 {
foundPort4000 = foundPort4000 + 1
} else if port.HostPort == 5000 {
@@ -463,6 +483,24 @@ var _ = Describe("Podman generate kube", func() {
Expect(foundPort4000).To(Equal(1))
Expect(foundPort5000).To(Equal(1))
Expect(foundOtherPort).To(Equal(0))
+
+ // Create container with UDP port and check the generated kube yaml
+ ctrWithUDP := podmanTest.Podman([]string{"create", "--pod", "new:test-pod", "-p", "6666:66/udp", ALPINE, "top"})
+ ctrWithUDP.WaitWithDefaultTimeout()
+ Expect(ctrWithUDP).Should(Exit(0))
+
+ kube = podmanTest.Podman([]string{"generate", "kube", "test-pod"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube).Should(Exit(0))
+
+ pod = new(v1.Pod)
+ err = yaml.Unmarshal(kube.Out.Contents(), pod)
+ Expect(err).To(BeNil())
+
+ containers := pod.Spec.Containers
+ Expect(len(containers)).To(Equal(1))
+ Expect(len(containers[0].Ports)).To(Equal(1))
+ Expect(containers[0].Ports[0].Protocol).To(Equal(v1.ProtocolUDP))
})
It("podman generate and reimport kube on pod", func() {
@@ -803,7 +841,7 @@ var _ = Describe("Podman generate kube", func() {
Expect(containers[0].Args).To(Equal([]string{"10s"}))
})
- It("podman generate kube - no command", func() {
+ It("podman generate kube - use command from image unless explicitly set in the podman command", func() {
session := podmanTest.Podman([]string{"create", "--name", "test", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
@@ -812,8 +850,8 @@ var _ = Describe("Podman generate kube", func() {
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))
- // Now make sure that the container's command is not set to the
- // entrypoint and it's arguments to "10s".
+ // Now make sure that the container's command in the kube yaml is not set to the
+ // image command.
pod := new(v1.Pod)
err := yaml.Unmarshal(kube.Out.Contents(), pod)
Expect(err).To(BeNil())
@@ -831,8 +869,8 @@ var _ = Describe("Podman generate kube", func() {
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))
- // Now make sure that the container's command is not set to the
- // entrypoint and it's arguments to "10s".
+ // Now make sure that the container's command in the kube yaml is set to the
+ // command passed via the cli to podman create.
pod = new(v1.Pod)
err = yaml.Unmarshal(kube.Out.Contents(), pod)
Expect(err).To(BeNil())
@@ -842,10 +880,10 @@ var _ = Describe("Podman generate kube", func() {
Expect(containers[0].Command).To(Equal(cmd))
})
- It("podman generate kube - use entrypoint from image", func() {
+ It("podman generate kube - use entrypoint from image unless --entrypoint is set", func() {
// Build an image with an entrypoint.
containerfile := `FROM quay.io/libpod/alpine:latest
-ENTRYPOINT /bin/sleep`
+ENTRYPOINT ["sleep"]`
targetPath, err := CreateTempDirInTempDir()
Expect(err).To(BeNil())
@@ -866,17 +904,34 @@ ENTRYPOINT /bin/sleep`
kube.WaitWithDefaultTimeout()
Expect(kube).Should(Exit(0))
- // Now make sure that the container's command is set to the
- // entrypoint and it's arguments to "10s".
+ // Now make sure that the container's command in the kube yaml is NOT set to the
+ // entrypoint but the arguments should be set to "10s".
pod := new(v1.Pod)
err = yaml.Unmarshal(kube.Out.Contents(), pod)
Expect(err).To(BeNil())
containers := pod.Spec.Containers
Expect(len(containers)).To(Equal(1))
-
- Expect(containers[0].Command).To(Equal([]string{"/bin/sh", "-c", "/bin/sleep"}))
Expect(containers[0].Args).To(Equal([]string{"10s"}))
+
+ session = podmanTest.Podman([]string{"create", "--pod", "new:testpod-2", "--entrypoint", "echo", image, "hello"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ kube = podmanTest.Podman([]string{"generate", "kube", "testpod-2"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube).Should(Exit(0))
+
+ // Now make sure that the container's command in the kube yaml is set to the
+ // entrypoint defined by the --entrypoint flag and the arguments should be set to "hello".
+ pod = new(v1.Pod)
+ err = yaml.Unmarshal(kube.Out.Contents(), pod)
+ Expect(err).To(BeNil())
+
+ containers = pod.Spec.Containers
+ Expect(len(containers)).To(Equal(1))
+ Expect(containers[0].Command).To(Equal([]string{"echo"}))
+ Expect(containers[0].Args).To(Equal([]string{"hello"}))
})
It("podman generate kube - --privileged container", func() {
@@ -942,7 +997,7 @@ USER test1`
pod := new(v1.Pod)
err = yaml.Unmarshal(kube.Out.Contents(), pod)
Expect(err).To(BeNil())
- Expect(*pod.Spec.Containers[0].SecurityContext.RunAsUser).To(Equal(int64(10001)))
+ Expect(pod.Spec.Containers[0].SecurityContext.RunAsUser).To(BeNil())
})
It("podman generate kube on named volume", func() {
diff --git a/test/e2e/network_create_test.go b/test/e2e/network_create_test.go
index ae9f112b5..c9e13e7d2 100644
--- a/test/e2e/network_create_test.go
+++ b/test/e2e/network_create_test.go
@@ -43,7 +43,7 @@ var _ = Describe("Podman network create", func() {
It("podman network create with name and subnet", func() {
netName := "subnet-" + stringid.GenerateNonCryptoID()
- nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.12.0/24", netName})
+ nc := podmanTest.Podman([]string{"network", "create", "--subnet", "10.11.12.0/24", "--ip-range", "10.11.12.0/26", netName})
nc.WaitWithDefaultTimeout()
defer podmanTest.removeCNINetwork(netName)
Expect(nc).Should(Exit(0))
@@ -61,7 +61,11 @@ var _ = Describe("Podman network create", func() {
result := results[0]
Expect(result.Name).To(Equal(netName))
Expect(result.Subnets).To(HaveLen(1))
+ Expect(result.Subnets[0].Subnet.String()).To(Equal("10.11.12.0/24"))
Expect(result.Subnets[0].Gateway.String()).To(Equal("10.11.12.1"))
+ Expect(result.Subnets[0].LeaseRange).ToNot(BeNil())
+ Expect(result.Subnets[0].LeaseRange.StartIP.String()).To(Equal("10.11.12.1"))
+ Expect(result.Subnets[0].LeaseRange.EndIP.String()).To(Equal("10.11.12.63"))
// Once a container executes a new network, the nic will be created. We should clean those up
// best we can
diff --git a/test/e2e/run_volume_test.go b/test/e2e/run_volume_test.go
index f1baa7780..634a498b9 100644
--- a/test/e2e/run_volume_test.go
+++ b/test/e2e/run_volume_test.go
@@ -222,7 +222,7 @@ var _ = Describe("Podman run with volumes", func() {
Expect(matches[0]).To(Not(ContainSubstring("nosuid")))
})
- // Container should start when workdir is overlayed volume
+ // Container should start when workdir is overlay volume
It("podman run with volume mounted as overlay and used as workdir", func() {
SkipIfRemote("Overlay volumes only work locally")
if os.Getenv("container") != "" {
@@ -236,7 +236,7 @@ var _ = Describe("Podman run with volumes", func() {
mountPath := filepath.Join(podmanTest.TempDir, "secrets")
os.Mkdir(mountPath, 0755)
- //Container should be able to start with custom overlayed volume
+ //Container should be able to start with custom overlay volume
session := podmanTest.Podman([]string{"run", "--rm", "-v", mountPath + ":/data:O", "--workdir=/data", ALPINE, "echo", "hello"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
@@ -262,15 +262,15 @@ var _ = Describe("Podman run with volumes", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- // create file on overlayed volume
- session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data:O", ALPINE, "sh", "-c", "echo hello >> " + "/data/overlayed"})
+ // create file on overlay volume
+ session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data:O", ALPINE, "sh", "-c", "echo hello >> " + "/data/overlay"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- // volume should contain only `test` not `overlayed`
+ // volume should contain only `test` not `overlay`
session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "ls /data"})
session.WaitWithDefaultTimeout()
- Expect(session.OutputToString()).To(Not(ContainSubstring("overlayed")))
+ Expect(session.OutputToString()).To(Not(ContainSubstring("overlay")))
Expect(session.OutputToString()).To(ContainSubstring("test"))
})
diff --git a/test/system/001-basic.bats b/test/system/001-basic.bats
index 2e5ebe4a3..2de96a01a 100644
--- a/test/system/001-basic.bats
+++ b/test/system/001-basic.bats
@@ -93,6 +93,15 @@ function setup() {
is "$output" "Error: unknown flag: --remote" "podman version --remote"
}
+@test "podman-remote: defaults" {
+ if is_remote; then
+ skip "only applicable on a local run"
+ fi
+
+ CONTAINER_HOST=foobar run_podman --log-level=info --help
+ is "$output" ".*defaulting to '--remote=true'" "CONTAINER_HOST sets --remote true"
+}
+
# Check that just calling "podman-remote" prints the usage message even
# without a running endpoint. Use "podman --remote" for this as this works the same.
@test "podman-remote: check for command usage message without a running endpoint" {