diff mbox series

[bug#45905,v3] IPFS service definition

Message ID 42e840c5a55968ecf8173e4eb84af7dc415f3a51.camel@telenet.be
State Accepted
Headers show
Series [bug#45905,v3] IPFS service definition | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

M March 30, 2021, 1:37 p.m. UTC
Hi Guix,

Revised patch series is attached.

Changes in v2:

* let the shepherd service depend on (loopback) instead of
  (networking)
* added a (broken) system test for the IPFS service

Changes in v3:

* added 'extensions' argument to 'marionette-operating-system'. 
* fixed the system test
* tweaked the documentation formatting and removed a misleading comment
  on forwarding (port forwarding would be fine here, as the test is run
  in a container so there is no risk of port conflicts IIUC)

Ludovic Courtès wrote:
> Nitpick: please avoid ‘@’.  Instead, explicitly do:
> [...]

I actually prefer '(@ (...) ...)' here, but whatever.  It's changed
in v3.

> As it stands, the test fails because you need to:
>  (define test
>    (with-extensions (list guile-json)
>      …))

As the uploading and downloading is done in the guest, not the host,
this needs to be done somewhat differently.  That's what the patch
‘tests: Support package extensions in the backdoor REPL’ is for.

Greetings,
Maxime

Comments

Ludovic Courtès April 12, 2021, 4:48 p.m. UTC | #1
Hi Maxime,

Apologies for the delay — I had not seen this new version.

Maxime Devos <maximedevos@telenet.be> skribis:

> From 74149efb0dbd1b412fdd14aa87bee80640ea5463 Mon Sep 17 00:00:00 2001
> From: Maxime Devos <maximedevos@telenet.be>
> Date: Fri, 15 Jan 2021 21:46:42 +0100
> Subject: [PATCH 1/4] services: Add ipfs-service-type
>
> * gnu/services/networking.scm (ipfs-service-type)
>   (%ipfs-home-mapping, %ipfs-environment)
>   (%ipfs-accounts, %ipfs-home): New variables.
>   (ipfs-configuration, ipfs-configuration?)
>   (ipfs-configuration-package, ipfs-configuration-gateway)
>   (ipfs-configuration-api, ipfs-shepherd-service)
>   (ipfs-binary, %ipfs-activation): New procedures.
> * doc/guix.texi (Networking Services): Document it.

[...]

> From c1ca4e25ff35fabe89fc7a8b2b4d3521840236c9 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
> Date: Fri, 28 Dec 2018 01:07:58 +0100
> Subject: [PATCH 2/4] Add (guix ipfs).
>
> This module allows for communicating with the IPFS
> gateway over the HTTP interface.  The commit has been
> cherry-picked from <https://issues.guix.gnu.org/33899>.
>
> The procedures for adding and restoring file trees have
> been removed as according to a reply issue 33899, a different
> format will be used.  The procedure 'add-data' has been
> exported as it will be used in the system test for IPFS.
>
> * guix/ipfs.scm: New file.
> * Makefile.am (MODULES): Add it.

[...]

> From bbf35272775de63ad64aed98a2fa081374f28505 Mon Sep 17 00:00:00 2001
> From: Maxime Devos <maximedevos@telenet.be>
> Date: Tue, 30 Mar 2021 12:40:14 +0200
> Subject: [PATCH 3/4] tests: Support package extensions in the backdoor REPL.
>
> * gnu/tests.scm
>   (<marionette-configuration>): Add 'extensions' field.
>   (marionette-shepherd-service): Honour the field.
>   (with-import-modules-and-extensions): Define a combination
>   of 'with-import-modules' and 'with-extensions'.

[...]

> From b9134c60d9e662dd497caf0c1819e3e04a5e8b4e Mon Sep 17 00:00:00 2001
> From: Maxime Devos <maximedevos@telenet.be>
> Date: Sun, 28 Mar 2021 17:01:49 +0200
> Subject: [PATCH 4/4] gnu: tests: Test basic funtionality of the IPFS service.
>
> It is tested whether the IPFS service listens
> at the gateway and API ports and whether it
> is possible to upload and download a bytevector.
>
> * gnu/tests/networking.scm
>   (%ipfs-os): New variable.
>   (run-ipfs-test): New procedure.
>   (%test-ipfs): New system test.

Pushed all four patches as 68c9e0a56e008f19427bd213cf5b24bdd8fe5922.

Thanks!

Ludo’.
M April 12, 2021, 6:35 p.m. UTC | #2
On Mon, 2021-04-12 at 18:48 +0200, Ludovic Courtès wrote:
> [...]
> 
> Pushed all four patches as 68c9e0a56e008f19427bd213cf5b24bdd8fe5922.
> 
> Thanks!

Thanks!

Maxime.
diff mbox series

Patch

From b9134c60d9e662dd497caf0c1819e3e04a5e8b4e Mon Sep 17 00:00:00 2001
From: Maxime Devos <maximedevos@telenet.be>
Date: Sun, 28 Mar 2021 17:01:49 +0200
Subject: [PATCH 4/4] gnu: tests: Test basic funtionality of the IPFS service.

It is tested whether the IPFS service listens
at the gateway and API ports and whether it
is possible to upload and download a bytevector.

* gnu/tests/networking.scm
  (%ipfs-os): New variable.
  (run-ipfs-test): New procedure.
  (%test-ipfs): New system test.
---
 gnu/tests/networking.scm | 92 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 91 insertions(+), 1 deletion(-)

diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm
index 022663aa67..453e63f52d 100644
--- a/gnu/tests/networking.scm
+++ b/gnu/tests/networking.scm
@@ -3,6 +3,7 @@ 
 ;;; Copyright © 2017, 2020 Marius Bakke <marius@gnu.org>
 ;;; Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -29,12 +30,15 @@ 
   #:use-module (guix gexp)
   #:use-module (guix store)
   #:use-module (guix monads)
+  #:use-module (guix modules)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages networking)
+  #:use-module (gnu packages guile)
   #:use-module (gnu services shepherd)
   #:use-module (ice-9 match)
-  #:export (%test-inetd %test-openvswitch %test-dhcpd %test-tor %test-iptables))
+  #:export (%test-inetd %test-openvswitch %test-dhcpd %test-tor %test-iptables
+                        %test-ipfs))
 
 (define %inetd-os
   ;; Operating system with 2 inetd services.
@@ -563,3 +567,89 @@  COMMIT
    (name "iptables")
    (description "Test a running iptables daemon.")
    (value (run-iptables-test))))
