samba.scm 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2022 Simon Streit <simon@netpanic.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu tests samba)
  19. #:use-module (gnu tests)
  20. #:use-module (gnu system)
  21. #:use-module (gnu system vm)
  22. #:use-module (gnu services)
  23. #:use-module (gnu services networking)
  24. #:use-module (gnu services samba)
  25. #:use-module (gnu packages samba)
  26. #:use-module (guix gexp)
  27. #:use-module (guix store)
  28. #:export (%test-samba
  29. %test-wsdd))
  30. ;;;
  31. ;;; The Samba service.
  32. ;;;
  33. (define %samba-os
  34. (let ((base-os (simple-operating-system
  35. (simple-service 'create-target-directory activation-service-type
  36. #~(begin
  37. (mkdir-p "/srv/samba/guest")
  38. (chown "/srv/samba/guest"
  39. (passwd:uid (getpw "nobody"))
  40. (passwd:gid (getpw "nobody")))))
  41. (service dhcp-client-service-type)
  42. (service samba-service-type
  43. (samba-configuration
  44. (config-file (plain-file "smb.conf" "
  45. [global]
  46. workgroup = WORKGROUP
  47. server string = Samba Server
  48. server role = standalone server
  49. log file = /var/log/samba/log.%m
  50. logging = file
  51. [guest]
  52. path = /srv/samba/guest
  53. read only = no
  54. guest ok = yes
  55. guest only = yes
  56. ")))))))
  57. (operating-system
  58. (inherit base-os)
  59. (packages (cons samba (operating-system-packages base-os))))))
  60. (define* (run-samba-test)
  61. "Return a test of an OS running Samba service."
  62. (define vm
  63. (virtual-machine
  64. (operating-system (marionette-operating-system
  65. %samba-os
  66. #:imported-modules '((gnu services herd))))
  67. (port-forwardings '((8135 . 135)
  68. (8137 . 137)
  69. (8138 . 138)
  70. (8445 . 445)))))
  71. (define test
  72. (with-imported-modules '((gnu build marionette))
  73. #~(begin
  74. (use-modules (gnu build marionette)
  75. (srfi srfi-26)
  76. (srfi srfi-64))
  77. (define marionette
  78. (make-marionette '(#$vm)))
  79. (test-runner-current (system-test-runner #$output))
  80. (test-begin "samba")
  81. (test-assert "samba-smbd running"
  82. (marionette-eval
  83. '(begin
  84. (use-modules (gnu services herd))
  85. (start-service 'samba-smbd))
  86. marionette))
  87. (test-assert "samba-nmbd running"
  88. (marionette-eval
  89. '(begin
  90. (use-modules (gnu services herd))
  91. (start-service 'samba-nmbd))
  92. marionette))
  93. (test-assert "samba-winbindd running"
  94. (marionette-eval
  95. '(begin
  96. (use-modules (gnu services herd))
  97. (start-service 'samba-winbindd))
  98. marionette))
  99. (test-assert "smbd service process id"
  100. (let ((pid
  101. (number->string (wait-for-file "/var/run/samba/smbd.pid"
  102. marionette))))
  103. (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
  104. marionette)))
  105. (test-assert "nmbd service process id"
  106. (let ((pid
  107. (number->string (wait-for-file "/var/run/samba/nmbd.pid"
  108. marionette))))
  109. (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
  110. marionette)))
  111. (test-assert "winbindd service process id"
  112. (let ((pid
  113. (number->string (wait-for-file "/var/run/samba/winbindd.pid"
  114. marionette))))
  115. (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
  116. marionette)))
  117. (test-assert "samba-smbd is listening for peers"
  118. (wait-for-tcp-port 445 marionette))
  119. (test-equal "smbclient connect"
  120. 0
  121. (marionette-eval
  122. '(system* #$(file-append samba "/bin/smbclient")
  123. "--list=localhost" "--no-pass")
  124. marionette))
  125. (test-equal "smbclient connect"
  126. 0
  127. (marionette-eval
  128. '(system* #$(file-append samba "/bin/smbclient")
  129. "--list=localhost" "--no-pass")
  130. marionette))
  131. (test-end))))
  132. (gexp->derivation "samba-test" test))
  133. (define %test-samba
  134. (system-test
  135. (name "samba")
  136. (description "Connect to a running Samba daemon.")
  137. (value (run-samba-test))))
  138. ;;;
  139. ;;; The wsdd service.
  140. ;;;
  141. (define %wsdd-os
  142. (let ((base-os (simple-operating-system
  143. (service dhcp-client-service-type)
  144. (service wsdd-service-type))))
  145. (operating-system
  146. (inherit base-os)
  147. (packages (cons wsdd (operating-system-packages base-os))))))
  148. (define* (run-wsdd-test)
  149. "Return a test of an OS running wsdd service."
  150. (define vm
  151. (virtual-machine
  152. (operating-system (marionette-operating-system
  153. %wsdd-os
  154. #:imported-modules '((gnu services herd))))
  155. (port-forwardings '((3702 . 3702)
  156. (5357 . 5357)))))
  157. (define test
  158. (with-imported-modules '((gnu build marionette))
  159. #~(begin
  160. (use-modules (gnu build marionette)
  161. (srfi srfi-26)
  162. (srfi srfi-64))
  163. (define marionette
  164. (make-marionette '(#$vm)))
  165. (test-runner-current (system-test-runner #$output))
  166. (test-begin "wsdd")
  167. ;; Here shall be more tests to begin with.
  168. (test-assert "wsdd running"
  169. (marionette-eval
  170. '(begin
  171. (use-modules (gnu services herd))
  172. (start-service 'wsdd))
  173. marionette))
  174. (test-end))))
  175. (gexp->derivation "wsdd-test" test))
  176. (define %test-wsdd
  177. (system-test
  178. (name "wsdd")
  179. (description "Connect to a running wsdd daemon.")
  180. (value (run-wsdd-test))))