1import ../make-test-python.nix ({ pkgs, lib, ... }: {
2 name = "lxd-ui";
3
4 meta = {
5 maintainers = lib.teams.lxc.members;
6 };
7
8 nodes.machine = { lib, ... }: {
9 virtualisation = {
10 lxd.enable = true;
11 lxd.ui.enable = true;
12 };
13
14 environment.systemPackages =
15 let
16 seleniumScript = pkgs.writers.writePython3Bin "selenium-script"
17 {
18 libraries = with pkgs.python3Packages; [ selenium ];
19 } ''
20 from selenium import webdriver
21 from selenium.webdriver.common.by import By
22 from selenium.webdriver.firefox.options import Options
23 from selenium.webdriver.support.ui import WebDriverWait
24
25 options = Options()
26 options.add_argument("--headless")
27 service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501
28
29 driver = webdriver.Firefox(options=options, service=service)
30 driver.implicitly_wait(10)
31 driver.get("https://localhost:8443/ui")
32
33 wait = WebDriverWait(driver, 60)
34
35 assert len(driver.find_elements(By.CLASS_NAME, "l-application")) > 0
36 assert len(driver.find_elements(By.CLASS_NAME, "l-navigation__drawer")) > 0
37
38 driver.close()
39 '';
40 in
41 with pkgs; [ curl firefox-unwrapped geckodriver seleniumScript ];
42 };
43
44
45 testScript = ''
46 machine.wait_for_unit("sockets.target")
47 machine.wait_for_unit("lxd.service")
48 machine.wait_for_file("/var/lib/lxd/unix.socket")
49
50 # Wait for lxd to settle
51 machine.succeed("lxd waitready")
52
53 # Configure LXC listen address
54 machine.succeed("lxc config set core.https_address :8443")
55 machine.succeed("systemctl restart lxd")
56
57 # Check that the LXD_UI environment variable is populated in the systemd unit
58 machine.succeed("cat /etc/systemd/system/lxd.service | grep 'LXD_UI'")
59
60 # Ensure the endpoint returns an HTML page with 'LXD UI' in the title
61 machine.succeed("curl -kLs https://localhost:8443/ui | grep '<title>LXD UI</title>'")
62
63 # Ensure the application is actually rendered by the Javascript
64 machine.succeed("PYTHONUNBUFFERED=1 selenium-script")
65 '';
66})