2024-08-10 18:03:28 +01:00
|
|
|
import ../make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
2023-07-03 17:57:55 +01:00
|
|
|
name = "lxd-ui";
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-07-03 17:57:55 +01:00
|
|
|
nodes.machine =
|
|
|
|
{ lib, ... }:
|
|
|
|
{
|
|
|
|
virtualisation = {
|
|
|
|
lxd.enable = true;
|
|
|
|
lxd.ui.enable = true;
|
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
environment.systemPackages =
|
|
|
|
let
|
|
|
|
seleniumScript =
|
|
|
|
pkgs.writers.writePython3Bin "selenium-script"
|
|
|
|
{
|
|
|
|
libraries = with pkgs.python3Packages; [ selenium ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
from selenium import webdriver
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from selenium.webdriver.firefox.options import Options
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
options = Options()
|
|
|
|
options.add_argument("--headless")
|
|
|
|
service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
driver = webdriver.Firefox(options=options, service=service)
|
|
|
|
driver.implicitly_wait(10)
|
|
|
|
driver.get("https://localhost:8443/ui")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
wait = WebDriverWait(driver, 60)
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
assert len(driver.find_elements(By.CLASS_NAME, "l-application")) > 0
|
|
|
|
assert len(driver.find_elements(By.CLASS_NAME, "l-navigation__drawer")) > 0
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
driver.close()
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
with pkgs;
|
|
|
|
[
|
|
|
|
curl
|
|
|
|
firefox-unwrapped
|
|
|
|
geckodriver
|
|
|
|
seleniumScript
|
|
|
|
];
|
2023-07-03 17:57:55 +01:00
|
|
|
};
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-07-03 17:57:55 +01:00
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("sockets.target")
|
|
|
|
machine.wait_for_unit("lxd.service")
|
|
|
|
machine.wait_for_file("/var/lib/lxd/unix.socket")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-07-03 17:57:55 +01:00
|
|
|
# Wait for lxd to settle
|
|
|
|
machine.succeed("lxd waitready")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-07-03 17:57:55 +01:00
|
|
|
# Configure LXC listen address
|
|
|
|
machine.succeed("lxc config set core.https_address :8443")
|
|
|
|
machine.succeed("systemctl restart lxd")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-07-03 17:57:55 +01:00
|
|
|
# Check that the LXD_UI environment variable is populated in the systemd unit
|
|
|
|
machine.succeed("cat /etc/systemd/system/lxd.service | grep 'LXD_UI'")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-07-03 17:57:55 +01:00
|
|
|
# Ensure the endpoint returns an HTML page with 'LXD UI' in the title
|
|
|
|
machine.succeed("curl -kLs https://localhost:8443/ui | grep '<title>LXD UI</title>'")
|
2024-12-10 19:26:33 +00:00
|
|
|
|
2023-11-22 15:58:05 +00:00
|
|
|
# Ensure the application is actually rendered by the Javascript
|
|
|
|
machine.succeed("PYTHONUNBUFFERED=1 selenium-script")
|
2023-07-03 17:57:55 +01:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|