1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-05-25 10:31:49 +02:00

services: dnsmasq: Add stats and reload shepherd actions.

* gnu/services/dns.scm (dnsmasq-service-reload-action): New function.
Implements SIGHUP handling for reloading configurations.
(dnsmasq-service-stats-action): New function. Implements SIGUSR1
handling for dumping statistics.
(dnsmasq-shepherd-service): Use new actions.
* doc/guix.texi: Document new actions with examples.
* gnu/tests/networking.scm (%test-dnsmasq): Add tests to verify the
functionality of new actions.

Change-Id: I31f0eb4b26a582e95f7bfdb240110c139f0e16cc
Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
This commit is contained in:
Alexey Abramov
2025-05-08 19:47:43 +02:00
committed by Maxim Cournoyer
parent 50126b39ac
commit efcf1a2334
3 changed files with 175 additions and 0 deletions
+98
View File
@@ -27,6 +27,7 @@
#:use-module (gnu system vm)
#:use-module (gnu services)
#:use-module (gnu services base)
#:use-module (gnu services dns)
#:use-module (gnu services networking)
#:use-module (guix gexp)
#:use-module (guix store)
@@ -46,6 +47,7 @@
%test-openvswitch
%test-dhcpd
%test-dhcpcd
%test-dnsmasq
%test-tor
%test-iptables
%test-ipfs))
@@ -675,6 +677,102 @@ subnet 192.168.1.0 netmask 255.255.255.0 {
(description "Test a running DHCP daemon configuration.")
(value (run-dhcpd-test))))
;;;
;;; dnsmasq tests.
;;;
(define dnsmasq-os-configuration
(dnsmasq-configuration))
(define %dnsmasq-os
(simple-operating-system
(service dhcp-client-service-type)
(service dnsmasq-service-type
(dnsmasq-configuration
(extra-options
(list "--log-facility=/tmp/dnsmasq.log"))))))
(define (run-dnsmasq-test)
(define os
(marionette-operating-system %dnsmasq-os
#:imported-modules '((gnu services herd))))
(define test
(with-imported-modules '((gnu build marionette))
#~(begin
(use-modules (gnu build marionette)
(srfi srfi-64))
(define marionette
(make-marionette (list #$(virtual-machine os))))
(test-runner-current (system-test-runner #$output))
(test-begin "dnsmasq")
(test-assert "dnsmasq is alive"
(marionette-eval
'(begin
(use-modules (gnu services herd))
(wait-for-service 'dnsmasq))
marionette))
(test-assert "pid file exists"
(wait-for-file
'#$(dnsmasq-configuration-pid-file dnsmasq-os-configuration)
marionette))
(test-assert "send SIGHUP"
(positive?
(marionette-eval
'(begin
(use-modules (ice-9 rdelim))
(system* "sync")
(let* ((port (open-input-file "/tmp/dnsmasq.log")))
(seek port 0 SEEK_END)
(system* "herd" "reload" "dnsmasq")
(system* "sync")
(let ((line (read-line port)))
(close-port port)
(string-contains line "read /etc/hosts"))))
marionette)))
(test-assert "send SIGUSR1"
(positive?
(marionette-eval
'(begin
(use-modules (ice-9 rdelim))
(system* "sync")
(let* ((port (open-input-file "/tmp/dnsmasq.log")))
(seek port 0 SEEK_END)
(system* "herd" "stats" "dnsmasq")
(system* "sync")
(let ((line (read-line port)))
(close-port port)
(string-contains-ci line "time"))))
marionette)))
(test-assert "dnsmasq is alive"
(marionette-eval
'(begin
(use-modules (gnu services herd))
(wait-for-service 'dnsmasq))
marionette))
(test-end))))
(gexp->derivation "dnsmasq-test" test))
(define %test-dnsmasq
(system-test
(name "dnsmasq")
(description "Test a running dnsmasq daemon configuration.")
(value (run-dnsmasq-test))))
;;;
;;; DHCPCD Daemon