1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2016 John Darrington <jmd@gnu.org>
4 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
5 ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
6 ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
7 ;;; Copyright © 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
9 ;;; This file is part of GNU Guix.
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24 (define-module (gnu tests nfs)
25 #:use-module (gnu tests)
26 #:use-module (gnu bootloader)
27 #:use-module (gnu bootloader grub)
28 #:use-module (gnu system)
29 #:use-module (gnu system file-systems)
30 #:use-module (gnu system shadow)
31 #:use-module (gnu system vm)
32 #:use-module (gnu services)
33 #:use-module (gnu services base)
34 #:use-module (gnu services nfs)
35 #:use-module (gnu services networking)
36 #:use-module (gnu packages onc-rpc)
37 #:use-module (gnu packages nfs)
38 #:use-module (guix gexp)
39 #:use-module (guix store)
40 #:use-module (guix monads)
46 (host-name "olitupmok")
47 (timezone "Europe/Berlin")
48 (locale "en_US.UTF-8")
50 (bootloader (bootloader-configuration
51 (bootloader grub-bootloader)
53 (file-systems %base-file-systems)
54 (users %base-user-accounts)
59 (service rpcbind-service-type)
60 (service dhcp-client-service-type)
63 (define (run-nfs-test name socket)
64 "Run a test of an OS running RPC-SERVICE, which should create SOCKET."
66 (marionette-operating-system
68 #:imported-modules '((gnu services herd)
72 (with-imported-modules '((gnu build marionette))
74 (use-modules (gnu build marionette)
78 (make-marionette (list #$(virtual-machine os))))
80 (define (wait-for-socket file)
81 ;; Wait until SOCKET exists in the guest
84 (cond ((and (file-exists? ,file)
85 (eq? 'socket (stat:type (stat ,file))))
91 (error "Socket didn't show up: " ,file))))
97 (test-begin "rpc-daemon")
99 ;; Wait for the rpcbind daemon to be up and running.
100 (test-assert "RPC service running"
103 (use-modules (gnu services herd))
104 (start-service 'rpcbind-daemon))
107 ;; Check the socket file and that the service is still running.
108 (test-assert "RPC socket exists"
110 (wait-for-socket #$socket)
113 (use-modules (gnu services herd)
116 (live-service-running
118 (memq 'rpcbind-daemon
119 (live-service-provision live)))
120 (current-services))))
123 (test-assert "Probe RPC daemon"
125 '(zero? (system* "rpcinfo" "-p"))
129 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
131 (gexp->derivation name test))
136 (description "Test some things related to NFS.")
137 (value (run-nfs-test name "/var/run/rpcbind.sock"))))
141 (let ((os (simple-operating-system
142 (simple-service 'create-target-directory activation-service-type
145 (chmod "/remote" #o777)
147 (service dhcp-client-service-type)
148 (service nfs-service-type
150 (debug '(nfs nfsd mountd))
151 (exports '(("/export"
152 ;; crossmnt = This is the pseudo root.
153 ;; fsid=0 = root file system of the export
154 "*(ro,insecure,no_subtree_check,crossmnt,fsid=0)"))))))))
157 (host-name "nfs-server")
158 ;; We need to use a tmpfs here, because the test system's root file
159 ;; system cannot be re-exported via NFS.
163 (mount-point "/export")
165 (create-mount-point? #t))
168 ;; Enable debugging output.
169 (modify-services (operating-system-user-services os)
170 (syslog-service-type config
172 (syslog-configuration
177 "*.* /dev/console\n")))))))))
179 (define (run-nfs-server-test)
180 "Run a test of an OS running a service of NFS-SERVICE-TYPE."
182 (marionette-operating-system
184 #:requirements '(nscd)
185 #:imported-modules '((gnu services herd)
186 (guix combinators))))
188 (with-imported-modules '((gnu build marionette))
190 (use-modules (gnu build marionette)
194 (make-marionette (list #$(virtual-machine os))))
195 (define (wait-for-file file)
196 ;; Wait until FILE exists in the guest
199 (cond ((file-exists? ,file)
205 (error "File didn't show up: " ,file))))
211 (test-begin "nfs-daemon")
215 (open-file "/dev/console" "w0"))
216 (chmod "/export" #o777)
217 (with-output-to-file "/export/hello"
218 (lambda () (display "hello world")))
219 (chmod "/export/hello" #o777))
222 (test-assert "nscd PID file is created"
225 (use-modules (gnu services herd))
226 (start-service 'nscd))
229 (test-assert "nscd is listening on its socket"
231 ;; XXX: Work around a race condition in nscd: nscd creates its
232 ;; PID file before it is listening on its socket.
233 '(let ((sock (socket PF_UNIX SOCK_STREAM 0)))
237 (connect sock AF_UNIX "/var/run/nscd/socket")
239 (format #t "nscd is ready~%")
242 (format #t "waiting for nscd...~%")
247 (test-assert "network is up"
250 (use-modules (gnu services herd))
251 (start-service 'networking))
254 ;; Wait for the NFS services to be up and running.
255 (test-assert "nfs services are running"
256 (and (marionette-eval
258 (use-modules (gnu services herd))
259 (start-service 'nfs))
261 (wait-for-file "/var/run/rpc.statd.pid")))
263 (test-assert "nfs share is advertised"
265 '(zero? (system* (string-append #$nfs-utils "/sbin/showmount")
269 (test-assert "nfs share mounted"
272 (and (zero? (system* (string-append #$nfs-utils "/sbin/mount.nfs4")
273 "nfs-server:/" "/remote" "-v"))
274 (file-exists? "/remote/hello")))
277 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
279 (gexp->derivation "nfs-server-test" test))
281 (define %test-nfs-server
284 (description "Test that an NFS server can be started and exported
285 directories can be mounted.")
286 (value (run-nfs-server-test))))