spiegel_podman/test
Paul Holzinger a55c2636de
file logger: fix podman logs --tail with partial lines
There is a problem where our tail code does not handles correctly
partial log lines. This makes podman logs --tail output possibly
incorrect lines when k8s-file is used.

This manifests as flake in CI because partial lines are only sometimes
written, basically always when the output is flushed before writing a
newline.

For our code we must not count partial lines which was already done but
the important thing we must keep reading backwards until the next full
(F) line. This is because all partial (P) lines still must be added to
the full line. See the added tests for details on how the log file looks
like.

While fixing this, I rework the tail logic a bit, there is absolutely no
reason to read the lines in a separate goroutine just to pass the lines
back via channel. We can do this in the same routine.
The logic is very simple, read the lines backwards, append lines to
result and then at the end invert the result slice as tail must return
the lines in the correct order. This more efficient then having to
allocate two different slices or to prepend the line as this would
require a new allocation for each line.

Lastly the readFromLogFile() function wrote the lines back to the log
line channel in the same routine as the log lines we read, this was bad
and causes a deadlock when the returned lines are bigger than the
channel size. There is no reason to allocate a big channel size we can
just write the log lines in a different goroutine, in this case the main
routine were read the logs anyway.

A new system test and unit tests have been added to check corner cases.

Fixes #19545

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-08-09 14:48:01 +02:00
..
apiv2 Add support for passing container stop timeout as -1 (infinite) 2023-08-04 08:36:45 -04:00
build
buildah-bud Fixes for vendoring Buildah 2023-06-27 18:04:42 +02:00
certs
checkseccomp go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
compose add a podman-compose command 2023-07-24 19:23:04 +02:00
e2e Merge pull request #19541 from containers/renovate/major-ci-vm-image 2023-08-08 17:11:22 -04:00
framework update to ginkgo v2 2023-05-02 11:27:35 +02:00
goecho
minikube Support Deployment generation with kube generate 2023-03-31 13:34:38 -04:00
python chore(deps): update dependency setuptools to v68 2023-06-19 18:59:03 +00:00
system file logger: fix podman logs --tail with partial lines 2023-08-09 14:48:01 +02:00
testvol Update docker.io/library/golang Docker tag to v1.21 2023-08-09 01:03:32 +00:00
tools fix(deps): update module golang.org/x/tools to v0.11.0 2023-07-05 17:43:10 +00:00
upgrade test/upgrade: correctly share mounts between host and container 2023-06-12 10:31:59 +02:00
utils e2e: fix two toolbox flakes 2023-07-05 06:52:13 -06:00
version enable staticcheck linter 2022-04-22 12:51:29 +02:00
deny.json Always allow pushing from containers-storage 2022-12-16 14:59:00 -05:00
policy.json
README.md Makefile: add ginkgo FOCUS/FOCUS_FILE options 2023-05-16 14:44:05 +02:00
redhat_sigstore.yaml
registries.conf container create: fix --tls-verify parsing 2021-10-27 14:36:25 +02:00
test_podman_baseline.sh volume: add new option -o o=noquota 2022-04-28 13:29:01 +02:00
test_podman_build.sh Use bash binary from env instead of /bin/bash for scripts 2020-08-17 10:42:23 +02:00
test_podman_pods.sh Add --time out for podman * rm -f commands 2021-10-04 07:07:56 -04:00

PODMAN logo

Test utils

Test utils provide common functions and structs for testing. It includes two structs:

  • PodmanTest: Handle the podman command and other global resources like temporary directory. It provides basic methods, like checking podman image and pod status. Test suites should create their owner test struct as a composite of PodmanTest, and their owner PodmanMakeOptions().

  • PodmanSession: Store execution session data and related methods. Such like get command output and so on. It can be used directly in the test suite, only embed it to your owner session struct if you need expend it.

Unittest for test/utils

To ensure neither tests nor utils break, There are unit-tests for each functions and structs in test/utils. When you adding functions or structs to this package, please update both unit-tests for it and this documentation.

Run unit test for test/utils

Run unit test for test/utils.

make localunit

Structure of the test utils and test suites

The test utils package is at the same level of test suites. Each test suites also have their owner common functions and structs stored in libpod_suite_test.go.

Ginkgo test framework

