virtualization.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
  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 virtualization)
  19. #:use-module (gnu tests)
  20. #:use-module (gnu system)
  21. #:use-module (gnu system file-systems)
  22. #:use-module (gnu system vm)
  23. #:use-module (gnu services)
  24. #:use-module (gnu services dbus)
  25. #:use-module (gnu services networking)
  26. #:use-module (gnu services virtualization)
  27. #:use-module (gnu packages virtualization)
  28. #:use-module (guix gexp)
  29. #:use-module (guix store)
  30. #:export (%test-libvirt))
  31. (define %libvirt-os
  32. (simple-operating-system
  33. (service dhcp-client-service-type)
  34. (dbus-service)
  35. (polkit-service)
  36. (service libvirt-service-type)))
  37. (define (run-libvirt-test)
  38. "Run tests in %LIBVIRT-OS."
  39. (define os
  40. (marionette-operating-system
  41. %libvirt-os
  42. #:imported-modules '((gnu services herd)
  43. (guix combinators))))
  44. (define vm
  45. (virtual-machine
  46. (operating-system os)
  47. (port-forwardings '())))
  48. (define test
  49. (with-imported-modules '((gnu build marionette))
  50. #~(begin
  51. (use-modules (srfi srfi-11) (srfi srfi-64)
  52. (gnu build marionette))
  53. (define marionette
  54. (make-marionette (list #$vm)))
  55. (mkdir #$output)
  56. (chdir #$output)
  57. (test-begin "libvirt")
  58. (test-assert "service running"
  59. (marionette-eval
  60. '(begin
  61. (use-modules (gnu services herd))
  62. (match (start-service 'libvirtd)
  63. (#f #f)
  64. (('service response-parts ...)
  65. (match (assq-ref response-parts 'running)
  66. ((pid) (number? pid))))))
  67. marionette))
  68. (test-eq "fetch version"
  69. 0
  70. (marionette-eval
  71. `(begin
  72. (system* ,(string-append #$libvirt "/bin/virsh")
  73. "-c" "qemu:///system" "version"))
  74. marionette))
  75. (test-end)
  76. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  77. (gexp->derivation "libvirt-test" test))
  78. (define %test-libvirt
  79. (system-test
  80. (name "libvirt")
  81. (description "Connect to the running LIBVIRT service.")
  82. (value (run-libvirt-test))))