nfs.scm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2016 John Darrington <jmd@gnu.org>
  4. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  5. ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (gnu tests nfs)
  22. #:use-module (gnu tests)
  23. #:use-module (gnu bootloader)
  24. #:use-module (gnu bootloader grub)
  25. #:use-module (gnu system)
  26. #:use-module (gnu system file-systems)
  27. #:use-module (gnu system shadow)
  28. #:use-module (gnu system vm)
  29. #:use-module (gnu services)
  30. #:use-module (gnu services base)
  31. #:use-module (gnu services nfs)
  32. #:use-module (gnu services networking)
  33. #:use-module (gnu packages onc-rpc)
  34. #:use-module (guix gexp)
  35. #:use-module (guix store)
  36. #:use-module (guix monads)
  37. #:export (%test-nfs))
  38. (define %base-os
  39. (operating-system
  40. (host-name "olitupmok")
  41. (timezone "Europe/Berlin")
  42. (locale "en_US.UTF-8")
  43. (bootloader (bootloader-configuration
  44. (bootloader grub-bootloader)
  45. (target "/dev/sdX")))
  46. (file-systems %base-file-systems)
  47. (users %base-user-accounts)
  48. (packages (cons*
  49. rpcbind
  50. %base-packages))
  51. (services (cons*
  52. (service rpcbind-service-type
  53. (rpcbind-configuration))
  54. (dhcp-client-service)
  55. %base-services))))
  56. (define (run-nfs-test name socket)
  57. "Run a test of an OS running RPC-SERVICE, which should create SOCKET."
  58. (define os
  59. (marionette-operating-system
  60. %base-os
  61. #:imported-modules '((gnu services herd)
  62. (guix combinators))))
  63. (define test
  64. (with-imported-modules '((gnu build marionette))
  65. #~(begin
  66. (use-modules (gnu build marionette)
  67. (srfi srfi-64))
  68. (define marionette
  69. (make-marionette (list #$(virtual-machine os))))
  70. (define (wait-for-socket file)
  71. ;; Wait until SOCKET exists in the guest
  72. (marionette-eval
  73. `(let loop ((i 10))
  74. (cond ((and (file-exists? ,file)
  75. (eq? 'socket (stat:type (stat ,file))))
  76. #t)
  77. ((> i 0)
  78. (sleep 1)
  79. (loop (- i 1)))
  80. (else
  81. (error "Socket didn't show up: " ,file))))
  82. marionette))
  83. (mkdir #$output)
  84. (chdir #$output)
  85. (test-begin "rpc-daemon")
  86. ;; Wait for the rpcbind daemon to be up and running.
  87. (test-eq "RPC service running"
  88. 'running!
  89. (marionette-eval
  90. '(begin
  91. (use-modules (gnu services herd))
  92. (start-service 'rpcbind-daemon)
  93. 'running!)
  94. marionette))
  95. ;; Check the socket file and that the service is still running.
  96. (test-assert "RPC socket exists"
  97. (and
  98. (wait-for-socket #$socket)
  99. (marionette-eval
  100. '(begin
  101. (use-modules (gnu services herd)
  102. (srfi srfi-1))
  103. (live-service-running
  104. (find (lambda (live)
  105. (memq 'rpcbind-daemon
  106. (live-service-provision live)))
  107. (current-services))))
  108. marionette)))
  109. (test-assert "Probe RPC daemon"
  110. (marionette-eval
  111. '(zero? (system* "rpcinfo" "-p"))
  112. marionette))
  113. (test-end)
  114. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  115. (gexp->derivation name test))
  116. (define %test-nfs
  117. (system-test
  118. (name "nfs")
  119. (description "Test some things related to NFS.")
  120. (value (run-nfs-test name "/var/run/rpcbind.sock"))))