Ginkgo is a BDD testing framework. This allows us to use native Golang to perform our tests and there is a strong affiliation between Ginkgo and the Go test framework.

Installing dependencies

Some external binaries are required to successfully run the tests. The test currently depend on:

  • normal podman runtime dependencies
  • coreutils
  • ncat
  • gzip
  • xz
  • htpasswd
  • iproute2
  • iptables
  • util-linux
  • tar
  • docker
  • systemd/systemctl

Most of these are only required for a few tests so it is not a big issue if not everything is installed. Only a few test should fail then.

Installing ginkgo

Build ginkgo and install it under ./test/tools/build/ginkgo with the following command:

make .install.ginkgo

Integration Tests

Test suite for integration test for podman command line. It has its own structs:

  • PodmanTestIntegration: Integration test struct as a composite of PodmanTest. It set up the global options for podman command to ignore the environment influence from different test system.

  • PodmanSessionIntegration: This struct has it own methods for checking command output with given format JSON by using structs defined in inspect package.

Running the integration tests

You can run the entire suite of integration tests with the following command:

make localintegration

To run the remote tests use:

make remoteintegration

Test variables

Some test only work as rootless while others only work as root. So to test everything you should make sure to run the make command above as normal user and root.

The following environment variables are supported by the test setup:

  • PODMAN_BINARY: path to the podman binary, defaults to bin/podman in the repository root.
  • PODMAN_REMOTE_BINARY: path to the podman-remote binary, defaults to bin/podman-remote in the repository root.
  • QUADLET_BINARY: path to the quadlet binary, defaults to bin/quadlet in the repository root.
  • CONMON_BINARY: path to th conmon binary, defaults to /usr/libexec/podman/conmon.
  • OCI_RUNTIME: which oci runtime to use, defaults to crun.
  • NETWORK_BACKEND: the network backend, either cni (default) or netavark.
  • PODMAN_DB: the database backend boltdb (default) or sqlite.
  • PODMAN_TEST_IMAGE_CACHE_DIR: path were the container images should be cached, defaults to /tmp.

Running a single file of integration tests

You can run a single file of integration tests using the go test command:

make localintegration FOCUS_FILE=your_test.go

FOCUS_FILE file maps to ginkgo's --focus-file option, see the ginkgo docs for the accepted syntax.

For remote tests use the remoteintegration Makefile target instead.

Running a single integration test

Before running the test suite, you have to declare which test you want run in the test file itself. Consider the following actual test:

It("podman inspect bogus pod", func() {
		session := podmanTest.Podman([]string{"pod", "inspect", "foobar"})
		session.WaitWithDefaultTimeout()
		Expect(session).To(ExitWithError())
	})

To mark this as the test you want run, you simply change the It description to FIt. Please note how both the F and I are capitalized. Also see the ginkgo docs.

Note: Be sure you remove the F from the tests before committing your changes or you will skip all tests in that file except the one with the FIt denotation.

Alternatively you can use the FOCUS option which maps to --focus, again see the ginkgo docs for more info about the syntax.

make localintegration FOCUS="podman inspect bogus pod"

System tests

System tests are used for testing the podman CLI in the context of a complete system. It requires that podman, all dependencies, and configurations are in place. The intention of system testing is to match as closely as possible with real-world user/developer use-cases and environments. The orchestration of the environments and tests is left to external tooling.

System tests use Bash Automated Testing System (bats) as a testing framework. Install it via your package manager or get latest stable version directly from the repository, e.g.:

mkdir -p ~/tools/bats
git clone --single-branch --branch v1.1.0 https://github.com/bats-core/bats-core.git ~/tools/bats

Make sure that bats binary (bin/bats in the repository) is in your PATH, if not - add it:

PATH=$PATH:~/tools/bats/bin

System tests also rely on jq, socat, nmap, and other tools. For a comprehensive list, see the %package tests section in the fedora specfile.

Running system tests

When bats is installed and is in your PATH, you can run the test suite with following command:

make localsystem

Running the system tests in a more controlled way

If you would like to run a subset of the system tests, or configure the environment (e.g. root vs rootless, local vs remote), use hack/bats.

For usage run:

hack/bats --help

Contributing to system tests

Please see the TODO list of needed workflows/tests.