summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/common/create.go3
-rw-r--r--pkg/api/handlers/libpod/containers.go17
-rw-r--r--pkg/bindings/containers/containers.go2
-rw-r--r--test/apiv2/20-containers.at21
-rw-r--r--test/system/055-rm.bats12
-rw-r--r--test/system/070-build.bats78
-rw-r--r--test/system/helpers.bash6
7 files changed, 135 insertions, 4 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index 921cd5a71..fbb7f449e 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -2,6 +2,7 @@ package common
import (
"fmt"
+ "os"
"github.com/containers/common/pkg/auth"
"github.com/containers/libpod/cmd/podman/registry"
@@ -464,7 +465,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
"Username or UID (format: <name|uid>[:<group|gid>])",
)
createFlags.String(
- "userns", "",
+ "userns", os.Getenv("PODMAN_USERNS"),
"User namespace to use",
)
createFlags.String(
diff --git a/pkg/api/handlers/libpod/containers.go b/pkg/api/handlers/libpod/containers.go
index 2556cdc2a..506286736 100644
--- a/pkg/api/handlers/libpod/containers.go
+++ b/pkg/api/handlers/libpod/containers.go
@@ -14,6 +14,7 @@ import (
"github.com/containers/libpod/pkg/ps"
"github.com/gorilla/schema"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
func ContainerExists(w http.ResponseWriter, r *http.Request) {
@@ -36,7 +37,8 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
query := struct {
All bool `schema:"all"`
Filters map[string][]string `schema:"filters"`
- Last int `schema:"last"`
+ Last int `schema:"last"` // alias for limit
+ Limit int `schema:"limit"`
Namespace bool `schema:"namespace"`
Pod bool `schema:"pod"`
Size bool `schema:"size"`
@@ -50,11 +52,22 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
return
}
+
+ limit := query.Limit
+ // Support `last` as an alias for `limit`. While Podman uses --last in
+ // the CLI, the API is using `limit`. As we first used `last` in the
+ // API as well, we decided to go with aliasing to prevent any
+ // regression. See github.com/containers/libpod/issues/6413.
+ if _, found := r.URL.Query()["last"]; found {
+ logrus.Info("List containers: received `last` parameter - overwriting `limit`")
+ limit = query.Last
+ }
+
runtime := r.Context().Value("runtime").(*libpod.Runtime)
opts := entities.ContainerListOptions{
All: query.All,
Filters: query.Filters,
- Last: query.Last,
+ Last: limit,
Size: query.Size,
Sort: "",
Namespace: query.Namespace,
diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go
index 929b6bbd5..8c588bb40 100644
--- a/pkg/bindings/containers/containers.go
+++ b/pkg/bindings/containers/containers.go
@@ -35,7 +35,7 @@ func List(ctx context.Context, filters map[string][]string, all *bool, last *int
params.Set("all", strconv.FormatBool(*all))
}
if last != nil {
- params.Set("last", strconv.Itoa(*last))
+ params.Set("limit", strconv.Itoa(*last))
}
if pod != nil {
params.Set("pod", strconv.FormatBool(*pod))
diff --git a/test/apiv2/20-containers.at b/test/apiv2/20-containers.at
index 60f6d97aa..9efebfeb9 100644
--- a/test/apiv2/20-containers.at
+++ b/test/apiv2/20-containers.at
@@ -26,6 +26,27 @@ t GET libpod/containers/json?all=true 200 \
.[0].ExitCode=0 \
.[0].IsInfra=false
+# Make sure `limit` works.
+t GET libpod/containers/json?limit=1 200 \
+ length=1 \
+ .[0].Id~[0-9a-f]\\{64\\} \
+ .[0].Image=$IMAGE \
+ .[0].Command[0]="true" \
+ .[0].State~\\\(exited\\\|stopped\\\) \
+ .[0].ExitCode=0 \
+ .[0].IsInfra=false
+
+# Make sure `last` works, which is an alias for `limit`.
+# See https://github.com/containers/libpod/issues/6413.
+t GET libpod/containers/json?last=1 200 \
+ length=1 \
+ .[0].Id~[0-9a-f]\\{64\\} \
+ .[0].Image=$IMAGE \
+ .[0].Command[0]="true" \
+ .[0].State~\\\(exited\\\|stopped\\\) \
+ .[0].ExitCode=0 \
+ .[0].IsInfra=false
+
cid=$(jq -r '.[0].Id' <<<"$output")
t DELETE libpod/containers/$cid 204
diff --git a/test/system/055-rm.bats b/test/system/055-rm.bats
index 8ef8a119e..6a381a187 100644
--- a/test/system/055-rm.bats
+++ b/test/system/055-rm.bats
@@ -21,6 +21,18 @@ load helpers
run_podman 125 inspect $rand
}
+@test "podman rm - running container, w/o and w/ force" {
+ run_podman run -d $IMAGE sleep 5
+ cid="$output"
+
+ # rm should fail
+ run_podman 2 rm $cid
+ is "$output" "Error: cannot remove container $cid as it is running - running or paused containers cannot be removed without force: container state improper" "error message"
+
+ # rm -f should succeed
+ run_podman rm -f $cid
+}
+
# I'm sorry! This test takes 13 seconds. There's not much I can do about it,
# please know that I think it's justified: podman 1.5.0 had a strange bug
# in with exit status was not preserved on some code paths with 'rm -f'
diff --git a/test/system/070-build.bats b/test/system/070-build.bats
index fd4ce03fc..793c2e5a0 100644
--- a/test/system/070-build.bats
+++ b/test/system/070-build.bats
@@ -99,6 +99,84 @@ EOF
}
+@test "podman build - workdir, cmd, env, label" {
+ tmpdir=$PODMAN_TMPDIR/build-test
+ mkdir -p $tmpdir
+
+ # Random workdir, and multiple random strings to verify command & env
+ workdir=/$(random_string 10)
+ s_echo=$(random_string 15)
+ s_env1=$(random_string 20)
+ s_env2=$(random_string 25)
+ s_env3=$(random_string 30)
+
+ # Label name: make sure it begins with a letter! jq barfs if you
+ # try to ask it for '.foo.<N>xyz', i.e. any string beginning with digit
+ label_name=l$(random_string 8)
+ label_value=$(random_string 12)
+
+ # Command to run on container startup with no args
+ cat >$tmpdir/mycmd <<EOF
+#!/bin/sh
+pwd
+echo "\$1"
+echo "\$MYENV1"
+echo "\$MYENV2"
+echo "\$MYENV3"
+EOF
+
+ cat >$tmpdir/Containerfile <<EOF
+FROM $IMAGE
+LABEL $label_name=$label_value
+RUN mkdir $workdir
+WORKDIR $workdir
+ENV MYENV1=$s_env1
+ENV MYENV2 $s_env2
+ENV MYENV3 this-should-be-overridden
+ADD mycmd /bin/mydefaultcmd
+RUN chmod 755 /bin/mydefaultcmd
+CMD ["/bin/mydefaultcmd","$s_echo"]
+EOF
+
+ # cd to the dir, so we test relative paths (important for podman-remote)
+ cd $PODMAN_TMPDIR
+ run_podman build -t build_test -f build-test/Containerfile build-test
+
+ # Run without args - should run the above script. Verify its output.
+ run_podman run --rm -e MYENV3="$s_env3" build_test
+ is "${lines[0]}" "$workdir" "container default command: pwd"
+ is "${lines[1]}" "$s_echo" "container default command: output from echo"
+ is "${lines[2]}" "$s_env1" "container default command: env1"
+ is "${lines[3]}" "$s_env2" "container default command: env2"
+ is "${lines[4]}" "$s_env3" "container default command: env3 (from cmdline)"
+
+ # test that workdir is set for command-line commands also
+ run_podman run --rm build_test pwd
+ is "$output" "$workdir" "pwd command in container"
+
+ # Confirm that 'podman inspect' shows the expected values
+ # FIXME: can we rely on .Env[0] being PATH, and the rest being in order??
+ run_podman image inspect build_test
+ tests="
+Env[1] | MYENV1=$s_env1
+Env[2] | MYENV2=$s_env2
+Env[3] | MYENV3=this-should-be-overridden
+Cmd[0] | /bin/mydefaultcmd
+Cmd[1] | $s_echo
+WorkingDir | $workdir
+Labels.$label_name | $label_value
+"
+
+ parse_table "$tests" | while read field expect; do
+ actual=$(jq -r ".[0].Config.$field" <<<"$output")
+ dprint "# actual=<$actual> expect=<$expect}>"
+ is "$actual" "$expect" "jq .Config.$field"
+ done
+
+ # Clean up
+ run_podman rmi -f build_test
+}
+
function teardown() {
# A timeout or other error in 'build' can leave behind stale images
# that podman can't even see and which will cascade into subsequent
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 7ec2105d1..7e6f1c1ca 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -2,6 +2,12 @@
# Podman command to run; may be podman-remote
PODMAN=${PODMAN:-podman}
+# If it's a relative path, convert to absolute; otherwise tests can't cd out
+if [[ "$PODMAN" =~ / ]]; then
+ if [[ ! "$PODMAN" =~ ^/ ]]; then
+ PODMAN=$(realpath $PODMAN)
+ fi
+fi
# Standard image to use for most tests
PODMAN_TEST_IMAGE_REGISTRY=${PODMAN_TEST_IMAGE_REGISTRY:-"quay.io"}