spiegel_podman/test/system
Stefano Brivio ea4f168b3a test/system: Use procfs to find bound ports, with optional address and protocol
Using bash /dev/tcp/ pseudo-device files to probe for bound ports has
indeed the advantage of simplicity, but comes with a few drawbacks:

- it will actually send data to unsuspecting services that might be
  running in the same network namespace as the tests, possibly
  causing unwanted interactions

- it doesn't allow for UDP probing

- it makes it impossible to clearly distinguish between different
  address bindings

Replace that approach with a new helper, port_is_bound(), that uses
procfs entries at /proc/net to detect bound ports, without the need
for active probing.

We can now implement optional parameters in callers, to check if a
port if free for binding to a given address, including any IPv4
(0.0.0.0) or any IPv6 (::0) address, and for a given protocol, TCP
or UDP.

Extend random_free_port() and random_free_port_range() to support
that.

The implementation of one function in the file
test/system/helpers.bash, namely ipv6_to_procfs(), and the
implementation of the corresponding own test, delimited by the
markers "# BEGIN ipv6_to_procfs" and "# END   ipv6_to_procfs" in the
file test/system/helpers.c was provided, on the public forum at:

  https://github.com/containers/podman/pull/16141

by Ed Santiago <santiago@redhat.com>, who expressly invited me to
include them in this code submission.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-11-08 00:16:35 +01:00
..
000-TEMPLATE system tests: add assert(), and start using it 2022-04-20 16:14:42 -06:00
001-basic.bats System tests: stop deep-checking log-level 2022-09-28 09:30:23 -06:00
005-info.bats CI: set and verify DESIRED_NETWORK (netavark, cni) 2022-11-03 04:40:42 -06:00
010-images.bats Add --insecure,--tls-verify,--verbose flags to podman manifest inspect 2022-11-03 08:00:15 -04:00
011-image.bats --authfile command line argument for image sign command. 2021-11-11 15:11:19 -05:00
012-manifest.bats Add --insecure,--tls-verify,--verbose flags to podman manifest inspect 2022-11-03 08:00:15 -04:00
015-help.bats Cleanup: fix problems reported by shell lint 2022-09-15 20:10:34 -06:00
020-tag.bats migrate Podman to containers/common/libimage 2021-05-05 11:30:12 +02:00
030-run.bats remove container/pod id file along with container/pod 2022-11-03 17:07:09 +01:00
032-sig-proxy.bats sig-proxy test: bump timeout 2022-10-25 15:12:56 +02:00
035-logs.bats System tests: fix three races 2022-09-14 10:49:18 -06:00
037-runlabel.bats system tests: runlabel: use podman-under-test 2022-10-26 05:35:10 -06:00
040-ps.bats system tests: add assert(), and start using it 2022-04-20 16:14:42 -06:00
045-start.bats System tests: fix three races 2022-09-14 10:49:18 -06:00
050-stop.bats Output messages display rawInput 2022-08-02 18:28:37 +09:00
055-rm.bats Add rm --filter option 2022-07-30 10:59:59 +09:00
060-mount.bats Fix spelling "read only" -> "read-only" 2022-07-02 08:37:43 +02:00
065-cp.bats Cleanup: fix problems reported by shell lint 2022-09-15 20:10:34 -06:00
070-build.bats Fixup Buildah merge 2022-09-23 14:13:12 -04:00
075-exec.bats System tests: reenable some skipped aarch64 tests 2022-09-21 14:07:22 -06:00
080-pause.bats Revamp Libpod state strings for Docker compat 2022-01-17 13:56:07 -05:00
090-events.bats system tests: periodic cleanup and fixes 2022-09-12 12:17:51 -06:00
110-history.bats Add CreatedSince & CreatedAt format fields to podman image history 2022-04-27 15:15:03 -04:00
120-load.bats buildah vendor treadmill 2022-07-18 10:49:33 -04:00
125-import.bats Add --time out for podman * rm -f commands 2021-10-04 07:07:56 -04:00
130-kill.bats podman wait: return 0 if container never ran 2022-07-11 13:06:40 +02:00
140-diff.bats Gating tests: diff test: workaround for RHEL8 failure 2021-02-02 15:23:48 -07:00
150-login.bats Add --insecure,--tls-verify,--verbose flags to podman manifest inspect 2022-11-03 08:00:15 -04:00
160-volumes.bats Allow volume mount dups, iff source and dest dirs 2022-10-15 07:38:08 -04:00
170-run-userns.bats System tests: teardown: clean up volumes 2022-10-26 09:56:58 -06:00
180-blkio.bats system tests: add assert(), and start using it 2022-04-20 16:14:42 -06:00
190-run-ipcns.bats system tests: add assert(), and start using it 2022-04-20 16:14:42 -06:00
200-pod.bats remove container/pod id file along with container/pod 2022-11-03 17:07:09 +01:00
220-healthcheck.bats System tests: teardown: clean up volumes 2022-10-26 09:56:58 -06:00
250-systemd.bats system tests: health-on-failure: fix broken logic 2022-10-12 06:29:59 -06:00
251-system-service.bats Return error in podman system service if URI scheme is not unix/tcp 2022-10-06 14:47:03 +03:00
255-auto-update.bats System tests: teardown: clean up volumes 2022-10-26 09:56:58 -06:00
260-sdnotify.bats testimage: add iproute2 & socat, for pasta networking 2022-10-18 11:50:48 -06:00
270-socket-activation.bats testimage: add iproute2 & socat, for pasta networking 2022-10-18 11:50:48 -06:00
271-tcp-cors-server.bats Enable /debug/pprof API service endpoints 2021-10-08 13:57:20 -07:00
272-system-connection.bats Add support for podman context as alias to podman system connection 2022-09-15 08:17:15 -04:00
280-update.bats System tests for podman-update 2022-09-01 15:42:35 -06:00
300-cli-parsing.bats provide better error on invalid flag 2022-02-21 19:12:12 +01:00
320-system-df.bats system df: fix image-size calculations 2022-10-19 11:20:41 +02:00
330-corrupt-images.bats Fix stutters 2022-09-10 07:52:00 -04:00
400-unprivileged-access.bats System tests: teardown: clean up volumes 2022-10-26 09:56:58 -06:00
410-selinux.bats System tests: reenable some skipped aarch64 tests 2022-09-21 14:07:22 -06:00
420-cgroups.bats System tests: fix three races 2022-09-14 10:49:18 -06:00
450-interactive.bats replace golint with revive linter 2022-04-22 15:12:33 +02:00
500-networking.bats Eval symlinks on XDG_RUNTIME_DIR 2022-10-28 14:32:39 -04:00
520-checkpoint.bats Output messages display rawInput 2022-08-02 18:28:37 +09:00
600-completion.bats shell completion: fix problems with container path completion 2022-06-09 13:46:55 +02:00
610-format.bats System tests: cleanup in --format test 2022-09-14 10:59:27 -06:00
700-play.bats podman kube play allow --network host 2022-09-29 18:07:41 +02:00
710-kube.bats Fix stutters 2022-09-10 07:52:00 -04:00
750-trust.bats system tests: add assert(), and start using it 2022-04-20 16:14:42 -06:00
800-config.bats Propagate $CONTAINERS_CONF to conmon 2022-02-18 12:35:25 +11:00
900-ssh.bats Fix documentation of use of tcp connections 2022-08-23 16:12:08 -04:00
build-testimage testimage: add iproute2 & socat, for pasta networking 2022-10-18 11:50:48 -06:00
helpers.bash test/system: Use procfs to find bound ports, with optional address and protocol 2022-11-08 00:16:35 +01:00
helpers.systemd.bash kube play: support auto updates and rollbacks 2022-09-06 08:56:55 +02:00
helpers.t test/system: Use procfs to find bound ports, with optional address and protocol 2022-11-08 00:16:35 +01:00
README.md Cirrus: Add netavark/aardvark system test task 2022-02-03 13:07:56 -05:00
TODO.md docs: update the podman logo 2022-08-07 09:11:53 +08:00

