summary refs log tree commit diff
path: root/nixos/tests/switch-test.nix
diff options
context:
space:
mode:
authorJanne Heß <janne@hess.ooo>2022-03-06 22:43:47 +0100
committerJanne Heß <janne@hess.ooo>2022-03-11 14:05:19 +0100
commitbc58430068d0bd0ffd3ef561a92a05f5970d149c (patch)
treedee35f2bf657e7056bdae49e67746089664334a1 /nixos/tests/switch-test.nix
parent3052d3aa50674f2cfeee7c7ddf42c36d84013e48 (diff)
downloadnixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.tar
nixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.tar.gz
nixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.tar.bz2
nixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.tar.lz
nixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.tar.xz
nixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.tar.zst
nixpkgs-bc58430068d0bd0ffd3ef561a92a05f5970d149c.zip
nixos/switch-to-configuration: Fix reloading of stopped services
Diffstat (limited to 'nixos/tests/switch-test.nix')
-rw-r--r--nixos/tests/switch-test.nix59
1 files changed, 59 insertions, 0 deletions
diff --git a/nixos/tests/switch-test.nix b/nixos/tests/switch-test.nix
index a994fb78160..93eee4babc2 100644
--- a/nixos/tests/switch-test.nix
+++ b/nixos/tests/switch-test.nix
@@ -208,6 +208,39 @@ in {
           systemd.services."escaped\\x2ddash".serviceConfig.X-Test = "test";
         };
 
+        unitWithRequirement.configuration = {
+          systemd.services.required-service = {
+            wantedBy = [ "multi-user.target" ];
+            serviceConfig = {
+              Type = "oneshot";
+              RemainAfterExit = true;
+              ExecStart = "${pkgs.coreutils}/bin/true";
+              ExecReload = "${pkgs.coreutils}/bin/true";
+            };
+          };
+          systemd.services.test-service = {
+            wantedBy = [ "multi-user.target" ];
+            requires = [ "required-service.service" ];
+            serviceConfig = {
+              Type = "oneshot";
+              RemainAfterExit = true;
+              ExecStart = "${pkgs.coreutils}/bin/true";
+              ExecReload = "${pkgs.coreutils}/bin/true";
+            };
+          };
+        };
+
+        unitWithRequirementModified.configuration = {
+          imports = [ unitWithRequirement.configuration ];
+          systemd.services.required-service.serviceConfig.X-Test = "test";
+          systemd.services.test-service.reloadTriggers = [ "test" ];
+        };
+
+        unitWithRequirementModifiedNostart.configuration = {
+          imports = [ unitWithRequirement.configuration ];
+          systemd.services.test-service.unitConfig.RefuseManualStart = true;
+        };
+
         restart-and-reload-by-activation-script.configuration = {
           systemd.services = rec {
             simple-service = {
@@ -574,6 +607,32 @@ in {
         assert_contains(out, "\nstarting the following units: escaped\\x2ddash.service\n")
         assert_lacks(out, "the following new units were started:")
 
+        # Ensure units that require changed units are properly reloaded
+        out = switch_to_specialisation("${machine}", "unitWithRequirement")
+        assert_contains(out, "stopping the following units: escaped\\x2ddash.service\n")
+        assert_lacks(out, "NOT restarting the following changed units:")
+        assert_lacks(out, "reloading the following units:")
+        assert_lacks(out, "\nrestarting the following units:")
+        assert_lacks(out, "\nstarting the following units:")
+        assert_contains(out, "the following new units were started: required-service.service, test-service.service\n")
+
+        out = switch_to_specialisation("${machine}", "unitWithRequirementModified")
+        assert_contains(out, "stopping the following units: required-service.service\n")
+        assert_lacks(out, "NOT restarting the following changed units:")
+        assert_lacks(out, "reloading the following units:")
+        assert_lacks(out, "\nrestarting the following units:")
+        assert_contains(out, "\nstarting the following units: required-service.service, test-service.service\n")
+        assert_lacks(out, "the following new units were started:")
+
+        # Unless the unit asks to be not restarted
+        out = switch_to_specialisation("${machine}", "unitWithRequirementModifiedNostart")
+        assert_contains(out, "stopping the following units: required-service.service\n")
+        assert_lacks(out, "NOT restarting the following changed units:")
+        assert_lacks(out, "reloading the following units:")
+        assert_lacks(out, "\nrestarting the following units:")
+        assert_contains(out, "\nstarting the following units: required-service.service\n")
+        assert_lacks(out, "the following new units were started:")
+
     with subtest("failing units"):
         # Let the simple service fail
         switch_to_specialisation("${machine}", "simpleServiceModified")