summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2020-01-16 15:35:31 -0700
committerBrent Baude <bbaude@redhat.com>2020-02-23 11:04:39 -0600
commitfab5b35b2ace79564ce182979887f5a062a0e55f (patch)
treed23c87efb042295e2cb8bea9a1ae3b3074073f30
parent5a1609b9cf89940c570e488a2ea0f481b22ed424 (diff)
downloadpodman-fab5b35b2ace79564ce182979887f5a062a0e55f.tar.gz
podman-fab5b35b2ace79564ce182979887f5a062a0e55f.tar.bz2
podman-fab5b35b2ace79564ce182979887f5a062a0e55f.zip
Friendly amendment: tests, and a help message
1) Help message for podman port was missing [PORT] 2) Add test for 'podman port'. And, actually, an entire networking test that I'd written some weeks ago but apparently didn't 'git add'. Signed-off-by: Ed Santiago <santiago@redhat.com> Signed-off-by: Brent Baude <bbaude@redhat.com>
-rw-r--r--cmd/podman/port.go2
-rw-r--r--pkg/adapter/containers.go2
-rw-r--r--test/system/500-networking.bats63
3 files changed, 65 insertions, 2 deletions
diff --git a/cmd/podman/port.go b/cmd/podman/port.go
index e6d10d5fa..4bb79a3a2 100644
--- a/cmd/podman/port.go
+++ b/cmd/podman/port.go
@@ -17,7 +17,7 @@ var (
portDescription = `List port mappings for the CONTAINER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT
`
_portCommand = &cobra.Command{
- Use: "port [flags] CONTAINER",
+ Use: "port [flags] CONTAINER [PORT]",
Short: "List port mappings or a specific mapping for the container",
Long: portDescription,
RunE: func(cmd *cobra.Command, args []string) error {
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index 2b9430d40..78057e3f9 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -1117,7 +1117,7 @@ func (r *LocalRuntime) Port(c *cliconfig.PortValues) ([]*Container, error) {
if !c.All {
names := []string{}
- if len(c.InputArgs) > 1 {
+ if len(c.InputArgs) >= 1 {
names = []string{c.InputArgs[0]}
}
containers, err = shortcuts.GetContainersByContext(false, c.Latest, names, r.Runtime)
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
new file mode 100644
index 000000000..cd836610b
--- /dev/null
+++ b/test/system/500-networking.bats
@@ -0,0 +1,63 @@
+#!/usr/bin/env bats -*- bats -*-
+#
+# Test podman local networking
+#
+
+load helpers
+
+# Copied from tsweeney's https://github.com/containers/libpod/issues/4827
+@test "podman networking: port on localhost" {
+ skip_if_remote
+ random_1=$(random_string 30)
+ random_2=$(random_string 30)
+
+ HOST_PORT=8080
+ SERVER=http://localhost:$HOST_PORT
+
+ # Create a test file with random content
+ INDEX1=$PODMAN_TMPDIR/hello.txt
+ echo $random_1 > $INDEX1
+
+ # Bind-mount this file with a different name to a container running httpd
+ run_podman run -d --name myweb -p "$HOST_PORT:80" \
+ -v $INDEX1:/var/www/index.txt \
+ -w /var/www \
+ busybox httpd -f -p 80
+ cid=$output
+
+ # In that container, create a second file, using exec and redirection
+ run_podman exec -i myweb sh -c "cat > index2.txt" <<<"$random_2"
+ # ...verify its contents as seen from container.
+ run_podman exec -i myweb cat /var/www/index2.txt
+ is "$output" "$random_2" "exec cat index2.txt"
+
+ # Verify http contents: curl from localhost
+ run curl -s $SERVER/index.txt
+ is "$output" "$random_1" "curl localhost:/index.txt"
+ run curl -s $SERVER/index2.txt
+ is "$output" "$random_2" "curl localhost:/index2.txt"
+
+ # Verify http contents: wget from a second container
+ run_podman run --rm --net=host busybox wget -qO - $SERVER/index.txt
+ is "$output" "$random_1" "podman wget /index.txt"
+ run_podman run --rm --net=host busybox wget -qO - $SERVER/index2.txt
+ is "$output" "$random_2" "podman wget /index2.txt"
+
+ # Tests #4889 - two-argument form of "podman ports" was broken
+ run_podman port myweb
+ is "$output" "80/tcp -> 0.0.0.0:$HOST_PORT" "port <cid>"
+ run_podman port myweb 80
+ is "$output" "0.0.0.0:$HOST_PORT" "port <cid> 80"
+ run_podman port myweb 80/tcp
+ is "$output" "0.0.0.0:$HOST_PORT" "port <cid> 80/tcp"
+
+ run_podman 125 port myweb 99/tcp
+ is "$output" 'Error: failed to find published port "99/tcp"'
+
+ # Clean up
+ run_podman stop -t 1 myweb
+ run_podman rm myweb
+ run_podman rmi busybox
+}
+
+# vim: filetype=sh