Merge pull request #248395 from adamcstephens/lxd/tests

nixos/tests/lxd: move into subdir, use minimal init, remove sleeps

authored by

Mario Rodas and committed by
GitHub
8720d962 90b11f06

+36 -51
+1 -3
nixos/tests/all-tests.nix
··· 443 443 loki = handleTest ./loki.nix {}; 444 444 luks = handleTest ./luks.nix {}; 445 445 lvm2 = handleTest ./lvm2 {}; 446 - lxd = handleTest ./lxd.nix {}; 447 - lxd-nftables = handleTest ./lxd-nftables.nix {}; 446 + lxd = handleTest ./lxd {}; 448 447 lxd-image-server = handleTest ./lxd-image-server.nix {}; 449 - lxd-ui = handleTest ./lxd-ui.nix {}; 450 448 #logstash = handleTest ./logstash.nix {}; 451 449 lorri = handleTest ./lorri/default.nix {}; 452 450 maddy = discoverTests (import ./maddy { inherit handleTest; });
-24
nixos/tests/common/lxd/config.yaml
··· 1 - storage_pools: 2 - - name: default 3 - driver: dir 4 - config: 5 - source: /var/lxd-pool 6 - 7 - networks: 8 - - name: lxdbr0 9 - type: bridge 10 - config: 11 - ipv4.address: auto 12 - ipv6.address: none 13 - 14 - profiles: 15 - - name: default 16 - devices: 17 - eth0: 18 - name: eth0 19 - network: lxdbr0 20 - type: nic 21 - root: 22 - path: / 23 - pool: default 24 - type: disk
+3 -3
nixos/tests/lxd-image-server.nix
··· 61 61 machine.wait_for_unit("lxd.service") 62 62 machine.wait_for_file("/var/lib/lxd/unix.socket") 63 63 64 - # It takes additional second for lxd to settle 65 - machine.sleep(1) 64 + # Wait for lxd to settle 65 + machine.succeed("lxd waitready") 66 66 67 67 # lxd expects the pool's directory to already exist 68 68 machine.succeed("mkdir /var/lxd-pool") 69 69 70 70 machine.succeed( 71 - "cat ${./common/lxd/config.yaml} | lxd init --preseed" 71 + "lxd init --minimal" 72 72 ) 73 73 74 74 machine.succeed(
+1 -1
nixos/tests/lxd-nftables.nix nixos/tests/lxd/nftables.nix
··· 5 5 # iptables to nftables requires a full reboot, which is a bit hard inside NixOS 6 6 # tests. 7 7 8 - import ./make-test-python.nix ({ pkgs, ...} : { 8 + import ../make-test-python.nix ({ pkgs, ...} : { 9 9 name = "lxd-nftables"; 10 10 11 11 meta = with pkgs.lib.maintainers; {
+1 -1
nixos/tests/lxd-ui.nix nixos/tests/lxd/ui.nix
··· 1 - import ./make-test-python.nix ({ pkgs, lib, ... }: { 1 + import ../make-test-python.nix ({ pkgs, lib, ... }: { 2 2 name = "lxd-ui"; 3 3 4 4 meta = with pkgs.lib.maintainers; {
+21 -17
nixos/tests/lxd.nix nixos/tests/lxd/container.nix
··· 1 - import ./make-test-python.nix ({ pkgs, lib, ... } : 1 + import ../make-test-python.nix ({ pkgs, lib, ... } : 2 2 3 3 let 4 - lxd-image = import ../release.nix { 4 + lxd-image = import ../../release.nix { 5 5 configuration = { 6 6 # Building documentation makes the test unnecessarily take a longer time: 7 7 documentation.enable = lib.mkForce false; ··· 38 38 }; 39 39 40 40 testScript = '' 41 + def instance_is_up(_) -> bool: 42 + status, _ = machine.execute("lxc exec container --disable-stdin --force-interactive /run/current-system/sw/bin/true") 43 + return status == 0 44 + 41 45 machine.wait_for_unit("sockets.target") 42 46 machine.wait_for_unit("lxd.service") 43 47 machine.wait_for_file("/var/lib/lxd/unix.socket") 44 48 45 - # It takes additional second for lxd to settle 46 - machine.sleep(1) 49 + # Wait for lxd to settle 50 + machine.succeed("lxd waitready") 47 51 48 - # lxd expects the pool's directory to already exist 49 - machine.succeed("mkdir /var/lxd-pool") 50 - 51 - machine.succeed( 52 - "cat ${./common/lxd/config.yaml} | lxd init --preseed" 53 - ) 52 + machine.succeed("lxd init --minimal") 54 53 55 54 machine.succeed( 56 55 "lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos" ··· 58 57 59 58 with subtest("Container can be managed"): 60 59 machine.succeed("lxc launch nixos container") 61 - machine.sleep(5) 60 + with machine.nested("Waiting for instance to start and be usable"): 61 + retry(instance_is_up) 62 62 machine.succeed("echo true | lxc exec container /run/current-system/sw/bin/bash -") 63 - machine.succeed("lxc exec container true") 64 63 machine.succeed("lxc delete -f container") 65 64 66 65 with subtest("Container is mounted with lxcfs inside"): 67 66 machine.succeed("lxc launch nixos container") 68 - machine.sleep(5) 67 + with machine.nested("Waiting for instance to start and be usable"): 68 + retry(instance_is_up) 69 69 70 70 ## ---------- ## 71 71 ## limits.cpu ## 72 72 73 73 machine.succeed("lxc config set container limits.cpu 1") 74 74 machine.succeed("lxc restart container") 75 - machine.sleep(5) 75 + with machine.nested("Waiting for instance to start and be usable"): 76 + retry(instance_is_up) 76 77 77 78 assert ( 78 79 "1" ··· 81 82 82 83 machine.succeed("lxc config set container limits.cpu 2") 83 84 machine.succeed("lxc restart container") 84 - machine.sleep(5) 85 + with machine.nested("Waiting for instance to start and be usable"): 86 + retry(instance_is_up) 85 87 86 88 assert ( 87 89 "2" ··· 93 95 94 96 machine.succeed("lxc config set container limits.memory 64MB") 95 97 machine.succeed("lxc restart container") 96 - machine.sleep(5) 98 + with machine.nested("Waiting for instance to start and be usable"): 99 + retry(instance_is_up) 97 100 98 101 assert ( 99 102 "MemTotal: 62500 kB" ··· 102 105 103 106 machine.succeed("lxc config set container limits.memory 128MB") 104 107 machine.succeed("lxc restart container") 105 - machine.sleep(5) 108 + with machine.nested("Waiting for instance to start and be usable"): 109 + retry(instance_is_up) 106 110 107 111 assert ( 108 112 "MemTotal: 125000 kB"
+9
nixos/tests/lxd/default.nix
··· 1 + { 2 + system ? builtins.currentSystem, 3 + config ? {}, 4 + pkgs ? import ../../.. {inherit system config;}, 5 + }: { 6 + container = import ./container.nix {inherit system pkgs;}; 7 + nftables = import ./nftables.nix {inherit system pkgs;}; 8 + ui = import ./ui.nix {inherit system pkgs;}; 9 + }
-2
pkgs/tools/admin/lxd/default.nix
··· 76 76 ''; 77 77 78 78 passthru.tests.lxd = nixosTests.lxd; 79 - passthru.tests.lxd-nftables = nixosTests.lxd-nftables; 80 - passthru.tests.lxd-ui = nixosTests.lxd-ui; 81 79 passthru.ui = callPackage ./ui.nix { }; 82 80 passthru.updateScript = gitUpdater { 83 81 url = "https://github.com/canonical/lxd.git";