1 import ../make-test-python.nix ({ lib, pkgs, ... }: let
2 oldNetbox = pkgs.netbox_3_6;
3 newNetbox = pkgs.netbox_3_7;
5 name = "netbox-upgrade";
7 meta = with lib.maintainers; {
8 maintainers = [ minijackson raitobezarius ];
11 nodes.machine = { config, ... }: {
12 virtualisation.memorySize = 2048;
16 secretKeyFile = pkgs.writeText "secret" ''
17 abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
24 recommendedProxySettings = true;
26 virtualHosts.netbox = {
28 locations."/".proxyPass = "http://localhost:${toString config.services.netbox.port}";
29 locations."/static/".alias = "/var/lib/netbox/static/";
33 users.users.nginx.extraGroups = [ "netbox" ];
35 networking.firewall.allowedTCPPorts = [ 80 ];
37 specialisation.upgrade.configuration.services.netbox.package = lib.mkForce newNetbox;
40 testScript = { nodes, ... }:
42 apiVersion = version: lib.pipe version [
45 (lib.concatStringsSep ".")
47 oldApiVersion = apiVersion oldNetbox.version;
48 newApiVersion = apiVersion newNetbox.version;
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")
56 def api_version(headers):
57 header = [header for header in headers.splitlines() if header.startswith("API-Version:")][0]
58 return header.split()[1]
60 def check_api_version(version):
61 headers = machine.succeed(
62 "curl -sSfL http://localhost/api/ --head -H 'Content-Type: application/json'"
64 assert api_version(headers) == version
66 with subtest("NetBox version is the old one"):
67 check_api_version("${oldApiVersion}")
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).
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.
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")
81 machine.wait_for_unit("netbox.service")
82 machine.succeed("systemctl start netbox-housekeeping.service")
84 with subtest("NetBox version is the new one"):
85 check_api_version("${newApiVersion}")