2
0
Fork 0

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.
This commit is contained in:
Ehmry - 2020-12-02 13:04:15 +01:00
parent 80c7fbba10
commit 257696260c
2 changed files with 18 additions and 13 deletions

View File

@ -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);

View File

@ -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"