tests: Factorize LUKS passphrase.

* gnu/tests/install.scm (%luks-passphrase): New variable.
(%encrypted-root-installation-script): Use it.
(enter-luks-passphrase): Use it.
This commit is contained in:
Ludovic Courtès 2020-02-21 20:49:46 +01:00
parent 5c04b00cf4
commit 43e282accc
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -651,9 +651,13 @@ (define-os-with-source (%encrypted-root-os %encrypted-root-os-source)
(guix combinators))))) (guix combinators)))))
%base-services)))) %base-services))))
(define %luks-passphrase
;; LUKS encryption passphrase used in tests.
"thepassphrase")
(define %encrypted-root-installation-script (define %encrypted-root-installation-script
;; Shell script of a simple installation. ;; Shell script of a simple installation.
"\ (string-append "\
. /etc/profile . /etc/profile
set -e -x set -e -x
guix --version guix --version
@ -665,9 +669,9 @@ (define %encrypted-root-installation-script
mkpart primary ext2 3M 1.4G \\ mkpart primary ext2 3M 1.4G \\
set 1 boot on \\ set 1 boot on \\
set 1 bios_grub on set 1 bios_grub on
echo -n thepassphrase | \\ echo -n " %luks-passphrase " | \\
cryptsetup luksFormat --uuid=12345678-1234-1234-1234-123456789abc -q /dev/vdb2 - cryptsetup luksFormat --uuid=12345678-1234-1234-1234-123456789abc -q /dev/vdb2 -
echo -n thepassphrase | \\ echo -n " %luks-passphrase " | \\
cryptsetup open --type luks --key-file - /dev/vdb2 the-root-device cryptsetup open --type luks --key-file - /dev/vdb2 the-root-device
mkfs.ext4 -L my-root /dev/mapper/the-root-device mkfs.ext4 -L my-root /dev/mapper/the-root-device
mount LABEL=my-root /mnt mount LABEL=my-root /mnt
@ -677,7 +681,7 @@ (define %encrypted-root-installation-script
guix system build /mnt/etc/config.scm guix system build /mnt/etc/config.scm
guix system init /mnt/etc/config.scm /mnt --no-substitutes guix system init /mnt/etc/config.scm /mnt --no-substitutes
sync sync
reboot\n") reboot\n"))
(define (enter-luks-passphrase marionette) (define (enter-luks-passphrase marionette)
"Return a gexp to be inserted in the basic system test running on MARIONETTE "Return a gexp to be inserted in the basic system test running on MARIONETTE
@ -698,7 +702,8 @@ (define (bios-boot-screen? text)
;; when the passphrase should be entered. ;; when the passphrase should be entered.
(wait-for-screen-text #$marionette passphrase-prompt? (wait-for-screen-text #$marionette passphrase-prompt?
#:ocrad #$ocrad) #:ocrad #$ocrad)
(marionette-type "thepassphrase\n" #$marionette) (marionette-type #$(string-append %luks-passphrase "\n")
#$marionette)
;; Now wait until we leave the boot screen. This is necessary so ;; Now wait until we leave the boot screen. This is necessary so
;; we can then be sure we match the "Enter passphrase" prompt from ;; we can then be sure we match the "Enter passphrase" prompt from
@ -714,7 +719,8 @@ (define (bios-boot-screen? text)
(wait-for-screen-text #$marionette passphrase-prompt? (wait-for-screen-text #$marionette passphrase-prompt?
#:ocrad #$ocrad #:ocrad #$ocrad
#:timeout 60) #:timeout 60)
(marionette-type "thepassphrase\n" #$marionette) (marionette-type #$(string-append %luks-passphrase "\n")
#$marionette)
;; Take a screenshot for debugging purposes. ;; Take a screenshot for debugging purposes.
(marionette-control (string-append "screendump " #$output (marionette-control (string-append "screendump " #$output