;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Maxim Cournoyer . ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu tests telephony) #:use-module (gnu) #:use-module (gnu packages guile) #:use-module (gnu tests) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services dbus) #:use-module (gnu services ssh) #:use-module (gnu services telephony) #:use-module (guix gexp) #:use-module (guix modules) #:export (%test-jami-daemon %test-jami-daemon-provisioning)) ;;; ;;; Jami daemon. ;;; (define define-with-retries (@@ (gnu services telephony) define-with-retries)) (include "data/jami-dummy-account.dat") ;defines %jami-account-content-sexp (define %dummy-jami-account ;; A Jami account archive is a gzipped JSON file. (computed-file "dummy-jami-account.gz" (with-extensions (list guile-json-4 guile-zlib) #~(begin (use-modules (json) (zlib)) (let ((port (open-output-file #$output))) (call-with-gzip-output-port port (lambda (port) (scm->json '#$%jami-account-content-sexp port)))))))) (define* (make-jami-daemon-os #:key provisioning?) (simple-operating-system (service jami-daemon-service-type (if provisioning? (jami-daemon-configuration (account-archives (list %dummy-jami-account))) (jami-daemon-configuration))) (service dbus-root-service-type) (service openssh-service-type ;for debugging (openssh-configuration (permit-root-login 'without-password))))) (define %jami-daemon-os (make-jami-daemon-os)) (define %jami-daemon-os-provisioning (make-jami-daemon-os #:provisioning? #t)) (define* (run-jami-daemon-test #:key provisioning?) "Run tests in %JAMI-DAEMON-OS. When PROVISIONING? is true, test the accounts provisioning feature of the service." (define os (marionette-operating-system (if provisioning? %jami-daemon-os-provisioning %jami-daemon-os) #:imported-modules '((gnu services herd) (guix combinators)))) (define vm (virtual-machine (operating-system os) (memory-size 512))) (define test (with-imported-modules '((gnu build marionette)) #~(begin (use-modules (rnrs base) (srfi srfi-11) (srfi srfi-64) (gnu build marionette)) (define marionette (make-marionette (list #$vm))) (mkdir #$output) (chdir #$output) (test-begin "jami-daemon") (test-assert "service running" (marionette-eval '(begin (use-modules (gnu services herd)) (match (start-service 'jami-daemon) (#f #f) (('service response-parts ...) (match (assq-ref response-parts 'running) ((pid) (number? pid)))))) marionette)) (test-assert "service can be stopped" (marionette-eval '(begin (use-modules (gnu services herd) (rnrs base)) #$define-with-retries (setenv "PATH" "/run/current-system/profile/bin") (let ((pid (match (start-service 'jami-daemon) (#f #f) (('service response-parts ...) (match (assq-ref response-parts 'running) ((pid) pid)))))) (assert (number? pid)) (match (stop-service 'jami-daemon) (services ;a list of service symbols (member 'jami-daemon services))) ;; Sometimes, the process still appear in pgrep, even ;; though we are using waitpid after sending it SIGTERM ;; in the service; use retries. (with-retries 19 1 (not (zero? (status:exit-val (system* "pgrep" "dring"))))))) marionette)) (test-assert "service can be restarted" (marionette-eval '(begin (use-modules (gnu services herd) (rnrs base)) ;; Start and retrieve the current PID. (define pid (match (start-service 'jami-daemon) (#f #f) (('service response-parts ...) (match (assq-ref response-parts 'running) ((pid) pid))))) (assert (number? pid)) ;; Restart the service. (restart-service 'jami-daemon) (define new-pid (match (start-service 'jami-daemon) (#f #f) (('service response-parts ...) (match (assq-ref response-parts 'running) ((pid) pid))))) (assert (number? new-pid)) (not (eq? pid new-pid))) marionette)) (unless #$provisioning? (test-skip 1)) (test-assert "jami accounts provisioning" (marionette-eval '(begin (use-modules (gnu services herd)) #$define-with-retries (setenv "PATH" "/run/current-system/profile/bin") ;; The imported account takes some time to appear in the ;; account files; retry for up to about 10 s. (with-retries 20 1 (zero? (status:exit-val (system* "grep" "-r" #$(assoc-ref %jami-account-content-sexp "Account.username") "/var/lib/jami/.local/share/jami/"))))) marionette)) (test-end) (exit (= (test-runner-fail-count (test-runner-current)) 0))))) (gexp->derivation (if provisioning? "jami-daemon-provisioning-test" "jami-daemon-test") test)) (define %test-jami-daemon (system-test (name "jami-daemon") (description "Basic tests for the jami-daemon service.") (value (run-jami-daemon-test)))) (define %test-jami-daemon-provisioning (system-test (name "jami-daemon-provisioning") (description "Provisioning test for the jami-daemon service.") (value (run-jami-daemon-test #:provisioning? #t))))