1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
3 ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
6 ;;; This file is part of GNU Guix.
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.
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.
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/>.
21 (define-module (gnu tests virtualization)
22 #:use-module (gnu tests)
23 #:use-module (gnu image)
24 #:use-module (gnu system)
25 #:use-module (gnu system file-systems)
26 #:use-module (gnu system image)
27 #:use-module (gnu system images hurd)
28 #:use-module (gnu system vm)
29 #:use-module (gnu services)
30 #:use-module (gnu services dbus)
31 #:use-module (gnu services networking)
32 #:use-module (gnu services virtualization)
33 #:use-module (gnu packages virtualization)
34 #:use-module (gnu packages ssh)
35 #:use-module (guix gexp)
36 #:use-module (guix records)
37 #:use-module (guix store)
38 #:export (%test-libvirt
47 (simple-operating-system
48 (service dhcp-client-service-type)
51 (service libvirt-service-type)))
53 (define (run-libvirt-test)
54 "Run tests in %LIBVIRT-OS."
56 (marionette-operating-system
58 #:imported-modules '((gnu services herd)
64 (port-forwardings '())))
67 (with-imported-modules '((gnu build marionette))
69 (use-modules (srfi srfi-11) (srfi srfi-64)
70 (gnu build marionette))
73 (make-marionette (list #$vm)))
78 (test-begin "libvirt")
80 (test-assert "service running"
83 (use-modules (gnu services herd))
84 (match (start-service 'libvirtd)
86 (('service response-parts ...)
87 (match (assq-ref response-parts 'running)
88 ((pid) (number? pid))))))
91 (test-eq "fetch version"
95 (system* ,(string-append #$libvirt "/bin/virsh")
96 "-c" "qemu:///system" "version"))
100 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
102 (gexp->derivation "libvirt-test" test))
104 (define %test-libvirt
107 (description "Connect to the running LIBVIRT service.")
108 (value (run-libvirt-test))))
112 ;;; GNU/Hurd virtual machines, aka. childhurds.
115 ;; Copy of `hurd-vm-disk-image', using plain disk-image for test
116 (define (hurd-vm-disk-image-raw config)
117 (let ((os ((@@ (gnu services virtualization) secret-service-operating-system)
118 (hurd-vm-configuration-os config)))
119 (disk-size (hurd-vm-configuration-disk-size config)))
122 (inherit hurd-disk-image)
125 (operating-system os)))))
127 (define %childhurd-os
128 (simple-operating-system
129 (service dhcp-client-service-type)
130 (service hurd-vm-service-type
131 (hurd-vm-configuration
132 (image (hurd-vm-disk-image-raw this-record))))))
134 (define (run-childhurd-test)
136 (marionette-operating-system
138 #:imported-modules '((gnu services herd)
139 (guix combinators))))
143 (operating-system os)
144 (memory-size (* 1024 3))))
146 (define run-uname-over-ssh
147 ;; Program that runs 'uname' over SSH and prints the result on standard
151 (with-extensions (list guile-ssh)
153 (use-modules (ssh session)
157 (ice-9 textual-ports))
159 (let ((session (make-session #:user "root"
162 #:log-verbosity 'rare)))
163 (match (connect! session)
165 (userauth-password! session "")
168 (open-remote-input-pipe* session "uname" "-on"))))
170 (error "could not connect to childhurd over SSH"
171 session status)))))))
173 (program-file "run-uname-over-ssh" run)))
176 (with-imported-modules '((gnu build marionette))
178 (use-modules (gnu build marionette)
183 (make-marionette (list #$vm)))
188 (test-begin "childhurd")
190 (test-assert "service running"
193 (use-modules (gnu services herd))
194 (match (start-service 'childhurd)
196 (('service response-parts ...)
197 (match (assq-ref response-parts 'running)
198 ((pid) (number? pid))))))
201 (test-equal "childhurd SSH server replies"
203 ;; Check from within the guest whether its childhurd's SSH
204 ;; server is reachable. Do that from the guest: port forwarding
205 ;; to the host won't work because QEMU listens on 127.0.0.1.
208 (use-modules (ice-9 match))
213 (let ((s (socket PF_INET SOCK_STREAM 0))
214 (a (make-socket-address AF_INET
217 (format #t "connecting to childhurd SSH server...~%")
219 (match (get-string-n s 3)
229 (test-equal "SSH up and running"
232 ;; Connect from the guest to the chidhurd over SSH and run the
236 (use-modules (ice-9 popen))
239 (open-input-pipe #$run-uname-over-ssh)))
243 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
245 (gexp->derivation "childhurd-test" test))
247 (define %test-childhurd
251 "Connect to the GNU/Hurd virtual machine service, aka. a childhurd, making
252 sure that the childhurd boots and runs its SSH server.")
253 (value (run-childhurd-test))))