From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eAKxL-0004aG-3v for guix-patches@gnu.org; Thu, 02 Nov 2017 15:15:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eAKxD-0005Yw-CL for guix-patches@gnu.org; Thu, 02 Nov 2017 15:15:11 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:39581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eAKxD-0005Ys-8Y for guix-patches@gnu.org; Thu, 02 Nov 2017 15:15:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eAKxD-0005KB-1c for guix-patches@gnu.org; Thu, 02 Nov 2017 15:15:03 -0400 Subject: [bug#29117] [PATCH 2/2] tests: networking: Add tests for OpenvSwitch. Resent-Message-ID: From: Marius Bakke Date: Thu, 2 Nov 2017 20:14:46 +0100 Message-Id: <20171102191446.11006-2-mbakke@fastmail.com> In-Reply-To: <20171102191446.11006-1-mbakke@fastmail.com> References: <20171102191446.11006-1-mbakke@fastmail.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 29117@debbugs.gnu.org * gnu/tests/networking.scm (setup-openvswitch, openvswitch-configuration-service, %openvswitch-os, run-openvswitch-test, %test-openvswitch): New variables. --- gnu/tests/networking.scm | 109 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm index aeee105a1..750125ded 100644 --- a/gnu/tests/networking.scm +++ b/gnu/tests/networking.scm @@ -26,7 +26,9 @@ #:use-module (guix store) #:use-module (guix monads) #:use-module (gnu packages bash) - #:export (%test-inetd)) + #:use-module (gnu packages networking) + #:use-module (gnu services shepherd) + #:export (%test-inetd %test-openvswitch)) (define %inetd-os ;; Operating system with 2 inetd services. @@ -135,3 +137,108 @@ port 7, and a dict service on port 2628." (name "inetd") (description "Connect to a host with an INETD server.") (value (run-inetd-test)))) + + +;;; +;;; Open vSwitch +;;; + +(define setup-openvswitch + #~(let ((ovs-vsctl (lambda (str) + (zero? (apply system* + #$(file-append openvswitch "/bin/ovs-vsctl") + (string-tokenize str))))) + (add-native-port (lambda (if) + (string-append "--may-exist add-port br0 " if + " vlan_mode=native-untagged" + " -- set Interface " if + " type=internal")))) + (and (ovs-vsctl "--may-exist add-br br0") + ;; Connect eth0 as an "untagged" port (no VLANs). + (ovs-vsctl "--may-exist add-port br0 eth0 vlan_mode=native-untagged") + (ovs-vsctl (add-native-port "ovs0"))))) + +(define openvswitch-configuration-service + (simple-service 'openvswitch-configuration shepherd-root-service-type + (list (shepherd-service + (provision '(openvswitch-configuration)) + (requirement '(vswitchd)) + (start #~(lambda () + #$setup-openvswitch)) + (respawn? #f))))) + +(define %openvswitch-os + (simple-operating-system + (static-networking-service "ovs0" "10.1.1.1" + #:netmask "255.255.255.252" + #:requirement '(openvswitch-configuration)) + (service openvswitch-service-type + (openvswitch-configuration + (package openvswitch))) + openvswitch-configuration-service)) + +(define (run-openvswitch-test) + (define os + (marionette-operating-system %openvswitch-os + #:imported-modules '((gnu services herd)))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (ice-9 popen) + (ice-9 rdelim) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$(virtual-machine os)))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "openvswitch") + + ;; Make sure the bridge is created. + (test-assert "br0 exists" + (marionette-eval + '(zero? (system* "ovs-vsctl" "br-exists" "br0")) + marionette)) + + ;; Make sure eth0 is connected to the bridge. + (test-equal "eth0 is connected to br0" + "br0" + (marionette-eval + '(begin + (use-modules (ice-9 popen) (ice-9 rdelim)) + (let* ((port (open-pipe* + OPEN_READ + (string-append #$openvswitch "/bin/ovs-vsctl") + "port-to-br" "eth0")) + (output (read-line port))) + (close-pipe port) + output)) + marionette)) + + ;; Make sure the virtual interface got a static IP. + (test-assert "networking has started on ovs0" + (marionette-eval + '(begin + (use-modules (gnu services herd) + (srfi srfi-1)) + (live-service-running + (find (lambda (live) + (memq 'networking-ovs0 + (live-service-provision live))) + (current-services)))) + marionette)) + + (test-end) + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "openvswitch-test" test)) + +(define %test-openvswitch + (system-test + (name "openvswitch") + (description "Test a running OpenvSwitch configuration.") + (value (run-openvswitch-test)))) -- 2.15.0