From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aGtZMgOm4mLdGgAAbAwnHQ (envelope-from ) for ; Thu, 28 Jul 2022 17:06:43 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id KKVfMgOm4mIjvgAA9RJhRA (envelope-from ) for ; Thu, 28 Jul 2022 17:06:43 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6EE8E2B9D0 for ; Thu, 28 Jul 2022 17:06:43 +0200 (CEST) Received: from localhost ([::1]:33354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oH562-00058Y-LY for larch@yhetil.org; Thu, 28 Jul 2022 11:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oH53W-0003Vu-EM for guix-patches@gnu.org; Thu, 28 Jul 2022 11:04:11 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:41285) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oH53S-0003Yu-8W for guix-patches@gnu.org; Thu, 28 Jul 2022 11:04:06 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oH53S-0000Xq-4b for guix-patches@gnu.org; Thu, 28 Jul 2022 11:04:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56813] [PATCH 2/2] tests: Add qemu-guest-agent system test. Resent-From: Timotej Lazar Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 28 Jul 2022 15:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56813 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56813@debbugs.gnu.org Cc: Timotej Lazar Received: via spool by 56813-submit@debbugs.gnu.org id=B56813.16590206302066 (code B ref 56813); Thu, 28 Jul 2022 15:04:02 +0000 Received: (at 56813) by debbugs.gnu.org; 28 Jul 2022 15:03:50 +0000 Received: from localhost ([127.0.0.1]:59266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oH53G-0000XG-At for submit@debbugs.gnu.org; Thu, 28 Jul 2022 11:03:50 -0400 Received: from araneo.si ([90.157.193.204]:53554) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oH53B-0000Wk-T0 for 56813@debbugs.gnu.org; Thu, 28 Jul 2022 11:03:46 -0400 Received: from araneo.si (localhost.lan [127.0.0.1]) by araneo.si (OpenSMTPD) with ESMTP id 58c9ebac for <56813@debbugs.gnu.org>; Thu, 28 Jul 2022 15:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=araneo.si; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=20180623; bh=2uAWWxxuFtNTO66J0AV8h OEeA14=; b=XqwV2hjNXFxqqPolKuaqAYqI5MeZZDzJpbs437kZY7ygj4I+Kvd0m /0sV1rNCykXkNZvutoB9fiT3mtc76VOhogVoH9eqlpqXKSkSpSpSAuO21ZuG9bWg CMGxLGI2FLI8qSHAtZRcnmF1FgVU3FelaHLo0nvAEY6gUtexDfHuKSTZcbMIKxSu SnVICS+Z5UitTCXkvJcM4OeRs2B2MTwEzjCImEK0UGoCo5l2PsakhOCaFTW9Aeoc qc+suyfIg/f81s+nz54tVilUe8brYRmVbslyGjzVGYDn9tpRtyEyyv/1x5fPECVy fPsF7VrTwX2UuYbNN1A/Sp4/Natls61WQ== Received: by araneo.si (OpenSMTPD) with ESMTPSA id 5a514d13 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 28 Jul 2022 15:03:42 +0000 (UTC) From: Timotej Lazar Date: Thu, 28 Jul 2022 17:03:26 +0200 Message-Id: <20220728150326.14182-2-timotej.lazar@araneo.si> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220728150326.14182-1-timotej.lazar@araneo.si> References: <87y1wdb7yk.fsf@araneo.si> <20220728150326.14182-1-timotej.lazar@araneo.si> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659020803; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=wJ27knZS2e5ra/p2zHM+7kDSJ9XCS1W0/c3klz54wDM=; b=E/VcqIsDd03NmfmcqmSV3DiXNkraWkrsss3IQcoPagBGFNgBLBtXnIPkyliG+MfE/xkL14 0t7jZ0q5yFWp3Y6uOaK8KxE9bSivLeyixxmcNdKxg8HNsb485G3BRa8r88OEukeEk9xo03 64KcVMAg7d7gGaxdmOs4R5pWjgrF+2xNLDYNkwe+djfSu+c9QQpK0Hji6rng0VUn+L60aY kPf6p45Z+qwtl9NTmGvhss2NWTsSAxT1dojbjbPWQK52Dxbhq62IF/h68eTGP+/Vua9HOY YrenLd9DsT6qPV3qB6TyPIj1vFQjdF5tS9lmylRQndbjR6/MZRO5Nwxc725S9A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659020803; a=rsa-sha256; cv=none; b=u3JiBsg8BPllMcEQT6hNP+IO9ZFY/NRsMWwiF0aG1Iovfx9onoAGWqfm85rWrk3R9UrAZv H230Yc5BiHJ+87w9Hr9m6jhCbMlEdInriVStUznJVoIOjp60ZWthzmSQeJs74jiCNY6sES MWd1CXGX5sFxBhCNR5TVn5kheuMZkTAOy+4tCFo3mlSXkUL/4VPt7iUxZ199DCvu4ZcIh8 IC7rVYup6VWxg3u/ndV+STml5oKG92VjEeHMrF5V09QWe5RhaRduD92EYh3P/r5fl7rqqv SPq3Jhtoap3oJuuFQauNPCk1v378E+VuvaWxgiwOiBA8LH8A/O106kieQ6VHzg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=araneo.si header.s=20180623 header.b=XqwV2hjN; dmarc=fail reason="SPF not aligned (relaxed)" header.from=araneo.si (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 7.57 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=araneo.si header.s=20180623 header.b=XqwV2hjN; dmarc=fail reason="SPF not aligned (relaxed)" header.from=araneo.si (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 6EE8E2B9D0 X-Spam-Score: 7.57 X-Migadu-Scanner: scn1.migadu.com X-TUID: 7USPFbu1oKm1 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. --- gnu/build/marionette.scm | 5 ++- gnu/tests/virtualization.scm | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/gnu/build/marionette.scm b/gnu/build/marionette.scm index 0d2af642c8..2b241d19e8 100644 --- a/gnu/build/marionette.scm +++ b/gnu/build/marionette.scm @@ -105,11 +105,14 @@ (define extra-options "-monitor" (string-append "unix:" socket-directory "/monitor") "-chardev" (string-append "socket,id=repl,path=" socket-directory "/repl") + "-chardev" (string-append "socket,id=qga,server=on,wait=off,path=" + socket-directory "/qemu-ga") ;; See ;; . "-device" "virtio-serial" - "-device" "virtserialport,chardev=repl,name=org.gnu.guix.port.0")) + "-device" "virtserialport,chardev=repl,name=org.gnu.guix.port.0" + "-device" "virtserialport,chardev=qga,name=org.qemu.guest_agent.0")) (define (accept* port) (match (select (list port) '() (list port) timeout) diff --git a/gnu/tests/virtualization.scm b/gnu/tests/virtualization.scm index 299acc4945..4bd56e5d9d 100644 --- a/gnu/tests/virtualization.scm +++ b/gnu/tests/virtualization.scm @@ -37,6 +37,7 @@ (define-module (gnu tests virtualization) #:use-module (guix records) #:use-module (guix store) #:export (%test-libvirt + %test-qemu-guest-agent %test-childhurd)) @@ -115,6 +116,89 @@ (define %test-libvirt (description "Connect to the running LIBVIRT service.") (value (run-libvirt-test)))) + +;;; +;;; QEMU Guest Agent service. +;;; + +(define %qemu-guest-agent-os + (simple-operating-system + (service qemu-guest-agent-service-type))) + +(define (run-qemu-guest-agent-test) + "Run tests in %QEMU-GUEST-AGENT-OS." + (define os + (marionette-operating-system + %qemu-guest-agent-os + #:imported-modules '((gnu services herd)))) + + (define vm + (virtual-machine + (operating-system os) + (port-forwardings '()))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (ice-9 rdelim) + (srfi srfi-64)) + + (define marionette + ;; Ensure we look for the socket in the correct place below. + (make-marionette (list #$vm) #:socket-directory "/tmp")) + + (define* (try-read port #:optional (attempts 10)) + ;; Try reading from a port several times before giving up. + (cond ((char-ready? port) + (let ((response (read-line port))) + (close-port port) + response)) + ((> attempts 1) + (sleep 1) + (try-read port (- attempts 1))) + (else ""))) + + (define (run command) + ;; Run a QEMU guest agent command and return the response. + (let ((s (socket PF_UNIX SOCK_STREAM 0))) + (connect s AF_UNIX "/tmp/qemu-ga") + (display command s) + (try-read s))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "qemu-guest-agent") + + (test-assert "service running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (match (start-service 'qemu-guest-agent) + (#f #f) + (('service response-parts ...) + (match (assq-ref response-parts 'running) + ((pid) (number? pid)))))) + marionette)) + + (test-equal "ping guest" + "{\"return\": {}}" + (run "{\"execute\": \"guest-ping\"}")) + + (test-assert "get network interfaces" + (string-contains + (run "{\"execute\": \"guest-network-get-interfaces\"}") + "127.0.0.1")) + + (test-end)))) + + (gexp->derivation "qemu-guest-agent-test" test)) + +(define %test-qemu-guest-agent + (system-test + (name "qemu-guest-agent") + (description "Run commands in a virtual machine using QEMU guest agent.") + (value (run-qemu-guest-agent-test)))) + ;;; ;;; GNU/Hurd virtual machines, aka. childhurds. -- 2.36.1