Commit Graph

11079 Commits

Author SHA1 Message Date
Tom Krizek
445b30b883 Handle missing test_results due to pytest runner interrupt
If pytest execution is interrupted, the hook that exposes test_results
to the pytest session is never called so the results can't be
interpreted.

(cherry picked from commit 0a063f51d3)
2023-05-23 17:41:33 +02:00
Tom Krizek
6103ee988e Run system tests sequentially if xdist is not available
(cherry picked from commit 1cc55d01c7)
2023-05-23 17:41:33 +02:00
Petr Špaček
8627d41d4d Include logs from failing tests in JUnit output
(cherry picked from commit 8952618262)
2023-05-23 17:41:33 +02:00
Petr Špaček
a802e84cd5 Enable live logging for non-parallel pytest runs
This provides incremental output when test is running _without xdist_,
just like the old runner did.

With xdist the live output is not available, I believe because of
https://github.com/pytest-dev/pytest-xdist/issues/402
https://github.com/pytest-dev/pytest-xdist/pull/883 might help with
that, but I'm not going to hold my breath until it is available on
distros we use.

(cherry picked from commit d0619c7a18)
2023-05-23 17:41:33 +02:00
Tom Krizek
a388a689cf Ensure --dist=loadscope is used when running pytest in parallel
The loadscope setting is required for parallel execution of our system
tests using pytest. The option ensure that all tests within a single
(module) scope will be assigned to the same worker.

This is neccessary because the worker sets up the nameservers for all
the tests within a module scope. If tests from the same module would be
assigned to different workers, then the setup could happen multiple
times, causing a race condition. This happens because each module uses
deterministic port numbers for the nameservers.

(cherry picked from commit 8f57bce7af)
2023-05-23 17:41:33 +02:00
Tom Krizek
ac1e7eb40d Invoke pytest runner from run.sh
Utilize developers' muscle memory to incentivize using the pytest runner
instead of the legacy one. The script also serves as basic examples of
how to run the pyest command to achieve the same results as the legacy
runner.

Invoking pytest directly should be the end goal, since it offers many
potentially useful options (refer to pytest --help).

(cherry picked from commit 4dbe8e5347)

(also manually added a additional run.sh -> legacy.run.sh renames)
2023-05-23 17:41:33 +02:00
Tom Krizek
2c167bb35f Add developer docs for pytest system test runner
(cherry picked from commit d1ef51f589)
2023-05-23 16:55:28 +02:00
Tom Krizek
e9c15a5736 Update user docs with pytest system test runner
(cherry picked from commit dc84121004)
2023-05-23 16:55:27 +02:00
Tom Krizek
3b6ca76f46 Add pytest functions for shell system tests
In order to run the shell system tests, the pytest runner has to pick
them up somehow. Adding an extra python file with a single function
for the shell tests for each system test proved to be the most
compatible way of running the shell tests across older pytest/xdist
versions.

Modify the legacy run.sh script to ignore these pytest-runner specific
glue files when executing tests written in pytest.

(cherry picked from commit 2f5bf6d971)

(manually added host/tests_sh_host.py, tkey/tests_sh_tkey.py on top)
2023-05-23 16:55:26 +02:00
Tom Krizek
0df2ea8fab Ignore tempdirs during pytest collection phase
(cherry picked from commit 8a406b73c9)
2023-05-23 16:17:24 +02:00
Tom Krizek
b8d6434d5d Ensure compatiblity with older pytest
Special care needs to be taken to support older pytest / xdist versions.
The target versions are what is available in EL8, since that seems to
have the oldest versions that can be reasonably supported.

(cherry picked from commit 527ac6ad26)
2023-05-23 16:17:24 +02:00
Tom Krizek
eaf64e93aa Keep the tempdir in case test setup/teardown fails
When an issue occurs inside a fixture (e.g. servers fail to start/stop),
the test result won't be detected as failed, but rather an error will be
thrown.

To ensure the tempdir is kept even if the test itself passes but the
system_test() fixture throws an error, a different mechanism is needed.
At the start of the critical test setup section, note that the fixture
hasn't finished yet. When this is detected in the system_test_dir()
fixture, it is recognized as error in test setup/teardown and the temp
directory is kept.

