1import ../make-test-python.nix (
2 {
3 pkgs,
4 lib,
5 lts ? true,
6 ...
7 }:
8 {
9 name = "incus-ui";
10
11 meta = {
12 maintainers = lib.teams.lxc.members;
13 };
14
15 nodes.machine =
16 { lib, ... }:
17 {
18
19 virtualisation.incus = {
20 enable = true;
21 package = if lts then pkgs.incus-lts else pkgs.incus;
22
23 preseed.config."core.https_address" = ":8443";
24 ui.enable = true;
25 };
26
27 networking.nftables.enable = true;
28
29 environment.systemPackages =
30 let
31 seleniumScript =
32 pkgs.writers.writePython3Bin "selenium-script"
33 {
34 libraries = with pkgs.python3Packages; [ selenium ];
35 }
36 ''
37 from selenium import webdriver
38 from selenium.webdriver.common.by import By
39 from selenium.webdriver.firefox.options import Options
40 from selenium.webdriver.support.ui import WebDriverWait
41
42 options = Options()
43 options.add_argument("--headless")
44 service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501
45
46 driver = webdriver.Firefox(options=options, service=service)
47 driver.implicitly_wait(10)
48 driver.get("https://localhost:8443/ui")
49
50 wait = WebDriverWait(driver, 60)
51
52 assert len(driver.find_elements(By.CLASS_NAME, "l-application")) > 0
53 assert len(driver.find_elements(By.CLASS_NAME, "l-navigation__drawer")) > 0
54
55 driver.close()
56 '';
57 in
58 with pkgs;
59 [
60 curl
61 firefox-unwrapped
62 geckodriver
63 seleniumScript
64 ];
65 };
66
67 testScript = ''
68 machine.wait_for_unit("incus.service")
69 machine.wait_for_unit("incus-preseed.service")
70
71 # Check that the INCUS_UI environment variable is populated in the systemd unit
72 machine.succeed("systemctl cat incus.service | grep 'INCUS_UI'")
73
74 # Ensure the endpoint returns an HTML page with 'Incus UI' in the title
75 machine.succeed("curl -kLs https://localhost:8443/ui | grep '<title>Incus UI</title>'")
76
77 # Ensure the documentation is rendering correctly
78 machine.succeed("curl -kLs https://localhost:8443/documentation/ | grep '<title>Incus documentation</title>'")
79
80 # Ensure the application is actually rendered by the Javascript
81 machine.succeed("PYTHONUNBUFFERED=1 selenium-script")
82 '';
83 }
84)