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