gnu: ardour: Update to 7.0
[jackhill/guix/guix.git] / gnu / tests / nfs.scm
CommitLineData
7d73b2c6 1;;; GNU Guix --- Functional package management for GNU
1fb75128 2;;; Copyright © 2016, 2017, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
7d73b2c6 3;;; Copyright © 2016 John Darrington <jmd@gnu.org>
b09a8da4 4;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
fdfdecdb 5;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
c24b1547 6;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
907eeac2 7;;; Copyright © 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
7d73b2c6
JD
8;;;
9;;; This file is part of GNU Guix.
10;;;
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.
15;;;
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.
20;;;
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/>.
23
24(define-module (gnu tests nfs)
25 #:use-module (gnu tests)
fdfdecdb 26 #:use-module (gnu bootloader)
b09a8da4 27 #:use-module (gnu bootloader grub)
7d73b2c6 28 #:use-module (gnu system)
7d73b2c6
JD
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)
dbd3454c 36 #:use-module (gnu packages admin)
7d73b2c6 37 #:use-module (gnu packages onc-rpc)
907eeac2 38 #:use-module (gnu packages nfs)
7d73b2c6
JD
39 #:use-module (guix gexp)
40 #:use-module (guix store)
41 #:use-module (guix monads)
907eeac2 42 #:export (%test-nfs
a1a39ed5 43 %test-nfs-server
dbd3454c 44 %test-nfs-full))
7d73b2c6
JD
45
46(define %base-os
47 (operating-system
48 (host-name "olitupmok")
49 (timezone "Europe/Berlin")
50 (locale "en_US.UTF-8")
51
fdfdecdb
TGR
52 (bootloader (bootloader-configuration
53 (bootloader grub-bootloader)
da4e4094 54 (targets '("/dev/sdX"))))
7d73b2c6
JD
55 (file-systems %base-file-systems)
56 (users %base-user-accounts)
57 (packages (cons*
58 rpcbind
59 %base-packages))
60 (services (cons*
907eeac2 61 (service rpcbind-service-type)
39d7fdce 62 (service dhcp-client-service-type)
7d73b2c6
JD
63 %base-services))))
64
65(define (run-nfs-test name socket)
66 "Run a test of an OS running RPC-SERVICE, which should create SOCKET."
8b113790
LC
67 (define os
68 (marionette-operating-system
69 %base-os
70 #:imported-modules '((gnu services herd)
71 (guix combinators))))
72
73 (define test
74 (with-imported-modules '((gnu build marionette))
75 #~(begin
76 (use-modules (gnu build marionette)
77 (srfi srfi-64))
78
79 (define marionette
80 (make-marionette (list #$(virtual-machine os))))
81
82 (define (wait-for-socket file)
83 ;; Wait until SOCKET exists in the guest
84 (marionette-eval
85 `(let loop ((i 10))
86 (cond ((and (file-exists? ,file)
87 (eq? 'socket (stat:type (stat ,file))))
88 #t)
89 ((> i 0)
90 (sleep 1)
91 (loop (- i 1)))
92 (else
93 (error "Socket didn't show up: " ,file))))
94 marionette))
95
89b05442 96 (test-runner-current (system-test-runner #$output))
8b113790
LC
97 (test-begin "rpc-daemon")
98
99 ;; Wait for the rpcbind daemon to be up and running.
c24b1547 100 (test-assert "RPC service running"
8b113790
LC
101 (marionette-eval
102 '(begin
103 (use-modules (gnu services herd))
e8cec7cc
LC
104
105 ;; Ensure 'rpcinfo' can be found below.
106 (setenv "PATH" "/run/current-system/profile/bin")
107
c24b1547 108 (start-service 'rpcbind-daemon))
8b113790
LC
109 marionette))
110
111 ;; Check the socket file and that the service is still running.
112 (test-assert "RPC socket exists"
113 (and
114 (wait-for-socket #$socket)
115 (marionette-eval
116 '(begin
117 (use-modules (gnu services herd)
118 (srfi srfi-1))
119
120 (live-service-running
121 (find (lambda (live)
122 (memq 'rpcbind-daemon
123 (live-service-provision live)))
124 (current-services))))
125 marionette)))
126
127 (test-assert "Probe RPC daemon"
128 (marionette-eval
129 '(zero? (system* "rpcinfo" "-p"))
130 marionette))
131
1fb75128 132 (test-end))))
8b113790
LC
133
134 (gexp->derivation name test))
7d73b2c6
JD
135
136(define %test-nfs
137 (system-test
138 (name "nfs")
139 (description "Test some things related to NFS.")
140 (value (run-nfs-test name "/var/run/rpcbind.sock"))))
907eeac2
RW
141
142\f
143(define %nfs-os
144 (let ((os (simple-operating-system
145 (simple-service 'create-target-directory activation-service-type
146 #~(begin
147 (mkdir "/remote")
148 (chmod "/remote" #o777)
149 #t))
150 (service dhcp-client-service-type)
151 (service nfs-service-type
152 (nfs-configuration
153 (debug '(nfs nfsd mountd))
154 (exports '(("/export"
155 ;; crossmnt = This is the pseudo root.
156 ;; fsid=0 = root file system of the export
157 "*(ro,insecure,no_subtree_check,crossmnt,fsid=0)"))))))))
158 (operating-system
159 (inherit os)
160 (host-name "nfs-server")
161 ;; We need to use a tmpfs here, because the test system's root file
162 ;; system cannot be re-exported via NFS.
163 (file-systems (cons
164 (file-system
165 (device "none")
166 (mount-point "/export")
167 (type "tmpfs")
168 (create-mount-point? #t))
169 %base-file-systems))
170 (services
171 ;; Enable debugging output.
172 (modify-services (operating-system-user-services os)
173 (syslog-service-type config
174 =>
175 (syslog-configuration
176 (inherit config)
177 (config-file
178 (plain-file
179 "syslog.conf"
180 "*.* /dev/console\n")))))))))
181
182(define (run-nfs-server-test)
183 "Run a test of an OS running a service of NFS-SERVICE-TYPE."
184 (define os
185 (marionette-operating-system
186 %nfs-os
187 #:requirements '(nscd)
188 #:imported-modules '((gnu services herd)
189 (guix combinators))))
190 (define test
191 (with-imported-modules '((gnu build marionette))
192 #~(begin
193 (use-modules (gnu build marionette)
194 (srfi srfi-64))
195
196 (define marionette
197 (make-marionette (list #$(virtual-machine os))))
907eeac2 198
89b05442 199 (test-runner-current (system-test-runner #$output))
907eeac2
RW
200 (test-begin "nfs-daemon")
201 (marionette-eval
202 '(begin
203 (current-output-port
204 (open-file "/dev/console" "w0"))
205 (chmod "/export" #o777)
206 (with-output-to-file "/export/hello"
207 (lambda () (display "hello world")))
208 (chmod "/export/hello" #o777))
209 marionette)
210
211 (test-assert "nscd PID file is created"
212 (marionette-eval
213 '(begin
214 (use-modules (gnu services herd))
215 (start-service 'nscd))
216 marionette))
217
218 (test-assert "nscd is listening on its socket"
a5547295
LC
219 (wait-for-unix-socket "/var/run/nscd/socket"
220 marionette))
907eeac2
RW
221
222 (test-assert "network is up"
223 (marionette-eval
224 '(begin
225 (use-modules (gnu services herd))
226 (start-service 'networking))
227 marionette))
228
229 ;; Wait for the NFS services to be up and running.
230 (test-assert "nfs services are running"
231 (and (marionette-eval
232 '(begin
233 (use-modules (gnu services herd))
234 (start-service 'nfs))
235 marionette)
eb019af8 236 (wait-for-file "/var/run/rpc.statd.pid" marionette)))
907eeac2
RW
237
238 (test-assert "nfs share is advertised"
239 (marionette-eval
240 '(zero? (system* (string-append #$nfs-utils "/sbin/showmount")
241 "-e" "nfs-server"))
242 marionette))
243
244 (test-assert "nfs share mounted"
245 (marionette-eval
246 '(begin
247 (and (zero? (system* (string-append #$nfs-utils "/sbin/mount.nfs4")
248 "nfs-server:/" "/remote" "-v"))
249 (file-exists? "/remote/hello")))
250 marionette))
1fb75128 251 (test-end))))
907eeac2
RW
252
253 (gexp->derivation "nfs-server-test" test))
254
255(define %test-nfs-server
256 (system-test
257 (name "nfs-server")
258 (description "Test that an NFS server can be started and exported
259directories can be mounted.")
260 (value (run-nfs-server-test))))
a1a39ed5 261
c4fe53bd 262\f
dbd3454c 263(define (run-nfs-full-test)
a1a39ed5
S
264 "Run a test of an OS mounting its root file system via NFS."
265 (define nfs-root-server-os
dbd3454c
MO
266 (let ((os (simple-operating-system)))
267 (marionette-operating-system
268 (operating-system
269 (inherit os)
270 (services
271 (cons*
272 (service static-networking-service-type
273 (list
274 (static-networking
275 (addresses (list (network-address
276 (device "ens5")
277 (value "10.0.2.15/24")))))))
278 (simple-service 'export activation-service-type
279 #~(begin
280 (mkdir-p "/export")
281 (chmod "/export" #o777)))
282 (service nfs-service-type
283 (nfs-configuration
284 (nfsd-port 2049)
285 (nfs-versions '("4.2"))
286 (exports '(("/export"
287 "*(rw,insecure,no_subtree_check,\
288crossmnt,fsid=root,no_root_squash,insecure,async)")))))
289 (modify-services (operating-system-user-services os)
290 (syslog-service-type config
291 =>
292 (syslog-configuration
293 (inherit config)
294 (config-file
295 (plain-file
296 "syslog.conf"
297 "*.* /dev/console\n"))))))))
298 #:requirements '(nscd)
299 #:imported-modules '((gnu services herd)
300 (guix combinators)))))
a1a39ed5
S
301
302 (define nfs-root-client-os
303 (marionette-operating-system
dbd3454c
MO
304 (simple-operating-system
305 (service static-networking-service-type
306 (list
307 (static-networking
308 (addresses
309 (list (network-address
310 (device "ens5")
311 (value "10.0.2.16/24")))))))
312 (service nfs-service-type
313 (nfs-configuration
314 (nfsd-port 2049)
315 (nfs-versions '("4.2"))))
316 (simple-service 'export activation-service-type
317 #~(begin
318 (mkdir-p "/export")
319 (chmod "/export" #o777))))
a1a39ed5
S
320 #:requirements '(nscd)
321 #:imported-modules '((gnu services herd)
322 (guix combinators))))
323
324 (define test
325 (with-imported-modules '((gnu build marionette))
326 #~(begin
327 (use-modules (gnu build marionette)
328 (srfi srfi-64))
329
89b05442 330 (test-runner-current (system-test-runner #$output))
c4fe53bd 331 (test-begin "start-nfs-boot-test")
c41a8572
DM
332
333 ;;; Start up NFS server host.
c41a8572
DM
334 (mkdir "/tmp/server")
335 (define server-marionette
dbd3454c
MO
336 (make-marionette
337 (cons* #$(virtual-machine
338 (operating-system nfs-root-server-os)
339 (volatile? #f))
340 '("-device" "e1000,netdev=n1,mac=52:54:00:12:34:56"
341 "-netdev" "socket,id=n1,listen=:1234"))
342 #:socket-directory "/tmp/server"))
a1a39ed5 343
c41a8572 344 ;;; Wait for the NFS services to be up and running.
a1a39ed5 345 (test-assert "nfs services are running"
dbd3454c 346 (wait-for-file "/var/run/rpc.statd.pid" server-marionette))
a1a39ed5 347
c41a8572
DM
348 (test-assert "NFS port is ready"
349 (wait-for-tcp-port 2049 server-marionette))
350
c41a8572 351 ;;; Start up NFS client host.
dbd3454c 352 (mkdir "/tmp/client")
c41a8572 353 (define client-marionette
dbd3454c
MO
354 (make-marionette
355 (cons* #$(virtual-machine
356 (operating-system nfs-root-client-os)
357 (volatile? #f))
358 '("-device" "e1000,netdev=n2,mac=52:54:00:12:34:57"
359 "-netdev" "socket,id=n2,connect=127.0.0.1:1234"))
360 #:socket-directory "/tmp/client"))
361
362 (test-assert "NFS port is ready"
363 (wait-for-tcp-port 2049 client-marionette))
c41a8572 364
a1a39ed5
S
365 (marionette-eval
366 '(begin
c4fe53bd 367 (use-modules (rnrs io ports))
a1a39ed5
S
368 (current-output-port
369 (open-file "/dev/console" "w0"))
dbd3454c
MO
370 (and
371 (system* (string-append #$nfs-utils "/sbin/mount.nfs")
372 "10.0.2.15:/export" "/export" "-v")
373 (let ((content (call-with-input-file "/proc/mounts"
374 get-string-all)))
375 (call-with-output-file "/export/mounts"
376 (lambda (port)
377 (display content port))))))
a1a39ed5
S
378 client-marionette)
379
c41a8572 380 ;;; Check whether NFS client host communicated with NFS server host.
c4fe53bd 381 (test-assert "nfs client deposited file"
dbd3454c
MO
382 (wait-for-file "/export/mounts" server-marionette))
383
a1a39ed5
S
384 (marionette-eval
385 '(begin
c4fe53bd
DM
386 (current-output-port
387 (open-file "/dev/console" "w0"))
388 (call-with-input-file "/export/mounts" display))
a1a39ed5
S
389 server-marionette)
390
1fb75128 391 (test-end))))
a1a39ed5 392
dbd3454c 393 (gexp->derivation "nfs-full-test" test))
a1a39ed5 394
dbd3454c 395(define %test-nfs-full
a1a39ed5 396 (system-test
dbd3454c 397 (name "nfs-full")
c41a8572 398 (description "Test that an NFS server can be started and the exported
dbd3454c
MO
399directory can be used by another machine.")
400 (value (run-nfs-full-test))))