diff options
author | Ludovic Courtès <ludo@gnu.org> | 2022-09-23 08:00:13 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-09-28 22:28:27 +0200 |
commit | 8bd4126917f59f4af9a4323c3d5699201862dca2 (patch) | |
tree | d5b9f225a0722239269f75c2b471394aa19f4b94 /tests | |
parent | f75592533e1921f4b3614a0de345f5c037b90cd6 (diff) | |
download | guix-8bd4126917f59f4af9a4323c3d5699201862dca2.tar guix-8bd4126917f59f4af9a4323c3d5699201862dca2.tar.gz |
substitute: Retry downloading when a nar is unavailable.
Fixes <https://issues.guix.gnu.org/57978>
Reported by Attila Lendvai <attila@lendvai.name>.
Previously, if a narinfo was available but its corresponding nar was
missing (for instance because the narinfo was cached and the server
became unreachable in the meantime), 'guix substitute --substitute'
would try to download the nar from its preferred location and abort when
that fails. This change forces one retry with each of the URLs.
* guix/scripts/substitute.scm (download-nar): Do not catch
'http-get-error?' exceptions.
(system-error?, network-error?, process-substitution/fallback): New
procedures.
(process-substitution): Call 'process-substitution/fallback' upon
'network-error?'.
* tests/substitute.scm ("substitute, first URL has narinfo but lacks nar, second URL unauthorized")
("substitute, first URL has narinfo but nar is 404, both URLs authorized")
("substitute, first URL has narinfo but nar is 404, one URL authorized")
("substitute, narinfo is available but nar is missing"): New tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/substitute.scm | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/substitute.scm b/tests/substitute.scm index 5315292987..9032a50268 100644 --- a/tests/substitute.scm +++ b/tests/substitute.scm @@ -523,6 +523,119 @@ System: mips64el-linux\n"))) (lambda () (false-if-exception (delete-file "substitute-retrieved"))))))) +(test-equal "substitute, first URL has narinfo but lacks nar, second URL unauthorized" + "Substitutable data." + (with-narinfo* + (string-append %narinfo "Signature: " + (signature-field + %narinfo + #:public-key %wrong-public-key)) + %alternate-substitute-directory + + (with-narinfo* (string-append %narinfo "Signature: " + (signature-field %narinfo)) + %main-substitute-directory + + (dynamic-wind + (const #t) + (lambda () + ;; Remove this file so that the substitute can only be retrieved + ;; from %ALTERNATE-SUBSTITUTE-DIRECTORY. + (delete-file (string-append %main-substitute-directory + "/example.nar")) + + (parameterize ((substitute-urls + (map (cut string-append "file://" <>) + (list %main-substitute-directory + %alternate-substitute-directory)))) + (request-substitution (string-append (%store-prefix) + "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") + "substitute-retrieved")) + (call-with-input-file "substitute-retrieved" get-string-all)) + (lambda () + (false-if-exception (delete-file "substitute-retrieved"))))))) + +(test-equal "substitute, first URL has narinfo but nar is 404, both URLs authorized" + "Substitutable data." + (with-narinfo* + (string-append %narinfo "Signature: " + (signature-field %narinfo)) + %main-substitute-directory + + (with-http-server `((200 ,(string-append %narinfo "Signature: " + (signature-field %narinfo))) + (404 "Sorry, nar is missing!")) + (dynamic-wind + (const #t) + (lambda () + (parameterize ((substitute-urls + (list (%local-url) + (string-append "file://" + %main-substitute-directory)))) + (request-substitution (string-append (%store-prefix) + "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") + "substitute-retrieved")) + (call-with-input-file "substitute-retrieved" get-string-all)) + (lambda () + (false-if-exception (delete-file "substitute-retrieved"))))))) + +(test-equal "substitute, first URL has narinfo but nar is 404, one URL authorized" + "Substitutable data." + (with-narinfo* + (string-append %narinfo "Signature: " + (signature-field + %narinfo + #:public-key %wrong-public-key)) + %main-substitute-directory + + (with-http-server `((200 ,(string-append %narinfo "Signature: " + (signature-field + %narinfo + #:public-key %wrong-public-key))) + (404 "Sorry, nar is missing!")) + (let ((url1 (%local-url))) + (parameterize ((%http-server-port 0)) + (with-http-server `((200 ,(string-append %narinfo "Signature: " + (signature-field %narinfo))) + (404 "Sorry, nar is missing!")) + (let ((url2 (%local-url))) + (dynamic-wind + (const #t) + (lambda () + (parameterize ((substitute-urls + (list url1 url2 + (string-append "file://" + %main-substitute-directory)))) + (request-substitution (string-append (%store-prefix) + "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") + "substitute-retrieved")) + (call-with-input-file "substitute-retrieved" get-string-all)) + (lambda () + (false-if-exception (delete-file "substitute-retrieved"))))))))))) + +(test-quit "substitute, narinfo is available but nar is missing" + "failed to find alternative substitute" + (with-narinfo* + (string-append %narinfo "Signature: " + (signature-field + %narinfo + #:public-key %wrong-public-key)) + %main-substitute-directory + + (with-http-server `((200 ,(string-append %narinfo "Signature: " + (signature-field %narinfo))) + (404 "Sorry, nar is missing!")) + (parameterize ((substitute-urls + (list (%local-url) + (string-append "file://" + %main-substitute-directory)))) + (delete-file (string-append %main-substitute-directory + "/example.nar")) + (request-substitution (string-append (%store-prefix) + "/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-foo") + "substitute-retrieved") + (not (file-exists? "substitute-retrieved")))))) + (test-equal "substitute, first narinfo is unsigned and has wrong hash" "Substitutable data." (with-narinfo* (regexp-substitute #f |