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