nixos/tests/lxd: move into subdir, use minimal init, remove sleeps
This commit is contained in:
parent
d41c2a87e3
commit
f1c0589e4c
8 changed files with 36 additions and 51 deletions
|
@ -440,10 +440,8 @@ in {
|
|||
loki = handleTest ./loki.nix {};
|
||||
luks = handleTest ./luks.nix {};
|
||||
lvm2 = handleTest ./lvm2 {};
|
||||
lxd = handleTest ./lxd.nix {};
|
||||
lxd-nftables = handleTest ./lxd-nftables.nix {};
|
||||
lxd = handleTest ./lxd {};
|
||||
lxd-image-server = handleTest ./lxd-image-server.nix {};
|
||||
lxd-ui = handleTest ./lxd-ui.nix {};
|
||||
#logstash = handleTest ./logstash.nix {};
|
||||
lorri = handleTest ./lorri/default.nix {};
|
||||
maddy = discoverTests (import ./maddy { inherit handleTest; });
|
||||
|
|
|
@ -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
|
|
@ -61,14 +61,14 @@ in {
|
|||
machine.wait_for_unit("lxd.service")
|
||||
machine.wait_for_file("/var/lib/lxd/unix.socket")
|
||||
|
||||
# It takes additional second for lxd to settle
|
||||
machine.sleep(1)
|
||||
# Wait for lxd to settle
|
||||
machine.succeed("lxd waitready")
|
||||
|
||||
# lxd expects the pool's directory to already exist
|
||||
machine.succeed("mkdir /var/lxd-pool")
|
||||
|
||||
machine.succeed(
|
||||
"cat ${./common/lxd/config.yaml} | lxd init --preseed"
|
||||
"lxd init --minimal"
|
||||
)
|
||||
|
||||
machine.succeed(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import ./make-test-python.nix ({ pkgs, lib, ... } :
|
||||
import ../make-test-python.nix ({ pkgs, lib, ... } :
|
||||
|
||||
let
|
||||
lxd-image = import ../release.nix {
|
||||
lxd-image = import ../../release.nix {
|
||||
configuration = {
|
||||
# Building documentation makes the test unnecessarily take a longer time:
|
||||
documentation.enable = lib.mkForce false;
|
||||
|
@ -38,19 +38,18 @@ in {
|
|||
};
|
||||
|
||||
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("lxd.service")
|
||||
machine.wait_for_file("/var/lib/lxd/unix.socket")
|
||||
|
||||
# It takes additional second for lxd to settle
|
||||
machine.sleep(1)
|
||||
# Wait for lxd to settle
|
||||
machine.succeed("lxd waitready")
|
||||
|
||||
# lxd expects the pool's directory to already exist
|
||||
machine.succeed("mkdir /var/lxd-pool")
|
||||
|
||||
machine.succeed(
|
||||
"cat ${./common/lxd/config.yaml} | lxd init --preseed"
|
||||
)
|
||||
machine.succeed("lxd init --minimal")
|
||||
|
||||
machine.succeed(
|
||||
"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"):
|
||||
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("lxc exec container true")
|
||||
machine.succeed("lxc delete -f container")
|
||||
|
||||
with subtest("Container is mounted with lxcfs inside"):
|
||||
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 ##
|
||||
|
||||
machine.succeed("lxc config set container limits.cpu 1")
|
||||
machine.succeed("lxc restart container")
|
||||
machine.sleep(5)
|
||||
with machine.nested("Waiting for instance to start and be usable"):
|
||||
retry(instance_is_up)
|
||||
|
||||
assert (
|
||||
"1"
|
||||
|
@ -81,7 +82,8 @@ in {
|
|||
|
||||
machine.succeed("lxc config set container limits.cpu 2")
|
||||
machine.succeed("lxc restart container")
|
||||
machine.sleep(5)
|
||||
with machine.nested("Waiting for instance to start and be usable"):
|
||||
retry(instance_is_up)
|
||||
|
||||
assert (
|
||||
"2"
|
||||
|
@ -93,7 +95,8 @@ in {
|
|||
|
||||
machine.succeed("lxc config set container limits.memory 64MB")
|
||||
machine.succeed("lxc restart container")
|
||||
machine.sleep(5)
|
||||
with machine.nested("Waiting for instance to start and be usable"):
|
||||
retry(instance_is_up)
|
||||
|
||||
assert (
|
||||
"MemTotal: 62500 kB"
|
||||
|
@ -102,7 +105,8 @@ in {
|
|||
|
||||
machine.succeed("lxc config set container limits.memory 128MB")
|
||||
machine.succeed("lxc restart container")
|
||||
machine.sleep(5)
|
||||
with machine.nested("Waiting for instance to start and be usable"):
|
||||
retry(instance_is_up)
|
||||
|
||||
assert (
|
||||
"MemTotal: 125000 kB"
|
9
nixos/tests/lxd/default.nix
Normal file
9
nixos/tests/lxd/default.nix
Normal 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;};
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
# iptables to nftables requires a full reboot, which is a bit hard inside NixOS
|
||||
# tests.
|
||||
|
||||
import ./make-test-python.nix ({ pkgs, ...} : {
|
||||
import ../make-test-python.nix ({ pkgs, ...} : {
|
||||
name = "lxd-nftables";
|
||||
|
||||
meta = with pkgs.lib.maintainers; {
|
|
@ -1,4 +1,4 @@
|
|||
import ./make-test-python.nix ({ pkgs, lib, ... }: {
|
||||
import ../make-test-python.nix ({ pkgs, lib, ... }: {
|
||||
name = "lxd-ui";
|
||||
|
||||
meta = with pkgs.lib.maintainers; {
|
|
@ -76,8 +76,6 @@ buildGoModule rec {
|
|||
'';
|
||||
|
||||
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.updateScript = gitUpdater {
|
||||
url = "https://github.com/canonical/lxd.git";
|
||||
|
|
Loading…
Reference in a new issue