Merge pull request #85635 from basvandijk/support-bigger-nixos-tests
Support more than 99 nodes in NixOS tests & export toHex and toBase
This commit is contained in:
commit
27296cc5c5
5 changed files with 82 additions and 11 deletions
|
@ -67,7 +67,7 @@ let
|
||||||
inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor
|
inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor
|
||||||
bitNot boolToString mergeAttrs flip mapNullable inNixShell min max
|
bitNot boolToString mergeAttrs flip mapNullable inNixShell min max
|
||||||
importJSON warn info showWarnings nixpkgsVersion version mod compare
|
importJSON warn info showWarnings nixpkgsVersion version mod compare
|
||||||
splitByAndCompare functionArgs setFunctionArgs isFunction;
|
splitByAndCompare functionArgs setFunctionArgs isFunction toHexString toBaseDigits;
|
||||||
inherit (fixedPoints) fix fix' converge extends composeExtensions
|
inherit (fixedPoints) fix fix' converge extends composeExtensions
|
||||||
makeExtensible makeExtensibleWithCustomName;
|
makeExtensible makeExtensibleWithCustomName;
|
||||||
inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
|
inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
|
||||||
|
|
|
@ -102,6 +102,16 @@ runTests {
|
||||||
expected = 9;
|
expected = 9;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
testToHexString = {
|
||||||
|
expr = toHexString 250;
|
||||||
|
expected = "FA";
|
||||||
|
};
|
||||||
|
|
||||||
|
testToBaseDigits = {
|
||||||
|
expr = toBaseDigits 2 6;
|
||||||
|
expected = [ 1 1 0 ];
|
||||||
|
};
|
||||||
|
|
||||||
# STRINGS
|
# STRINGS
|
||||||
|
|
||||||
testConcatMapStrings = {
|
testConcatMapStrings = {
|
||||||
|
|
|
@ -332,4 +332,55 @@ rec {
|
||||||
*/
|
*/
|
||||||
isFunction = f: builtins.isFunction f ||
|
isFunction = f: builtins.isFunction f ||
|
||||||
(f ? __functor && isFunction (f.__functor f));
|
(f ? __functor && isFunction (f.__functor f));
|
||||||
|
|
||||||
|
/* Convert the given positive integer to a string of its hexadecimal
|
||||||
|
representation. For example:
|
||||||
|
|
||||||
|
toHexString 0 => "0"
|
||||||
|
|
||||||
|
toHexString 16 => "10"
|
||||||
|
|
||||||
|
toHexString 250 => "FA"
|
||||||
|
*/
|
||||||
|
toHexString = i:
|
||||||
|
let
|
||||||
|
toHexDigit = d:
|
||||||
|
if d < 10
|
||||||
|
then toString d
|
||||||
|
else
|
||||||
|
{
|
||||||
|
"10" = "A";
|
||||||
|
"11" = "B";
|
||||||
|
"12" = "C";
|
||||||
|
"13" = "D";
|
||||||
|
"14" = "E";
|
||||||
|
"15" = "F";
|
||||||
|
}.${toString d};
|
||||||
|
in
|
||||||
|
lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
|
||||||
|
|
||||||
|
/* `toBaseDigits base i` converts the positive integer i to a list of its
|
||||||
|
digits in the given base. For example:
|
||||||
|
|
||||||
|
toBaseDigits 10 123 => [ 1 2 3 ]
|
||||||
|
|
||||||
|
toBaseDigits 2 6 => [ 1 1 0 ]
|
||||||
|
|
||||||
|
toBaseDigits 16 250 => [ 15 10 ]
|
||||||
|
*/
|
||||||
|
toBaseDigits = base: i:
|
||||||
|
let
|
||||||
|
go = i:
|
||||||
|
if i < base
|
||||||
|
then [i]
|
||||||
|
else
|
||||||
|
let
|
||||||
|
r = i - ((i / base) * base);
|
||||||
|
q = (i - r) / base;
|
||||||
|
in
|
||||||
|
[r] ++ go q;
|
||||||
|
in
|
||||||
|
assert (base >= 2);
|
||||||
|
assert (i >= 0);
|
||||||
|
lib.reverseList (go i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,18 @@
|
||||||
{ pkgs }:
|
{ pkgs }:
|
||||||
|
|
||||||
let
|
let
|
||||||
zeroPad = n: if n < 10 then "0${toString n}" else toString n;
|
zeroPad = n:
|
||||||
|
pkgs.lib.optionalString (n < 16) "0" +
|
||||||
|
(if n > 255
|
||||||
|
then throw "Can't have more than 255 nets or nodes!"
|
||||||
|
else pkgs.lib.toHexString n);
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
rec {
|
||||||
|
qemuNicMac = net: machine: "52:54:00:12:${zeroPad net}:${zeroPad machine}";
|
||||||
|
|
||||||
qemuNICFlags = nic: net: machine:
|
qemuNICFlags = nic: net: machine:
|
||||||
[ "-device virtio-net-pci,netdev=vlan${toString nic},mac=52:54:00:12:${zeroPad net}:${zeroPad machine}"
|
[ "-device virtio-net-pci,netdev=vlan${toString nic},mac=${qemuNicMac net machine}"
|
||||||
"-netdev vde,id=vlan${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
|
"-netdev vde,id=vlan${toString nic},sock=$QEMU_VDE_SOCKET_${toString net}"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
router = { config, pkgs, ... }:
|
qemu-flags = import ../lib/qemu-flags.nix { inherit pkgs; };
|
||||||
|
|
||||||
|
router = { config, pkgs, lib, ... }:
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
let
|
let
|
||||||
vlanIfs = range 1 (length config.virtualisation.vlans);
|
vlanIfs = range 1 (length config.virtualisation.vlans);
|
||||||
|
@ -31,16 +33,19 @@ let
|
||||||
enable = true;
|
enable = true;
|
||||||
interfaces = map (n: "eth${toString n}") vlanIfs;
|
interfaces = map (n: "eth${toString n}") vlanIfs;
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
authoritative;
|
|
||||||
'' + flip concatMapStrings vlanIfs (n: ''
|
'' + flip concatMapStrings vlanIfs (n: ''
|
||||||
subnet 192.168.${toString n}.0 netmask 255.255.255.0 {
|
subnet 192.168.${toString n}.0 netmask 255.255.255.0 {
|
||||||
option routers 192.168.${toString n}.1;
|
option routers 192.168.${toString n}.1;
|
||||||
# XXX: technically it's _not guaranteed_ that IP addresses will be
|
|
||||||
# issued from the first item in range onwards! We assume that in
|
|
||||||
# our tests however.
|
|
||||||
range 192.168.${toString n}.2 192.168.${toString n}.254;
|
|
||||||
}
|
}
|
||||||
'');
|
'')
|
||||||
|
;
|
||||||
|
machines = lib.flip map vlanIfs (vlan:
|
||||||
|
{
|
||||||
|
hostName = "client${toString vlan}";
|
||||||
|
ethernetAddress = qemu-flags.qemuNicMac vlan 1;
|
||||||
|
ipAddress = "192.168.${toString vlan}.2";
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
services.radvd = {
|
services.radvd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
Loading…
Reference in a new issue