at 23.11-beta 3.0 kB view raw
1import ../make-test-python.nix ({ lib, pkgs, ... }: let 2 oldNetbox = pkgs.netbox_3_5; 3 newNetbox = pkgs.netbox_3_6; 4in { 5 name = "netbox-upgrade"; 6 7 meta = with lib.maintainers; { 8 maintainers = [ minijackson raitobezarius ]; 9 }; 10 11 nodes.machine = { config, ... }: { 12 virtualisation.memorySize = 2048; 13 services.netbox = { 14 enable = true; 15 package = oldNetbox; 16 secretKeyFile = pkgs.writeText "secret" '' 17 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 18 ''; 19 }; 20 21 services.nginx = { 22 enable = true; 23 24 recommendedProxySettings = true; 25 26 virtualHosts.netbox = { 27 default = true; 28 locations."/".proxyPass = "http://localhost:${toString config.services.netbox.port}"; 29 locations."/static/".alias = "/var/lib/netbox/static/"; 30 }; 31 }; 32 33 users.users.nginx.extraGroups = [ "netbox" ]; 34 35 networking.firewall.allowedTCPPorts = [ 80 ]; 36 37 specialisation.upgrade.configuration.services.netbox.package = lib.mkForce newNetbox; 38 }; 39 40 testScript = { nodes, ... }: 41 let 42 apiVersion = version: lib.pipe version [ 43 (lib.splitString ".") 44 (lib.take 2) 45 (lib.concatStringsSep ".") 46 ]; 47 oldApiVersion = apiVersion oldNetbox.version; 48 newApiVersion = apiVersion newNetbox.version; 49 in 50 '' 51 start_all() 52 machine.wait_for_unit("netbox.target") 53 machine.wait_for_unit("nginx.service") 54 machine.wait_until_succeeds("journalctl --since -1m --unit netbox --grep Listening") 55 56 def api_version(headers): 57 header = [header for header in headers.splitlines() if header.startswith("API-Version:")][0] 58 return header.split()[1] 59 60 def check_api_version(version): 61 headers = machine.succeed( 62 "curl -sSfL http://localhost/api/ --head -H 'Content-Type: application/json'" 63 ) 64 assert api_version(headers) == version 65 66 with subtest("NetBox version is the old one"): 67 check_api_version("${oldApiVersion}") 68 69 # Somehow, even though netbox-housekeeping.service has After=netbox.service, 70 # netbox-housekeeping.service and netbox.service still get started at the 71 # same time, making netbox-housekeeping fail (can't really do some house 72 # keeping job if the database is not correctly formed). 73 # 74 # So we don't check that the upgrade went well, we just check that 75 # netbox.service is active, and that netbox-housekeeping can be run 76 # successfully afterwards. 77 # 78 # This is not good UX, but the system should be working nonetheless. 79 machine.execute("${nodes.machine.system.build.toplevel}/specialisation/upgrade/bin/switch-to-configuration test >&2") 80 81 machine.wait_for_unit("netbox.service") 82 machine.succeed("systemctl start netbox-housekeeping.service") 83 84 with subtest("NetBox version is the new one"): 85 check_api_version("${newApiVersion}") 86 ''; 87})