mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-11 07:15:54 +03:00
nixosTest.lxdImage: add lxdImage test
This commit is contained in:
parent
a797967cec
commit
1c31f8db6a
@ -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 {};
|
||||
|
91
nixos/tests/lxd-image.nix
Normal file
91
nixos/tests/lxd-image.nix
Normal file
@ -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…
Reference in New Issue
Block a user