From 257696260c1daa7709269ee079cac557a808ebad Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 2 Dec 2020 13:04:15 +0100 Subject: [PATCH] tests: use config.networking.hosts not networking.extraHosts The latter is an opaque string but IP addresses can be extracted by hostname from the former. --- tests/lib/build-vms.nix | 17 ++++++++--------- tests/networking.nix | 14 ++++++++++---- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/lib/build-vms.nix b/tests/lib/build-vms.nix index 8224a73..1e3db3f 100644 --- a/tests/lib/build-vms.nix +++ b/tests/lib/build-vms.nix @@ -91,15 +91,14 @@ rec { # interfaces, use the IP address corresponding to # the first interface (i.e. the first network in its # virtualisation.vlans option). - networking.extraHosts = flip concatMapStrings machines (m': - let config = (getAttr m' nodes).config; - in optionalString (config.networking.primaryIPAddress != "") - ("${config.networking.primaryIPAddress} " - + optionalString (config.networking.domain != null) - "${config.networking.hostName}.${config.networking.domain} " - + '' - ${config.networking.hostName} - '')); + networking.hosts = mapAttrs' (name: machine: + let config = machine.config; + in { + name = config.networking.primaryIPAddress; + value = optional (config.networking.domain != null) + "${config.networking.hostName}.${config.networking.domain}" + ++ [ config.networking.hostName ]; + }) nodes; virtualisation.qemu.options = forEach interfacesNumbered ({ fst, snd }: qemuNICFlags snd fst m.snd); diff --git a/tests/networking.nix b/tests/networking.nix index b3a47f3..67d0d39 100644 --- a/tests/networking.nix +++ b/tests/networking.nix @@ -4,13 +4,17 @@ a = { pkgs, ... }: { imports = [ ../nixos-modules/hardware.nix ]; }; - b = { config, pkgs, ... }: { + b = { config, pkgs, lib, ... }: { imports = [ ../nixos-modules/hardware.nix ]; networking.interfaces.eth1.genode.stack = null; genode.init.children.ping = { inputs = with pkgs.genodePackages; [ ping ]; configFile = let - ip = builtins.head config.networking.interfaces.eth1.ipv4.addresses; + ipA = builtins.head config.networking.interfaces.eth1.ipv4.addresses; + ipAddrB = with builtins; + head (attrNames + (lib.attrsets.filterAttrs (name: (any (host: host == "a"))) + config.networking.hosts)); in pkgs.writeText "ping.dhall" '' let Genode = env:DHALL_GENODE @@ -25,8 +29,10 @@ , routes = [ Init.ServiceRoute.child "Nic" "eth1.driver" ] , config = Init.Config::{ , attributes = toMap - { interface = "${ip.address}/${toString ip.prefixLength}" - , dst_ip = "192.168.1.1" + { interface = "${ipA.address}/${ + toString ipA.prefixLength + }" + , dst_ip = "${ipAddrB}" , period_sec = "1" , count = "10" , verbose = "yes"