This may seem cumbersome, because it is. It's basically a workaround for
the way pytest handles fixtures and test errors in general.

(cherry picked from commit 247e90c382)
2023-05-23 16:17:24 +02:00
Tom Krizek
cdbdbd9eaf Ensure tempdir is kept for failed system tests
The temporary directory contains artifacts for the pytest module. That
module may contain multiple individual tests which were executed
sequentially. The artifacts should be kept if even one of these tests
failed.

Since pytest doesn't have any facility to expose test results to
fixtures, customize the pytest_runtest_makereport() hook to enable that.
It stores the test results into a session scope variable which is
available in all fixtures.

When deciding whether to remove the temporary directory, find the
relevant test results for this module and don't remove the tmpdir if any
one the tests failed.

(cherry picked from commit 2d93ed8546)
2023-05-23 16:17:24 +02:00
Tom Krizek
ba922ba774 Add --noclean option to pytest runner
Support the --noclean option to allow the user to keep the artifacts
from any test run.

(cherry picked from commit 8b1a906b39)
2023-05-23 16:17:24 +02:00
Tom Krizek
d1e6400d63 Run system tests inside temporary directories
For every pytest module, create a copy of its system test directory and
run the test from that directory. This makes it easier to clean up
afterwards and makes it less error-prone when re-running (failed) tests.

Configure the logger to capture the module's log output into a separate
file available from the temporary directory. This is quite convenient
for exploring failures.

Cases where temporary directory should be kept are handled in a
follow-up commits.

(cherry picked from commit c571af8c8f)
2023-05-23 16:17:24 +02:00
Tom Krizek
0ed639010c Execute the system test workflow in pytest runner
This is basically the pytest re-implementation of the run.sh script.

The fixture is applied to every module and ensures complete test
setup/teardown, such as starting/stopping servers, detecting coredumps
etc.

Note that the fixture system_test_dir is not defined yet. It is omitted
now for review readability and it's added in follow-up commits.

(cherry picked from commit 2b64618624)
2023-05-23 16:17:24 +02:00
Tom Krizek
23cecd2190 Utility fixtures for pytest runner
Add fixtures for deriving system test name from the directory name and
for a module-specific logger.

Add fixtures to execute shell and perl scripts. Similar to how run.sh
calls commands, this functionality is also needed in pytest. The
fixtures take care of switching to a proper directory, logging
everything and handling errors.

Note that the fixture system_test_dir is not defined yet. It is omitted
now for review readability and it's added in follow-up commits.

(cherry picked from commit 6886cc1826)
2023-05-23 16:17:23 +02:00
Tom Krizek
aa199e2726 Assign unique ports to pytest modules
This is basically a pytest re-implementation of the get_ports.sh script.
The main difference is that ports are assigned on a module basis, rather
than a directory basis. Module is the new atomic unit for parallel
execution, therefore it needs to have unique ports to avoid collisions.

Each module gets its ports through the env fixture which is updated with
ports and other module-specific variables.

(cherry picked from commit 0061758156)
2023-05-23 16:17:23 +02:00
Tom Krizek
f23ce6a37f Ensure system test programs and deps are compiled
Some system tests require extra programs and/or dependencies to be
compiled first. This is done via `make check` with the automake
framework when using check_* variables such as check_PROGRAMS.

To avoid running any tests via the automake framework, set the TESTS
env variable to empty string and utilize `make -e check` to override
default Makefile variables with environment ones. This ensures automake
will only compile the needed dependencies without running any tests.

Additional consideration needs to be taken for xdist. The compilation
command should be called just once before any tests are executed. To
achieve that, use the pytest_configure() hook and check that the
PYTEST_XDIST_WORKER env variable isn't set -- if it is, it indicates
we're in the spawned xdist worker and the compilation was already done
by the main pytest process that spawned the workers.

This is mostly done to have on-par functionality with legacy test
framework. In the future, we should get rid of the need to run "empty"
make -e check and perhaps compile test-stuff by default.

(cherry picked from commit ee26066897)
2023-05-23 16:17:23 +02:00
Tom Krizek
6000883f8d Obtain env vars from conf.sh in pytest runner
The commands executed by pytest during a system test need to have the
same environment variables set as if they were executed by the run.sh
shell script.

