Add --noout option to prevent the output of ids

Fixes: https://github.com/containers/podman/issues/11515

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2021-11-01 06:27:13 -04:00
parent c75c6ce908
commit fde6ad6373
No known key found for this signature in database
GPG key ID: A2DF901DABE2C028
8 changed files with 41 additions and 5 deletions

View file

@ -114,6 +114,10 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
}
cfg := registry.PodmanConfig()
if cfg.NoOut {
null, _ := os.Open(os.DevNull)
os.Stdout = null
}
// Currently it is only possible to restore a container with the same runtime
// as used for checkpointing. It should be possible to make crun and runc
@ -343,6 +347,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
lFlags.StringVar(&opts.Identity, identityFlagName, ident, "path to SSH identity file, (CONTAINER_SSHKEY)")
_ = cmd.RegisterFlagCompletionFunc(identityFlagName, completion.AutocompleteDefault)
lFlags.BoolVar(&opts.NoOut, "noout", false, "do not output to stdout")
lFlags.BoolVarP(&opts.Remote, "remote", "r", registry.IsRemote(), "Access remote Podman service")
pFlags := cmd.PersistentFlags()
if registry.IsRemote() {

View file

@ -92,6 +92,11 @@ When namespace is set, created containers and pods will join the given namespace
#### **--network-cmd-path**=*path*
Path to the command binary to use for setting up a network. It is currently only used for setting up a slirp4netns network. If "" is used then the binary is looked up using the $PATH environment variable.
#### **--noout**
Redirect stdout to /dev/null. This command will prevent all stdout from the Podman command. The **--noout** option will not block stderr or stdout from containers.
#### **--remote**, **-r**
When true, access to the Podman service will be remote. Defaults to false.
Settings can be modified in the containers.conf file. If the CONTAINER_HOST

View file

@ -40,6 +40,7 @@ type PodmanConfig struct {
Identity string // ssh identity for connecting to server
MaxWorks int // maximum number of parallel threads
MemoryProfile string // Hidden: Should memory profile be taken
NoOut bool // Don't output to stdout
RegistriesConf string // allows for specifying a custom registries.conf
Remote bool // Connection to Podman API Service will use RESTful API
RuntimePath string // --runtime flag will set Engine.RuntimePath

View file

@ -509,6 +509,21 @@ json-file | f
rm -f $new_runtime
}
@test "podman --noout run should print output" {
run_podman --noout run -d --name test $IMAGE echo hi
is "$output" "" "output should be empty"
run_podman wait test
run_podman --noout rm test
is "$output" "" "output should be empty"
}
@test "podman --noout create should print output" {
run_podman --noout create --name test $IMAGE echo hi
is "$output" "" "output should be empty"
run_podman --noout rm test
is "$output" "" "output should be empty"
}
# Regression test for issue #8082
@test "podman run : look up correct image name" {
# Create a 2nd tag for the local image. Force to lower case, and apply it.

View file

@ -173,4 +173,9 @@ load helpers
is "$output" ".*StopSignal SIGTERM failed to stop container stopme in 1 seconds, resorting to SIGKILL" "stopping container should print warning"
}
@test "podman stop --noout" {
run_podman run --rm --name stopme -d $IMAGE top
run_podman --noout stop -t 0 stopme
is "$output" "" "output should be empty"
}
# vim: filetype=sh

View file

@ -21,7 +21,8 @@ load helpers
# time to write a new post-restart time value. Pause by CID, unpause
# by name, just to exercise code paths. While paused, check 'ps'
# and 'inspect', then check again after restarting.
run_podman pause $cid
run_podman --noout pause $cid
is "$output" "" "output should be empty"
run_podman inspect --format '{{.State.Status}}' $cid
is "$output" "paused" "podman inspect .State.Status"
sleep 3

View file

@ -57,7 +57,8 @@ function teardown() {
fi
# Clean up
run_podman pod rm -f -t 0 $podid
run_podman --noout pod rm -f -t 0 $podid
is "$output" "" "output should be empty"
}
@ -330,7 +331,8 @@ EOF
# Note that the internal pause image is built even when --infra-image is
# set to the K8s one.
run_podman pod create --name $pod_name --infra-name "$infra_name" --infra-image "k8s.gcr.io/pause:3.5"
run_podman --noout pod create --name $pod_name --infra-name "$infra_name" --infra-image "k8s.gcr.io/pause:3.5"
is "$output" "" "output should be empty"
run_podman '?' pod create --infra-name "$infra_name"
if [ $status -eq 0 ]; then
die "Podman should fail when user try to create two pods with the same infra-name value"

View file

@ -332,7 +332,8 @@ load helpers
is_rootless || skip "only meaningful for rootless"
local mynetname=testnet-$(random_string 10)
run_podman network create $mynetname
run_podman --noout network create $mynetname
is "$output" "" "output should be empty"
# Test that rootless cni adds /usr/sbin to $PATH
# iptables is located under /usr/sbin and is needed for the CNI plugins.
@ -340,7 +341,8 @@ load helpers
PATH=/usr/local/bin:/usr/bin run_podman run --rm --network $mynetname $IMAGE ip addr
is "$output" ".*eth0.*" "Interface eth0 not found in ip addr output"
run_podman network rm -t 0 -f $mynetname
run_podman --noout network rm -t 0 -f $mynetname
is "$output" "" "output should be empty"
}
@test "podman ipv6 in /etc/resolv.conf" {