From patchwork Fri May 9 06:02:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 42473 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 237D227BC4B; Fri, 9 May 2025 07:04:46 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 39C1C27BC49 for ; Fri, 9 May 2025 07:04:45 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uDGq9-0004cj-WE; Fri, 09 May 2025 02:04:10 -0400 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 1uDGq5-0004cI-6K for guix-patches@gnu.org; Fri, 09 May 2025 02:04:07 -0400 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 1uDGq4-0003AB-HD for guix-patches@gnu.org; Fri, 09 May 2025 02:04:04 -0400 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=S+NO9SJzxQE2zGlSlbZzl/g8uHPAbQ6vrrt/Gbbp7+w=; b=jjYYn1tjSTDegLvvWsuVx/z8EysG2lblH/lfr1OJO5PouaD08imoRVSali2gLcYb5qWenR8/CNqEEqKG2CmG2LH8y8o+6kDtIGAK8o6iwZASIyZ6eMHqR7SF8iqAGAxxAoREXXR8wABGkc8pDcaswGy6br053fwUyVVNK8IfOy16yM4uyENxPz/CYo9n7jVK/4GBphwCVwycm21pNDgAsZ6udRXqdvIFPmeIvajTUGUiOEt4UaZYHxDfXDVs36c6is4h84Xp0P2ubLngkM6/QcLb215DFeGsS4igAgKFY7sAV5qe03e5epCG2Lhk3Yb7TqFs5aE+aT20ixmWUTrb2g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uDGq4-0002Zy-CT for guix-patches@gnu.org; Fri, 09 May 2025 02:04:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#75010] [PATCH v4 5/5] gnu: tests: Add module for guix deploy tests. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 09 May 2025 06:04:04 +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 moreinfo To: 75010@debbugs.gnu.org Received: via spool by 75010-submit@debbugs.gnu.org id=B75010.17467706239847 (code B ref 75010); Fri, 09 May 2025 06:04:04 +0000 Received: (at 75010) by debbugs.gnu.org; 9 May 2025 06:03:43 +0000 Received: from localhost ([127.0.0.1]:34619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uDGpi-0002Yj-Sw for submit@debbugs.gnu.org; Fri, 09 May 2025 02:03:43 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:50871 helo=email.rimm.ee) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uDGpd-0002XI-Oi for 75010@debbugs.gnu.org; Fri, 09 May 2025 02:03:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1746770604; 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=S+NO9SJzxQE2zGlSlbZzl/g8uHPAbQ6vrrt/Gbbp7+w=; b=bgbZGVH9Vj42+TATxJXwXCGvC5NuPCPHRpte/aMrR2EvMU3XcAOiclwLkyZb492x919Bjh JuCAjFolkvMXdEXhydScOKQNFsWT5EwTtXDLYc7NUXOMCYXnihvUF+vkrSi+OsOMjn1cqk OWulNwA1g9B2IoThMEvJQNyn2xftOmp9takfaIZPsY/XhNA5MI6wSULe/+VCq1rAPD6FXG 6/Y71rLbqSbN0amVlyLQT8FpeKVqBWzrBf3k8vzA9yzwPbKwNTMVp2enCQPhoOO/U7pby6 /ysk08Q2QwBd04rofb6G9wWT0h0BpO18N+vBNs2F0r6WixvOS9UjpKvLhExLGA== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id cebc9fe7 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for <75010@debbugs.gnu.org>; Fri, 9 May 2025 06:03:24 +0000 (UTC) Date: Fri, 9 May 2025 08:02:29 +0200 Message-ID: <23f3850c0d0d62fb78137e694dc96b34a54c15ec.1746769714.git.herman@rimm.ee> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 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 X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/tests/deploy.scm: Add file. * gnu/local.mk (GNU_SYSTEM_MODULES): Register file. Change-Id: I348c8bf2e518ec6c00af126993eaca3fcd453901 --- gnu/local.mk | 3 +- gnu/tests/deploy.scm | 223 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 gnu/tests/deploy.scm diff --git a/gnu/local.mk b/gnu/local.mk index e6ece8cc483..157d327e53b 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -62,7 +62,7 @@ # Copyright © 2023 B. Wilson # Copyright © 2023 Bruno Victal # Copyright © 2023, 2024 gemmaro -# Copyright © 2023 Herman Rimm +# Copyright © 2023, 2025 Herman Rimm # Copyright © 2023 Troy Figiel # Copyright © 2024, 2025 David Elsing # Copyright © 2024 Ashish SHUKLA @@ -847,6 +847,7 @@ GNU_SYSTEM_MODULES = \ %D%/tests/containers.scm \ %D%/tests/cups.scm \ %D%/tests/databases.scm \ + %D%/tests/deploy.scm \ %D%/tests/desktop.scm \ %D%/tests/dns.scm \ %D%/tests/dict.scm \ diff --git a/gnu/tests/deploy.scm b/gnu/tests/deploy.scm new file mode 100644 index 00000000000..55d3edb78ef --- /dev/null +++ b/gnu/tests/deploy.scm @@ -0,0 +1,223 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Jakob L. Kreuze +;;; Copyright © 2024, 2025 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 (gnu packages package-management) + #:use-module (gnu packages ssh) + #: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-source) + (scheme-file "machines.scm" + #~(begin (use-modules (gnu machine ssh) + (guix utils) + (ice-9 textual-ports)) + ;; XXX: (guix platforms ...) are not found in %load-path. + (set! (@ (guix platform) systems) + (compose list %current-system)) + (list (machine + (configuration + (machine-ssh-configuration + (host-name "localhost") + (host-key + (call-with-input-file "/etc/ssh/ssh_host_ed25519_key.pub" + get-string-all)) + (system (%current-system)))) + (environment managed-host-environment-type) + (operating-system #$os-source)))))) + +(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 os-source) + (program-file "deploy.scm" + (with-extensions (list guile-gcrypt guile-ssh) + (with-imported-modules + `(((guix config) => ,(make-config.scm))) + #~(execl #$(file-append (current-guix) "/bin/guix") + "guix" "deploy" #$(machines os-source)))))) + +(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 system-generations-definition + #~(define (system-generations marionette) + "Return the names of the generation symlinks on MARIONETTE." + (marionette-eval + '(begin (use-modules (ice-9 ftw)) + (define (select? entry) + (not (member entry '("per-user" "system" "." "..")))) + (scandir "/var/guix/profiles/" select?)) + marionette))) + +(define* (run-deploy-test) + "Run a test of an OS running DEPLOY-PROGRAM, which creates a new +generation of the system profile." + (define new-os-source + '(begin + (use-modules (gnu tests)) + (operating-system + (inherit %simple-os) + (host-name (substring (operating-system-host-name %simple-os) + 0 1))))) + + (define (test script) + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (ice-9 match) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$vm))) + + #$system-generations-definition + + (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-assert "uname" + (match (marionette-eval '(uname) marionette) + (#("Linux" host-name _ ...) + (string=? host-name #$(operating-system-host-name os))))) + + (test-end)))) + + (gexp->derivation "deploy" (test (deploy-program new-os-source)))) + +(define* (run-rollback-test) + "Run a test of an OS with a faulty bootloader running DEPLOY-PROGRAM, +which causes a rollback." + (define bad-os-source + '(begin + (use-modules (gnu tests)) + (operating-system + (inherit %simple-os) + (host-name (substring (operating-system-host-name %simple-os) + 0 1)) + (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) + (ice-9 match) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$vm))) + + #$system-generations-definition + + (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-assert "uname" + (match (marionette-eval '(uname) marionette) + (#("Linux" host-name _ ...) + (string=? host-name #$(operating-system-host-name os))))) + + (test-end)))) + + (gexp->derivation "rollback" (test (deploy-program bad-os-source)))) + +(define %test-deploy + (system-test + (name "deploy") + (description "Deploy to the local machine.") + (value (run-deploy-test)))) + +(define %test-rollback + (system-test + (name "deploy-rollback") + (description "Rollback guix deploy with a faulty bootloader.") + (value (run-rollback-test))))