nixos/tests/lxd: move into subdir, use minimal init, remove sleeps

This commit is contained in:
Adam Stephens 2023-08-10 14:07:42 -04:00
parent d41c2a87e3
commit f1c0589e4c
No known key found for this signature in database
8 changed files with 36 additions and 51 deletions

View File

@ -440,10 +440,8 @@ in {
loki = handleTest ./loki.nix {}; loki = handleTest ./loki.nix {};
luks = handleTest ./luks.nix {}; luks = handleTest ./luks.nix {};
lvm2 = handleTest ./lvm2 {}; lvm2 = handleTest ./lvm2 {};
lxd = handleTest ./lxd.nix {}; lxd = handleTest ./lxd {};
lxd-nftables = handleTest ./lxd-nftables.nix {};
lxd-image-server = handleTest ./lxd-image-server.nix {}; lxd-image-server = handleTest ./lxd-image-server.nix {};
lxd-ui = handleTest ./lxd-ui.nix {};
#logstash = handleTest ./logstash.nix {}; #logstash = handleTest ./logstash.nix {};
lorri = handleTest ./lorri/default.nix {}; lorri = handleTest ./lorri/default.nix {};
maddy = discoverTests (import ./maddy { inherit handleTest; }); maddy = discoverTests (import ./maddy { inherit handleTest; });

View File

@ -1,24 +0,0 @@
storage_pools:
- name: default
driver: dir
config:
source: /var/lxd-pool
networks:
- name: lxdbr0
type: bridge
config:
ipv4.address: auto
ipv6.address: none
profiles:
- name: default
devices:
eth0:
name: eth0
network: lxdbr0
type: nic
root:
path: /
pool: default
type: disk

View File

@ -61,14 +61,14 @@ in {
machine.wait_for_unit("lxd.service") machine.wait_for_unit("lxd.service")
machine.wait_for_file("/var/lib/lxd/unix.socket") machine.wait_for_file("/var/lib/lxd/unix.socket")
# It takes additional second for lxd to settle # Wait for lxd to settle
machine.sleep(1) machine.succeed("lxd waitready")
# lxd expects the pool's directory to already exist # lxd expects the pool's directory to already exist
machine.succeed("mkdir /var/lxd-pool") machine.succeed("mkdir /var/lxd-pool")
machine.succeed( machine.succeed(
"cat ${./common/lxd/config.yaml} | lxd init --preseed" "lxd init --minimal"
) )
machine.succeed( machine.succeed(

View File

@ -1,7 +1,7 @@
import ./make-test-python.nix ({ pkgs, lib, ... } : import ../make-test-python.nix ({ pkgs, lib, ... } :
let let
lxd-image = import ../release.nix { lxd-image = import ../../release.nix {
configuration = { configuration = {
# Building documentation makes the test unnecessarily take a longer time: # Building documentation makes the test unnecessarily take a longer time:
documentation.enable = lib.mkForce false; documentation.enable = lib.mkForce false;
@ -38,19 +38,18 @@ in {
}; };
testScript = '' testScript = ''
def instance_is_up(_) -> bool:
status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true")
return status == 0
machine.wait_for_unit("sockets.target") machine.wait_for_unit("sockets.target")
machine.wait_for_unit("lxd.service") machine.wait_for_unit("lxd.service")
machine.wait_for_file("/var/lib/lxd/unix.socket") machine.wait_for_file("/var/lib/lxd/unix.socket")
# It takes additional second for lxd to settle # Wait for lxd to settle
machine.sleep(1) machine.succeed("lxd waitready")
# lxd expects the pool's directory to already exist machine.succeed("lxd init --minimal")
machine.succeed("mkdir /var/lxd-pool")
machine.succeed(
"cat ${./common/lxd/config.yaml} | lxd init --preseed"
)
machine.succeed( machine.succeed(
"lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos" "lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos"
@ -58,21 +57,23 @@ in {
with subtest("Container can be managed"): with subtest("Container can be managed"):
machine.succeed("lxc launch nixos container") machine.succeed("lxc launch nixos container")
machine.sleep(5) with machine.nested("Waiting for instance to start and be usable"):
retry(instance_is_up)
machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -") machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -")
machine.succeed("lxc exec container true")
machine.succeed("lxc delete -f container") machine.succeed("lxc delete -f container")
with subtest("Container is mounted with lxcfs inside"): with subtest("Container is mounted with lxcfs inside"):
machine.succeed("lxc launch nixos container") machine.succeed("lxc launch nixos container")
machine.sleep(5) with machine.nested("Waiting for instance to start and be usable"):
retry(instance_is_up)
## ---------- ## ## ---------- ##
## limits.cpu ## ## limits.cpu ##
machine.succeed("lxc config set container limits.cpu 1") machine.succeed("lxc config set container limits.cpu 1")
machine.succeed("lxc restart container") machine.succeed("lxc restart container")
machine.sleep(5) with machine.nested("Waiting for instance to start and be usable"):
retry(instance_is_up)
assert ( assert (
"1" "1"
@ -81,7 +82,8 @@ in {
machine.succeed("lxc config set container limits.cpu 2") machine.succeed("lxc config set container limits.cpu 2")
machine.succeed("lxc restart container") machine.succeed("lxc restart container")
machine.sleep(5) with machine.nested("Waiting for instance to start and be usable"):
retry(instance_is_up)
assert ( assert (
"2" "2"
@ -93,7 +95,8 @@ in {
machine.succeed("lxc config set container limits.memory 64MB") machine.succeed("lxc config set container limits.memory 64MB")
machine.succeed("lxc restart container") machine.succeed("lxc restart container")
machine.sleep(5) with machine.nested("Waiting for instance to start and be usable"):
retry(instance_is_up)
assert ( assert (
"MemTotal: 62500 kB" "MemTotal: 62500 kB"
@ -102,7 +105,8 @@ in {
machine.succeed("lxc config set container limits.memory 128MB") machine.succeed("lxc config set container limits.memory 128MB")
machine.succeed("lxc restart container") machine.succeed("lxc restart container")
machine.sleep(5) with machine.nested("Waiting for instance to start and be usable"):
retry(instance_is_up)
assert ( assert (
"MemTotal: 125000 kB" "MemTotal: 125000 kB"

View File

@ -0,0 +1,9 @@
{
system ? builtins.currentSystem,
config ? {},
pkgs ? import ../../.. {inherit system config;},
}: {
container = import ./container.nix {inherit system pkgs;};
nftables = import ./nftables.nix {inherit system pkgs;};
ui = import ./ui.nix {inherit system pkgs;};
}

View File

@ -5,7 +5,7 @@
# iptables to nftables requires a full reboot, which is a bit hard inside NixOS # iptables to nftables requires a full reboot, which is a bit hard inside NixOS
# tests. # tests.
import ./make-test-python.nix ({ pkgs, ...} : { import ../make-test-python.nix ({ pkgs, ...} : {
name = "lxd-nftables"; name = "lxd-nftables";
meta = with pkgs.lib.maintainers; { meta = with pkgs.lib.maintainers; {

View File

@ -1,4 +1,4 @@
import ./make-test-python.nix ({ pkgs, lib, ... }: { import ../make-test-python.nix ({ pkgs, lib, ... }: {
name = "lxd-ui"; name = "lxd-ui";
meta = with pkgs.lib.maintainers; { meta = with pkgs.lib.maintainers; {

View File

@ -76,8 +76,6 @@ buildGoModule rec {
''; '';
passthru.tests.lxd = nixosTests.lxd; passthru.tests.lxd = nixosTests.lxd;
passthru.tests.lxd-nftables = nixosTests.lxd-nftables;
passthru.tests.lxd-ui = nixosTests.lxd-ui;
passthru.ui = callPackage ./ui.nix { }; passthru.ui = callPackage ./ui.nix { };
passthru.updateScript = gitUpdater { passthru.updateScript = gitUpdater {
url = "https://github.com/canonical/lxd.git"; url = "https://github.com/canonical/lxd.git";