It was decided that for the moment, legacy way of executing system tests
with run.sh should be kept, which complicates things a bit. In order to
avoid duplicating the required variables in both conf.sh and pytest, it
was decided to use the existing conf.sh as the only authoritative
place for the variables.

It is necessary to process the environment variables from conf.sh right
when conftest.py is loaded, since they might be needed right away (e.g.
to test for feature support during test collection).

This solution is a bit hacky and is only meant to be used during the
transitory phase when both pytest and the legacy run.sh are both
supported. In the future, a superior pytest-only solution should be
used.

For discussion of other options, refer to
https://gitlab.isc.org/isc-projects/bind9/-/merge_requests/6809#note_318889

(cherry picked from commit 2f7af791a1)
2023-05-23 16:17:23 +02:00
Tom Krizek
495216f81c Collect existing tests in pytest runner
Ensure pytest picks up our python test modules, since we're using
tests_*.py convention, which is different from the default.

Configure pytest logging to display the output from all tests (even the
ones that passed). This ensures we have sufficient amount of information
to debug test post-mortem just from the artifacts.

(cherry picked from commit 08c4e35bc0)
2023-05-23 16:17:23 +02:00
Tom Krizek
9112b51bb9 Support both pytest and legacy system test runner
The legacy system test framework uses pytest to execute some tests.
Since it'd be quite difficult to convince pytest to decide whether to
include conftest.py (or which ones to include when launching from
subdir), it makes more sense to have a shared conftest.py which is used
by both the legacy test runner invocations of pytest and the new pytest
system test runner. It is ugly, but once we drop support for the legacy
runner, we'll get rid of it.

Properly scope the *port fixtures in order to ensure they'll work as
expected with the new pytest runner. Instead of using "session" (which
means the fixture is only evaluated once for the entire execution of
pytest), use "module" scope, which is evaluated separately for each
module. The legacy runner invoked pytest for each system test
separately, while the new pytest runner is invoked once for all system
tests -- therefore it requires the more fine-grained "module" scope to
for the fixtures to work properly.

Remove python shebang, as conftest.py isn't supposed to be an executable
script.

(cherry picked from commit 30cb9b7e28)
2023-05-23 16:17:20 +02:00
Michal Nowak
1fa70a559c TSAN summarising line was misplaced in get_core_dumps.sh
The line summarising TSAN reports was misplaced in the ASAN territory
and thus never used.

I also made core dumps, assertion failures, and TSAN reports detection
independent of each other.

(cherry picked from commit 0c4c7ddec4)
2023-05-19 09:20:51 +02:00
Michal Nowak
858954da9a Rewrite the ttl system test to pytest
(cherry picked from commit 0c05c3d97b)
2023-05-11 16:10:23 +02:00
Michal Nowak
da74157440 Rewrite the hooks system test to pytest
Also, enable the test under TSAN.

(cherry picked from commit 5a84c7a09b)
2023-05-11 12:27:42 +02:00
Aram Sargsyan
906525642d dighost.c: don't call check_if_done() twice successively
The check_if_done() function can pass control back out to
dighost_shutdown() (which is part of dig.c, host.c, or nslookup.c),
and calling that twice can cause unexpected problems, if it is not
designed to be idempotent.

Since cancel_lookup() calls check_if_done() implicitly, don't call
check_if_done() again when 'next' is NULL.

(cherry picked from commit e4604b71d2)
2023-05-10 11:41:35 +00:00
Tom Krizek
8820c459c6 Replace dnspython resolver.query with resolver.resolve
The resolver.query() has been deprecated in favor of resolver.resolve();
used that.

This is an omission from 3b1756d450

(cherry picked from commit dee49b7a1f)
2023-05-10 12:55:30 +02:00
Tom Krizek
2dfe5367b7 Ensure named always terminates in the shutdown test
Previously, if an exception would happen inside the `with` block, the
error handler would wait indefinitely for the process to end. That would
never happen, since the termination signal was never sent to named and
the test would get stuck.

Using the try-finally block ensures that the named process is always
killed and any exception or errors will be handled gracefully.

