summaryrefslogtreecommitdiff
path: root/gnu/tests
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.si>2022-07-28 17:03:26 +0200
committerLudovic Courtès <ludo@gnu.org>2022-08-09 17:15:45 +0200
commitfd74fe6325eb54a48e496b3afe5001005b15d802 (patch)
tree1ce80c353cbcac91c698950dfcee096ca9de9484 /gnu/tests
parentee199cd3baf3f2f207223749e0c1015432826bd3 (diff)
tests: Add qemu-guest-agent system test.
Enable the QEMU guest agent interface in marionette VMs, run the qemu-guest-agent service in one and try talking to it. * gnu/build/marionette.scm (make-marionette): Enable the guest agent device. * gnu/tests/virtualization.scm (run-qemu-guest-agent-test): New procedure. (%test-qemu-guest-agent): New variable. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/tests')
-rw-r--r--gnu/tests/virtualization.scm84
1 files changed, 84 insertions, 0 deletions
diff --git a/gnu/tests/virtualization.scm b/gnu/tests/virtualization.scm
index 299acc49453..4bd56e5d9d5 100644
--- a/gnu/tests/virtualization.scm
+++ b/gnu/tests/virtualization.scm
@@ -37,6 +37,7 @@
37 #:use-module (guix records) 37 #:use-module (guix records)
38 #:use-module (guix store) 38 #:use-module (guix store)
39 #:export (%test-libvirt 39 #:export (%test-libvirt
40 %test-qemu-guest-agent
40 %test-childhurd)) 41 %test-childhurd))
41 42
42 43
@@ -117,6 +118,89 @@
117 118
118 119
119;;; 120;;;
121;;; QEMU Guest Agent service.
122;;;
123
124(define %qemu-guest-agent-os
125 (simple-operating-system
126 (service qemu-guest-agent-service-type)))
127
128(define (run-qemu-guest-agent-test)
129 "Run tests in %QEMU-GUEST-AGENT-OS."
130 (define os
131 (marionette-operating-system
132 %qemu-guest-agent-os
133 #:imported-modules '((gnu services herd))))
134
135 (define vm
136 (virtual-machine
137 (operating-system os)
138 (port-forwardings '())))
139
140 (define test
141 (with-imported-modules '((gnu build marionette))
142 #~(begin
143 (use-modules (gnu build marionette)
144 (ice-9 rdelim)
145 (srfi srfi-64))
146
147 (define marionette
148 ;; Ensure we look for the socket in the correct place below.
149 (make-marionette (list #$vm) #:socket-directory "/tmp"))
150
151 (define* (try-read port #:optional (attempts 10))
152 ;; Try reading from a port several times before giving up.
153 (cond ((char-ready? port)
154 (let ((response (read-line port)))
155 (close-port port)
156 response))
157 ((> attempts 1)
158 (sleep 1)
159 (try-read port (- attempts 1)))
160 (else "")))
161
162 (define (run command)
163 ;; Run a QEMU guest agent command and return the response.
164 (let ((s (socket PF_UNIX SOCK_STREAM 0)))
165 (connect s AF_UNIX "/tmp/qemu-ga")
166 (display command s)
167 (try-read s)))
168
169 (test-runner-current (system-test-runner #$output))
170 (test-begin "qemu-guest-agent")
171
172 (test-assert "service running"
173 (marionette-eval
174 '(begin
175 (use-modules (gnu services herd))
176 (match (start-service 'qemu-guest-agent)
177 (#f #f)
178 (('service response-parts ...)
179 (match (assq-ref response-parts 'running)
180 ((pid) (number? pid))))))
181 marionette))
182
183 (test-equal "ping guest"
184 "{\"return\": {}}"
185 (run "{\"execute\": \"guest-ping\"}"))
186
187 (test-assert "get network interfaces"
188 (string-contains
189 (run "{\"execute\": \"guest-network-get-interfaces\"}")
190 "127.0.0.1"))
191
192 (test-end))))
193
194 (gexp->derivation "qemu-guest-agent-test" test))
195
196(define %test-qemu-guest-agent
197 (system-test
198 (name "qemu-guest-agent")
199 (description "Run commands in a virtual machine using QEMU guest agent.")
200 (value (run-qemu-guest-agent-test))))
201
202
203;;;
120;;; GNU/Hurd virtual machines, aka. childhurds. 204;;; GNU/Hurd virtual machines, aka. childhurds.
121;;; 205;;;
122 206