From 4d12b79cd7edfbe01216171dd6ef0e4c64851b0a Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 26 Feb 2022 16:04:44 +0900 Subject: [PATCH 1/2] logrotate: do not enable logrotate.service itself logrotate.timer is enough for rotating logs. Enabling logrotate.service would make the service start on every configuration switch, leading to tests failure when logrotate is enabled. Also update test to make sure the timer is active and runs the service on date change. --- nixos/modules/services/logging/logrotate.nix | 1 - nixos/tests/logrotate.nix | 17 +++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nixos/modules/services/logging/logrotate.nix b/nixos/modules/services/logging/logrotate.nix index 77e4fc395981..082cf92ff4ef 100644 --- a/nixos/modules/services/logging/logrotate.nix +++ b/nixos/modules/services/logging/logrotate.nix @@ -167,7 +167,6 @@ in systemd.services.logrotate = { description = "Logrotate Service"; - wantedBy = [ "multi-user.target" ]; startAt = "hourly"; serviceConfig = { diff --git a/nixos/tests/logrotate.nix b/nixos/tests/logrotate.nix index 0f6b59f071d4..0dee5d4502d9 100644 --- a/nixos/tests/logrotate.nix +++ b/nixos/tests/logrotate.nix @@ -15,19 +15,20 @@ import ./make-test-python.nix ({ pkgs, ...} : rec { with subtest("whether logrotate works"): machine.succeed( # we must rotate once first to create logrotate stamp - "systemctl start --wait logrotate.service", + "systemctl start logrotate.service") + # we need to wait for console text once here to + # clear console buffer up to this point for next wait + machine.wait_for_console_text('logrotate.service: Deactivated successfully') + machine.succeed( # wtmp is present in default config. "rm -f /var/log/wtmp*", "echo test > /var/log/wtmp", - # move into the future and rotate - "date -s 'now + 1 month + 1 day'", - # systemd will run logrotate from logrotate.timer automatically - # on date change, but if we want to wait for it to terminate - # it's easier to run again... - "systemctl start --wait logrotate.service", - + # move into the future and check rotation. + "date -s 'now + 1 month + 1 day'") + machine.wait_for_console_text('logrotate.service: Deactivated successfully') + machine.succeed( # check rotate worked "[ -e /var/log/wtmp.1 ]", ) From 8022c82a39c19bd1fe000884703601532204b82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Fri, 25 Feb 2022 18:03:55 +0100 Subject: [PATCH 2/2] nixosTests.switchTest: fix race condition on /testpath Currently the test-watch.service gets started in a loop as long as /testpath exists, so `rm /testpath /testpath-modified` runs into a race condition where if the service was just getting activated, it will create /testpath-modified and make the test fail. This is fixed by making the service RemainAfterExit so that it only starts once, and stopping it manually after we remove /testpath. --- nixos/tests/switch-test.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix index 4f297b6521d1..b429babce838 100644 --- a/nixos/tests/switch-test.nix +++ b/nixos/tests/switch-test.nix @@ -283,6 +283,7 @@ import ./make-test-python.nix ({ pkgs, ...} : { systemd.services.test-watch = { serviceConfig = { Type = "oneshot"; + RemainAfterExit = true; ExecStart = "${pkgs.coreutils}/bin/touch /testpath-modified"; }; }; @@ -723,6 +724,7 @@ import ./make-test-python.nix ({ pkgs, ...} : { machine.succeed("touch /testpath") machine.wait_until_succeeds("test -f /testpath-modified") machine.succeed("rm /testpath /testpath-modified") + machine.systemctl("stop test-watch.service") switch_to_specialisation("${machine}", "pathModified") machine.succeed("touch /testpath") machine.fail("test -f /testpath-modified")