(cherry picked from commit 836e6ed284)
2023-05-10 12:55:30 +02:00
Tom Krizek
947212a93f Refactor shutdown test into more helper functions
Improve code readability by splitting the test into more functions. Some
could be re-used later on for more general-purpose subprocess handling
or named checks.

(cherry picked from commit 9d64f1c1ed)
2023-05-10 12:55:27 +02:00
Evan Hunt
248f765e73 set the default rndc read timeout to 60 seconds
While the connect timeout was set to 60 seconds in rndc, the
idle read timeout was left at the default value of 30 seconds.
This commit sets it back to 60, to match the behavior in 9.16
and earlier.

(cherry picked from commit 9cacf9e336)
2023-05-05 11:46:55 +02:00
Matthijs Mekking
cf8bf1e084 Add log rotation test with absolute file path
Add a test to the logfileconfig system test to test log file rotation
when using absolute file paths.

(cherry picked from commit d9b1df3b5d)
2023-05-03 10:13:02 +02:00
Matthijs Mekking
eb37fd2f13 Add more log/tap rotation tests
Add more tests to the dnstap system test to roll with different values.
Touch some files to make sure the number of existing files exceed the
number that we want to keep.

Add a test to the logfileconfig system test for the increment suffix.

(cherry picked from commit 9fb9670ebc)
2023-05-03 10:12:56 +02:00
Mark Andrews
a3c3012c25 Check removal of ENT when subdomains are removed
Empty-non-terminal NSEC records where not always removed when the
delegations generating them where removed via update. Check that
they now are.

(cherry picked from commit ad91a70d15)
2023-04-25 06:46:08 +01:00
Aram Sargsyan
bc0461d4ae Implement new checks for the xfer system test
Check the max-transfer-time-in and max-transfer-idle-in options.

(cherry picked from commit 5324f047b2)
2023-04-21 17:21:32 +02:00
Aram Sargsyan
305bf677ab Implement new -T options for xfer system tests
'-T transferinsecs' makes named interpret the max-transfer-time-out,
max-transfer-idle-out, max-transfer-time-in and max-transfer-idle-in
configuration options as seconds instead of minutes.

'-T transferslowly' makes named to sleep for one second for every
xfrout message.

'-T transferstuck' makes named to sleep for one minute for every
xfrout message.

(cherry picked from commit dfaecfd752)
2023-04-21 17:21:32 +02:00
Aram Sargsyan
50493282a6 Fix variable name error in the xfer system test
There is no 'ret' in this test, and it is obvious that 'ret=1'
should be 'tmp=1' for the check to work correctly, if the string
is not found in the log file.

(cherry picked from commit 613a9fc659)
2023-04-18 09:39:30 +00:00
Matthijs Mekking
e2167eb1d1 kasp: Add test case for migrating KSK/ZSK to CSK
Add a test case to cover #3679 where a user migrates from a KSK/ZSK
split using auto-dnssec maintain, to the default dnssec-policy (CSK).

The test actually does not use the default dnssec-policy, but it does
use one that has the same keys clause. For testing convenience, we use
the same propagation time values as other test cases that migrate to
dnssec-policy with mismatching existing key set.

(cherry picked from commit c42ec8a56e)
2023-04-17 12:14:00 +02:00
Michal Nowak
fab91f89e6 Do not retry in resolution_fails() on timeout
At the time of test number (19), there were 10 "sending packet to
10.53.0.7" lines in the "legacy/ns1/named.run" file; usually, only seven
are present:

    I:legacy:checking recursive lookup to edns 512 + no tcp server does not cause query loops (19)
    I:legacy:ns1 sent 10 queries to ns7, expected less than 10
    I:legacy:failed

Those three can be attributed to tests "8", "10", and "18", where the
dig of "resolution_fails()" retried after a timeout to succeed with
"status: SERVFAIL" subsequently, as seen in each of
dig.out.test{8,10,18} files.

    ;; communications error to 10.53.0.1#13093: timed out

    ; <<>> DiG 9.19.12-dev <<>> -p 13093 +tcp @10.53.0.1 edns512-notcp. TXT
    ; (1 server found)
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 5368
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

