···
1
+
import ./make-test-python.nix ({ pkgs, ...} :
4
+
# Since we don't have access to the internet during the tests, we have to
5
+
# pre-fetch lxd containers beforehand.
7
+
# I've chosen to import Alpine Linux, because its image is turbo-tiny and,
8
+
# generally, sufficient for our tests.
9
+
alpine-meta = pkgs.fetchurl {
10
+
url = "https://tarballs.nixos.org/alpine/3.12/lxd.tar.xz";
11
+
hash = "sha256-1tcKaO9lOkvqfmG/7FMbfAEToAuFy2YMewS8ysBKuLA=";
14
+
alpine-rootfs = pkgs.fetchurl {
15
+
url = "https://tarballs.nixos.org/alpine/3.12/rootfs.tar.xz";
16
+
hash = "sha256-Tba9sSoaiMtQLY45u7p5DMqXTSDgs/763L/SQp0bkCA=";
19
+
lxd-config = pkgs.writeText "config.yaml" ''
24
+
source: /var/lxd-pool
48
+
name = "lxd-image-server";
50
+
meta = with pkgs.lib.maintainers; {
51
+
maintainers = [ mkg20001 ];
54
+
machine = { lib, ... }: {
61
+
lxc.lxcfs.enable = true;
65
+
security.pki.certificates = [
66
+
(builtins.readFile ./common/acme/server/ca.cert.pem)
73
+
services.lxd-image-server = {
77
+
domain = "acme.test";
81
+
services.nginx.virtualHosts."acme.test" = {
83
+
sslCertificate = ./common/acme/server/acme.test.cert.pem;
84
+
sslCertificateKey = ./common/acme/server/acme.test.key.pem;
87
+
networking.hosts = {
88
+
"::1" = [ "acme.test" ];
93
+
machine.wait_for_unit("sockets.target")
94
+
machine.wait_for_unit("lxd.service")
95
+
machine.wait_for_file("/var/lib/lxd/unix.socket")
97
+
# It takes additional second for lxd to settle
100
+
# lxd expects the pool's directory to already exist
101
+
machine.succeed("mkdir /var/lxd-pool")
105
+
"cat ${lxd-config} | lxd init --preseed"
109
+
"lxc image import ${alpine-meta} ${alpine-rootfs} --alias alpine"
112
+
loc = "/var/www/simplestreams/images/iats/alpine/amd64/default/v1"
114
+
with subtest("push image to server"):
115
+
machine.succeed("lxc launch alpine test")
116
+
machine.succeed("lxc stop test")
117
+
machine.succeed("lxc publish --public test --alias=testimg")
118
+
machine.succeed("lxc image export testimg")
119
+
machine.succeed("ls >&2")
120
+
machine.succeed("mkdir -p " + loc)
121
+
machine.succeed("mv *.tar.gz " + loc)
123
+
with subtest("pull image from server"):
124
+
machine.succeed("lxc remote add img https://acme.test --protocol=simplestreams")
125
+
machine.succeed("lxc image list img: >&2")