[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/01: tests: Add docker integration test.
From: |
guix-commits |
Subject: |
01/01: tests: Add docker integration test. |
Date: |
Fri, 11 Jan 2019 11:12:55 -0500 (EST) |
dannym pushed a commit to branch wip-docker-test
in repository guix.
commit 08c5013e50a858b11ad258ab80cc1ca865f97fb4
Author: Danny Milosavljevic <address@hidden>
Date: Fri Jan 11 16:09:00 2019 +0100
tests: Add docker integration test.
* tests/docker-inception.scm: New file.
* Makefile.am (SCM_TESTS): Add it.
---
Makefile.am | 1 +
tests/docker-inception.scm | 172 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 173 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 0590c51..ab0865f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -395,6 +395,7 @@ SCM_TESTS = \
tests/containers.scm \
tests/opam.scm \
tests/pack.scm \
+ tests/docker-inception.scm \
tests/pypi.scm \
tests/import-utils.scm \
tests/store-database.scm \
diff --git a/tests/docker-inception.scm b/tests/docker-inception.scm
new file mode 100644
index 0000000..aa654b8
--- /dev/null
+++ b/tests/docker-inception.scm
@@ -0,0 +1,172 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Danny Milosavljevic <address@hidden>
+;;; Copyright © 2017 Christopher Baines <address@hidden>
+;;;
+;;; 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 (test-docker-inception)
+ #:use-module (gnu tests)
+ #:use-module (gnu system)
+ #:use-module (gnu system file-systems)
+ #:use-module (gnu system vm)
+ #:use-module (gnu services)
+ #:use-module (gnu services dbus)
+ #:use-module (gnu services networking)
+ #:use-module (gnu services docker)
+ #:use-module (gnu services desktop)
+ #:use-module (gnu packages bootstrap)
+ #:use-module (gnu packages docker)
+ #:use-module (guix derivations)
+ #:use-module (guix gexp)
+ #:use-module (guix grafts)
+ #:use-module (guix monads)
+ #:use-module (guix packages)
+ #:use-module (guix profiles)
+ #:use-module (guix scripts pack)
+ #:use-module (guix store)
+ #:use-module (guix tests)
+ #:use-module (srfi srfi-64))
+
+(define %store
+ (open-connection-for-tests))
+
+;; Globally disable grafts because they can trigger early builds.
+(%graft? #f)
+
+(define %docker-os
+ (simple-operating-system
+ (service dhcp-client-service-type)
+ (dbus-service)
+ (polkit-service)
+ (service elogind-service-type)
+ (service docker-service-type)))
+
+(define (run-docker-test docker-tarball)
+ "Run tests in %DOCKER-OS."
+ (define os
+ (marionette-operating-system
+ %docker-os
+ #:imported-modules '((gnu services herd)
+ (guix combinators))))
+
+ (define vm
+ (virtual-machine
+ (operating-system os)
+ (memory-size 500)
+ (disk-image-size (* 250 (expt 2 20)))
+ (port-forwardings '())))
+
+ (define test
+ (with-imported-modules '((gnu build marionette))
+ #~(begin
+ (use-modules (srfi srfi-11) (srfi srfi-64)
+ (gnu build marionette))
+
+ (define marionette
+ (make-marionette (list #$vm)))
+
+ (mkdir #$output)
+ (chdir #$output)
+
+ (test-begin "docker")
+
+ (test-assert "service running"
+ (marionette-eval
+ '(begin
+ (use-modules (gnu services herd))
+ (match (start-service 'dockerd)
+ (#f #f)
+ (('service response-parts ...)
+ (match (assq-ref response-parts 'running)
+ ((pid) (number? pid))))))
+ marionette))
+
+ (test-eq "fetch version"
+ 0
+ (marionette-eval
+ `(begin
+ (system* ,(string-append #$docker-cli "/bin/docker")
+ "version"))
+ marionette))
+
+ (test-eq "pack guest OS as docker image, load it and run it"
+ 0
+ (marionette-eval
+ `(begin
+ (define slurp
+ (lambda args
+ (let* ((port (apply open-pipe* OPEN_READ args))
+ (output (read-line port))
+ (status (close-pipe port)))
+ output)))
+ (let* ((image-id (slurp ,(string-append #$docker-cli
+ "/bin/docker")
+ "load" "-i" ,#$docker-tarball))
+ (_ (write image-id)))
+ (system* ,(string-append #$docker-cli "/bin/docker")
+ "run" "-e"
+ "GUIX_NEW_SYSTEM=/var/guix/profiles/system"
+ "--entrypoint"
+ "/var/guix/profiles/system/profile/bin/guile"
+ image-id
+ "/var/guix/profiles/system/boot")))
+ marionette))
+
+ (test-end)
+ (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+ (gexp->derivation "docker-test" test))
+
+(define-syntax-rule (test-assertm name store exp)
+ (test-assert name
+ (parameterize ((%store-prefix "/gnu/store"))
+ (let ((guile (package-derivation store %bootstrap-guile)))
+ (run-with-store store exp
+ #:guile-for-build guile)))))
+
+(test-begin "docker-inception")
+
+;; The following test needs guile-sqlite3, libgcrypt, etc. as a consequence of
+;; commit c45477d2a1a651485feede20fe0f3d15aec48b39 and related changes. Thus,
+;; run it on the user's store, if it's available, on the grounds that these
+;; dependencies may be already there, or we can get substitutes or build them
+;; quite inexpensively; see <https://bugs.gnu.org/32184>.
+
+(with-external-store store
+ (unless store (test-skip 1))
+
+ ;; FIXME
+ ;(setenv "NIX_STORE" "/gnu/store")
+;"/home/dannym/src/guix-ns13/guix/test-tmp/store"
+
+ (test-assertm "docker can load guix docker-image" store
+ (mlet* %store-monad
+ ((guile (set-guile-for-build (default-guile)))
+ (profile (profile-derivation (packages->manifest
+ (list %bootstrap-guile))
+ #:hooks '()
+ #:locales? #f))
+ (tarball (docker-image "docker-pack" profile
+ #:symlinks '(("/bin/Guile" -> "bin/guile"))
+ #:localstatedir? #t))
+ (check (run-docker-test tarball)))
+ (built-derivations (list check)))))
+
+(test-end)
+
+;; Local Variables:
+;; eval: (put 'test-assertm 'scheme-indent-function 2)
+;; End: