Skip to content

Commit

Permalink
nixos/lxd: improve tests
Browse files Browse the repository at this point in the history
- Make tests/lxd.nix use NixOS's lxdMeta & lxdImage to avoid relying on
  3rd party containers such as Alpine Linux for testing purposes.
- Merge tests/lxd-image.nix into tests/lxd.nix, since now both have a
  similar structure.
- Extract duplicated inline LXD configuration into a separate file,
- Add passthru.lxd-nftables & passthru.lxd-image-server.
  • Loading branch information
Patryk27 committed May 3, 2022
1 parent d33eace commit 56ab4f6
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 234 deletions.
2 changes: 1 addition & 1 deletion nixos/maintainers/scripts/lxd/lxd-image.nix
Expand Up @@ -27,7 +27,7 @@ with lib;
networking.useDHCP = false;
networking.interfaces.eth0.useDHCP = true;

# As this is intended as a stadalone image, undo some of the minimal profile stuff
# As this is intended as a standalone image, undo some of the minimal profile stuff
documentation.enable = true;
documentation.nixos.enable = true;
environment.noXlibs = false;
Expand Down
1 change: 0 additions & 1 deletion nixos/tests/all-tests.nix
Expand Up @@ -284,7 +284,6 @@ in
loki = handleTest ./loki.nix {};
lvm2 = handleTest ./lvm2 {};
lxd = handleTest ./lxd.nix {};
lxd-image = handleTest ./lxd-image.nix {};
lxd-nftables = handleTest ./lxd-nftables.nix {};
lxd-image-server = handleTest ./lxd-image-server.nix {};
#logstash = handleTest ./logstash.nix {};
Expand Down
24 changes: 24 additions & 0 deletions nixos/tests/common/lxd/config.yaml
@@ -0,0 +1,24 @@
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
63 changes: 15 additions & 48 deletions nixos/tests/lxd-image-server.nix
@@ -1,54 +1,21 @@
import ./make-test-python.nix ({ pkgs, ...} :
import ./make-test-python.nix ({ pkgs, lib, ... } :

let
# Since we don't have access to the internet during the tests, we have to
# pre-fetch lxd containers beforehand.
#
# I've chosen to import Alpine Linux, because its image is turbo-tiny and,
# generally, sufficient for our tests.
alpine-meta = pkgs.fetchurl {
url = "https://tarballs.nixos.org/alpine/3.12/lxd.tar.xz";
hash = "sha256-1tcKaO9lOkvqfmG/7FMbfAEToAuFy2YMewS8ysBKuLA=";
};

alpine-rootfs = pkgs.fetchurl {
url = "https://tarballs.nixos.org/alpine/3.12/rootfs.tar.xz";
hash = "sha256-Tba9sSoaiMtQLY45u7p5DMqXTSDgs/763L/SQp0bkCA=";
lxd-image = import ../release.nix {
configuration = {
# Building documentation makes the test unnecessarily take a longer time:
documentation.enable = lib.mkForce false;
};
};

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
'';

lxd-image-metadata = lxd-image.lxdMeta.${pkgs.system};
lxd-image-rootfs = lxd-image.lxdImage.${pkgs.system};

in {
name = "lxd-image-server";

meta = with pkgs.lib.maintainers; {
maintainers = [ mkg20001 ];
maintainers = [ mkg20001 patryk27 ];
};

nodes.machine = { lib, ... }: {
Expand Down Expand Up @@ -100,20 +67,20 @@ in {
# lxd expects the pool's directory to already exist
machine.succeed("mkdir /var/lxd-pool")
machine.succeed(
"cat ${lxd-config} | lxd init --preseed"
"cat ${./common/lxd/config.yaml} | lxd init --preseed"
)
machine.succeed(
"lxc image import ${alpine-meta} ${alpine-rootfs} --alias alpine"
"lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos"
)
loc = "/var/www/simplestreams/images/iats/alpine/amd64/default/v1"
loc = "/var/www/simplestreams/images/iats/nixos/amd64/default/v1"
with subtest("push image to server"):
machine.succeed("lxc launch alpine test")
machine.succeed("lxc stop test")
machine.succeed("lxc launch nixos test")
machine.sleep(5)
machine.succeed("lxc stop -f test")
machine.succeed("lxc publish --public test --alias=testimg")
machine.succeed("lxc image export testimg")
machine.succeed("ls >&2")
Expand Down
89 changes: 0 additions & 89 deletions nixos/tests/lxd-image.nix

This file was deleted.

0 comments on commit 56ab4f6

Please sign in to comment.