Merge pull request #29040 from NeQuissimus/tests_sys

More basic system tests
This commit is contained in:
Tim Steinbach 2017-09-06 15:04:10 -04:00 committed by GitHub
commit 7faad2dce8
5 changed files with 90 additions and 0 deletions

View File

@ -84,6 +84,7 @@ in rec {
nixos.tests.docker.x86_64-linux
nixos.tests.docker-edge.x86_64-linux
(all nixos.tests.ecryptfs)
(all nixos.tests.env)
(all nixos.tests.ipv6)
(all nixos.tests.i3wm)
(all nixos.tests.keymap.azerty)
@ -95,6 +96,7 @@ in rec {
(all nixos.tests.plasma5)
(all nixos.tests.kernel-latest)
(all nixos.tests.kernel-lts)
(all nixos.tests.kernel-params)
#(all nixos.tests.lightdm)
(all nixos.tests.login)
(all nixos.tests.misc)
@ -117,6 +119,7 @@ in rec {
(all nixos.tests.sddm.default)
(all nixos.tests.simple)
(all nixos.tests.slim)
(all nixos.tests.sysctl)
(all nixos.tests.udisks2)
(all nixos.tests.xfce)
(all nixos.tests.xmonad)

View File

@ -241,6 +241,7 @@ in rec {
tests.ec2-nixops = hydraJob (import tests/ec2.nix { system = "x86_64-linux"; }).boot-ec2-nixops;
tests.ec2-config = hydraJob (import tests/ec2.nix { system = "x86_64-linux"; }).boot-ec2-config;
tests.elk = callTest tests/elk.nix {};
tests.env = callTest tests/env.nix {};
tests.ferm = callTest tests/ferm.nix {};
tests.firefox = callTest tests/firefox.nix {};
tests.firewall = callTest tests/firewall.nix {};
@ -265,6 +266,7 @@ in rec {
tests.kernel-copperhead = tests/kernel-copperhead.nix {};
tests.kernel-latest = tests/kernel-latest.nix {};
tests.kernel-lts = tests/kernel-lts.nix {};
tests.kernel-params = tests/kernel-params.nix {};
tests.keystone = callTest tests/keystone.nix {};
tests.kubernetes = hydraJob (import tests/kubernetes.nix { system = "x86_64-linux"; });
tests.latestKernel.login = callTest tests/login.nix { latestKernel = true; };
@ -310,6 +312,7 @@ in rec {
tests.slim = callTest tests/slim.nix {};
tests.smokeping = callTest tests/smokeping.nix {};
tests.snapper = callTest tests/snapper.nix {};
tests.sysctl = callTest tests/sysctl.nix {};
tests.taskserver = callTest tests/taskserver.nix {};
tests.tomcat = callTest tests/tomcat.nix {};
tests.udisks2 = callTest tests/udisks2.nix {};

35
nixos/tests/env.nix Normal file
View File

@ -0,0 +1,35 @@
import ./make-test.nix ({ pkgs, ...} : {
name = "environment";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ nequissimus ];
};
machine = { config, lib, pkgs, ... }:
{
boot.kernelPackages = pkgs.linuxPackages;
environment.etc."plainFile".text = ''
Hello World
'';
environment.etc."folder/with/file".text = ''
Foo Bar!
'';
environment.sessionVariables = {
TERMINFO_DIRS = "/run/current-system/sw/share/terminfo";
NIXCON = "awesome";
};
};
testScript =
''
$machine->succeed('[ -L "/etc/plainFile" ]');
$machine->succeed('cat "/etc/plainFile" | grep "Hello World"');
$machine->succeed('[ -d "/etc/folder" ]');
$machine->succeed('[ -d "/etc/folder/with" ]');
$machine->succeed('[ -L "/etc/folder/with/file" ]');
$machine->succeed('cat "/etc/plainFile" | grep "Hello World"');
$machine->succeed('echo ''${TERMINFO_DIRS} | grep "/run/current-system/sw/share/terminfo"');
$machine->succeed('echo ''${NIXCON} | grep "awesome"');
'';
})

View File

@ -0,0 +1,24 @@
import ./make-test.nix ({ pkgs, ...} : {
name = "kernel-params";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ nequissimus ];
};
machine = { config, lib, pkgs, ... }:
{
boot.kernelPackages = pkgs.linuxPackages;
boot.kernelParams = [
"nohibernate"
"page_poison=1"
"vsyscall=none"
];
};
testScript =
''
$machine->fail("cat /proc/cmdline | grep page_poison=0");
$machine->succeed("cat /proc/cmdline | grep nohibernate");
$machine->succeed("cat /proc/cmdline | grep page_poison=1");
$machine->succeed("cat /proc/cmdline | grep vsyscall=none");
'';
})

25
nixos/tests/sysctl.nix Normal file
View File

@ -0,0 +1,25 @@
import ./make-test.nix ({ pkgs, ...} : {
name = "sysctl";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ nequissimus ];
};
machine = { config, lib, pkgs, ... }:
{
boot.kernelPackages = pkgs.linuxPackages;
boot.kernel.sysctl = {
"kernel.dmesg_restrict" = true; # Restrict dmesg access
"net.core.bpf_jit_enable" = false; # Turn off bpf JIT
"user.max_user_namespaces" = 0; # Disable user namespaces
"vm.swappiness" = 2; # Low swap usage
};
};
testScript =
''
$machine->succeed("sysctl kernel.dmesg_restrict | grep 'kernel.dmesg_restrict = 1'");
$machine->succeed("sysctl net.core.bpf_jit_enable | grep 'net.core.bpf_jit_enable = 0'");
$machine->succeed("sysctl user.max_user_namespaces | grep 'user.max_user_namespaces = 0'");
$machine->succeed("sysctl vm.swappiness | grep 'vm.swappiness = 2'");
'';
})