Skip to content

Commit

Permalink
Merge pull request containers#6456 from edsantiago/bats
Browse files Browse the repository at this point in the history
system tests : more tests
  • Loading branch information
openshift-merge-robot authored Jun 1, 2020
2 parents 85d3641 + 03d32d0 commit d6bf6b9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
15 changes: 15 additions & 0 deletions test/system/075-exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ load helpers
}

# Issue #4785 - piping to exec statement - fixed in #4818
# Issue #5046 - piping to exec truncates results (actually a conmon issue)
@test "podman exec - cat from stdin" {
skip_if_remote

Expand All @@ -60,6 +61,20 @@ load helpers
run_podman exec -i $cid cat < <(echo $echo_string)
is "$output" "$echo_string" "output read back from 'exec cat'"

# #5046 - large file content gets lost via exec
# Generate a large file with random content; get a hash of its content
local bigfile=${PODMAN_TMPDIR}/bigfile
dd if=/dev/urandom of=$bigfile bs=1024 count=1500
expect=$(sha512sum $bigfile | awk '{print $1}')
# Transfer it to container, via exec, make sure correct #bytes are sent
run_podman exec -i $cid dd of=/tmp/bigfile bs=512 <$bigfile
is "${lines[0]}" "3000+0 records in" "dd: number of records in"
is "${lines[1]}" "3000+0 records out" "dd: number of records out"
# Verify sha. '% *' strips off the path, keeping only the SHA
run_podman exec $cid sha512sum /tmp/bigfile
is "${output% *}" "$expect" "SHA of file in container"

# Clean up
run_podman exec $cid touch /stop
run_podman wait $cid
run_podman rm $cid
Expand Down
32 changes: 23 additions & 9 deletions test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ function teardown() {
skip_if_remote "podman-pod does not work with podman-remote"

podname=pod$(random_string)
run_podman 1 pod exists $podname
run_podman pod create --infra=true --name=$podname
podid="$output"
run_podman pod exists $podname
run_podman pod exists $podid

# Randomly-assigned port in the 5xxx range
for port in $(shuf -i 5000-5999);do
Expand Down Expand Up @@ -91,6 +95,10 @@ function teardown() {
# ...then rm the pod, then rmi the pause image so we don't leave strays.
run_podman pod rm $podname
run_podman rmi $pause_iid

# Pod no longer exists
run_podman 1 pod exists $podid
run_podman 1 pod exists $podname
}

# Random byte
Expand Down Expand Up @@ -131,6 +139,9 @@ function random_ip() {

hostname=$(random_string | tr A-Z a-z).$(random_string | tr A-Z a-z).net

labelname=$(random_string 11)
labelvalue=$(random_string 22)

pod_id_file=${PODMAN_TMPDIR}/pod-id-file

# Create a pod with all the desired options
Expand All @@ -143,7 +154,8 @@ function random_ip() {
--add-host "$add_host_n:$add_host_ip" \
--dns "$dns_server" \
--dns-search "$dns_search" \
--dns-opt "$dns_opt"
--dns-opt "$dns_opt" \
--label "${labelname}=${labelvalue}"
pod_id="$output"

# Check --pod-id-file
Expand All @@ -168,18 +180,20 @@ function random_ip() {
is "$output" ".*nameserver $dns_server" "--dns [server] was added"
is "$output" ".*search $dns_search" "--dns-search was added"
is "$output" ".*options $dns_opt" "--dns-opt was added"
}

@test "podman pod inspect - format" {
skip_if_remote "podman-pod does not work with podman-remote"
# pod inspect
run_podman pod inspect --format '{{.Name}}: {{.ID}} : {{.NumContainers}} : {{.Labels}}' mypod
is "$output" "mypod: $pod_id : 1 : map\[${labelname}:${labelvalue}]" \
"pod inspect --format ..."

run_podman pod create --name podtest
podid=$output
# pod ps
run_podman pod ps --format '{{.ID}} {{.Name}} {{.Status}} {{.Labels}}'
is "$output" "${pod_id:0:12} mypod Running map\[${labelname}:${labelvalue}]" "pod ps"

run_podman pod inspect --format '-> {{.Name}}: {{.NumContainers}}' podtest
is "$output" "-> podtest: 1"
run_podman pod ps --no-trunc --filter "label=${labelname}=${labelvalue}" --format '{{.ID}}'
is "$output" "$pod_id" "pod ps --filter label=..."

run_podman pod rm -f podtest
run_podman pod rm -f mypod
}

# vim: filetype=sh
23 changes: 23 additions & 0 deletions test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,27 @@ load helpers
run_podman rmi busybox
}

# Issue #5466 - port-forwarding doesn't work with this option and -d
@test "podman networking: port with --userns=keep-id" {
skip_if_remote

# FIXME: randomize port, and create second random host port
myport=54321

# Container will exit as soon as 'nc' receives input
run_podman run -d --userns=keep-id -p 127.0.0.1:$myport:$myport \
$IMAGE nc -l -p $myport
cid="$output"

# emit random string, and check it
teststring=$(random_string 30)
echo "$teststring" | nc 127.0.0.1 $myport

run_podman logs $cid
is "$output" "$teststring" "test string received on container"

# Clean up
run_podman rm $cid
}

# vim: filetype=sh

0 comments on commit d6bf6b9

Please sign in to comment.