···
+
import ./make-test-python.nix ({ pkgs, ...} :
+
# 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-config = pkgs.writeText "config.yaml" ''
+
name = "lxd-image-server";
+
meta = with pkgs.lib.maintainers; {
+
maintainers = [ mkg20001 ];
+
machine = { lib, ... }: {
+
lxc.lxcfs.enable = true;
+
security.pki.certificates = [
+
(builtins.readFile ./common/acme/server/ca.cert.pem)
+
services.lxd-image-server = {
+
services.nginx.virtualHosts."acme.test" = {
+
sslCertificate = ./common/acme/server/acme.test.cert.pem;
+
sslCertificateKey = ./common/acme/server/acme.test.key.pem;
+
"::1" = [ "acme.test" ];
+
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
+
# lxd expects the pool's directory to already exist
+
machine.succeed("mkdir /var/lxd-pool")
+
"cat ${lxd-config} | lxd init --preseed"
+
"lxc image import ${alpine-meta} ${alpine-rootfs} --alias alpine"
+
loc = "/var/www/simplestreams/images/iats/alpine/amd64/default/v1"
+
with subtest("push image to server"):
+
machine.succeed("lxc launch alpine test")
+
machine.succeed("lxc stop test")
+
machine.succeed("lxc publish --public test --alias=testimg")
+
machine.succeed("lxc image export testimg")
+
machine.succeed("ls >&2")
+
machine.succeed("mkdir -p " + loc)
+
machine.succeed("mv *.tar.gz " + loc)
+
with subtest("pull image from server"):
+
machine.succeed("lxc remote add img https://acme.test --protocol=simplestreams")
+
machine.succeed("lxc image list img: >&2")