| author | |
| committer | |
| log | 16755e176f00faeed64d1cf82053129722dd69f7 |
| tree | bab53d432fc41fa86fce1496a300399fefdcdb3b |
| parent | 0786e0d038ecc3beecd8b582a082e679bd86f88b |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Assisted-by: gpt-6.1-sol2 files changed, 42 insertions(+), 3 deletions(-)
tools/release-host-test.py+39| ... | ... | @@ -42,6 +42,45 @@ class HostConfiguration(unittest.TestCase): |
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | class ActivationEnvironment(unittest.TestCase): |
| 45 | def test_flake_paths_are_resolved_again_after_the_release_store_moves(self): | |
| 46 | with tempfile.TemporaryDirectory() as temporary: | |
| 47 | root = Path(temporary).resolve() | |
| 48 | previous = root / release.transition.PREVIOUS | |
| 49 | canonical = root / "snowglobe" | |
| 50 | source = previous / "releases" / ("a" * 16) | |
| 51 | (source / "tools").mkdir(parents=True) | |
| 52 | (source / "tools/snowglobe.py").touch() | |
| 53 | (source / ".snowglobe-release.json").write_text('{"version":1}') | |
| 54 | canonical.symlink_to(previous, target_is_directory=True) | |
| 55 | logical_source = canonical / "releases" / source.name | |
| 56 | observed = [] | |
| 57 | ||
| 58 | def activate(path): | |
| 59 | self.assertEqual(path, logical_source) | |
| 60 | canonical.unlink() | |
| 61 | previous.rename(canonical) | |
| 62 | previous.symlink_to(canonical, target_is_directory=True) | |
| 63 | ||
| 64 | def run(argv, **kwargs): | |
| 65 | if argv[0] in {"nix", "nixos-rebuild"}: | |
| 66 | observed.append(argv) | |
| 67 | output = '["snowglobe"]' if argv[0] == "nix" else '"leader"' | |
| 68 | return subprocess.CompletedProcess(argv, 0, output) | |
| 69 | ||
| 70 | with patch.dict(os.environ), patch.object(release, "ROOT", canonical), patch.object(release, "STATE", root), patch.object( | |
| 71 | release, "check_release", return_value=logical_source, | |
| 72 | ), patch.object(release, "current_release", return_value=None), patch.object( | |
| 73 | release, "host_digest", return_value="new", | |
| 74 | ), patch.object(release, "jobs", return_value=set()), patch.object( | |
| 75 | release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"), | |
| 76 | ), patch.object(release.subprocess, "run", side_effect=run), patch.object( | |
| 77 | release.transition, "activate", side_effect=activate, | |
| 78 | ): | |
| 79 | release.activate(source.name, initial=True) | |
| 80 | self.assertIn(f"path:{source}#nixosConfigurations", observed[0]) | |
| 81 | self.assertEqual(observed[1], ["nixos-rebuild", "dry-build", "--flake", f"path:{source}#snowglobe"]) | |
| 82 | self.assertEqual(observed[2], ["nixos-rebuild", "switch", "--flake", f"path:{logical_source}#snowglobe"]) | |
| 83 | ||
| 45 | 84 | def test_host_switch_refreshes_inherited_name_and_preserves_overrides(self): |
| 46 | 85 | for before, after, inherited, expected in ( |
| 47 | 86 | (PREVIOUS_HOST, "snowglobe", PREVIOUS_HOST, "snowglobe"), |
tools/release.py+3-3| ... | ... | @@ -139,7 +139,7 @@ def jobs(path): |
| 139 | 139 | def host_configuration(path): |
| 140 | 140 | hostname = os.uname().nodename.split(".", 1)[0] |
| 141 | 141 | available = json.loads(subprocess.run( |
| 142 | ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path}#nixosConfigurations", "--apply", "builtins.attrNames"], | |
| 142 | ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path.resolve()}#nixosConfigurations", "--apply", "builtins.attrNames"], | |
| 143 | 143 | check=True, capture_output=True, text=True, |
| 144 | 144 | ).stdout) |
| 145 | 145 | return transition.host_configuration(hostname, available) |
| ... | ... | @@ -161,7 +161,7 @@ def activate(release, legacy=False, initial=False): |
| 161 | 161 | old_digest = recorded.read_text().strip() if recorded.exists() else None |
| 162 | 162 | if old_digest != digest: |
| 163 | 163 | configuration = host_configuration(path) |
| 164 | subprocess.run(["nixos-rebuild", "dry-build", "--flake", f"path:{path}#{configuration}"], check=True) | |
| 164 | subprocess.run(["nixos-rebuild", "dry-build", "--flake", f"path:{path.resolve()}#{configuration}"], check=True) | |
| 165 | 165 | subprocess.run(["python3", str(script), "preflight"], check=True, env=environment) |
| 166 | 166 | backup = None |
| 167 | 167 | if current and not initial: |
| ... | ... | @@ -179,7 +179,7 @@ def activate(release, legacy=False, initial=False): |
| 179 | 179 | (ROOT / "current").symlink_to(path) |
| 180 | 180 | hostname = os.uname().nodename.split(".", 1)[0] |
| 181 | 181 | transition.activate(path) |
| 182 | subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path}#{configuration}"], check=True) | |
| 182 | subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path.resolve()}#{configuration}"], check=True) | |
| 183 | 183 | if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname: |
| 184 | 184 | os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0] |
| 185 | 185 | environment = transition.environment(path) |