-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- introduces a `--swap,s` flag which controls whether `/proc/swaps` is captured in the report, `false` by default. - introduces a `--ephemeral,e` flag which controls whether ephemeral properties are captured in the report, `false` by default and only includes `swap` for now. - refactors the `basic` vm test to use Disko's testLib and checks more properties of the report output. Closes #8. Signed-off-by: Brian McGee <brian@bmcgee.ie>
- Loading branch information
1 parent
6532af4
commit 6b16886
Showing
14 changed files
with
522 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,76 @@ | ||
{ | ||
pkgs, | ||
flake, | ||
inputs, | ||
system, | ||
perSystem, | ||
... | ||
}: let | ||
inherit (flake.packages.${system}) nixos-facter; | ||
# we have to import diskoLib like this because there are some impure default imports e.g. <nixpkgs> | ||
diskoLib = import "${inputs.disko}/lib" { | ||
inherit (pkgs) lib; | ||
makeTest = import "${inputs.nixpkgs}/nixos/tests/make-test-python.nix"; | ||
eval-config = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix"; | ||
}; | ||
in | ||
# for now we only run the tests in x86_64-linux since we don't have access to a bare-metal ARM box or a VM that supports nested | ||
# virtualization which makes the test take forever and ultimately fail | ||
pkgs.lib.optionalAttrs pkgs.stdenv.isx86_64 { | ||
basic = pkgs.nixosTest { | ||
basic = diskoLib.testLib.makeDiskoTest { | ||
inherit pkgs; | ||
name = "basic"; | ||
nodes.machine = { | ||
environment.systemPackages = [nixos-facter]; | ||
disko-config = ./disko.nix; | ||
extraSystemConfig = { | ||
environment.systemPackages = [ | ||
perSystem.self.nixos-facter | ||
]; | ||
|
||
systemd.services = { | ||
create-swap-files = { | ||
serviceConfig.Type = "oneshot"; | ||
wantedBy = ["multi-user.target"]; | ||
path = with pkgs; [ | ||
coreutils | ||
util-linux | ||
]; | ||
script = '' | ||
# create some swap files | ||
mkdir -p /swap | ||
for (( i=1; i<=3; i++ )); do | ||
out="/swap/swapfile-$i" | ||
dd if=/dev/zero of="$out" bs=1MB count=10 | ||
chmod 600 "$out" | ||
mkswap "$out" | ||
swapon "$out" | ||
done | ||
''; | ||
}; | ||
}; | ||
}; | ||
testScript = '' | ||
machine.succeed("nixos-facter generate report -o /report.json") | ||
|
||
extraTestScript = '' | ||
import json | ||
report = json.loads(machine.succeed("nixos-facter -e")) | ||
with subtest("Capture system"): | ||
assert report['system'] == '${system}' | ||
with subtest("Capture virtualisation"): | ||
virt = report['virtualisation'] | ||
# kvm for systems that support it, otherwise the vm test should present itself as qemu | ||
# todo double-check this is the same for intel | ||
assert virt in ("kvm", "qemu"), f"expected virtualisation to be either kvm or qemu, got {virt}" | ||
with subtest("Capture swap entries"): | ||
assert 'swap' in report, "'swap' not found in the report" | ||
assert report['swap'] == [ | ||
{ 'path': '/dev/vda4', 'type': 'partition', 'size': 1048572, 'used': 0, 'priority': -2 }, | ||
{ 'path': '/dev/dm-0', 'type': 'partition', 'size': 10236, 'used': 0, 'priority': 100 }, | ||
{ 'path': '/swap/swapfile-1', 'type': 'file', 'size': 9760, 'used': 0, 'priority': -3 }, | ||
{ 'path': '/swap/swapfile-2', 'type': 'file', 'size': 9760, 'used': 0, 'priority': -4 }, | ||
{ 'path': '/swap/swapfile-3', 'type': 'file', 'size': 9760, 'used': 0, 'priority': -5 } | ||
], "swap entries did not match what we expected" | ||
# todo is there a nice way of showing a diff? | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
disko = { | ||
devices = { | ||
disk = { | ||
main = { | ||
device = "/dev/vdb"; | ||
type = "disk"; | ||
content = { | ||
type = "gpt"; | ||
partitions = { | ||
ESP = { | ||
size = "500M"; | ||
type = "EF00"; | ||
content = { | ||
type = "filesystem"; | ||
format = "vfat"; | ||
mountpoint = "/boot"; | ||
}; | ||
}; | ||
root = { | ||
end = "-1G"; | ||
content = { | ||
type = "filesystem"; | ||
format = "ext4"; | ||
mountpoint = "/"; | ||
}; | ||
}; | ||
encryptedSwap = { | ||
size = "10M"; | ||
content = { | ||
type = "swap"; | ||
randomEncryption = true; | ||
priority = 100; # prefer to encrypt as long as we have space for it | ||
}; | ||
}; | ||
plainSwap = { | ||
size = "100%"; | ||
content = { | ||
type = "swap"; | ||
discardPolicy = "both"; | ||
resumeDevice = true; # resume from hiberation from this device | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.