summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-09-29 21:33:49 +0200
committerLudovic Courtès <ludo@gnu.org>2020-09-29 21:56:28 +0200
commitc11c19bd4d0dc4ec56b949647057dbf00567f2ae (patch)
treec3a9dcbd29c48c2e36fd36d023822e3bec73eb46
parentd5366500ec1aeecad6fc292b195088e30aa715fd (diff)
services: hurd-vm: Add system test.
* gnu/tests/virtualization.scm (%childhurd-os): New variable. (run-childhurd-test): New procedure. (%test-childhurd): New variable.
-rw-r--r--gnu/tests/virtualization.scm141
1 files changed, 140 insertions, 1 deletions
diff --git a/gnu/tests/virtualization.scm b/gnu/tests/virtualization.scm
index fbdec208050..9d381695be8 100644
--- a/gnu/tests/virtualization.scm
+++ b/gnu/tests/virtualization.scm
@@ -1,5 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> 2;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
3;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
3;;; 4;;;
4;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
5;;; 6;;;
@@ -26,9 +27,16 @@
26 #:use-module (gnu services networking) 27 #:use-module (gnu services networking)
27 #:use-module (gnu services virtualization) 28 #:use-module (gnu services virtualization)
28 #:use-module (gnu packages virtualization) 29 #:use-module (gnu packages virtualization)
30 #:use-module (gnu packages ssh)
29 #:use-module (guix gexp) 31 #:use-module (guix gexp)
30 #:use-module (guix store) 32 #:use-module (guix store)
31 #:export (%test-libvirt)) 33 #:export (%test-libvirt
34 %test-childhurd))
35
36
37;;;
38;;; Libvirt.
39;;;
32 40
33(define %libvirt-os 41(define %libvirt-os
34 (simple-operating-system 42 (simple-operating-system
@@ -93,3 +101,134 @@
93 (name "libvirt") 101 (name "libvirt")
94 (description "Connect to the running LIBVIRT service.") 102 (description "Connect to the running LIBVIRT service.")
95 (value (run-libvirt-test)))) 103 (value (run-libvirt-test))))
104
105
106;;;
107;;; GNU/Hurd virtual machines, aka. childhurds.
108;;;
109
110(define %childhurd-os
111 (simple-operating-system
112 (service dhcp-client-service-type)
113 (service hurd-vm-service-type)))
114
115(define (run-childhurd-test)
116 (define os
117 (marionette-operating-system
118 %childhurd-os
119 #:imported-modules '((gnu services herd)
120 (guix combinators))))
121
122 (define vm
123 (virtual-machine
124 (operating-system os)
125 (memory-size (* 1024 3))))
126
127 (define run-uname-over-ssh
128 ;; Program that runs 'uname' over SSH and prints the result on standard
129 ;; output.
130 (let ()
131 (define run
132 (with-extensions (list guile-ssh)
133 #~(begin
134 (use-modules (ssh session)
135 (ssh auth)
136 (ssh popen)
137 (ice-9 match)
138 (ice-9 textual-ports))
139
140 (let ((session (make-session #:user "root"
141 #:port 10022
142 #:host "localhost"
143 #:log-verbosity 'rare)))
144 (match (connect! session)
145 ('ok
146 (userauth-password! session "")
147 (display
148 (get-string-all
149 (open-remote-input-pipe* session "uname" "-on"))))
150 (status
151 (error "could not connect to childhurd over SSH"
152 session status)))))))
153
154 (program-file "run-uname-over-ssh" run)))
155
156 (define test
157 (with-imported-modules '((gnu build marionette))
158 #~(begin
159 (use-modules (gnu build marionette)
160 (srfi srfi-64)
161 (ice-9 match))
162
163 (define marionette
164 (make-marionette (list #$vm)))
165
166 (mkdir #$output)
167 (chdir #$output)
168
169 (test-begin "childhurd")
170
171 (test-assert "service running"
172 (marionette-eval
173 '(begin
174 (use-modules (gnu services herd))
175 (match (start-service 'childhurd)
176 (#f #f)
177 (('service response-parts ...)
178 (match (assq-ref response-parts 'running)
179 ((pid) (number? pid))))))
180 marionette))
181
182 (test-equal "childhurd SSH server replies"
183 "SSH"
184 ;; Check from within the guest whether its childhurd's SSH
185 ;; server is reachable. Do that from the guest: port forwarding
186 ;; to the host won't work because QEMU listens on 127.0.0.1.
187 (marionette-eval
188 '(begin
189 (use-modules (ice-9 match))
190
191 (let loop ((n 60))
192 (if (zero? n)
193 'all-attempts-failed
194 (let ((s (socket PF_INET SOCK_STREAM 0))
195 (a (make-socket-address AF_INET
196 INADDR_LOOPBACK
197 10022)))
198 (format #t "connecting to childhurd SSH server...~%")
199 (connect s a)
200 (match (get-string-n s 3)
201 ((? eof-object?)
202 (close-port s)
203 (sleep 1)
204 (loop (- n 1)))
205 (str
206 (close-port s)
207 str))))))
208 marionette))
209
210 (test-equal "SSH up and running"
211 "childhurd GNU\n"
212
213 ;; Connect from the guest to the chidhurd over SSH and run the
214 ;; 'uname' command.
215 (marionette-eval
216 '(begin
217 (use-modules (ice-9 popen))
218
219 (get-string-all
220 (open-input-pipe #$run-uname-over-ssh)))
221 marionette))
222
223 (test-end)
224 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
225
226 (gexp->derivation "childhurd-test" test))
227
228(define %test-childhurd
229 (system-test
230 (name "childhurd")
231 (description
232 "Connect to the GNU/Hurd virtual machine service, aka. a childhurd, making
233sure that the childhurd boots and runs its SSH server.")
234 (value (run-childhurd-test))))