2020-02-19 17:25:58 -05:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
|
2020-03-24 04:21:02 -04:00
|
|
|
;;; Copyright © 2020 Mathieu Othacehe <m.othacehe@gmail.com>
|
2020-02-19 17:25:58 -05:00
|
|
|
;;;
|
|
|
|
;;; 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 installer tests)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
#:use-module (srfi srfi-35)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
#:use-module (ice-9 pretty-print)
|
|
|
|
#:export (&pattern-not-matched
|
|
|
|
pattern-not-matched?
|
|
|
|
|
|
|
|
%installer-socket-file
|
|
|
|
open-installer-socket
|
|
|
|
|
|
|
|
converse
|
|
|
|
conversation-log-port
|
|
|
|
|
|
|
|
choose-locale+keyboard
|
|
|
|
enter-host-name+passwords
|
|
|
|
choose-services
|
|
|
|
choose-partitioning
|
2021-04-27 11:30:28 -04:00
|
|
|
start-installation
|
|
|
|
complete-installation
|
2020-02-19 17:25:58 -05:00
|
|
|
|
|
|
|
edit-configuration-file))
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; This module provides tools to test the guided "graphical" installer in a
|
|
|
|
;;; non-interactive fashion. The core of it is 'converse': it allows you to
|
|
|
|
;;; state Expect-style dialogues, which happen over the Unix-domain socket the
|
|
|
|
;;; installer listens to. Higher-level procedures such as
|
|
|
|
;;; 'choose-locale+keyboard' are provided to perform specific parts of the
|
|
|
|
;;; dialogue.
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(define %installer-socket-file
|
|
|
|
;; Socket the installer listens to.
|
|
|
|
"/var/guix/installer-socket")
|
|
|
|
|
|
|
|
(define* (open-installer-socket #:optional (file %installer-socket-file))
|
|
|
|
"Return a socket connected to the installer."
|
|
|
|
(let ((sock (socket AF_UNIX SOCK_STREAM 0)))
|
|
|
|
(connect sock AF_UNIX file)
|
|
|
|
sock))
|
|
|
|
|
|
|
|
(define-condition-type &pattern-not-matched &error
|
|
|
|
pattern-not-matched?
|
|
|
|
(pattern pattern-not-matched-pattern)
|
|
|
|
(sexp pattern-not-matched-sexp))
|
|
|
|
|
|
|
|
(define (pattern-error pattern sexp)
|
|
|
|
(raise (condition
|
|
|
|
(&pattern-not-matched
|
|
|
|
(pattern pattern) (sexp sexp)))))
|
|
|
|
|
|
|
|
(define conversation-log-port
|
|
|
|
;; Port where debugging info is logged
|
|
|
|
(make-parameter (current-error-port)))
|
|
|
|
|
|
|
|
(define (converse-debug pattern)
|
|
|
|
(format (conversation-log-port)
|
|
|
|
"conversation expecting pattern ~s~%"
|
|
|
|
pattern))
|
|
|
|
|
|
|
|
(define-syntax converse
|
|
|
|
(lambda (s)
|
|
|
|
"Convert over PORT: read sexps from there, match them against each
|
|
|
|
PATTERN, and send the corresponding REPLY. Raise to '&pattern-not-matched'
|
|
|
|
when one of the PATTERNs is not matched."
|
|
|
|
|
|
|
|
;; XXX: Strings that appear in PATTERNs must be in the language the
|
|
|
|
;; installer is running in. In the future, we should add support to allow
|
|
|
|
;; writing English strings in PATTERNs and have the pattern matcher
|
|
|
|
;; automatically translate them.
|
|
|
|
|
|
|
|
;; Here we emulate 'pmatch' syntax on top of 'match'. This is ridiculous
|
|
|
|
;; but that's because 'pmatch' compares objects with 'eq?', making it
|
|
|
|
;; pretty useless, and it doesn't support ellipses and such.
|
|
|
|
|
|
|
|
(define (quote-pattern s)
|
|
|
|
;; Rewrite the pattern S from pmatch style (a ,b) to match style like
|
|
|
|
;; ('a b).
|
|
|
|
(with-ellipsis :::
|
|
|
|
(syntax-case s (unquote _ ...)
|
|
|
|
((unquote id) #'id)
|
|
|
|
(_ #'_)
|
|
|
|
(... #'...)
|
|
|
|
(id
|
|
|
|
(identifier? #'id)
|
|
|
|
#''id)
|
|
|
|
((lst :::) (map quote-pattern #'(lst :::)))
|
|
|
|
(pattern #'pattern))))
|
|
|
|
|
|
|
|
(define (match-pattern s)
|
|
|
|
;; Match one pattern without a guard.
|
|
|
|
(syntax-case s ()
|
|
|
|
((port (pattern reply) continuation)
|
|
|
|
(with-syntax ((pattern (quote-pattern #'pattern)))
|
|
|
|
#'(let ((pat 'pattern))
|
|
|
|
(converse-debug pat)
|
|
|
|
(match (read port)
|
|
|
|
(pattern
|
|
|
|
(let ((data (call-with-values (lambda () reply)
|
|
|
|
list)))
|
|
|
|
(for-each (lambda (obj)
|
|
|
|
(write obj port)
|
|
|
|
(newline port))
|
|
|
|
data)
|
|
|
|
(force-output port)
|
|
|
|
(continuation port)))
|
|
|
|
(sexp
|
|
|
|
(pattern-error pat sexp))))))))
|
|
|
|
|
|
|
|
(syntax-case s ()
|
|
|
|
((_ port (pattern reply) rest ...)
|
|
|
|
(match-pattern #'(port (pattern reply)
|
|
|
|
(lambda (port)
|
|
|
|
(converse port rest ...)))))
|
|
|
|
((_ port (pattern guard reply) rest ...)
|
|
|
|
#`(let ((skip? (not guard))
|
|
|
|
(next (lambda (p)
|
|
|
|
(converse p rest ...))))
|
|
|
|
(if skip?
|
|
|
|
(next port)
|
|
|
|
#,(match-pattern #'(port (pattern reply) next)))))
|
|
|
|
((_ port)
|
|
|
|
#t))))
|
|
|
|
|
|
|
|
(define* (choose-locale+keyboard port
|
|
|
|
#:key
|
|
|
|
(language "English")
|
|
|
|
(location "Hong Kong")
|
|
|
|
(timezone '("Europe" "Zagreb"))
|
|
|
|
(keyboard
|
|
|
|
'("English (US)"
|
|
|
|
"English (intl., with AltGr dead keys)")))
|
|
|
|
"Converse over PORT with the guided installer to choose the specified
|
|
|
|
LANGUAGE, LOCATION, TIMEZONE, and KEYBOARD."
|
|
|
|
(converse port
|
|
|
|
((list-selection (title "Locale language")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
|
|
|
language)
|
|
|
|
((list-selection (title "Locale location")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
|
|
|
location)
|
|
|
|
((menu (title "GNU Guix install")
|
|
|
|
(text _)
|
|
|
|
(items (,guided _ ...))) ;"Guided graphical installation"
|
|
|
|
guided)
|
|
|
|
((list-selection (title "Timezone")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
|
|
|
(first timezone))
|
|
|
|
((list-selection (title "Timezone")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
|
|
|
(second timezone))
|
|
|
|
((list-selection (title "Layout")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
|
|
|
(first keyboard))
|
|
|
|
((list-selection (title "Variant")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
|
|
|
(second keyboard))))
|
|
|
|
|
|
|
|
(define* (enter-host-name+passwords port
|
|
|
|
#:key
|
|
|
|
(host-name "guix")
|
|
|
|
(root-password "foo")
|
|
|
|
(users '(("alice" "pass1")
|
|
|
|
("bob" "pass2")
|
|
|
|
("charlie" "pass3"))))
|
|
|
|
"Converse over PORT with the guided installer to choose HOST-NAME,
|
|
|
|
ROOT-PASSWORD, and USERS."
|
|
|
|
(converse port
|
|
|
|
((input (title "Hostname") (text _) (default _))
|
|
|
|
host-name)
|
|
|
|
((input (title "System administrator password") (text _) (default _))
|
|
|
|
root-password)
|
|
|
|
((input (title "Password confirmation required") (text _) (default _))
|
|
|
|
root-password)
|
|
|
|
((add-users)
|
|
|
|
(match users
|
|
|
|
(((names passwords) ...)
|
|
|
|
(map (lambda (name password)
|
|
|
|
`(user (name ,name) (real-name ,(string-titlecase name))
|
|
|
|
(home-directory ,(string-append "/home/" name))
|
|
|
|
(password ,password)))
|
|
|
|
names passwords))))))
|
|
|
|
|
|
|
|
(define* (choose-services port
|
|
|
|
#:key
|
2020-03-24 04:21:02 -04:00
|
|
|
(choose-desktop-environment? (const #f))
|
2020-02-19 17:25:58 -05:00
|
|
|
(choose-network-service?
|
|
|
|
(lambda (service)
|
|
|
|
(or (string-contains service "SSH")
|
|
|
|
(string-contains service "NSS"))))
|
|
|
|
(choose-network-management-tool?
|
|
|
|
(lambda (service)
|
2021-07-03 11:13:14 -04:00
|
|
|
(string-contains service "DHCP")))
|
2021-04-23 14:50:15 -04:00
|
|
|
(choose-misc-service?
|
|
|
|
(lambda (service)
|
|
|
|
(string-contains service "NTP")))
|
2021-07-03 11:13:14 -04:00
|
|
|
(choose-other-service? (const #f)))
|
2021-04-23 14:50:15 -04:00
|
|
|
|
2021-07-03 11:13:14 -04:00
|
|
|
"Converse over PORT to choose services."
|
2020-03-24 04:21:02 -04:00
|
|
|
(define desktop-environments '())
|
|
|
|
|
2020-02-19 17:25:58 -05:00
|
|
|
(converse port
|
|
|
|
((checkbox-list (title "Desktop environment") (text _)
|
2020-03-24 04:21:02 -04:00
|
|
|
(items ,services))
|
|
|
|
(let ((desktops (filter choose-desktop-environment? services)))
|
|
|
|
(set! desktop-environments desktops)
|
|
|
|
desktops))
|
2020-02-19 17:25:58 -05:00
|
|
|
((checkbox-list (title "Network service") (text _)
|
|
|
|
(items ,services))
|
|
|
|
(filter choose-network-service? services))
|
|
|
|
|
|
|
|
;; The "Network management" dialog shows up only when no desktop
|
|
|
|
;; environments have been selected, hence the guard.
|
|
|
|
((list-selection (title "Network management")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items ,services))
|
|
|
|
(null? desktop-environments)
|
2021-07-03 11:13:14 -04:00
|
|
|
(find choose-network-management-tool? services))
|
|
|
|
|
2021-04-23 14:50:15 -04:00
|
|
|
((checkbox-list (title "Console services") (text _)
|
|
|
|
(items ,services))
|
|
|
|
(null? desktop-environments)
|
|
|
|
(filter choose-misc-service? services))
|
|
|
|
|
installer: Offer the CUPS printing service on a dedicated page.
Currently, the installer page RUN-OTHER-SERVICES-CBT-PAGE offers to the user all
installer services that are not of the types 'desktop', 'network-management', or
'networking'. Concretely, this means that it offers the CUPS printing service,
because that is the only service of a different type defined in the installer.
In later commits, we will add some services of a new type, and we only want them
to be offered when the user is installing a non-graphical system.
At least one of these new services (NTP) is part of %DESKTOP-SERVICES. If it
was also offered on RUN-OTHER-SERVICES-CBT-PAGE, and the user had configured a
system using %DESKTOP-SERVICES, the user could accidentally add NTP to their
services twice, which is an error and would break installation.
So, this commit makes the RUN-OTHER-SERVICES-CBT-PAGE be more specific about
what services to offer. This makes it easier to discriminate between desktop and
non-desktop installations, in terms of when a given service is offered.
* gnu/installer/newt/services.scm (RUN-OTHER-SERVICES-CBT-PAGE): Rename to ...
(RUN-PRINTING-SERVICES-CBT-PAGE): ... new variable, and select only 'document' services.
(RUN-SERVICES-PAGE): Adjust accordingly.
* gnu/installer/tests.scm (CHOOSE-SERVICES): Adjust accordingly.
2021-12-25 00:54:48 -05:00
|
|
|
((checkbox-list (title "Printing and document services") (text _)
|
2021-07-03 11:13:14 -04:00
|
|
|
(items ,services))
|
|
|
|
(filter choose-other-service? services))))
|
2020-02-19 17:25:58 -05:00
|
|
|
|
|
|
|
(define (edit-configuration-file file)
|
|
|
|
"Edit FILE, an operating system configuration file generated by the
|
|
|
|
installer, by adding a marionette service such that the installed OS is
|
|
|
|
instrumented for further testing."
|
|
|
|
(define (read-expressions port)
|
|
|
|
(let loop ((result '()))
|
|
|
|
(match (read port)
|
|
|
|
((? eof-object?)
|
|
|
|
(reverse result))
|
|
|
|
(exp
|
|
|
|
(loop (cons exp result))))))
|
|
|
|
|
|
|
|
(define (edit exp)
|
|
|
|
(match exp
|
|
|
|
(('operating-system _ ...)
|
|
|
|
`(marionette-operating-system ,exp
|
|
|
|
#:imported-modules
|
|
|
|
'((gnu services herd)
|
|
|
|
(guix build utils)
|
|
|
|
(guix combinators))))
|
|
|
|
(_
|
|
|
|
exp)))
|
|
|
|
|
|
|
|
(let ((content (call-with-input-file file read-expressions)))
|
2022-09-24 06:42:21 -04:00
|
|
|
;; XXX: Remove the file before re-writing it, to be sure there are no
|
2022-09-24 08:15:12 -04:00
|
|
|
;; leftovers. We shouldn't have to do that as CALL-WITH-OUTPUT-FILE uses
|
2022-09-24 06:42:21 -04:00
|
|
|
;; the O_TRUNC flag by default.
|
|
|
|
(delete-file file)
|
2020-02-19 17:25:58 -05:00
|
|
|
(call-with-output-file file
|
|
|
|
(lambda (port)
|
|
|
|
(format port "\
|
|
|
|
;; Operating system configuration edited for automated testing.~%~%")
|
|
|
|
|
|
|
|
(pretty-print '(use-modules (gnu tests)) port)
|
|
|
|
(for-each (lambda (exp)
|
|
|
|
(pretty-print (edit exp) port)
|
|
|
|
(newline port))
|
|
|
|
content)))
|
|
|
|
|
|
|
|
#t))
|
|
|
|
|
|
|
|
(define* (choose-partitioning port
|
|
|
|
#:key
|
|
|
|
(encrypted? #t)
|
2021-04-27 11:30:28 -04:00
|
|
|
(uefi-support? #f)
|
2020-02-19 17:25:58 -05:00
|
|
|
(passphrase "thepassphrase")
|
|
|
|
(edit-configuration-file
|
|
|
|
edit-configuration-file))
|
|
|
|
"Converse over PORT to choose the partitioning method. When ENCRYPTED? is
|
|
|
|
true, choose full-disk encryption with PASSPHRASE as the LUKS passphrase.
|
2021-04-27 11:30:28 -04:00
|
|
|
|
|
|
|
When UEFI-SUPPORT? is true, assume that we are running the installation tests
|
|
|
|
on an UEFI capable machine.
|
|
|
|
|
2020-10-23 05:31:56 -04:00
|
|
|
This conversation stops when the user partitions have been formatted, right
|
|
|
|
before the installer generates the configuration file and shows it in a dialog
|
2021-04-27 11:30:28 -04:00
|
|
|
box. "
|
2020-02-19 17:25:58 -05:00
|
|
|
(converse port
|
|
|
|
((list-selection (title "Partitioning method")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items (,not-encrypted ,encrypted _ ...)))
|
|
|
|
(if encrypted?
|
|
|
|
encrypted
|
|
|
|
not-encrypted))
|
|
|
|
((list-selection (title "Disk") (multiple-choices? #f)
|
2020-04-10 09:44:30 -04:00
|
|
|
(items (,disks ...)))
|
|
|
|
;; When running the installation from an ISO image, the CD/DVD drive
|
|
|
|
;; shows up in the list. Avoid it.
|
|
|
|
(find (lambda (disk)
|
|
|
|
(not (or (string-contains disk "DVD")
|
|
|
|
(string-contains disk "CD-ROM"))))
|
|
|
|
disks))
|
2020-02-19 17:25:58 -05:00
|
|
|
|
|
|
|
;; The "Partition table" dialog pops up only if there's not already a
|
2021-04-27 11:30:28 -04:00
|
|
|
;; partition table and if the system does not support UEFI.
|
2020-02-19 17:25:58 -05:00
|
|
|
((list-selection (title "Partition table")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items _))
|
2021-04-27 11:30:28 -04:00
|
|
|
;; When UEFI is supported, the partition is forced to GPT by the
|
|
|
|
;; installer.
|
|
|
|
(not uefi-support?)
|
2020-02-19 17:25:58 -05:00
|
|
|
"gpt")
|
2021-04-27 11:30:28 -04:00
|
|
|
|
2020-02-19 17:25:58 -05:00
|
|
|
((list-selection (title "Partition scheme")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items (,one-partition _ ...)))
|
|
|
|
one-partition)
|
|
|
|
((list-selection (title "Guided partitioning")
|
|
|
|
(multiple-choices? #f)
|
|
|
|
(items (,disk _ ...)))
|
|
|
|
disk)
|
|
|
|
((input (title "Password required")
|
|
|
|
(text _) (default #f))
|
|
|
|
encrypted? ;only when ENCRYPTED?
|
|
|
|
passphrase)
|
|
|
|
((input (title "Password confirmation required")
|
|
|
|
(text _) (default #f))
|
|
|
|
encrypted?
|
|
|
|
passphrase)
|
|
|
|
((confirmation (title "Format disk?") (text _))
|
|
|
|
#t)
|
|
|
|
((info (title "Preparing partitions") _ ...)
|
|
|
|
(values)) ;nothing to return
|
2020-10-23 05:31:56 -04:00
|
|
|
((starting-final-step)
|
|
|
|
;; Do not return anything. The reply will be sent by
|
|
|
|
;; 'conclude-installation' and in the meantime the installer just waits
|
|
|
|
;; for us, giving us a chance to do things such as changing partition
|
|
|
|
;; UUIDs before it generates the configuration file.
|
|
|
|
(values))))
|
2020-02-19 17:25:58 -05:00
|
|
|
|
2021-04-27 11:30:28 -04:00
|
|
|
(define (start-installation port)
|
|
|
|
"Start the installation by checking over PORT that we get the generated
|
2020-10-23 05:31:56 -04:00
|
|
|
configuration file, accepting it and starting the installation, and then
|
2021-04-27 11:30:28 -04:00
|
|
|
receiving the pause message once the 'guix system init' process has
|
2020-10-23 05:31:56 -04:00
|
|
|
completed."
|
|
|
|
;; Assume the previous message received was 'starting-final-step'; here we
|
|
|
|
;; send the reply to that message, which lets the installer continue.
|
|
|
|
(write #t port)
|
|
|
|
(newline port)
|
|
|
|
(force-output port)
|
|
|
|
|
2020-02-19 17:25:58 -05:00
|
|
|
(converse port
|
2020-10-23 05:31:56 -04:00
|
|
|
((file-dialog (title "Configuration file")
|
|
|
|
(text _)
|
|
|
|
(file ,configuration-file))
|
|
|
|
(edit-configuration-file configuration-file))
|
2020-02-19 17:25:58 -05:00
|
|
|
((pause) ;"Press Enter to continue."
|
2021-04-27 11:30:28 -04:00
|
|
|
(values))))
|
|
|
|
|
|
|
|
(define (complete-installation port)
|
|
|
|
"Complete the installation by replying to the installer pause message and
|
|
|
|
waiting for the installation-complete message."
|
|
|
|
;; Assume the previous message received was 'pause'; here we send the reply
|
|
|
|
;; to that message, which lets the installer continue.
|
|
|
|
(write #t port)
|
|
|
|
(newline port)
|
|
|
|
(force-output port)
|
|
|
|
|
|
|
|
(converse port
|
|
|
|
((installation-complete)
|
2020-02-19 17:25:58 -05:00
|
|
|
(values))))
|
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
;;; eval: (put 'converse 'scheme-indent-function 1)
|
|
|
|
;;; eval: (put 'with-ellipsis 'scheme-indent-function 1)
|
|
|
|
;;; End:
|