Skip to content

Commit

Permalink
Merge pull request containers#12151 from rhatdan/noout
Browse files Browse the repository at this point in the history
Add --noout option to prevent the output of ids
  • Loading branch information
openshift-merge-robot authored Jan 12, 2022
2 parents f69fcb2 + fde6ad6 commit 3f06616
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions docs/source/markdown/podman.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/entities/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions test/system/050-stop.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/system/080-pause.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand Down Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,17 @@ 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.
# Debian doesn't add /usr/sbin to $PATH for rootless users so we have to add it.
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" {
Expand Down

0 comments on commit 3f06616

Please sign in to comment.