From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 6AAmGQ/7ZmcP2gAAqHPOHw:P1 (envelope-from ) for ; Sat, 21 Dec 2024 17:29:51 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 6AAmGQ/7ZmcP2gAAqHPOHw (envelope-from ) for ; Sat, 21 Dec 2024 18:29:51 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=BJ8Iy9Fz; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=eTWF4QOM; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1734802191; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: 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=q8l2CGW8ua0o6eD68houCMsDsSN0DbJ0eXCyDxg2/X8=; b=hDGY59mxy43uJtaffoAB3BeEgCbut+sEEValFtjPulwmwApQWJB8nbuX4m0DbS0Gx5ms5b h8VmZGyGJvOEEpQnIpABbxh17y/DbJRcgW/vDaH4/CaSM4diUhcykh00qgdCUHsXhxQQIQ 8+2FLQKbor3WA62//I4O1w6uGwep14ag27EYd/yw+VD0n3pNVX5Bi2i8ObI+0C6AQswSxR tCNm7egSNJ46H+dxG6Zj3Tl5PWVDsFLVLbsjrQ9S0R3mVSIyBgBkGcm3BgaIdq97d89FlM ZItteuBo+QHJCjbvSnCQ8qnVZ5OuJ4CHehy3hp7yl5nEuQTUkZZtVBBXvi3mhg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=BJ8Iy9Fz; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=eTWF4QOM; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734802191; a=rsa-sha256; cv=none; b=gI+vOPRfoUScsPCYqOqIgdiPrLxBzU0RdEOAUeFvHeepjgtpOQlTCyuBRPUq1soWiDP+2K B4m6/JCh16PLrYS0oFUgaM134M9XSzZaqcxNgZSjwKWlo5n9xCRrHqE+24iNXwE/41lSZf MjrFX7tkxfWemLq5CGZct7daQE0dzC6wlIHjXiI/0io3wccNKJJZvUMshlbc0TVZnDf5vj hiIokozypfkDTJvk7MID0wvqexloNzATOzTIIdI90zYSSKwWO3yS0NHtdS95tM06p9UVH9 3QwH2o+sXQesgQIV7BzyYdyhk57JjZ7LH28hFKbrZhMIQNfY18xBX8y+q12AKw== 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 18E1890FC1 for ; Sat, 21 Dec 2024 18:29:51 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tP2ve-0005TV-DK; Sat, 21 Dec 2024 12:06:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tP2vW-0005R6-NJ for guix-patches@gnu.org; Sat, 21 Dec 2024 12:06:06 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tP2vV-0003PZ-UD for guix-patches@gnu.org; Sat, 21 Dec 2024 12:06:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=q8l2CGW8ua0o6eD68houCMsDsSN0DbJ0eXCyDxg2/X8=; b=BJ8Iy9Fz5iNG3hin17OfQyxAhR3sb/JIMIqrQnbU8N4xpEQ3liNBEUGTCffK6XrBf5vbCQ2RG5Cl9aXu4KrhcPSwA1Vlwxg3tIyEztE+ZBOR2rRm09UH9FUWveHHiSz+d6Uq1f4iNnh3qwkav+U862q/YT1QMQRiYsCojqTQECehkLRsmzJYzo9i0sKx/ep3xa/7nhlWnSmPAXTzEap2RcdnRXIdV21sztfvO9sq0yCp3JXkId6qCehjW/lNbYVx9hjTsVfdcPYHM2OfRblIYufuxXi/ngHzZ1yRLArnAEO/NCJVVaUbWEEjTlVydrZZkk9Bs85OOEDNoJKhusaqXA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tP2vV-0005Rn-Ob for guix-patches@gnu.org; Sat, 21 Dec 2024 12:06:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75010] [PATCH 7/7] WIP: gnu: tests: Add module for guix deploy tests. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 21 Dec 2024 17:06:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75010 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75010@debbugs.gnu.org Received: via spool by 75010-submit@debbugs.gnu.org id=B75010.173480071720822 (code B ref 75010); Sat, 21 Dec 2024 17:06:05 +0000 Received: (at 75010) by debbugs.gnu.org; 21 Dec 2024 17:05:17 +0000 Received: from localhost ([127.0.0.1]:47527 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tP2ui-0005Pg-Qs for submit@debbugs.gnu.org; Sat, 21 Dec 2024 12:05:17 -0500 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:43315 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tP2ud-0005Kx-Jc for 75010@debbugs.gnu.org; Sat, 21 Dec 2024 12:05:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1734800700; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q8l2CGW8ua0o6eD68houCMsDsSN0DbJ0eXCyDxg2/X8=; b=eTWF4QOMTkmXKcYONocuNLyjGHAloL4444ByhYZJJuxovnRsVPjTrXnr5KR+J2oIR34U1i c1OBtNZHMJzs6XwLH/dK21+BDN+gOy+aWiI7DuES4WHhWJqWgxLouYjtYR3xnYcFlDigBx 0gNHu8rjCOYmHr4oyF0mlr734I/iETrkdafoe8j5qyZLxDf1PGjfI2kvuT1/CPr7Aks1bS MTzsJFT7/bzIuei7n3GRFkBWKVxDV582zulKwHXpg0c5u+FBAwN7lmwKHvZG5ufi/E0orY 062JhGuAFdVB69/vVU4gT8CNNls2StC2ruDlbdVgndUakkvn80QINv5DMAUm9A== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id bdd870d6 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for <75010@debbugs.gnu.org>; Sat, 21 Dec 2024 17:05:00 +0000 (UTC) Date: Sat, 21 Dec 2024 18:04:11 +0100 Message-ID: <6438a457713360741155104b3b2c8af6fda50ee4.1734798943.git.herman@rimm.ee> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches From: Herman Rimm via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -6.52 X-Spam-Score: -6.52 X-Migadu-Queue-Id: 18E1890FC1 X-TUID: H1C4yI2xYXVe * gnu/tests/deploy.scm: Add file. Change-Id: I348c8bf2e518ec6c00af126993eaca3fcd453901 --- gnu/tests/deploy.scm | 203 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 gnu/tests/deploy.scm diff --git a/gnu/tests/deploy.scm b/gnu/tests/deploy.scm new file mode 100644 index 0000000000..24671cddec --- /dev/null +++ b/gnu/tests/deploy.scm @@ -0,0 +1,203 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Jakob L. Kreuze +;;; Copyright © 2024 Herman Rimm +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu tests deploy) + #:use-module (gnu packages gnupg) + #:use-module ((guix self) #:select (make-config.scm)) + #:use-module (gnu services) + #:use-module (gnu services base) + #:use-module (gnu services ssh) + #:use-module (gnu system) + #:use-module (gnu system vm) + #:use-module (gnu tests) + #:use-module (guix gexp) + #:use-module (guix modules) + #:use-module (ice-9 match) + #:export (%test-deploy + %test-rollback)) + +;;; Commentary: +;;; +;;; Test in-place system deployment: advancing the system generation on +;;; a running instance of the Guix System. +;;; +;;; Code: + +(define (machines os) + (program-file "machines.scm" + #~(list (machine (configuration + (machine-ssh-configuration + (host-name "localhost") + (system (%current-system)))) + (environment managed-host-environment-type) + (operating-system #$os))))) + +(define not-config? + ;; Select (guix …) and (gnu …) modules, except (guix config). + (match-lambda + (('guix 'config) #f) + (('guix rest ...) #t) + (('gnu rest ...) #t) + (_ #f))) + +(define* (deploy-program #:optional (os #~%simple-os)) + (program-file "deploy.scm" + (with-extensions (list guile-gcrypt) + (with-imported-modules `(,@(source-module-closure + '((guix scripts deploy)) + #:select? not-config?) + ((guix config) => ,(make-config.scm))) + #~(begin + (use-modules (guix scripts deploy)) + (guix-deploy #$(machines os))))))) + +(define os + (marionette-operating-system + (simple-operating-system + (service openssh-service-type + (openssh-configuration + (permit-root-login #t) + (allow-empty-passwords? #t))) + (service static-networking-service-type + (list (static-networking + (inherit %loopback-static-networking) + (provision '(networking)))))) + #:imported-modules '((gnu services herd) + (guix combinators)))) + +(define vm (virtual-machine os)) + +(define* (run-deploy-test) + "Run a test of an OS running DEPLOY-PROGRAM, which creates a new +generation of the system profile." + (define (test script) + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$vm))) + + ;; Return the names of the generation symlinks on MARIONETTE. + (define (system-generations marionette) + (marionette-eval + '(begin + (use-modules (ice-9 ftw) + (srfi srfi-1)) + (let* ((profile-dir "/var/guix/profiles/") + (entries (map first (cddr (file-system-tree profile-dir))))) + (remove (lambda (entry) + (member entry '("per-user" "system"))) + entries))) + marionette)) + + (test-runner-current (system-test-runner #$output)) + (test-begin "deploy") + + (let ((generations-prior (system-generations marionette))) + (test-assert "script successfully evaluated" + (marionette-eval + '(primitive-load #$script) + marionette)) + + (test-equal "script created new generation" + (length (system-generations marionette)) + (1+ (length generations-prior))) + + (test-equal "script activated the new generation" + (string-append "/var/guix/profiles/system-" + (number->string (+ 1 (length generations-prior))) + "-link") + (marionette-eval '(readlink "/run/current-system") + marionette))) + + (test-end)))) + + (gexp->derivation "deploy" (test (deploy-program)))) + +(define* (run-rollback-test) + "Run a test of an OS with a faulty bootloader running DEPLOY-PROGRAM, +which causes a rollback." + (define os + #~(operating-system + (inherit %simple-os) + (bootloader + (bootloader-configuration + (inherit (operating-system-bootloader + %simple-os)) + (targets '("/dev/null")))))) + + (define (test script) + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$vm))) + + ;; Return the names of the generation symlinks on MARIONETTE. + (define (system-generations marionette) + (marionette-eval + '(begin + (use-modules (ice-9 ftw) + (srfi srfi-1)) + (let* ((profile-dir "/var/guix/profiles/") + (entries (map first (cddr (file-system-tree profile-dir))))) + (remove (lambda (entry) + (member entry '("per-user" "system"))) + entries))) + marionette)) + + (test-runner-current (system-test-runner #$output)) + (test-begin "rollback") + + (let ((generations-prior (system-generations marionette))) + (test-assert "script successfully evaluated" + (marionette-eval + '(primitive-load #$script) + marionette)) + + (test-equal "script created new generation" + (length (system-generations marionette)) + (1+ (length generations-prior))) + + (test-equal "script rolled back the new generation" + (string-append "/var/guix/profiles/system-" + (number->string (length generations-prior)) + "-link") + (marionette-eval '(readlink "/run/current-system") + marionette))) + + (test-end)))) + + (gexp->derivation "rollback" (test (deploy-program os)))) + +(define %test-deploy + (system-test + (name "deploy") + (description "Deploy to the local machine.") + (value (run-deploy-test)))) + +(define %test-rollback + (system-test + (name "rollback") + (description "Rollback the deployment of a faulty bootloader.") + (value (run-rollback-test)))) -- 2.45.2