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