gnu: Add system test for the rpcbind-daemon service.
[jackhill/guix/guix.git] / gnu / tests / nfs.scm
CommitLineData
7d73b2c6
JD
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2016 John Darrington <jmd@gnu.org>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu tests nfs)
21 #:use-module (gnu tests)
22 #:use-module (gnu system)
23 #:use-module (gnu system grub)
24 #:use-module (gnu system file-systems)
25 #:use-module (gnu system shadow)
26 #:use-module (gnu system vm)
27 #:use-module (gnu services)
28 #:use-module (gnu services base)
29 #:use-module (gnu services nfs)
30 #:use-module (gnu services networking)
31 #:use-module (gnu packages onc-rpc)
32 #:use-module (guix gexp)
33 #:use-module (guix store)
34 #:use-module (guix monads)
35 #:export (%test-nfs))
36
37(define %base-os
38 (operating-system
39 (host-name "olitupmok")
40 (timezone "Europe/Berlin")
41 (locale "en_US.UTF-8")
42
43 (bootloader (grub-configuration (device "/dev/sdX")))
44 (file-systems %base-file-systems)
45 (users %base-user-accounts)
46 (packages (cons*
47 rpcbind
48 %base-packages))
49 (services (cons*
50 (service rpcbind-service-type
51 (rpcbind-configuration))
52 (dhcp-client-service)
53 %base-services))))
54
55(define (run-nfs-test name socket)
56 "Run a test of an OS running RPC-SERVICE, which should create SOCKET."
57 (mlet* %store-monad ((os -> (marionette-operating-system
58 %base-os
59 #:imported-modules '((gnu services herd)
60 (guix combinators))))
61 (command (system-qemu-image/shared-store-script
62 os #:graphic? #f)))
63 (define test
64 (with-imported-modules '((gnu build marionette))
65 #~(begin
66 (use-modules (gnu build marionette)
67 (srfi srfi-64))
68
69 (define marionette
70 (make-marionette (list #$command)))
71
72 (define (wait-for-socket file)
73 ;; Wait until SOCKET exists in the guest
74 (marionette-eval
75 `(let loop ((i 10))
76 (cond ((and (file-exists? ,file)
77 (eq? 'socket (stat:type (stat ,file))))
78 #t)
79 ((> i 0)
80 (sleep 1)
81 (loop (- i 1)))
82 (else
83 (error "Socket didn't show up: " ,file))))
84 marionette))
85
86 (mkdir #$output)
87 (chdir #$output)
88
89 (test-begin "rpc-daemon")
90
91 ;; Wait for the rpcbind daemon to be up and running.
92 (test-eq "RPC service running"
93 'running!
94 (marionette-eval
95 '(begin
96 (use-modules (gnu services herd))
97 (start-service 'rpcbind-daemon)
98 'running!)
99 marionette))
100
101 ;; Check the socket file and that the service is still running.
102 (test-assert "RPC socket exists"
103 (and
104 (wait-for-socket #$socket)
105 (marionette-eval
106 '(begin
107 (use-modules (gnu services herd)
108 (srfi srfi-1))
109
110 (live-service-running
111 (find (lambda (live)
112 (memq 'rpcbind-daemon
113 (live-service-provision live)))
114 (current-services))))
115 marionette)))
116
117 (test-assert "Probe RPC daemon"
118 (marionette-eval
119 '(zero? (system* "rpcinfo" "-p"))
120 marionette))
121
122 (test-end)
123 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
124
125 (gexp->derivation name test)))
126
127(define %test-nfs
128 (system-test
129 (name "nfs")
130 (description "Test some things related to NFS.")
131 (value (run-nfs-test name "/var/run/rpcbind.sock"))))