|
| 1 | +import ./make-test-python.nix ({ ... }: { |
| 2 | + name = "nixversions"; |
| 3 | + nodes = let |
| 4 | + mkTestVM = { location, withSlurm ? false, production ? true }: { lib, pkgs, ... }: { |
| 5 | + imports = [ ../nixos ../nixos/roles ]; |
| 6 | + flyingcircus.agent.package = lib.mkIf withSlurm pkgs.fc.agentWithSlurm; |
| 7 | + flyingcircus.enc.parameters = { |
| 8 | + inherit location production; |
| 9 | + resource_group = "test"; |
| 10 | + interfaces.srv = { |
| 11 | + mac = "52:54:00:12:34:56"; |
| 12 | + bridged = false; |
| 13 | + networks = { |
| 14 | + "192.168.101.0/24" = [ "192.168.101.7" ]; |
| 15 | + "2001:db8:f030:1c3::/64" = [ "2001:db8:f030:1c3::7" ]; |
| 16 | + }; |
| 17 | + gateways = {}; |
| 18 | + }; |
| 19 | + }; |
| 20 | + }; |
| 21 | + in { |
| 22 | + production = mkTestVM { location = "rzob"; }; |
| 23 | + nonProd = mkTestVM { location = "rzob"; production = false; }; |
| 24 | + slurmOnProduction = mkTestVM { location = "rzob"; withSlurm = true; }; |
| 25 | + slurmOnNonProd = mkTestVM { location = "rzob"; withSlurm = true; production = false; }; |
| 26 | + |
| 27 | + devVM = mkTestVM { location = "dev"; }; |
| 28 | + whqVM = mkTestVM { location = "whq"; }; |
| 29 | + whqVMNonProd = mkTestVM { location = "whq"; production = false; }; |
| 30 | + }; |
| 31 | + |
| 32 | + testScript = '' |
| 33 | + import os.path |
| 34 | + import re |
| 35 | +
|
| 36 | + relevant_nix_versions = [ |
| 37 | + # the default on production |
| 38 | + "2.18", |
| 39 | + # default Nix in 24.11 |
| 40 | + "2.24", |
| 41 | + # the default on staging |
| 42 | + "2.25", |
| 43 | + ] |
| 44 | +
|
| 45 | + def strip_hash(store_path): |
| 46 | + basename = os.path.basename(store_path) |
| 47 | + return basename.split("-", 1)[1] |
| 48 | +
|
| 49 | + def verify_nix_versions(vm, expected_nix="2.25", expect_slurm=False): |
| 50 | + vm.start() |
| 51 | + version = vm.succeed("nix --version") |
| 52 | + assert version.startswith(f"nix (Nix) {expected_nix}."), f""" |
| 53 | + Expected Nix version to start with |
| 54 | + nix (Nix) {expected_nix}. |
| 55 | + Full output: |
| 56 | + {version} |
| 57 | + """ |
| 58 | + nix = os.path.dirname(os.path.dirname(vm.succeed("readlink -f $(type -P nix)"))) |
| 59 | + fc_agent = vm.succeed("readlink -f $(type -P fc-manage)") |
| 60 | +
|
| 61 | + # no `nix why-depends` here since it always gives 0 as exit code and we'd have to |
| 62 | + # match the stderr. |
| 63 | + agent_closure = vm.succeed(f"nix-store -qR {fc_agent}").rstrip("\n").split("\n") |
| 64 | + assert nix in agent_closure, f""" |
| 65 | + Expected Nix {expected_nix} (i.e. store-path {nix}) to be in |
| 66 | + the agent closure: |
| 67 | +
|
| 68 | + {agent_closure} |
| 69 | + """ |
| 70 | +
|
| 71 | + nix_versions_not_used = [x for x in relevant_nix_versions if x != expected_nix] |
| 72 | + assert all( |
| 73 | + not strip_hash(p).startswith(f"nix-{majorminor}.") |
| 74 | + for p in agent_closure |
| 75 | + for majorminor in nix_versions_not_used |
| 76 | + ), f""" |
| 77 | + Expected Nix versions {", ".join(nix_versions_not_used)} to NOT be in the agent closure: |
| 78 | +
|
| 79 | + {agent_closure} |
| 80 | + """ |
| 81 | +
|
| 82 | + assert any(strip_hash(p).startswith("slurm-") for p in agent_closure) == expect_slurm, """ |
| 83 | + Expected no `slurm` in agent closure: |
| 84 | +
|
| 85 | + {agent_closure} |
| 86 | + """ |
| 87 | +
|
| 88 | + vm.shutdown() |
| 89 | +
|
| 90 | +
|
| 91 | + with subtest("rzob production vm"): |
| 92 | + verify_nix_versions(production, "2.18") |
| 93 | +
|
| 94 | + with subtest("rzob non-prod vm"): |
| 95 | + verify_nix_versions(nonProd, "2.25") |
| 96 | +
|
| 97 | + with subtest("rzob prod vm with slurm"): |
| 98 | + verify_nix_versions(slurmOnProduction, "2.18", expect_slurm=True) |
| 99 | +
|
| 100 | + with subtest("rzob non-prod vm with slurm"): |
| 101 | + verify_nix_versions(slurmOnNonProd, "2.25", expect_slurm=True) |
| 102 | +
|
| 103 | + with subtest("whq vm"): |
| 104 | + verify_nix_versions(whqVM, "2.25") |
| 105 | +
|
| 106 | + with subtest("whq vm with non-prod flag"): |
| 107 | + verify_nix_versions(whqVMNonProd, "2.25") |
| 108 | +
|
| 109 | + with subtest("dev vm"): |
| 110 | + verify_nix_versions(devVM, "2.25") |
| 111 | + ''; |
| 112 | +}) |
0 commit comments