diff options
| author | Giacomo Leidi <goodoldpaul@autistici.org> | 2025-08-24 16:59:46 +0200 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2025-08-25 13:04:36 +0900 |
| commit | cc07ecd7ccc52540113414eaebafc0fb218ef9ff (patch) | |
| tree | 3a2502f89d904ac45956eda15354010d0664a1ea /gnu/tests | |
| parent | 60f4d72590abf11885ea3e2ec2a7c277683417aa (diff) | |
tests: Use lower-oci-image-state in container tests.
This patch replaces boilerplate in container related tests with
oci-image plumbing from (gnu services containers).
* gnu/tests/containers.scm (%oci-tarball): New variable;
(run-rootless-podman-test): use %oci-tarball;
(build-tarball&run-rootless-podman-test): drop procedure.
* gnu/tests/docker.scm (%docker-tarball): New variable;
(build-tarball&run-docker-test): use %docker-tarball;
(%docker-system-tarball): New variable;
(build-tarball&run-docker-system-test): new procedure.
Change-Id: Iad6f0704aee188d89464c83722dea0bb7adb084a
Signed-off-by: Maxim Cournoyer <maxim@guixotic.coop>
Diffstat (limited to 'gnu/tests')
| -rw-r--r-- | gnu/tests/containers.scm | 84 | ||||
| -rw-r--r-- | gnu/tests/docker.scm | 104 |
2 files changed, 101 insertions, 87 deletions
diff --git a/gnu/tests/containers.scm b/gnu/tests/containers.scm index 1a442cddc64..089303643c9 100644 --- a/gnu/tests/containers.scm +++ b/gnu/tests/containers.scm | |||
| @@ -46,6 +46,9 @@ | |||
| 46 | %test-oci-service-rootless-podman | 46 | %test-oci-service-rootless-podman |
| 47 | %test-oci-service-docker)) | 47 | %test-oci-service-docker)) |
| 48 | 48 | ||
| 49 | (define lower-oci-image-state | ||
| 50 | (@@ (gnu services containers) lower-oci-image-state)) | ||
| 51 | |||
| 49 | 52 | ||
| 50 | (define %rootless-podman-os | 53 | (define %rootless-podman-os |
| 51 | (simple-operating-system | 54 | (simple-operating-system |
| @@ -69,13 +72,48 @@ | |||
| 69 | (supplementary-groups '("wheel" "netdev" "cgroup" | 72 | (supplementary-groups '("wheel" "netdev" "cgroup" |
| 70 | "audio" "video"))))))) | 73 | "audio" "video"))))))) |
| 71 | 74 | ||
| 72 | (define (run-rootless-podman-test oci-tarball) | 75 | (define %oci-tarball |
| 76 | (lower-oci-image-state | ||
| 77 | "guile-guest" | ||
| 78 | (packages->manifest | ||
| 79 | (list | ||
| 80 | guile-3.0 guile-json-3 | ||
| 81 | (package | ||
| 82 | (name "guest-script") | ||
| 83 | (version "0") | ||
| 84 | (source #f) | ||
| 85 | (build-system trivial-build-system) | ||
| 86 | (arguments | ||
| 87 | (list | ||
| 88 | #:guile guile-3.0 | ||
| 89 | #:builder | ||
| 90 | #~(let ((out #$output)) | ||
| 91 | (mkdir out) | ||
| 92 | (call-with-output-file (string-append out "/a.scm") | ||
| 93 | (lambda (port) | ||
| 94 | (display "(display \"hello world\n\")" port)))))) | ||
| 95 | (synopsis "Display hello world using Guile") | ||
| 96 | (description "This package displays the text \"hello world\" on the | ||
| 97 | standard output device and then enters a new line.") | ||
| 98 | (home-page #f) | ||
| 99 | (license license:public-domain)))) | ||
| 100 | '(#:entry-point "bin/guile" | ||
| 101 | #:localstatedir? #t | ||
| 102 | #:extra-options (#:image-tag "guile-guest") | ||
| 103 | #:symlinks (("/bin/Guile" -> "bin/guile") | ||
| 104 | ("aa.scm" -> "a.scm"))) | ||
| 105 | "guile-guest" | ||
| 106 | (%current-target-system) | ||
| 107 | (%current-system) | ||
| 108 | #f)) | ||
| 109 | |||
| 110 | (define (run-rootless-podman-test) | ||
| 73 | 111 | ||
| 74 | (define os | 112 | (define os |
| 75 | (marionette-operating-system | 113 | (marionette-operating-system |
| 76 | (operating-system-with-gc-roots | 114 | (operating-system-with-gc-roots |
| 77 | %rootless-podman-os | 115 | %rootless-podman-os |
| 78 | (list oci-tarball)) | 116 | (list %oci-tarball)) |
| 79 | #:imported-modules '((gnu services herd) | 117 | #:imported-modules '((gnu services herd) |
| 80 | (guix combinators)))) | 118 | (guix combinators)))) |
| 81 | 119 | ||
| @@ -254,7 +292,7 @@ | |||
| 254 | (let* ((loaded (slurp ,(string-append #$podman | 292 | (let* ((loaded (slurp ,(string-append #$podman |
| 255 | "/bin/podman") | 293 | "/bin/podman") |
| 256 | "load" "-i" | 294 | "load" "-i" |
| 257 | ,#$oci-tarball)) | 295 | ,#$%oci-tarball)) |
| 258 | (repository&tag "localhost/guile-guest:latest") | 296 | (repository&tag "localhost/guile-guest:latest") |
| 259 | (response1 (slurp | 297 | (response1 (slurp |
| 260 | ,(string-append #$podman "/bin/podman") | 298 | ,(string-append #$podman "/bin/podman") |
| @@ -307,49 +345,11 @@ | |||
| 307 | 345 | ||
| 308 | (gexp->derivation "rootless-podman-test" test)) | 346 | (gexp->derivation "rootless-podman-test" test)) |
| 309 | 347 | ||
| 310 | (define (build-tarball&run-rootless-podman-test) | ||
| 311 | (mlet* %store-monad | ||
| 312 | ((_ (set-grafting #f)) | ||
| 313 | (guile (set-guile-for-build (default-guile))) | ||
| 314 | (guest-script-package -> | ||
| 315 | (package | ||
| 316 | (name "guest-script") | ||
| 317 | (version "0") | ||
| 318 | (source #f) | ||
| 319 | (build-system trivial-build-system) | ||
| 320 | (arguments `(#:guile ,guile-3.0 | ||
| 321 | #:builder | ||
| 322 | (let ((out (assoc-ref %outputs "out"))) | ||
| 323 | (mkdir out) | ||
| 324 | (call-with-output-file (string-append out "/a.scm") | ||
| 325 | (lambda (port) | ||
| 326 | (display "(display \"hello world\n\")" port))) | ||
| 327 | #t))) | ||
| 328 | (synopsis "Display hello world using Guile") | ||
| 329 | (description "This package displays the text \"hello world\" on the | ||
| 330 | standard output device and then enters a new line.") | ||
| 331 | (home-page #f) | ||
| 332 | (license license:public-domain))) | ||
| 333 | (profile (profile-derivation (packages->manifest | ||
| 334 | (list guile-3.0 guile-json-3 | ||
| 335 | guest-script-package)) | ||
| 336 | #:hooks '() | ||
| 337 | #:locales? #f)) | ||
| 338 | (tarball (pack:docker-image | ||
| 339 | "docker-pack" profile | ||
| 340 | #:symlinks '(("/bin/Guile" -> "bin/guile") | ||
| 341 | ("aa.scm" -> "a.scm")) | ||
| 342 | #:extra-options | ||
| 343 | '(#:image-tag "guile-guest") | ||
| 344 | #:entry-point "bin/guile" | ||
| 345 | #:localstatedir? #t))) | ||
| 346 | (run-rootless-podman-test tarball))) | ||
| 347 | |||
| 348 | (define %test-rootless-podman | 348 | (define %test-rootless-podman |
| 349 | (system-test | 349 | (system-test |
| 350 | (name "rootless-podman") | 350 | (name "rootless-podman") |
| 351 | (description "Test rootless Podman service.") | 351 | (description "Test rootless Podman service.") |
| 352 | (value (build-tarball&run-rootless-podman-test)))) | 352 | (value (run-rootless-podman-test)))) |
| 353 | 353 | ||
| 354 | 354 | ||
| 355 | (define %oci-network | 355 | (define %oci-network |
diff --git a/gnu/tests/docker.scm b/gnu/tests/docker.scm index 9fee3905f0e..4fc50a99a72 100644 --- a/gnu/tests/docker.scm +++ b/gnu/tests/docker.scm | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #:use-module (gnu system image) | 26 | #:use-module (gnu system image) |
| 27 | #:use-module (gnu system vm) | 27 | #:use-module (gnu system vm) |
| 28 | #:use-module (gnu services) | 28 | #:use-module (gnu services) |
| 29 | #:use-module (gnu services containers) | ||
| 29 | #:use-module (gnu services dbus) | 30 | #:use-module (gnu services dbus) |
| 30 | #:use-module (gnu services networking) | 31 | #:use-module (gnu services networking) |
| 31 | #:use-module (gnu services docker) | 32 | #:use-module (gnu services docker) |
| @@ -48,6 +49,9 @@ | |||
| 48 | %test-docker-system | 49 | %test-docker-system |
| 49 | %test-oci-container)) | 50 | %test-oci-container)) |
| 50 | 51 | ||
| 52 | (define lower-oci-image-state | ||
| 53 | (@@ (gnu services containers) lower-oci-image-state)) | ||
| 54 | |||
| 51 | (define %docker-os | 55 | (define %docker-os |
| 52 | (simple-operating-system | 56 | (simple-operating-system |
| 53 | (service dhcpcd-service-type) | 57 | (service dhcpcd-service-type) |
| @@ -57,6 +61,41 @@ | |||
| 57 | (service containerd-service-type) | 61 | (service containerd-service-type) |
| 58 | (service docker-service-type))) | 62 | (service docker-service-type))) |
| 59 | 63 | ||
| 64 | (define %docker-tarball | ||
| 65 | (lower-oci-image-state | ||
| 66 | "guile-guest" | ||
| 67 | (packages->manifest | ||
| 68 | (list | ||
| 69 | guile-3.0 guile-json-3 | ||
| 70 | (package | ||
| 71 | (name "guest-script") | ||
| 72 | (version "0") | ||
| 73 | (source #f) | ||
| 74 | (build-system trivial-build-system) | ||
| 75 | (arguments | ||
| 76 | (list | ||
| 77 | #:guile guile-3.0 | ||
| 78 | #:builder | ||
| 79 | #~(let ((out #$output)) | ||
| 80 | (mkdir out) | ||
| 81 | (call-with-output-file (string-append out "/a.scm") | ||
| 82 | (lambda (port) | ||
| 83 | (display "(display \"hello world\n\")" port)))))) | ||
| 84 | (synopsis "Display hello world using Guile") | ||
| 85 | (description "This package displays the text \"hello world\" on the | ||
| 86 | standard output device and then enters a new line.") | ||
| 87 | (home-page #f) | ||
| 88 | (license license:public-domain)))) | ||
| 89 | '(#:entry-point "bin/guile" | ||
| 90 | #:localstatedir? #t | ||
| 91 | #:extra-options (#:image-tag "guile-guest") | ||
| 92 | #:symlinks (("/bin/Guile" -> "bin/guile") | ||
| 93 | ("aa.scm" -> "a.scm"))) | ||
| 94 | "guile-guest" | ||
| 95 | (%current-target-system) | ||
| 96 | (%current-system) | ||
| 97 | #f)) | ||
| 98 | |||
| 60 | (define (run-docker-test docker-tarball) | 99 | (define (run-docker-test docker-tarball) |
| 61 | "Load DOCKER-TARBALL as Docker image and run it in a Docker container, | 100 | "Load DOCKER-TARBALL as Docker image and run it in a Docker container, |
| 62 | inside %DOCKER-OS." | 101 | inside %DOCKER-OS." |
| @@ -173,40 +212,7 @@ inside %DOCKER-OS." | |||
| 173 | (gexp->derivation "docker-test" test)) | 212 | (gexp->derivation "docker-test" test)) |
| 174 | 213 | ||
| 175 | (define (build-tarball&run-docker-test) | 214 | (define (build-tarball&run-docker-test) |
| 176 | (mlet* %store-monad | 215 | (run-docker-test %docker-tarball)) |
| 177 | ((_ (set-grafting #f)) | ||
| 178 | (guile (set-guile-for-build (default-guile))) | ||
| 179 | (guest-script-package -> | ||
| 180 | (package | ||
| 181 | (name "guest-script") | ||
| 182 | (version "0") | ||
| 183 | (source #f) | ||
| 184 | (build-system trivial-build-system) | ||
| 185 | (arguments `(#:guile ,guile-3.0 | ||
| 186 | #:builder | ||
| 187 | (let ((out (assoc-ref %outputs "out"))) | ||
| 188 | (mkdir out) | ||
| 189 | (call-with-output-file (string-append out "/a.scm") | ||
| 190 | (lambda (port) | ||
| 191 | (display "(display \"hello world\n\")" port))) | ||
| 192 | #t))) | ||
| 193 | (synopsis "Display hello world using Guile") | ||
| 194 | (description "This package displays the text \"hello world\" on the | ||
| 195 | standard output device and then enters a new line.") | ||
| 196 | (home-page #f) | ||
| 197 | (license license:public-domain))) | ||
| 198 | (profile (profile-derivation (packages->manifest | ||
| 199 | (list guile-3.0 guile-json-3 | ||
| 200 | guest-script-package)) | ||
| 201 | #:hooks '() | ||
| 202 | #:locales? #f)) | ||
| 203 | (tarball (pack:docker-image | ||
| 204 | "docker-pack" profile | ||
| 205 | #:symlinks '(("/bin/Guile" -> "bin/guile") | ||
| 206 | ("aa.scm" -> "a.scm")) | ||
| 207 | #:entry-point "bin/guile" | ||
| 208 | #:localstatedir? #t))) | ||
| 209 | (run-docker-test tarball))) | ||
| 210 | 216 | ||
| 211 | (define %test-docker | 217 | (define %test-docker |
| 212 | (system-test | 218 | (system-test |
| @@ -215,8 +221,22 @@ standard output device and then enters a new line.") | |||
| 215 | (value (build-tarball&run-docker-test)))) | 221 | (value (build-tarball&run-docker-test)))) |
| 216 | 222 | ||
| 217 | 223 | ||
| 224 | (define %docker-system-tarball | ||
| 225 | (lower-oci-image-state | ||
| 226 | "guix-system-guest" | ||
| 227 | (operating-system | ||
| 228 | (inherit (simple-operating-system)) | ||
| 229 | ;; Use locales for a single libc to | ||
| 230 | ;; reduce space requirements. | ||
| 231 | (locale-libcs (list glibc))) | ||
| 232 | '() | ||
| 233 | "guix-system-guest" | ||
| 234 | (%current-target-system) | ||
| 235 | (%current-system) | ||
| 236 | #f)) | ||
| 237 | |||
| 218 | (define (run-docker-system-test tarball) | 238 | (define (run-docker-system-test tarball) |
| 219 | "Load DOCKER-TARBALL as Docker image and run it in a Docker container, | 239 | "Load TARBALL as Docker image and run it in a Docker container, |
| 220 | inside %DOCKER-OS." | 240 | inside %DOCKER-OS." |
| 221 | (define os | 241 | (define os |
| 222 | (marionette-operating-system | 242 | (marionette-operating-system |
| @@ -333,21 +353,15 @@ inside %DOCKER-OS." | |||
| 333 | 353 | ||
| 334 | (gexp->derivation "docker-system-test" test)) | 354 | (gexp->derivation "docker-system-test" test)) |
| 335 | 355 | ||
| 356 | (define (build-tarball&run-docker-system-test) | ||
| 357 | (run-docker-system-test %docker-system-tarball)) | ||
| 358 | |||
| 336 | (define %test-docker-system | 359 | (define %test-docker-system |
| 337 | (system-test | 360 | (system-test |
| 338 | (name "docker-system") | 361 | (name "docker-system") |
| 339 | (description "Run a system image as produced by @command{guix system | 362 | (description "Run a system image as produced by @command{guix system |
| 340 | docker-image} inside Docker.") | 363 | docker-image} inside Docker.") |
| 341 | (value (with-monad %store-monad | 364 | (value (build-tarball&run-docker-system-test)))) |
| 342 | (>>= (lower-object | ||
| 343 | (system-image (os->image | ||
| 344 | (operating-system | ||
| 345 | (inherit (simple-operating-system)) | ||
| 346 | ;; Use locales for a single libc to | ||
| 347 | ;; reduce space requirements. | ||
| 348 | (locale-libcs (list glibc))) | ||
| 349 | #:type docker-image-type))) | ||
| 350 | run-docker-system-test))))) | ||
| 351 | 365 | ||
| 352 | 366 | ||
| 353 | (define %oci-os | 367 | (define %oci-os |
