diff options
| author | Ludovic Courtès <ludovic.courtes@inria.fr> | 2019-06-04 22:29:40 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2019-06-07 09:57:19 +0200 |
| commit | 08814aec6ae75adcd059c5235c90ad26e5d5607e (patch) | |
| tree | 7546c30c13c520c43d87791f085da856ea1dc087 /gnu/tests/singularity.scm | |
| parent | cd37b144e498ee0ee030306b319cdc4ef1ec5e6f (diff) | |
services: Add Singularity.
* gnu/packages/linux.scm (singularity)[source](snippet): Change file
name of setuid helpers in libexec/cli/*.exec.
[arguments]: Remove "--disable-suid".
* gnu/services/docker.scm (%singularity-activation): New variable.
(singularity-setuid-programs): New procedure.
(singularity-service-type): New variable.
* gnu/tests/singularity.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* doc/guix.texi (Miscellaneous Services): Document it.
Diffstat (limited to 'gnu/tests/singularity.scm')
| -rw-r--r-- | gnu/tests/singularity.scm | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/gnu/tests/singularity.scm b/gnu/tests/singularity.scm new file mode 100644 index 00000000000..55324ef9ea0 --- /dev/null +++ b/gnu/tests/singularity.scm | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu tests singularity) | ||
| 20 | #:use-module (gnu tests) | ||
| 21 | #:use-module (gnu system) | ||
| 22 | #:use-module (gnu system vm) | ||
| 23 | #:use-module (gnu system shadow) | ||
| 24 | #:use-module (gnu services) | ||
| 25 | #:use-module (gnu services docker) | ||
| 26 | #:use-module (gnu packages bash) | ||
| 27 | #:use-module (gnu packages guile) | ||
| 28 | #:use-module (gnu packages linux) ;singularity | ||
| 29 | #:use-module (guix gexp) | ||
| 30 | #:use-module (guix store) | ||
| 31 | #:use-module (guix grafts) | ||
| 32 | #:use-module (guix monads) | ||
| 33 | #:use-module (guix packages) | ||
| 34 | #:use-module (guix profiles) | ||
| 35 | #:use-module (guix scripts pack) | ||
| 36 | #:export (%test-singularity)) | ||
| 37 | |||
| 38 | (define %singularity-os | ||
| 39 | (simple-operating-system | ||
| 40 | (service singularity-service-type) | ||
| 41 | (simple-service 'guest-account | ||
| 42 | account-service-type | ||
| 43 | (list (user-account (name "guest") (uid 1000) (group "guest")) | ||
| 44 | (user-group (name "guest") (id 1000)))))) | ||
| 45 | |||
| 46 | (define (run-singularity-test image) | ||
| 47 | "Load IMAGE, a Squashfs image, as a Singularity image and run it inside | ||
| 48 | %SINGULARITY-OS." | ||
| 49 | (define os | ||
| 50 | (marionette-operating-system %singularity-os)) | ||
| 51 | |||
| 52 | (define singularity-exec | ||
| 53 | #~(begin | ||
| 54 | (use-modules (ice-9 popen) (rnrs io ports)) | ||
| 55 | |||
| 56 | (let* ((pipe (open-pipe* OPEN_READ | ||
| 57 | #$(file-append singularity | ||
| 58 | "/bin/singularity") | ||
| 59 | "exec" #$image "/bin/guile" | ||
| 60 | "-c" "(display \"hello, world\")")) | ||
| 61 | (str (get-string-all pipe)) | ||
| 62 | (status (close-pipe pipe))) | ||
| 63 | (and (zero? status) | ||
| 64 | (string=? str "hello, world"))))) | ||
| 65 | |||
| 66 | (define test | ||
| 67 | (with-imported-modules '((gnu build marionette)) | ||
| 68 | #~(begin | ||
| 69 | (use-modules (srfi srfi-11) (srfi srfi-64) | ||
| 70 | (gnu build marionette)) | ||
| 71 | |||
| 72 | (define marionette | ||
| 73 | (make-marionette (list #$(virtual-machine os)))) | ||
| 74 | |||
| 75 | (mkdir #$output) | ||
| 76 | (chdir #$output) | ||
| 77 | |||
| 78 | (test-begin "singularity") | ||
| 79 | |||
| 80 | (test-assert "singularity exec /bin/guile (as root)" | ||
| 81 | (marionette-eval '#$singularity-exec | ||
| 82 | marionette)) | ||
| 83 | |||
| 84 | (test-equal "singularity exec /bin/guile (unprivileged)" | ||
| 85 | 0 | ||
| 86 | (marionette-eval | ||
| 87 | `(begin | ||
| 88 | (use-modules (ice-9 match)) | ||
| 89 | |||
| 90 | (match (primitive-fork) | ||
| 91 | (0 | ||
| 92 | (dynamic-wind | ||
| 93 | (const #f) | ||
| 94 | (lambda () | ||
| 95 | (setgid 1000) | ||
| 96 | (setuid 1000) | ||
| 97 | (execl #$(program-file "singularity-exec-test" | ||
| 98 | #~(exit #$singularity-exec)) | ||
| 99 | "test")) | ||
| 100 | (lambda () | ||
| 101 | (primitive-exit 127)))) | ||
| 102 | (pid | ||
| 103 | (cdr (waitpid pid))))) | ||
| 104 | marionette)) | ||
| 105 | |||
| 106 | (test-end) | ||
| 107 | (exit (= (test-runner-fail-count (test-runner-current)) 0))))) | ||
| 108 | |||
| 109 | (gexp->derivation "singularity-test" test)) | ||
| 110 | |||
| 111 | (define (build-tarball&run-singularity-test) | ||
| 112 | (mlet* %store-monad | ||
| 113 | ((_ (set-grafting #f)) | ||
| 114 | (guile (set-guile-for-build (default-guile))) | ||
| 115 | ;; 'singularity exec' insists on having /bin/sh in the image. | ||
| 116 | (profile (profile-derivation (packages->manifest | ||
| 117 | (list bash-minimal guile-2.2)) | ||
| 118 | #:hooks '() | ||
| 119 | #:locales? #f)) | ||
| 120 | (tarball (squashfs-image "singularity-pack" profile | ||
| 121 | #:symlinks '(("/bin" -> "bin"))))) | ||
| 122 | (run-singularity-test tarball))) | ||
| 123 | |||
| 124 | (define %test-singularity | ||
| 125 | (system-test | ||
| 126 | (name "singularity") | ||
| 127 | (description "Test Singularity container of Guix.") | ||
| 128 | (value (build-tarball&run-singularity-test)))) | ||
