diff options
author | Janne Heß <janne@hess.ooo> | 2021-10-10 17:58:06 +0200 |
---|---|---|
committer | Janne Heß <janne@hess.ooo> | 2021-10-17 14:35:46 +0200 |
commit | de128feaccaf9751d7092d83f7dcc488f51a4dda (patch) | |
tree | a4007b4c0f231be6c34c670beb165a355c39dc67 /nixos/tests/switch-test.nix | |
parent | b515bae5cfa67e1407df1942252c98e401890c09 (diff) |
nixos/switch-to-configuration: Ignore slice units
Diffstat (limited to 'nixos/tests/switch-test.nix')
-rw-r--r-- | nixos/tests/switch-test.nix | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix index 76a9ef6f624ed..1acccbd175406 100644 --- a/nixos/tests/switch-test.nix +++ b/nixos/tests/switch-test.nix @@ -107,6 +107,8 @@ import ./make-test-python.nix ({ pkgs, ...} : { }; }; }; + + # The same system but with an activation script that restarts all services restart-and-reload-by-activation-script.configuration = { imports = [ config.specialisation.service-and-socket.configuration ]; system.activationScripts.restart-and-reload-test = { @@ -128,6 +130,25 @@ import ./make-test-python.nix ({ pkgs, ...} : { ''; }; }; + + # A system with a slice + with-slice.configuration = { + systemd.slices.testslice.sliceConfig.MemoryMax = "1"; # don't allow memory allocation + systemd.services.testservice = { + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = "${pkgs.coreutils}/bin/true"; + Slice = "testslice.slice"; + }; + }; + }; + + # The same system but the slice allows to allocate memory + with-slice-non-crashing.configuration = { + imports = [ config.specialisation.with-slice.configuration ]; + systemd.slices.testslice.sliceConfig.MemoryMax = lib.mkForce null; + }; }; }; other = { ... }: { @@ -263,5 +284,18 @@ import ./make-test-python.nix ({ pkgs, ...} : { assert_contains(out, "would restart the following units: simple-restart-service.service\n") assert_contains(out, "\nwould start the following units: simple-service.service") + # This test ensures that changes to slice configuration get applied. + # We test this by having a slice that allows no memory allocation at + # all and starting a service within it. If the service crashes, the slice + # is applied and if we modify the slice to allow memory allocation, the + # service should successfully start. + with subtest("slices"): + machine.succeed("echo 0 > /proc/sys/vm/panic_on_oom") # allow OOMing + out = switch_to_specialisation("with-slice") + machine.fail("systemctl start testservice.service") + out = switch_to_specialisation("with-slice-non-crashing") + machine.succeed("systemctl start testservice.service") + machine.succeed("echo 1 > /proc/sys/vm/panic_on_oom") # disallow OOMing + ''; }) |