From patchwork Wed Oct 27 14:02:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 34108 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 99DEA27BBE3; Wed, 27 Oct 2021 15:52:07 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1AF3027BBE1 for ; Wed, 27 Oct 2021 15:52:07 +0100 (BST) Received: from localhost ([::1]:54538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfkHd-0001i6-5v for patchwork@mira.cbaines.net; Wed, 27 Oct 2021 10:52:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfjX8-0008Je-Ba for guix-patches@gnu.org; Wed, 27 Oct 2021 10:04:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfjX8-0005Fc-2Q for guix-patches@gnu.org; Wed, 27 Oct 2021 10:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mfjX7-0002Yl-UM for guix-patches@gnu.org; Wed, 27 Oct 2021 10:04:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51440] [PATCH 01/10] tests: Add 'static-networking' test. References: <20211027135918.18833-1-ludo@gnu.org> In-Reply-To: <20211027135918.18833-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 27 Oct 2021 14:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51440 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51440@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 51440-submit@debbugs.gnu.org id=B51440.16353433839630 (code B ref 51440); Wed, 27 Oct 2021 14:04:01 +0000 Received: (at 51440) by debbugs.gnu.org; 27 Oct 2021 14:03:03 +0000 Received: from localhost ([127.0.0.1]:50052 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfjWB-0002VG-AZ for submit@debbugs.gnu.org; Wed, 27 Oct 2021 10:03:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mfjW9-0002UZ-60 for 51440@debbugs.gnu.org; Wed, 27 Oct 2021 10:03:01 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfjW3-00057C-Jr; Wed, 27 Oct 2021 10:02:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=nIMYMSxGuVBBp0yBxrJ8NiTzp8VkdLuICWMDvMaM/7M=; b=LQDQbBJ8WERjiw r26s9bCgxillYF+2glRFmODt+dSJZDomJGnVODNMkZO6EHApZBZd2FAaARGeaPh5KGJ/v2olUrZKP 5V9RPgiWfqp3c5kc9OTdWNOBdEmedD00lRhvRWZbHF4L8LSj8tlGNM3wKF3NA9/UWTOVV6JKrvJCE eWLTxpKLDIOrnMhjRN2KY6n+0SPv0yjd1XkYL/gIh71VeNjXr6ru/XHgxh5fUBCljMAZgaaxqMEhE 1M8FwO4uYn0ZMIG1logivZVbNM1+KbrTmRY+HmRaEvvLjAo0Vpu+K1p8g9uxQyOCELJQIo2X1msw+ HaQnw+CZBcv6HjR51rJQ==; Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=55004 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfjW1-0002Tf-0w; Wed, 27 Oct 2021 10:02:53 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 27 Oct 2021 16:02:36 +0200 Message-Id: <20211027140245.18970-1-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/tests/networking.scm (run-static-networking-test): New procedure. (%test-static-networking): New variable. --- gnu/tests/networking.scm | 99 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm index 453e63f52d..5da1c91da6 100644 --- a/gnu/tests/networking.scm +++ b/gnu/tests/networking.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2018 Chris Marusich ;;; Copyright © 2018 Arun Isaac ;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -37,8 +38,102 @@ (define-module (gnu tests networking) #:use-module (gnu packages guile) #:use-module (gnu services shepherd) #:use-module (ice-9 match) - #:export (%test-inetd %test-openvswitch %test-dhcpd %test-tor %test-iptables - %test-ipfs)) + #:export (%test-static-networking + %test-inetd + %test-openvswitch + %test-dhcpd + %test-tor + %test-iptables + %test-ipfs)) + + +;;; +;;; Static networking. +;;; + +(define (run-static-networking-test vm) + (define test + (with-imported-modules '((gnu build marionette) + (guix build syscalls)) + #~(begin + (use-modules (gnu build marionette) + (guix build syscalls) + (srfi srfi-64)) + + (define marionette + (make-marionette + '(#$vm "-nic" "user,model=virtio-net-pci"))) + + (mkdir #$output) + (chdir #$output) + + (test-begin "static-networking") + + (test-assert "service is up" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'networking)) + marionette)) + + (test-assert "network interfaces" + (marionette-eval + '(begin + (use-modules (guix build syscalls)) + (network-interface-names)) + marionette)) + + (test-equal "address of eth0" + "10.0.2.15" + (marionette-eval + '(let* ((sock (socket AF_INET SOCK_STREAM 0)) + (addr (network-interface-address sock "eth0"))) + (close-port sock) + (inet-ntop (sockaddr:fam addr) (sockaddr:addr addr))) + marionette)) + + (test-equal "netmask of eth0" + "255.255.255.0" + (marionette-eval + '(let* ((sock (socket AF_INET SOCK_STREAM 0)) + (mask (network-interface-netmask sock "eth0"))) + (close-port sock) + (inet-ntop (sockaddr:fam mask) (sockaddr:addr mask))) + marionette)) + + (test-equal "eth0 is up" + IFF_UP + (marionette-eval + '(let* ((sock (socket AF_INET SOCK_STREAM 0)) + (flags (network-interface-flags sock "eth0"))) + (logand flags IFF_UP)) + marionette)) + + (test-end) + + (exit (= (test-runner-fail-count (test-runner-current)) 0))))) + + (gexp->derivation "static-networking" test)) + +(define %test-static-networking + (system-test + (name "static-networking") + (description "Test the 'static-networking' service.") + (value + (let ((os (marionette-operating-system + (simple-operating-system + (static-networking-service "eth0" "10.0.2.15" + #:netmask "255.255.255.0" + #:gateway "10.0.2.2" + #:name-servers '("10.0.2.2"))) + #:imported-modules '((gnu services herd) + (guix combinators))))) + (run-static-networking-test (virtual-machine os)))))) + + +;;; +;;; Inetd. +;;; (define %inetd-os ;; Operating system with 2 inetd services.