Quick overview of podman system tests. The idea is to use BATS, but with a framework for making it easy to add new tests and to debug failures.

Quick Start

Look at 030-run.bats for a simple but packed example. This introduces the basic set of helper functions:

  • setup (implicit) - resets container storage so there's one and only one (standard) image, and no running containers.

  • parse_table - you can define tables of inputs and expected results, then read those in a while loop. This makes it easy to add new tests. Because bash is not a programming language, the caller of parse_table sometimes needs to massage the returned values; 015-run.bats offers examples of how to deal with the more typical such issues.

  • run_podman - runs command defined in $PODMAN (default: 'podman' but could also be './bin/podman' or 'podman-remote'), with a timeout. Checks its exit status.

  • is - compare actual vs expected output. Emits a useful diagnostic on failure.

  • die - output a properly-formatted message to stderr, and fail test

  • skip_if_rootless - if rootless, skip this test with a helpful message.

  • skip_if_remote - like the above, but skip if testing podman-remote

  • random_string - returns a pseudorandom alphanumeric string

Test files are of the form NNN-name.bats where NNN is a three-digit number. Please preserve this convention, it simplifies viewing the directory and understanding test order. In particular, 00x tests should be reserved for a first-pass fail-fast subset of tests:

bats test/system/00*.bats || exit 1
bats test/system

...the goal being to provide quick feedback on catastrophic failures without having to wait for the entire test suite.

Running tests

To run the tests locally in your sandbox, you can use one of these methods:

  • make;PODMAN=./bin/podman bats ./test/system/070-build.bats # runs just the specified test
  • make;PODMAN=./bin/podman bats ./test/system # runs all
  • make;PODMAN=./bin/podman NETWORK_BACKEND=netavark bats ./test/system # Assert & enable netavark testing

To test as root:

  • $ PODMAN=./bin/podman sudo --preserve-env=PODMAN bats test/system

Analyzing test failures

The top priority for this scheme is to make it easy to diagnose what went wrong. To that end, podman_run always logs all invoked commands, their output and exit codes. In a normal run you will never see this, but BATS will display it on failure. The goal here is to give you everything you need to diagnose without having to rerun tests.

The is comparison function is designed to emit useful diagnostics, in particular, the actual and expected strings. Please do not use the horrible BATS standard of [ x = y ]; that's nearly useless for tracking down failures.

If the above are not enough to help you track down a failure:

Debugging tests

Some functions have dprint statements. To see the output of these, set PODMAN_TEST_DEBUG="funcname" where funcname is the name of the function or perhaps just a substring.

Requirements

The jq tool is needed for parsing JSON output.

Further Details

TBD. For now, look in helpers.bash; each helper function has (what are intended to be) helpful header comments. For even more examples, see and/or run helpers.t; that's a regression test and provides a thorough set of examples of how the helpers work.