diff options
| author | Sören Tempel <soeren@soeren-tempel.net> | 2025-03-07 15:29:05 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-03-08 16:09:41 +0100 |
| commit | 5ead9fa56c9ca97456796b09079fcfe0f24d8aa3 (patch) | |
| tree | f3745c362b94621a309450acdb35e5c610698c2a /gnu/tests | |
| parent | a8db2cb547f93f915726eae8ebae7646a4361094 (diff) | |
services: networking: Add dhcpcd service.
This is intended as an alternative to dhcp-client-service-type as
isc-dhcp has reached its end-of-life in 2022 (three years ago!),
see #68619 for more details. Long-term, this services is therefore
intended to replace dhcp-client-service-type.
* gnu/services/networking.scm (dhcpcd-service-type): New service.
(dhcpcd-shepherd-service): New procedure.
(dhcpcd-account-service): New variable.
(dhcpcd-config-file): New procedure.
(dhcpcd-configuration): New record type.
(dhcpcd-serialize-list-of-strings, dhcpcd-serialize-boolean)
(dhcpcd-serialize-string): New procedures.
(serialize-field-name): New procedure.
* gnu/tests/networking.scm (run-dhcpcd-test): New procedure.
(%dhcpcd-os, %test-dhcpcd): New variables.
* doc/guix.texi (Networking Services): Document it.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/tests')
| -rw-r--r-- | gnu/tests/networking.scm | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm index e7c02b9e009..7d54ebba50e 100644 --- a/gnu/tests/networking.scm +++ b/gnu/tests/networking.scm | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #:use-module (guix store) | 32 | #:use-module (guix store) |
| 33 | #:use-module (guix monads) | 33 | #:use-module (guix monads) |
| 34 | #:use-module (guix modules) | 34 | #:use-module (guix modules) |
| 35 | #:use-module (gnu packages admin) | ||
| 35 | #:use-module (gnu packages bash) | 36 | #:use-module (gnu packages bash) |
| 36 | #:use-module (gnu packages linux) | 37 | #:use-module (gnu packages linux) |
| 37 | #:use-module (gnu packages networking) | 38 | #:use-module (gnu packages networking) |
| @@ -44,6 +45,7 @@ | |||
| 44 | %test-inetd | 45 | %test-inetd |
| 45 | %test-openvswitch | 46 | %test-openvswitch |
| 46 | %test-dhcpd | 47 | %test-dhcpd |
| 48 | %test-dhcpcd | ||
| 47 | %test-tor | 49 | %test-tor |
| 48 | %test-iptables | 50 | %test-iptables |
| 49 | %test-ipfs)) | 51 | %test-ipfs)) |
| @@ -675,6 +677,110 @@ subnet 192.168.1.0 netmask 255.255.255.0 { | |||
| 675 | 677 | ||
| 676 | 678 | ||
| 677 | ;;; | 679 | ;;; |
| 680 | ;;; DHCPCD Daemon | ||
| 681 | ;;; | ||
| 682 | |||
| 683 | (define %dhcpcd-os | ||
| 684 | (let ((base-os | ||
| 685 | (simple-operating-system | ||
| 686 | (service dhcpcd-service-type | ||
| 687 | (dhcpcd-configuration | ||
| 688 | (command-arguments '("--debug" "--logfile" "/dev/console")) | ||
| 689 | (interfaces '("ens3"))))))) | ||
| 690 | (operating-system | ||
| 691 | (inherit base-os) | ||
| 692 | (packages | ||
| 693 | (append (list dhcpcd iproute) | ||
| 694 | (operating-system-packages base-os)))))) | ||
| 695 | |||
| 696 | (define (run-dhcpcd-test) | ||
| 697 | "Run tests in %dhcpcd-os with a running dhcpcd daemon on localhost." | ||
| 698 | (define os | ||
| 699 | (marionette-operating-system | ||
| 700 | %dhcpcd-os | ||
| 701 | #:imported-modules '((gnu services herd)))) | ||
| 702 | |||
| 703 | (define vm | ||
| 704 | (virtual-machine os)) | ||
| 705 | |||
| 706 | (define test | ||
| 707 | (with-imported-modules '((gnu build marionette)) | ||
| 708 | #~(begin | ||
| 709 | (use-modules (srfi srfi-64) | ||
| 710 | (gnu build marionette)) | ||
| 711 | (define marionette | ||
| 712 | (make-marionette (list #$vm))) | ||
| 713 | |||
| 714 | (define (wait-for-lease) | ||
| 715 | (marionette-eval | ||
| 716 | '(begin | ||
| 717 | (use-modules (ice-9 popen) (ice-9 rdelim)) | ||
| 718 | |||
| 719 | (let loop ((i 15)) | ||
| 720 | (if (> i 0) | ||
| 721 | (let* ((port (open-input-pipe "dhcpcd --dumplease ens3")) | ||
| 722 | (output (read-string port))) | ||
| 723 | (close-port port) | ||
| 724 | (unless (string-contains output "reason=BOUND") | ||
| 725 | (sleep 1) | ||
| 726 | (loop (- i 1)))) | ||
| 727 | (error "failed to obtain a DHCP lease")))) | ||
| 728 | marionette)) | ||
| 729 | |||
| 730 | (test-runner-current (system-test-runner #$output)) | ||
| 731 | (test-begin "dhcpcd") | ||
| 732 | |||
| 733 | (test-assert "service is running" | ||
| 734 | (marionette-eval | ||
| 735 | '(begin | ||
| 736 | (use-modules (gnu services herd)) | ||
| 737 | |||
| 738 | ;; Make sure the 'dhcpcd' command is found. | ||
| 739 | (setenv "PATH" "/run/current-system/profile/sbin") | ||
| 740 | |||
| 741 | (wait-for-service 'networking)) | ||
| 742 | marionette)) | ||
| 743 | |||
| 744 | (test-assert "IPC socket exists" | ||
| 745 | (marionette-eval | ||
| 746 | '(file-exists? "/var/run/dhcpcd/ens3.sock") | ||
| 747 | marionette)) | ||
| 748 | |||
| 749 | (test-equal "IPC is functional" | ||
| 750 | 0 | ||
| 751 | (marionette-eval | ||
| 752 | '(status:exit-val | ||
| 753 | (system* "dhcpcd" "--dumplease" "ens3")) | ||
| 754 | marionette)) | ||
| 755 | |||
| 756 | (test-equal "aquires IPv4 address via DHCP" | ||
| 757 | 1 | ||
| 758 | (and | ||
| 759 | (wait-for-lease) | ||
| 760 | (marionette-eval | ||
| 761 | '(begin | ||
| 762 | (use-modules (ice-9 popen) (ice-9 rdelim)) | ||
| 763 | |||
| 764 | (let* ((port (open-input-pipe "ip -4 address show dev ens3")) | ||
| 765 | (lines (string-split (read-string port) #\newline))) | ||
| 766 | (close-port port) | ||
| 767 | (length | ||
| 768 | (filter (lambda (line) | ||
| 769 | (string-contains line "scope global dynamic")) | ||
| 770 | lines)))) | ||
| 771 | marionette))) | ||
| 772 | |||
| 773 | (test-end)))) | ||
| 774 | (gexp->derivation "dhcpcd-test" test)) | ||
| 775 | |||
| 776 | (define %test-dhcpcd | ||
| 777 | (system-test | ||
| 778 | (name "dhcpcd") | ||
| 779 | (description "Test that the dhcpcd obtains IP DHCP leases.") | ||
| 780 | (value (run-dhcpcd-test)))) | ||
| 781 | |||
| 782 | |||
| 783 | ;;; | ||
| 678 | ;;; Services related to Tor | 784 | ;;; Services related to Tor |
| 679 | ;;; | 785 | ;;; |
| 680 | 786 | ||
