nixosTest.lxdImage: add lxdImage test

main
Maciej Krüger 3 years ago
parent a797967cec
commit 1c31f8db6a
No known key found for this signature in database
GPG Key ID: 0D948CE19CF49C5F
  1. 1
      nixos/maintainers/scripts/lxd/lxd-image-inner.nix
  2. 7
      nixos/maintainers/scripts/lxd/lxd-image.nix
  3. 1
      nixos/modules/virtualisation/lxc-container.nix
  4. 1
      nixos/tests/all-tests.nix
  5. 91
      nixos/tests/lxd-image.nix

@ -9,7 +9,6 @@ with lib;
{
imports =
[ # Include the default lxd configuration.
# <nixpkgs/nixos/modules/virtualisation/lxc-container.nix>
../../../modules/virtualisation/lxc-container.nix
# Include the container-specific autogenerated configuration.
./lxd.nix

@ -19,15 +19,10 @@ with lib;
if [ ! -e /etc/nixos/configuration.nix ]; then
mkdir -p /etc/nixos
cat ${./lxd-image-inner.nix} > /etc/nixos/configuration.nix
sed 's|../../../modules/virtualisation/lxc-container.nix|<nixpkgs/nixos/modules/virtualisation/lxc-container.nix>|g' -i /etc/nixos/configuration.nix
fi
'';
# Make lxc exec work properly
system.activationScripts.bash = ''
mkdir -p /bin
ln -sf /run/current-system/sw/bin/bash /bin/bash
'';
# Network
networking.useDHCP = false;
networking.interfaces.eth0.useDHCP = true;

@ -124,6 +124,7 @@ in
] ++ templates.files;
};
# TODO: build rootfs as squashfs for faster unpack
system.build.tarball = pkgs.callPackage ../../lib/make-system-tarball.nix {
extraArgs = "--owner=0";

@ -236,6 +236,7 @@ in
login = handleTest ./login.nix {};
loki = handleTest ./loki.nix {};
lxd = handleTest ./lxd.nix {};
lxd-image = handleTest ./lxd-image.nix {};
lxd-nftables = handleTest ./lxd-nftables.nix {};
#logstash = handleTest ./logstash.nix {};
lorri = handleTest ./lorri/default.nix {};

@ -0,0 +1,91 @@
# This test ensures that the nixOS lxd images builds and functions properly
# It has been extracted from `lxd.nix` to seperate failures of just the image and the lxd software
import ./make-test-python.nix ({ pkgs, ...} : let
release = import ../release.nix {
/* configuration = {
environment.systemPackages = with pkgs; [ stdenv ]; # inject stdenv so rebuild test works
}; */
};
metadata = release.lxdMeta.${pkgs.system};
image = release.lxdImage.${pkgs.system};
lxd-config = pkgs.writeText "config.yaml" ''
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
'';
in {
name = "lxd-image";
meta = with pkgs.lib.maintainers; {
maintainers = [ mkg20001 ];
};
machine = { lib, ... }: {
virtualisation = {
# OOMs otherwise
memorySize = 1024;
# disk full otherwise
diskSize = 2048;
lxc.lxcfs.enable = true;
lxd.enable = true;
};
};
testScript = ''
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)
# lxd expects the pool's directory to already exist
machine.succeed("mkdir /var/lxd-pool")
machine.succeed(
"cat ${lxd-config} | lxd init --preseed"
)
# TODO: test custom built container aswell
with subtest("importing container works"):
machine.succeed("lxc image import ${metadata}/*/*.tar.xz ${image}/*/*.tar.xz --alias nixos")
with subtest("launching container works"):
machine.succeed("lxc launch nixos machine -c security.nesting=true")
# make sure machine boots up properly
machine.sleep(5)
with subtest("container shell works"):
machine.succeed("echo true | lxc exec machine /run/current-system/sw/bin/bash -")
machine.succeed("lxc exec machine /run/current-system/sw/bin/true")
# with subtest("rebuilding works"):
# machine.succeed("lxc exec machine /run/current-system/sw/bin/nixos-rebuild switch")
'';
})
Loading…
Cancel
Save