This retry is unnecessary because "resolution_fails()" considers timeout
a positive result.

(cherry picked from commit e05460c813)
2023-04-06 11:39:57 +02:00
Petr Špaček
8f86b48c46 Make rndc dnstap -roll docs easier to read
(cherry picked from commit 2897a45644)
2023-04-05 16:03:24 +02:00
Petr Menšík
c16cabff04 Make it obvious -roll number is optional
Manual page were updated to indicate it, but rndc -h still displays it
as required parameter. Make it look like optional.

(cherry picked from commit 0627214568)
2023-04-05 14:05:14 +02:00
Mark Andrews
bb705e9a90 Remove 'inst != NULL' from cleanup check in plugin_register
'inst' is guarenteed to be non NULL at this point.

    358        *instp = inst;
    359
    360cleanup:

    CID 281450 (#2 of 2): Dereference before null check (REVERSE_INULL)
    check_after_deref: Null-checking inst suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
    361        if (result != ISC_R_SUCCESS && inst != NULL) {
    362                plugin_destroy((void **)&inst);
    363        }
    364
    365        return (result);

(cherry picked from commit 8c5539e905)
2023-04-05 10:27:52 +10:00
Ondřej Surý
36572d4a1a Bump the requirement in the shutdown test to dnspython 2.0.0
The dnspython.Resolve.resolve() requires at least dnspython >= 2.0.0,
this wasn't enforced in the shutdown system test leading to infinite
loop waiting for the server start due to failing resolve() call.
2023-04-04 19:58:45 +00:00
Ondřej Surý
947540fc7f Bump the requirement in dnstap test to dnspython 2.0.0
The dnspython.Resolve.resolve() requires at least dnspython >= 2.0.0,
this wasn't enforced in the dnstap system test.
2023-04-04 16:44:19 +00:00
Ondřej Surý
1b1eaa20bc Squash both rpzextra tests into tests_rpzextra.py
We don't need a separate module/file for every test. Both the rpz tests
could live in the same file.

The setup/teardown of servers if performed separately for each module --
unless there is a need to do that, it's better to avoid it.

(cherry picked from commit 1734d4a33e)
2023-04-04 16:27:48 +02:00
Tom Krizek
b765eac703 Use more concise syntax to check responses in rpzextra tests
All the answers are expected to have exactly one resource record. Check
it directly instead of iterating over all (possible) records.

(cherry picked from commit 2ed26609b8)
2023-04-04 16:27:48 +02:00
Ondřej Surý
f60bed5eb1 Add test for RPZ in multiple views
This adds rudimentary test for response-policy zones in multiple
views.  Different combinations are tested:

- two views with response-policy inherited from options {};
- two views view explicit response-policy using same RPZ zone name
- two views view explicit response-policy using secondary RPZ zone

(cherry picked from commit 1649c768e9)
2023-04-04 16:27:46 +02:00
Ondřej Surý
f38860d561 Replace dnspython resolver.query() with resolver.resolve()
The resolver.query() has been deprecated in favor of resolver.resolve();
used that.

(cherry picked from commit 3b1756d450)
2023-04-04 16:27:31 +02:00
Aram Sargsyan
a7d5ccdb1b nsupdate: set network manager default timeout values
The default values are currently set to 30 seconds, use nsupdate
default (or overriden using the -t option) timeout value instead.

(cherry picked from commit 98c8135692)
2023-04-03 16:19:18 +00:00
Aram Sargsyan
9e42bfd1a0 nsupdate: use the configurable timeout and retry values for all queries
The 'nsupdate' tool, when sending SOA queries, uses a hard-coded value
3 UDP retries and of 5 seconds of timeout for UDP queries, and 100
seconds of timeout for TCP queries.

Use the timeout and retry values which can be configured using the
-t, -u, -r command line options, and which are already used for
sending the update query.

(cherry picked from commit 3ef2a30c75)
2023-04-03 16:18:39 +00:00
Aram Sargsyan
d861433ad4 Update nsupdate -t option's documentation
Add some clarifications about the -t option's behavior differences
in TCP and UDP modes.

(cherry picked from commit a00540ac24)
2023-04-03 16:18:39 +00:00