1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016, 2017, 2020 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))
105 ;; Ensure 'rpcinfo' can be found below.
106 (setenv "PATH" "/run/current-system/profile/bin")
108 (start-service 'rpcbind-daemon))
111 ;; Check the socket file and that the service is still running.
112 (test-assert "RPC socket exists"
114 (wait-for-socket #$socket)
117 (use-modules (gnu services herd)
120 (live-service-running
122 (memq 'rpcbind-daemon
123 (live-service-provision live)))
124 (current-services))))
127 (test-assert "Probe RPC daemon"
129 '(zero? (system* "rpcinfo" "-p"))
133 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
135 (gexp->derivation name test))
140 (description "Test some things related to NFS.")
141 (value (run-nfs-test name "/var/run/rpcbind.sock"))))
145 (let ((os (simple-operating-system
146 (simple-service 'create-target-directory activation-service-type
149 (chmod "/remote" #o777)
151 (service dhcp-client-service-type)
152 (service nfs-service-type
154 (debug '(nfs nfsd mountd))
155 (exports '(("/export"
156 ;; crossmnt = This is the pseudo root.
157 ;; fsid=0 = root file system of the export
158 "*(ro,insecure,no_subtree_check,crossmnt,fsid=0)"))))))))
161 (host-name "nfs-server")
162 ;; We need to use a tmpfs here, because the test system's root file
163 ;; system cannot be re-exported via NFS.
167 (mount-point "/export")
169 (create-mount-point? #t))
172 ;; Enable debugging output.
173 (modify-services (operating-system-user-services os)
174 (syslog-service-type config
176 (syslog-configuration
181 "*.* /dev/console\n")))))))))
183 (define (run-nfs-server-test)
184 "Run a test of an OS running a service of NFS-SERVICE-TYPE."
186 (marionette-operating-system
188 #:requirements '(nscd)
189 #:imported-modules '((gnu services herd)
190 (guix combinators))))
192 (with-imported-modules '((gnu build marionette))
194 (use-modules (gnu build marionette)
198 (make-marionette (list #$(virtual-machine os))))
203 (test-begin "nfs-daemon")
207 (open-file "/dev/console" "w0"))
208 (chmod "/export" #o777)
209 (with-output-to-file "/export/hello"
210 (lambda () (display "hello world")))
211 (chmod "/export/hello" #o777))
214 (test-assert "nscd PID file is created"
217 (use-modules (gnu services herd))
218 (start-service 'nscd))
221 (test-assert "nscd is listening on its socket"
222 (wait-for-unix-socket "/var/run/nscd/socket"
225 (test-assert "network is up"
228 (use-modules (gnu services herd))
229 (start-service 'networking))
232 ;; Wait for the NFS services to be up and running.
233 (test-assert "nfs services are running"
234 (and (marionette-eval
236 (use-modules (gnu services herd))
237 (start-service 'nfs))
239 (wait-for-file "/var/run/rpc.statd.pid")))
241 (test-assert "nfs share is advertised"
243 '(zero? (system* (string-append #$nfs-utils "/sbin/showmount")
247 (test-assert "nfs share mounted"
250 (and (zero? (system* (string-append #$nfs-utils "/sbin/mount.nfs4")
251 "nfs-server:/" "/remote" "-v"))
252 (file-exists? "/remote/hello")))
255 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
257 (gexp->derivation "nfs-server-test" test))
259 (define %test-nfs-server
262 (description "Test that an NFS server can be started and exported
263 directories can be mounted.")
264 (value (run-nfs-server-test))))