;;; Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
;;; License: GPL-3.0 or later.
;;;
-;;; DHCP / networking test cases.
+;;; Static networking test cases.
(define-module (tests networking)
#:use-module (guix gexp)
#:export (networking-test-cases))
(define (networking-test-cases marionette)
- "Return a gexp that tests the DHCP client starts and the network
-comes up."
+ "Return a gexp with static networking test assertions."
#~(begin
- (test-begin "networking")
-
- (test-assert "dhcpcd running"
+ (test-assert "net: service running"
(marionette-eval '(begin
(use-modules (gnu services herd))
(start-service 'networking))
#$marionette))
- (test-end)))
+ (test-assert "net: eth0 is up"
+ (marionette-eval '(file-exists?
+ "/sys/class/net/eth0/operstate")
+ #$marionette))))
#:export (sshd-test-cases))
(define (sshd-test-cases marionette connect-gexp)
- "Return a gexp testing the SSH daemon. CONNECT-GEXP is a gexp
-that evaluates to a thunk which, when called, returns the result of a
-shell command run via SSH."
+ "Return a gexp with SSH daemon test assertions."
#~(begin
- (test-begin "sshd")
-
- (test-assert "service running"
+ (test-assert "sshd: service running"
(marionette-eval '(begin
(use-modules (gnu services herd))
(start-service 'ssh-daemon))
#$marionette))
- (test-assert "port 72 TCP"
+ (test-assert "sshd: port 72 TCP"
(wait-for-tcp-port 72
#$marionette))
- (test-equal "shell command via key auth"
+ (test-equal "sshd: shell command via key auth"
'hello
- (#$connect-gexp))
-
- (test-end)))
+ (#$connect-gexp))))
;; extra-content, and accepted-environment mirror production. Auth
;; is relaxed for testing (root login with empty password) following
;; the same pattern as %test-openssh in gnu/tests/ssh.scm.
- (openssh-configuration (openssh openssh-sans-x)
- (port-number 72)
- (permit-root-login #t)
- (allow-empty-passwords? #t)
- (accepted-environment '("LANG" "LC_*"))
- (extra-content (string-append "PrintMotd no\n"
- "ClientAliveInterval 120\n"
- "ClientAliveCountMax 1\n"
- "UseDNS no\n"))))
-
-;; Operating system based on %simple-os with the VPS services and a
-;; test authorized key injected into the OpenSSH configuration.
+ (let ((key-file %test-authorized-keys-file))
+ (openssh-configuration (openssh openssh-sans-x)
+ (port-number 72)
+ (permit-root-login #t)
+ (allow-empty-passwords? #t)
+ (accepted-environment '("LANG" "LC_*"))
+ (extra-content (string-append "PrintMotd no\n"
+ "ClientAliveInterval 120\n"
+ "ClientAliveCountMax 1\n"
+ "UseDNS no\n"))
+ (authorized-keys `(("root" ,key-file))))))
+
+;; Use static networking instead of DHCP -- QEMU user-mode
+;; networking does provide DHCP but it can be unreliable during
+;; early boot, causing dhcpcd to hang and block the marionette REPL.
+(define %static-network-config
+ (let ((addr (network-address (device "eth0")
+ (value "10.0.2.15/24")))
+ (route (network-route (destination "default")
+ (gateway "10.0.2.2"))))
+ (static-networking (addresses (list addr))
+ (routes (list route)))))
+
+(define %static-networking
+ (service static-networking-service-type
+ (list %static-network-config)))
+
(define %vps-test-os
(marionette-operating-system (operating-system
(inherit %simple-os)
(operating-system-packages
%simple-os)))
(services
- (cons* (service dhcpcd-service-type)
+ (cons* %static-networking
(service openssh-service-type
%test-openssh-config)
(service ntp-service-type)
(test-runner-current runner)
+ (test-begin "vps")
+
#$@(map (lambda (tc)
(tc #~marionette))
- test-cases)))))
+ test-cases)
+
+ (test-end "vps")))))
(gexp->derivation "vps-test" test))
;;;
(call-with-connected-session ssh-proc)))
(define %test-vps
- (let ((cases (list (lambda (m)
- (sshd-test-cases m
- (make-ssh-connect m)))
- networking-test-cases ntp-test-cases)))
+ (let ((ssh (lambda (m)
+ (sshd-test-cases m
+ (make-ssh-connect m))))
+ (net (lambda (m)
+ (networking-test-cases m)))
+ (ntp (lambda (m)
+ (ntp-test-cases m))))
(system-test (name "vps")
- (description "VPS test suite: SSH, DHCP, NTP.")
- (value (run-vps-test cases)))))
+ (description "VPS test suite.")
+ (value (run-vps-test (list ssh net ntp))))))