all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 8aa531117173a86edf23bc9ce406bb103edefe4e 6992 bytes (raw)
name: gnu/tests/reconfigure.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.org>
;;;
;;; 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 <http://www.gnu.org/licenses/>.

(define-module (gnu tests reconfigure)
  #:use-module (gnu bootloader)
  #:use-module (gnu services shepherd)
  #:use-module (gnu system)
  #:use-module (gnu system accounts)
  #:use-module (gnu system shadow)
  #:use-module (gnu system vm)
  #:use-module (gnu tests)
  #:use-module (guix derivations)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix scripts system reconfigure)
  #:use-module (guix store)
  #:export (%test-switch-to-system
            %test-upgrade-services))

;;; Commentary:
;;;
;;; Test in-place system reconfiguration: advancing the system generation on a
;;; running instance of the Guix System.
;;;
;;; Code:

(define* (run-switch-to-system-test)
  "Run a test of an OS running SWITCH-SYSTEM-PROGRAM, which creates a new
generation of the system profile."
  (define os
    (marionette-operating-system
     (operating-system
       (inherit (simple-operating-system))
       (users (cons (user-account
                     (name "jakob")
                     (group "users")
                     (home-directory "/home/jakob"))
                    %base-user-accounts)))
     #:imported-modules '((gnu services herd)
                          (guix combinators))))

  (define vm (virtual-machine os))

  (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 "switch-to-system")

          (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 "script activated user accounts"
              (marionette-eval
               '(begin
                  (use-modules (rnrs io ports))
                  (string-contains (call-with-input-file "/etc/passwd"
                                     get-string-all)
                                   "jakob"))
               marionette)))

          (test-end))))

  (gexp->derivation "switch-to-system" (test (switch-system-program os))))

(define* (run-upgrade-services-test)
  "Run a test of an OS running UPGRADE-SERVICES-PROGRAM, which upgrades the
Shepherd (PID 1) by unloading obsolete services and loading new services."
  (define os
    (marionette-operating-system
     (simple-operating-system)
     #:imported-modules '((gnu services herd)
                          (guix combinators))))

  (define vm (virtual-machine os))

  (define dummy-service
    ;; Shepherd service that does nothing, for the sole purpose of ensuring
    ;; that it is properly installed and started by the script.
    (shepherd-service (provision '(dummy))
                      (start #~(const #t))
                      (stop #~(const #t))
                      (respawn? #f)))

  (define (test enable-dummy disable-dummy)
    (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 running services on MARIONETTE.
          (define (running-services marionette)
            (marionette-eval
             '(begin
                (use-modules (gnu services herd))
                (map live-service-canonical-name (current-services)))
             marionette))

          (test-runner-current (system-test-runner #$output))
          (test-begin "upgrade-services")

          (let ((services-prior (running-services marionette)))
            (test-assert "script successfully evaluated"
              (marionette-eval
               '(primitive-load #$enable-dummy)
               marionette))

            (test-assert "script started new service"
              (and (not (memq 'dummy services-prior))
                   (memq 'dummy (running-services marionette))))

            (test-assert "script successfully evaluated"
              (marionette-eval
               '(primitive-load #$disable-dummy)
               marionette))

            (test-assert "script stopped obsolete service"
              (not (memq 'dummy (running-services marionette)))))

          (test-end))))

  (gexp->derivation
   "upgrade-services"
   (let* ((file (shepherd-service-file dummy-service))
          (enable (upgrade-services-program (list file) '(dummy) '() '()))
          (disable (upgrade-services-program '() '() '(dummy) '())))
     (test enable disable))))

(define %test-switch-to-system
  (system-test
   (name "switch-to-system")
   (description "Create a new generation of the system profile.")
   (value (run-switch-to-system-test))))

(define %test-upgrade-services
  (system-test
   (name "upgrade-services")
   (description "Upgrade the Shepherd by unloading obsolete services and
loading new services.")
   (value (run-upgrade-services-test))))

debug log:

solving 8aa5311171 ...
found 8aa5311171 in https://yhetil.org/guix/58bd6e83712e96acd4c2c29ed7ff8be3c75a9d5a.1726827025.git.herman@rimm.ee/ ||
	https://yhetil.org/guix/b5b6223c077c323b2bb40e2266b233c46bda8730.1727345067.git.herman@rimm.ee/ ||
	https://yhetil.org/guix/72fc11d9e6fe8b32a2afccd684371bacbb5a24b8.1722741997.git.lilah@lunabee.space/ ||
	https://yhetil.org/guix/d0f0139cc4f40654de5e8c349eff4d5f59948c44.1722794774.git.lilah@lunabee.space/ ||
	https://yhetil.org/guix/37d9ed7280f720a59d8659cb716502c5c2c8fa73.1722803521.git.lilah@lunabee.space/ ||
	https://yhetil.org/guix/0425b46c66e8328ee6b2364d8fd827b2cb9c955f.1722912293.git.lilah@lunabee.space/ ||
	https://yhetil.org/guix/618b1179224d966f44d8a7bd1461a31dfb3fd7da.1722989488.git.lilah@lunabee.space/
found bcc7645fa3 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 bcc7645fa3512d05d3b06a9a912ae11a573b03fb	gnu/tests/reconfigure.scm

applying [1/1] https://yhetil.org/guix/58bd6e83712e96acd4c2c29ed7ff8be3c75a9d5a.1726827025.git.herman@rimm.ee/
diff --git a/gnu/tests/reconfigure.scm b/gnu/tests/reconfigure.scm
index bcc7645fa3..8aa5311171 100644

Checking patch gnu/tests/reconfigure.scm...
Applied patch gnu/tests/reconfigure.scm cleanly.

skipping https://yhetil.org/guix/b5b6223c077c323b2bb40e2266b233c46bda8730.1727345067.git.herman@rimm.ee/ for 8aa5311171
skipping https://yhetil.org/guix/72fc11d9e6fe8b32a2afccd684371bacbb5a24b8.1722741997.git.lilah@lunabee.space/ for 8aa5311171
skipping https://yhetil.org/guix/d0f0139cc4f40654de5e8c349eff4d5f59948c44.1722794774.git.lilah@lunabee.space/ for 8aa5311171
skipping https://yhetil.org/guix/37d9ed7280f720a59d8659cb716502c5c2c8fa73.1722803521.git.lilah@lunabee.space/ for 8aa5311171
skipping https://yhetil.org/guix/0425b46c66e8328ee6b2364d8fd827b2cb9c955f.1722912293.git.lilah@lunabee.space/ for 8aa5311171
skipping https://yhetil.org/guix/618b1179224d966f44d8a7bd1461a31dfb3fd7da.1722989488.git.lilah@lunabee.space/ for 8aa5311171
index at:
100644 8aa531117173a86edf23bc9ce406bb103edefe4e	gnu/tests/reconfigure.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.