| author | |
| committer | |
| log | 1ec773200ff768847f5e58ac0cc1b1e2f355668b |
| tree | 54fd43c4e110762be3f1639003797d684a312337 |
| parent | 16755e176f00faeed64d1cf82053129722dd69f7 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Assisted-by: gpt-6.1-sol4 files changed, 39 insertions(+), 7 deletions(-)
tools/dashboard-deploy-test.py+5-1| ... | ... | @@ -162,6 +162,7 @@ class DeploymentBoundary(unittest.TestCase): |
| 162 | 162 | |
| 163 | 163 | def test_first_activation_exposes_current_before_starting_host_units(self): |
| 164 | 164 | (self.root / "current").unlink() |
| 165 | read_text = Path.read_text | |
| 165 | 166 | |
| 166 | 167 | def execute(argv, **kwargs): |
| 167 | 168 | if argv[:2] == ["nixos-rebuild", "switch"]: |
| ... | ... | @@ -169,7 +170,10 @@ class DeploymentBoundary(unittest.TestCase): |
| 169 | 170 | output = 'job "fixture" {\n' if argv[-1] == "render" else '"leader"' |
| 170 | 171 | return subprocess.CompletedProcess(argv, 0, stdout=output, stderr="") |
| 171 | 172 | |
| 172 | with patch.object(release.subprocess, "run", side_effect=execute), patch.object(release, "host_configuration", return_value="snowglobe"), patch.object(release.transition, "activate"): | |
| 173 | with patch.object(release.subprocess, "run", side_effect=execute), patch.object(release, "host_configuration", return_value="snowglobe"), patch.object(release.transition, "activate"), patch.object( | |
| 174 | Path, "read_text", autospec=True, | |
| 175 | side_effect=lambda path: os.uname().nodename + "\n" if path == Path("/etc/hostname") else read_text(path), | |
| 176 | ): | |
| 173 | 177 | self.assertIsNone(release.activate(self.version, initial=True)) |
| 174 | 178 | self.assertEqual(release.current_release(), self.version) |
| 175 | 179 |
tools/namespace-transition-test.py+5-1| ... | ... | @@ -127,6 +127,7 @@ class NamespaceTransition(unittest.TestCase): |
| 127 | 127 | (source / "nixos/dashboard.nix").touch() |
| 128 | 128 | transition.layout(source)["manifest"].write_text('{"version":2}') |
| 129 | 129 | observed = [] |
| 130 | read_text = Path.read_text | |
| 130 | 131 | |
| 131 | 132 | def run(argv, **kwargs): |
| 132 | 133 | observed.append((argv, kwargs)) |
| ... | ... | @@ -140,7 +141,10 @@ class NamespaceTransition(unittest.TestCase): |
| 140 | 141 | release, "host_configuration", return_value=transition.NAMESPACE["previousHost"], |
| 141 | 142 | ), patch.object(release, "jobs", return_value=set()), patch.object( |
| 142 | 143 | release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"), |
| 143 | ), patch.object(release.subprocess, "run", side_effect=run), patch.object(transition, "activate") as activate: | |
| 144 | ), patch.object(release.subprocess, "run", side_effect=run), patch.object(transition, "activate") as activate, patch.object( | |
| 145 | Path, "read_text", autospec=True, | |
| 146 | side_effect=lambda path: "snowglobe\n" if path == Path("/etc/hostname") else read_text(path), | |
| 147 | ): | |
| 144 | 148 | release.activate(revision, initial=True) |
| 145 | 149 | activate.assert_called_once_with(source) |
| 146 | 150 | scripts = [(argv, kwargs) for argv, kwargs in observed if argv[0] == "python3"] |
tools/release-host-test.py+26-5| ... | ... | @@ -54,6 +54,7 @@ class ActivationEnvironment(unittest.TestCase): |
| 54 | 54 | canonical.symlink_to(previous, target_is_directory=True) |
| 55 | 55 | logical_source = canonical / "releases" / source.name |
| 56 | 56 | observed = [] |
| 57 | read_text = Path.read_text | |
| 57 | 58 | |
| 58 | 59 | def activate(path): |
| 59 | 60 | self.assertEqual(path, logical_source) |
| ... | ... | @@ -75,6 +76,9 @@ class ActivationEnvironment(unittest.TestCase): |
| 75 | 76 | release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"), |
| 76 | 77 | ), patch.object(release.subprocess, "run", side_effect=run), patch.object( |
| 77 | 78 | release.transition, "activate", side_effect=activate, |
| 79 | ), patch.object( | |
| 80 | Path, "read_text", autospec=True, | |
| 81 | side_effect=lambda path: "snowglobe\n" if path == Path("/etc/hostname") else read_text(path), | |
| 78 | 82 | ): |
| 79 | 83 | release.activate(source.name, initial=True) |
| 80 | 84 | self.assertIn(f"path:{source}#nixosConfigurations", observed[0]) |
| ... | ... | @@ -94,17 +98,22 @@ class ActivationEnvironment(unittest.TestCase): |
| 94 | 98 | source = root / "release" |
| 95 | 99 | source.mkdir() |
| 96 | 100 | (source / "tools").mkdir() |
| 97 | (source / "tools/snowglobe.py").touch() | |
| 98 | (source / ".snowglobe-release.json").write_text('{"version":1}') | |
| 101 | prefix = release.transition.PREVIOUS if after == PREVIOUS_HOST else "snowglobe" | |
| 102 | (source / "tools" / (prefix + ".py")).touch() | |
| 103 | (source / ("." + prefix + "-release.json")).write_text('{"version":1}') | |
| 99 | 104 | hostname = before |
| 100 | 105 | observed = [] |
| 106 | calls = [] | |
| 107 | read_text = Path.read_text | |
| 101 | 108 | |
| 102 | 109 | def run(argv, **kwargs): |
| 103 | 110 | nonlocal hostname |
| 104 | if argv[:2] == ["nixos-rebuild", "switch"]: | |
| 111 | calls.append(argv) | |
| 112 | if argv[:3] == ["hostnamectl", "set-hostname", "--transient"]: | |
| 105 | 113 | hostname = after |
| 106 | 114 | if argv[-1] == "deploy": |
| 107 | observed.append(os.environ.get("SNOWGLOBE_NODE_NAME")) | |
| 115 | key = prefix.upper() + "_NODE_NAME" | |
| 116 | observed.append(kwargs["env"].get(key)) | |
| 108 | 117 | return subprocess.CompletedProcess(argv, 0, '"leader"') |
| 109 | 118 | |
| 110 | 119 | with patch.dict(os.environ), patch.object(release, "ROOT", root), patch.object( |
| ... | ... | @@ -120,9 +129,21 @@ class ActivationEnvironment(unittest.TestCase): |
| 120 | 129 | os.environ.pop("SNOWGLOBE_NODE_NAME", None) |
| 121 | 130 | else: |
| 122 | 131 | os.environ["SNOWGLOBE_NODE_NAME"] = inherited |
| 123 | with patch.object(release.transition, "activate"): | |
| 132 | with patch.object(release.transition, "activate"), patch.object( | |
| 133 | Path, "read_text", autospec=True, | |
| 134 | side_effect=lambda path: after + "\n" if path == Path("/etc/hostname") else read_text(path), | |
| 135 | ): | |
| 124 | 136 | release.activate("0123456789abcdef", initial=True) |
| 125 | 137 | self.assertEqual(observed, [expected]) |
| 138 | self.assertEqual(hostname, after) | |
| 139 | changes = [argv for argv in calls if argv[0] == "hostnamectl"] | |
| 140 | self.assertEqual(changes, [["hostnamectl", "set-hostname", "--transient", after]] if before != after else []) | |
| 141 | if changes: | |
| 142 | switch = next(i for i, argv in enumerate(calls) if argv[:2] == ["nixos-rebuild", "switch"]) | |
| 143 | rename = calls.index(changes[0]) | |
| 144 | deploy = next(i for i, argv in enumerate(calls) if argv[-1] == "deploy") | |
| 145 | self.assertLess(switch, rename) | |
| 146 | self.assertLess(rename, deploy) | |
| 126 | 147 | |
| 127 | 148 | |
| 128 | 149 | if __name__ == "__main__": |
tools/release.py+3| ... | ... | @@ -180,6 +180,9 @@ def activate(release, legacy=False, initial=False): |
| 180 | 180 | hostname = os.uname().nodename.split(".", 1)[0] |
| 181 | 181 | transition.activate(path) |
| 182 | 182 | subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path.resolve()}#{configuration}"], check=True) |
| 183 | configured_hostname = Path("/etc/hostname").read_text().strip() | |
| 184 | if os.uname().nodename != configured_hostname: | |
| 185 | subprocess.run(["hostnamectl", "set-hostname", "--transient", configured_hostname], check=True) | |
| 183 | 186 | if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname: |
| 184 | 187 | os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0] |
| 185 | 188 | environment = transition.environment(path) |