summaryrefslogtreecommitdiff
path: root/gnu/tests/nfs.scm
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2020-01-03 18:19:50 +0100
committerRicardo Wurmus <rekado@elephly.net>2020-01-08 23:56:16 +0100
commit907eeac2e7d5d9c10b65038d486876e577c80d85 (patch)
tree19c64a28cf6c0b0a258720a6a1cb23be1f28022c /gnu/tests/nfs.scm
parenta6bdca6b9b7a5de8244b46d0e16047f6deb31272 (diff)
services: nfs: Add nfs-service-type.
* gnu/services/nfs.scm (<nfs-configuration>): New record. (nfs-configuration, nfs-configuration?, nfs-configuration-nfs-utils, nfs-configuration-nfs-version, nfs-configuration-exports, nfs-configuration-rpcmountd-port, nfs-configuration-rpcstatd-port, nfs-configuration-rpcbind, nfs-configuration-idmap-domain, nfs-configuration-nfsd-port, nfs-configuration-nfsd-threads, nfs-configuration-pipefs-directory, nfs-configuration-debug, nfs-shepherd-services): New procedures. (nfs-service-type): New variable. * doc/guix.texi (Network File System): Document it. * gnu/tests/nfs.scm (%test-nfs-server): New variable. (%base-os): Use default value of rpcbind-service-type.
Diffstat (limited to 'gnu/tests/nfs.scm')
-rw-r--r--gnu/tests/nfs.scm157
1 files changed, 154 insertions, 3 deletions
diff --git a/gnu/tests/nfs.scm b/gnu/tests/nfs.scm
index 7ef9f1f7bfb..014d049ab51 100644
--- a/gnu/tests/nfs.scm
+++ b/gnu/tests/nfs.scm
@@ -4,6 +4,7 @@
4;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com> 4;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
5;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr> 5;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
6;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> 6;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
7;;; Copyright © 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
7;;; 8;;;
8;;; This file is part of GNU Guix. 9;;; This file is part of GNU Guix.
9;;; 10;;;
@@ -33,10 +34,12 @@
33 #:use-module (gnu services nfs) 34 #:use-module (gnu services nfs)
34 #:use-module (gnu services networking) 35 #:use-module (gnu services networking)
35 #:use-module (gnu packages onc-rpc) 36 #:use-module (gnu packages onc-rpc)
37 #:use-module (gnu packages nfs)
36 #:use-module (guix gexp) 38 #:use-module (guix gexp)
37 #:use-module (guix store) 39 #:use-module (guix store)
38 #:use-module (guix monads) 40 #:use-module (guix monads)
39 #:export (%test-nfs)) 41 #:export (%test-nfs
42 %test-nfs-server))
40 43
41(define %base-os 44(define %base-os
42 (operating-system 45 (operating-system
@@ -53,8 +56,7 @@
53 rpcbind 56 rpcbind
54 %base-packages)) 57 %base-packages))
55 (services (cons* 58 (services (cons*
56 (service rpcbind-service-type 59 (service rpcbind-service-type)
57 (rpcbind-configuration))
58 (service dhcp-client-service-type) 60 (service dhcp-client-service-type)
59 %base-services)))) 61 %base-services))))
60 62
@@ -133,3 +135,152 @@
133 (name "nfs") 135 (name "nfs")
134 (description "Test some things related to NFS.") 136 (description "Test some things related to NFS.")
135 (value (run-nfs-test name "/var/run/rpcbind.sock")))) 137 (value (run-nfs-test name "/var/run/rpcbind.sock"))))
138
139
140(define %nfs-os
141 (let ((os (simple-operating-system
142 (simple-service 'create-target-directory activation-service-type
143 #~(begin
144 (mkdir "/remote")
145 (chmod "/remote" #o777)
146 #t))
147 (service dhcp-client-service-type)
148 (service nfs-service-type
149 (nfs-configuration
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)"))))))))
155 (operating-system
156 (inherit os)
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.
160 (file-systems (cons
161 (file-system
162 (device "none")
163 (mount-point "/export")
164 (type "tmpfs")
165 (create-mount-point? #t))
166 %base-file-systems))
167 (services
168 ;; Enable debugging output.
169 (modify-services (operating-system-user-services os)
170 (syslog-service-type config
171 =>
172 (syslog-configuration
173 (inherit config)
174 (config-file
175 (plain-file
176 "syslog.conf"
177 "*.* /dev/console\n")))))))))
178
179(define (run-nfs-server-test)
180 "Run a test of an OS running a service of NFS-SERVICE-TYPE."
181 (define os
182 (marionette-operating-system
183 %nfs-os
184 #:requirements '(nscd)
185 #:imported-modules '((gnu services herd)
186 (guix combinators))))
187 (define test
188 (with-imported-modules '((gnu build marionette))
189 #~(begin
190 (use-modules (gnu build marionette)
191 (srfi srfi-64))
192
193 (define marionette
194 (make-marionette (list #$(virtual-machine os))))
195 (define (wait-for-file file)
196 ;; Wait until FILE exists in the guest
197 (marionette-eval
198 `(let loop ((i 10))
199 (cond ((file-exists? ,file)
200 #t)
201 ((> i 0)
202 (sleep 1)
203 (loop (- i 1)))
204 (else
205 (error "File didn't show up: " ,file))))
206 marionette))
207
208 (mkdir #$output)
209 (chdir #$output)
210
211 (test-begin "nfs-daemon")
212 (marionette-eval
213 '(begin
214 (current-output-port
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))
220 marionette)
221
222 (test-assert "nscd PID file is created"
223 (marionette-eval
224 '(begin
225 (use-modules (gnu services herd))
226 (start-service 'nscd))
227 marionette))
228
229 (test-assert "nscd is listening on its socket"
230 (marionette-eval
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)))
234 (let try ()
235 (catch 'system-error
236 (lambda ()
237 (connect sock AF_UNIX "/var/run/nscd/socket")
238 (close-port sock)
239 (format #t "nscd is ready~%")
240 #t)
241 (lambda args
242 (format #t "waiting for nscd...~%")
243 (usleep 500000)
244 (try)))))
245 marionette))
246
247 (test-assert "network is up"
248 (marionette-eval
249 '(begin
250 (use-modules (gnu services herd))
251 (start-service 'networking))
252 marionette))
253
254 ;; Wait for the NFS services to be up and running.
255 (test-assert "nfs services are running"
256 (and (marionette-eval
257 '(begin
258 (use-modules (gnu services herd))
259 (start-service 'nfs))
260 marionette)
261 (wait-for-file "/var/run/rpc.statd.pid")))
262
263 (test-assert "nfs share is advertised"
264 (marionette-eval
265 '(zero? (system* (string-append #$nfs-utils "/sbin/showmount")
266 "-e" "nfs-server"))
267 marionette))
268
269 (test-assert "nfs share mounted"
270 (marionette-eval
271 '(begin
272 (and (zero? (system* (string-append #$nfs-utils "/sbin/mount.nfs4")
273 "nfs-server:/" "/remote" "-v"))
274 (file-exists? "/remote/hello")))
275 marionette))
276 (test-end)
277 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
278
279 (gexp->derivation "nfs-server-test" test))
280
281(define %test-nfs-server
282 (system-test
283 (name "nfs-server")
284 (description "Test that an NFS server can be started and exported
285directories can be mounted.")
286 (value (run-nfs-server-test))))