bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#44491: Support GUIX_DISABLE_NETWORK_TESTS environment variable


From: Vagrant Cascadian
Subject: bug#44491: Support GUIX_DISABLE_NETWORK_TESTS environment variable
Date: Fri, 06 Nov 2020 13:30:39 -0800

The following patch adds a GUIX_DISABLE_NETWORK_TESTS environment
variable and disables tests that require network access when it is set.

This is needed for packaging GNU Guix in Debian, where packaging policies
prohibit network access during builds, but may not technically block network
access during builds.

If this could be considered for the upcoming 1.2 release, that would be
appreciated, though I can also carry the patches in Debian...


live well,
  vagrant
From 36516e767f68dbc2bd3dc186f956c0b0fd7de9f1 Mon Sep 17 00:00:00 2001
From: Vagrant Cascadian <vagrant@debian.org>
Date: Thu, 5 Nov 2020 17:35:52 -0800
Subject: [PATCH] tests: Support disabling network tests.

This is needed for packaging GNU Guix in Debian, where packaging policies
prohibit network access during builds, but may not technically block network
access during builds.

* guix/tests.scm (network-reachable): Return #f when
  GUIX_DISABLE_NETWORK_TESTS is set.
* tests/common.sh: New file.
* tests/guix-build-branch.sh, tests/guix-environment.sh,
  tests/guix-pack.sh, tests/guix-package-net.sh: Use
  network_reachable function from common.sh.
---
 guix/tests.scm             | 7 +++++--
 tests/common.sh            | 8 ++++++++
 tests/guix-build-branch.sh | 8 ++------
 tests/guix-environment.sh  | 5 ++---
 tests/guix-pack.sh         | 5 ++---
 tests/guix-package-net.sh  | 9 ++-------
 6 files changed, 21 insertions(+), 21 deletions(-)
 create mode 100644 tests/common.sh

diff --git a/guix/tests.scm b/guix/tests.scm
index fc3d521163..9f98cef33f 100644
--- a/guix/tests.scm
+++ b/guix/tests.scm
@@ -204,8 +204,11 @@ too expensive to build entirely in the test store."
              (zero? (logand #o222 (stat:mode st)))))))
 
 (define (network-reachable?)
-  "Return true if we can reach the Internet."
-  (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)))
+  "Return true if we can reach the Internet and GUIX_DISABLE_NETWORK_TESTS
+is not set."
+  (if (getenv "GUIX_DISABLE_NETWORK_TESTS")
+      #f
+      (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))))
 
 (define-syntax-rule (mock (module proc replacement) body ...)
   "Within BODY, replace the definition of PROC from MODULE with the definition
diff --git a/tests/common.sh b/tests/common.sh
new file mode 100644
index 0000000000..b91c0bdcd4
--- /dev/null
+++ b/tests/common.sh
@@ -0,0 +1,8 @@
+network_reachable() {
+    if [ -n "$GUIX_DISABLE_NETWORK_TESTS" ]; then
+               exit 77
+    fi
+    if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> 
/dev/null; then
+        exit 77
+    fi
+}
diff --git a/tests/guix-build-branch.sh b/tests/guix-build-branch.sh
index 79aa06a58f..55f8f388ab 100644
--- a/tests/guix-build-branch.sh
+++ b/tests/guix-build-branch.sh
@@ -24,12 +24,8 @@ guix build --version
 
 # 'guix build --with-branch' requires access to the network to clone the
 # Git repository below.
-
-if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
-then
-    # Skipping.
-    exit 77
-fi
+. $(dirname $0)/common.sh
+network_reachable
 
 orig_drv="`guix build guile-gcrypt -d`"
 latest_drv="`guix build guile-gcrypt --with-branch=guile-gcrypt=master -d`"
diff --git a/tests/guix-environment.sh b/tests/guix-environment.sh
index f8be48f0c0..d140566aef 100644
--- a/tests/guix-environment.sh
+++ b/tests/guix-environment.sh
@@ -174,9 +174,9 @@ case "$transformed_drv" in
     *)           false;;
 esac
 
+. $(dirname $0)/common.sh
+network_reachable
 
-if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
-then
     # Compute the build environment for the initial GNU Make.
     guix environment --bootstrap --no-substitutes --search-paths --pure \
          -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
@@ -244,4 +244,3 @@ then
     do
        guix gc --references "$profile" | grep "$dep"
     done
-fi
diff --git a/tests/guix-pack.sh b/tests/guix-pack.sh
index 0339221ac2..bc902c7e90 100644
--- a/tests/guix-pack.sh
+++ b/tests/guix-pack.sh
@@ -23,9 +23,8 @@
 
 # A network connection is required to build %bootstrap-coreutils&co,
 # which is required to run these tests with the --bootstrap option.
-if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null; 
then
-    exit 77
-fi
+. $(dirname $0)/common.sh
+network_reachable
 
 guix pack --version
 
diff --git a/tests/guix-package-net.sh b/tests/guix-package-net.sh
index 6d21c6cff6..ec7952f63d 100644
--- a/tests/guix-package-net.sh
+++ b/tests/guix-package-net.sh
@@ -38,13 +38,8 @@ shebang_too_long ()
         -ge 128
 }
 
-if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \
-       || shebang_too_long
-then
-    # Skipping.
-    exit 77
-fi
-
+. $(dirname $0)/common.sh
+network_reachable
 
 profile="t-profile-$$"
 profile_alt="t-profile-alt-$$"
-- 
2.20.1

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]