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.
nixosModules
Emery Hemingway 2 years ago
parent 80c7fbba10
commit 257696260c
  1. 17
      tests/lib/build-vms.nix
  2. 14
      tests/networking.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);

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

Loading…
Cancel
Save