+
+
+;;;
+;;; IPFS service
+;;;
+
+(define %ipfs-os
+  (simple-operating-system
+   (service ipfs-service-type)))
+
+(define (run-ipfs-test)
+  (define os
+    (marionette-operating-system %ipfs-os
+                                 #:imported-modules (source-module-closure
+                                                     '((gnu services herd)
+                                                       (guix ipfs)))
+                                 #:extensions (list guile-json-4)
+                                 #:requirements '(ipfs)))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (gnu build marionette)
+                       (rnrs bytevectors)
+                       (srfi srfi-64)
+                       (ice-9 binary-ports))
+
+          (define marionette
+            (make-marionette (list #$(virtual-machine os))))
+
+          (define (ipfs-is-alive?)
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd)
+                             (srfi srfi-1))
+                (live-service-running
+                 (find (lambda (live)
+                         (memq 'ipfs
+                               (live-service-provision live)))
+                       (current-services))))
+             marionette))
+
+          ;; The default API endpoint port 5001 is used,
+          ;; so there is no need to parameterize %ipfs-base-url.
+          (define (add-data data)
+            (marionette-eval `(content-name (add-data ,data)) marionette))
+          (define (read-contents object)
+            (marionette-eval
+             `(let* ((input (read-contents ,object))
+                     (all-input (get-bytevector-all input)))
+                (close-port input)
+                all-input)
+             marionette))
+
+          (marionette-eval '(use-modules (guix ipfs)) marionette)
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin "ipfs")
+
+          ;; Test the IPFS service.
+
+          (test-assert "ipfs is alive" (ipfs-is-alive?))
+
+          (test-assert "ipfs is listening on the gateway"
+            (let ((default-port 8082))
+              (wait-for-tcp-port default-port marionette)))
+
+          (test-assert "ipfs is listening on the API endpoint"
+            (let ((default-port 5001))
+              (wait-for-tcp-port default-port marionette)))
+
+          (define test-bv (string->utf8 "hello ipfs!"))
+          (test-equal "can upload and download a file to/from ipfs"
+            test-bv
+            (read-contents (add-data test-bv)))
+
+          (test-end)
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+  (gexp->derivation "ipfs-test" test))
+
+(define %test-ipfs
+  (system-test
+   (name "ipfs")
+   (description "Test a running IPFS daemon configuration.")
+   (value (run-ipfs-test))))
-- 
2.31.1