1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2022 Simon Streit <simon@netpanic.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu tests samba)
20 #:use-module (gnu tests)
21 #:use-module (gnu system)
22 #:use-module (gnu system vm)
23 #:use-module (gnu services)
24 #:use-module (gnu services networking)
25 #:use-module (gnu services samba)
26 #:use-module (gnu packages samba)
27 #:use-module (guix gexp)
28 #:use-module (guix store)
34 ;;; The Samba service.
38 (let ((base-os (simple-operating-system
39 (simple-service 'create-target-directory activation-service-type
41 (mkdir-p "/srv/samba/guest")
42 (chown "/srv/samba/guest"
43 (passwd:uid (getpw "nobody"))
44 (passwd:gid (getpw "nobody")))))
45 (service dhcp-client-service-type)
46 (service samba-service-type
48 (config-file (plain-file "smb.conf" "
51 server string = Samba Server
52 server role = standalone server
53 log file = /var/log/samba/log.%m
57 path = /srv/samba/guest
64 (packages (cons samba (operating-system-packages base-os))))))
66 (define* (run-samba-test)
67 "Return a test of an OS running Samba service."
71 (operating-system (marionette-operating-system
73 #:imported-modules '((gnu services herd))))
74 (port-forwardings '((8135 . 135)
80 (with-imported-modules '((gnu build marionette))
82 (use-modules (gnu build marionette)
87 (make-marionette '(#$vm)))
89 (test-runner-current (system-test-runner #$output))
92 (test-assert "samba-smbd running"
95 (use-modules (gnu services herd))
96 (start-service 'samba-smbd))
99 (test-assert "samba-nmbd running"
102 (use-modules (gnu services herd))
103 (start-service 'samba-nmbd))
106 (test-assert "samba-winbindd running"
109 (use-modules (gnu services herd))
110 (start-service 'samba-winbindd))
113 (test-assert "smbd service process id"
115 (number->string (wait-for-file "/var/run/samba/smbd.pid"
117 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
120 (test-assert "nmbd service process id"
122 (number->string (wait-for-file "/var/run/samba/nmbd.pid"
124 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
127 (test-assert "winbindd service process id"
129 (number->string (wait-for-file "/var/run/samba/winbindd.pid"
131 (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
134 (test-assert "samba-smbd is listening for peers"
135 (wait-for-tcp-port 445 marionette))
137 (test-equal "smbclient connect"
140 '(system* #$(file-append samba "/bin/smbclient")
141 "--list=localhost" "--no-pass")
144 (test-equal "smbclient connect"
147 '(system* #$(file-append samba "/bin/smbclient")
148 "--list=localhost" "--no-pass")
153 (gexp->derivation "samba-test" test))
158 (description "Connect to a running Samba daemon.")
159 (value (run-samba-test))))
163 ;;; The wsdd service.
167 (let ((base-os (simple-operating-system
168 (service dhcp-client-service-type)
169 (service wsdd-service-type))))
172 (packages (cons wsdd (operating-system-packages base-os))))))
174 (define* (run-wsdd-test)
175 "Return a test of an OS running wsdd service."
179 (operating-system (marionette-operating-system
181 #:imported-modules '((gnu services herd))))
182 (port-forwardings '((3702 . 3702)
186 (with-imported-modules '((gnu build marionette))
188 (use-modules (gnu build marionette)
193 (make-marionette '(#$vm)))
195 (test-runner-current (system-test-runner #$output))
198 ;; Here shall be more tests to begin with.
200 (test-assert "wsdd running"
203 (use-modules (gnu services herd))
204 (start-service 'wsdd))
209 (gexp->derivation "wsdd-test" test))
214 (description "Connect to a running wsdd daemon.")
215 (value (run-wsdd-test))))