bind9/bin/tests/system/configloading/tests_configloading.py
Nicki Křížek f33e2b6d87 Refactor NamedInstance.rndc() to use EnvCmd() interface
To unify the command handling, utilize EnvCmd() to handle rndc commands:

1. Remove isctest.rndc abstractions. They were intended for an upcoming
   python-only implementation. A couple of years later, it doesn't seem
   to be coming any time soon, so let's stick with the interface that
   makes sense today, i.e. use the same command handling interface
   everywhere.
2. Remove the specialized rndc.log in favor of the generic logging
   already implemented by isctest.run.cmd(). I believe the cause of the
   many rndc(log=False) invocations was that nobody wanted this extra
   file. Yet, logging everything by default makes sense for debugging,
   unless there's a good reason not to. In almost all cases, logging was
   switched to the default (enabled).
3. With the NamedInstance.rndc() call now returning CmdResult rather
   than combined stdout+stderr string, adjust all the invocations to use
   `.out` or `.err` as necessary.
4. Replace some manual rndc invocation and its base argument
   construction with the standardized nsX.rndc() call.
5. In cases where rndc is expected to fail, utilize
   raise_on_exception=False and check the `.rc` from the result, rather
   than handling an exception.
6. In addzone/tests_rndc_deadlock.py, refactor the test slightly to
   avoid using EnvCmd() entirely to avoid spamming the logs. This test
   calls rndc in a loop from multiple threads and such test case is an
   exception which doesn't warrant changing the `isctest.run.cmd()`
   implementation.
2025-12-08 14:57:47 +01:00

69 lines
2.4 KiB
Python

# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
from re import compile as Re
def test_configloading_log(ns1):
"""
This test is a "guard/warning" to make sure the named.conf loading
(parsing), keystore building, kasplist building and view creation is done
outside of the exclusive mode (so, named is still able to answer queries
and operating normally in case of configuration reload). It
is currently based on logging, so it's quite brittle.
"""
log_sequence = [
"load_configuration",
"parsing user configuration from ",
"apply_configuration",
"apply_configuration: configure_keystores",
"apply_configuration: configure_kasplist",
"apply_configuration: create_views",
"loop exclusive mode: starting",
"running",
]
with ns1.watch_log_from_start() as watcher:
watcher.wait_for_sequence(log_sequence)
with ns1.watch_log_from_here() as watcher:
ns1.rndc("reconfig")
watcher.wait_for_sequence(log_sequence)
with ns1.watch_log_from_here() as watcher:
ns1.rndc("reload")
watcher.wait_for_sequence(log_sequence)
def test_reload_fails_log(ns1, templates):
"""
This test ensures that when a reconfig fails during view configuration (or
after), views/zones (which are newly created view/zones which won't be used
and local of apply_configuration) are detached (and freed) before the
exclusive mode is released
"""
log_sequence = [
"apply_configuration",
"loop exclusive mode: starting",
"apply_configuration: configure_views",
Re(r".*port '9999999' out of range"),
"apply_configuration: detaching views",
"loop exclusive mode: ending",
"reloading configuration failed",
]
with ns1.watch_log_from_here() as watcher:
templates.render("ns1/named.conf", {"wrongoption": True})
cmd = ns1.rndc("reload", raise_on_exception=False)
assert cmd.rc != 0
watcher.wait_for_sequence(log_sequence)